mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-01 20:06:53 +01:00
Pretty OSD.
This commit is contained in:
parent
fc2877dc30
commit
7d5673930d
@ -73,5 +73,7 @@
|
||||
<file>media-playlist-shuffle-off.png</file>
|
||||
<file>schema-4.sql</file>
|
||||
<file>schema-5.sql</file>
|
||||
<file>osd_shadow_corner.png</file>
|
||||
<file>osd_shadow_edge.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
data/osd_shadow_corner.png
Normal file
BIN
data/osd_shadow_corner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 421 B |
BIN
data/osd_shadow_edge.png
Normal file
BIN
data/osd_shadow_edge.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 208 B |
@ -64,6 +64,7 @@ set(CLEMENTINE-SOURCES
|
||||
globalshortcuts/globalshortcuts.cpp
|
||||
fixlastfm.cpp
|
||||
backgroundthread.cpp
|
||||
osdpretty.cpp
|
||||
)
|
||||
|
||||
# Header files that have Q_OBJECT in
|
||||
@ -120,6 +121,7 @@ set(CLEMENTINE-MOC-HEADERS
|
||||
analyzers/sonogram.h
|
||||
analyzers/turbine.h
|
||||
globalshortcuts/globalshortcuts.h
|
||||
osdpretty.h
|
||||
)
|
||||
|
||||
# UI files
|
||||
@ -139,6 +141,7 @@ set(CLEMENTINE-UI
|
||||
addstreamdialog.ui
|
||||
albumcovermanager.ui
|
||||
playlistsequence.ui
|
||||
osdpretty.ui
|
||||
)
|
||||
|
||||
# Resource files
|
||||
|
17
src/osd.cpp
17
src/osd.cpp
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "osd.h"
|
||||
#include "osdpretty.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QtDebug>
|
||||
@ -28,12 +29,17 @@ OSD::OSD(QSystemTrayIcon* tray_icon, QObject* parent)
|
||||
timeout_(5000),
|
||||
behaviour_(Native),
|
||||
show_on_volume_change_(false),
|
||||
show_art_(true)
|
||||
show_art_(true),
|
||||
pretty_popup_(new OSDPretty)
|
||||
{
|
||||
ReloadSettings();
|
||||
Init();
|
||||
}
|
||||
|
||||
OSD::~OSD() {
|
||||
delete pretty_popup_;
|
||||
}
|
||||
|
||||
void OSD::ReloadSettings() {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
@ -46,10 +52,12 @@ void OSD::ReloadSettings() {
|
||||
behaviour_ = TrayPopup;
|
||||
if (!SupportsTrayPopups() && behaviour_ == TrayPopup)
|
||||
behaviour_ = Disabled;
|
||||
|
||||
pretty_popup_->set_popup_duration(timeout_);
|
||||
pretty_popup_->ReloadSettings();
|
||||
}
|
||||
|
||||
void OSD::SongChanged(const Song &song) {
|
||||
qDebug() << __PRETTY_FUNCTION__;
|
||||
QString summary(song.PrettyTitle());
|
||||
if (!song.artist().isEmpty())
|
||||
summary = QString("%1 - %2").arg(song.artist(), summary);
|
||||
@ -98,6 +106,11 @@ void OSD::ShowMessage(const QString& summary,
|
||||
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_);
|
||||
break;
|
||||
|
||||
case Pretty:
|
||||
pretty_popup_->SetMessage(summary, message, image);
|
||||
pretty_popup_->show();
|
||||
break;
|
||||
|
||||
case Disabled:
|
||||
default:
|
||||
break;
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "engine_fwd.h"
|
||||
#include "song.h"
|
||||
|
||||
class OSDPretty;
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <QDBusArgument>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
@ -39,6 +41,7 @@ class OSD : public QObject {
|
||||
|
||||
public:
|
||||
OSD(QSystemTrayIcon* tray_icon, QObject* parent = 0);
|
||||
~OSD();
|
||||
|
||||
static const char* kSettingsGroup;
|
||||
|
||||
@ -46,6 +49,7 @@ class OSD : public QObject {
|
||||
Disabled = 0,
|
||||
Native,
|
||||
TrayPopup,
|
||||
Pretty,
|
||||
};
|
||||
|
||||
// Implemented in the OS-specific files
|
||||
@ -82,6 +86,8 @@ class OSD : public QObject {
|
||||
bool show_on_volume_change_;
|
||||
bool show_art_;
|
||||
|
||||
OSDPretty* pretty_popup_;
|
||||
|
||||
#ifdef Q_OS_DARWIN
|
||||
class GrowlNotificationWrapper;
|
||||
GrowlNotificationWrapper* wrapper_;
|
||||
|
277
src/osdpretty.cpp
Normal file
277
src/osdpretty.cpp
Normal file
@ -0,0 +1,277 @@
|
||||
/* This file is part of Clementine.
|
||||
|
||||
Clementine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Clementine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "osdpretty.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QLayout>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QSettings>
|
||||
#include <QMouseEvent>
|
||||
#include <QTimer>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
const char* OSDPretty::kSettingsGroup = "OSDPretty";
|
||||
|
||||
const int OSDPretty::kDropShadowSize = 13;
|
||||
const int OSDPretty::kBorderRadius = 10;
|
||||
const int OSDPretty::kMaxIconSize = 100;
|
||||
|
||||
const QRgb OSDPretty::kPresetBlue = qRgb(102, 150, 227);
|
||||
const QRgb OSDPretty::kPresetOrange = qRgb(254, 156, 67);
|
||||
|
||||
OSDPretty::OSDPretty(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
mode_(Mode_Popup),
|
||||
background_color_(kPresetOrange),
|
||||
background_opacity_(0.85),
|
||||
popup_display_(0),
|
||||
timeout_(new QTimer(this))
|
||||
{
|
||||
setWindowFlags(Qt::ToolTip |
|
||||
Qt::FramelessWindowHint |
|
||||
Qt::WindowStaysOnTopHint);
|
||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
ui_.setupUi(this);
|
||||
SetMode(mode_);
|
||||
|
||||
timeout_->setSingleShot(true);
|
||||
timeout_->setInterval(5000);
|
||||
connect(timeout_, SIGNAL(timeout()), SLOT(hide()));
|
||||
|
||||
ui_.icon->setMaximumSize(kMaxIconSize, kMaxIconSize);
|
||||
|
||||
// Load the show edges and corners
|
||||
QImage shadow_edge(":osd_shadow_edge.png");
|
||||
QImage shadow_corner(":osd_shadow_corner.png");
|
||||
for (int i=0 ; i<4 ; ++i) {
|
||||
QTransform rotation = QTransform().rotate(90 * i);
|
||||
shadow_edge_[i] = QPixmap::fromImage(shadow_edge.transformed(rotation));
|
||||
shadow_corner_[i] = QPixmap::fromImage(shadow_corner.transformed(rotation));
|
||||
}
|
||||
|
||||
// Set the margins to allow for the drop shadow
|
||||
int margin = layout()->contentsMargins().left() + kDropShadowSize;
|
||||
layout()->setContentsMargins(margin, margin, margin, margin);
|
||||
|
||||
Load();
|
||||
}
|
||||
|
||||
void OSDPretty::Load() {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
foreground_color_ = QColor(s.value("foreground_color", 0).toInt());
|
||||
background_color_ = QColor(s.value("background_color", kPresetBlue).toInt());
|
||||
background_opacity_ = s.value("background_opacity", 0.85).toReal();
|
||||
popup_display_ = s.value("popup_display", -1).toInt();
|
||||
popup_pos_ = s.value("popup_pos", QPoint(0, 0)).toPoint();
|
||||
|
||||
set_foreground_color(foreground_color());
|
||||
}
|
||||
|
||||
void OSDPretty::ReloadSettings() {
|
||||
Load();
|
||||
if (isVisible())
|
||||
update();
|
||||
}
|
||||
|
||||
void OSDPretty::SetMode(Mode mode) {
|
||||
mode_ = mode;
|
||||
|
||||
switch (mode_) {
|
||||
case Mode_Popup:
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
break;
|
||||
|
||||
case Mode_Draggable:
|
||||
setCursor(QCursor(Qt::OpenHandCursor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OSDPretty::paintEvent(QPaintEvent *) {
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
|
||||
QRect box(rect().adjusted(kDropShadowSize, kDropShadowSize, -kDropShadowSize, -kDropShadowSize));
|
||||
|
||||
// Shadow corners
|
||||
const int kShadowCornerSize = kDropShadowSize + kBorderRadius;
|
||||
p.drawPixmap(0, 0, shadow_corner_[0]);
|
||||
p.drawPixmap(width() - kShadowCornerSize, 0, shadow_corner_[1]);
|
||||
p.drawPixmap(width() - kShadowCornerSize, height() - kShadowCornerSize, shadow_corner_[2]);
|
||||
p.drawPixmap(0, height() - kShadowCornerSize, shadow_corner_[3]);
|
||||
|
||||
// Shadow edges
|
||||
p.drawTiledPixmap(kShadowCornerSize, 0,
|
||||
width() - kShadowCornerSize*2, kDropShadowSize,
|
||||
shadow_edge_[0]);
|
||||
p.drawTiledPixmap(width() - kDropShadowSize, kShadowCornerSize,
|
||||
kDropShadowSize, height() - kShadowCornerSize*2,
|
||||
shadow_edge_[1]);
|
||||
p.drawTiledPixmap(kShadowCornerSize, height() - kDropShadowSize,
|
||||
width() - kShadowCornerSize*2, kDropShadowSize,
|
||||
shadow_edge_[2]);
|
||||
p.drawTiledPixmap(0, kShadowCornerSize,
|
||||
kDropShadowSize, height() - kShadowCornerSize*2,
|
||||
shadow_edge_[3]);
|
||||
|
||||
// Box background
|
||||
p.setBrush(background_color_);
|
||||
p.setPen(QPen());
|
||||
p.setOpacity(background_opacity_);
|
||||
p.drawRoundedRect(box, kBorderRadius, kBorderRadius);
|
||||
|
||||
// Gradient overlay
|
||||
QLinearGradient gradient(0, 0, 0, height());
|
||||
gradient.setColorAt(0, QColor(255, 255, 255, 130));
|
||||
gradient.setColorAt(1, QColor(255, 255, 255, 50));
|
||||
p.setBrush(gradient);
|
||||
p.setOpacity(1.0);
|
||||
p.drawRoundedRect(box, kBorderRadius, kBorderRadius);
|
||||
|
||||
// Box border
|
||||
p.setBrush(QBrush());
|
||||
p.setPen(QPen(background_color_.darker(150), 2));
|
||||
p.drawRoundedRect(box, kBorderRadius, kBorderRadius);
|
||||
}
|
||||
|
||||
void OSDPretty::SetMessage(const QString& summary, const QString& message,
|
||||
const QImage& image) {
|
||||
|
||||
if (!image.isNull()) {
|
||||
QImage scaled_image =
|
||||
image.scaled(kMaxIconSize, kMaxIconSize,
|
||||
Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
ui_.icon->setPixmap(QPixmap::fromImage(scaled_image));
|
||||
ui_.icon->show();
|
||||
} else {
|
||||
ui_.icon->hide();
|
||||
}
|
||||
|
||||
ui_.summary->setText(summary);
|
||||
ui_.message->setText(message);
|
||||
|
||||
if (isVisible())
|
||||
Reposition();
|
||||
|
||||
if (isVisible() && mode_ == Mode_Popup)
|
||||
timeout_->start(); // Restart the timer
|
||||
}
|
||||
|
||||
void OSDPretty::showEvent(QShowEvent* e) {
|
||||
QWidget::showEvent(e);
|
||||
|
||||
Reposition();
|
||||
setWindowOpacity(1.0);
|
||||
|
||||
if (mode_ == Mode_Popup)
|
||||
timeout_->start();
|
||||
}
|
||||
|
||||
void OSDPretty::Reposition() {
|
||||
QDesktopWidget* desktop = QApplication::desktop();
|
||||
|
||||
layout()->activate();
|
||||
resize(sizeHint());
|
||||
|
||||
int screen = popup_display_ >= desktop->screenCount() ? -1 : popup_display_;
|
||||
QRect geometry(desktop->availableGeometry(screen));
|
||||
|
||||
int x = popup_pos_.x() + geometry.left();
|
||||
int y = popup_pos_.y() + geometry.top();
|
||||
|
||||
move(qBound(0, x, geometry.right() - width()),
|
||||
qBound(0, y, geometry.bottom() - height()));
|
||||
}
|
||||
|
||||
void OSDPretty::enterEvent(QEvent *) {
|
||||
if (mode_ == Mode_Popup)
|
||||
setWindowOpacity(0.25);
|
||||
}
|
||||
|
||||
void OSDPretty::leaveEvent(QEvent *) {
|
||||
setWindowOpacity(1.0);
|
||||
}
|
||||
|
||||
void OSDPretty::mousePressEvent(QMouseEvent* e) {
|
||||
if (mode_ == Mode_Popup)
|
||||
hide();
|
||||
else {
|
||||
original_window_pos_ = pos();
|
||||
drag_start_pos_ = e->globalPos();
|
||||
}
|
||||
}
|
||||
|
||||
void OSDPretty::mouseMoveEvent(QMouseEvent* e) {
|
||||
if (mode_ == Mode_Draggable) {
|
||||
QPoint delta = e->globalPos() - drag_start_pos_;
|
||||
QPoint new_pos = original_window_pos_ + delta;
|
||||
|
||||
// Keep it to the bounds of the desktop
|
||||
QDesktopWidget* desktop = QApplication::desktop();
|
||||
QRect geometry(desktop->availableGeometry(e->globalPos()));
|
||||
|
||||
new_pos.setX(qBound(geometry.left(), new_pos.x(), geometry.right() - width()));
|
||||
new_pos.setY(qBound(geometry.top(), new_pos.y(), geometry.bottom() - height()));
|
||||
|
||||
move(new_pos);
|
||||
}
|
||||
}
|
||||
|
||||
QPoint OSDPretty::current_pos() const {
|
||||
QDesktopWidget* desktop = QApplication::desktop();
|
||||
QRect geometry(desktop->availableGeometry(current_display()));
|
||||
|
||||
return QPoint(pos().x() - geometry.left(),
|
||||
pos().y() - geometry.top());
|
||||
}
|
||||
|
||||
int OSDPretty::current_display() const {
|
||||
QDesktopWidget* desktop = QApplication::desktop();
|
||||
return desktop->screenNumber(pos());
|
||||
}
|
||||
|
||||
void OSDPretty::set_background_color(QRgb color) {
|
||||
background_color_ = color;
|
||||
if (isVisible())
|
||||
update();
|
||||
}
|
||||
|
||||
void OSDPretty::set_background_opacity(qreal opacity) {
|
||||
background_opacity_ = opacity;
|
||||
if (isVisible())
|
||||
update();
|
||||
}
|
||||
|
||||
void OSDPretty::set_foreground_color(QRgb color) {
|
||||
foreground_color_ = QColor(color);
|
||||
|
||||
QPalette p;
|
||||
p.setColor(QPalette::WindowText, foreground_color_);
|
||||
|
||||
ui_.summary->setPalette(p);
|
||||
ui_.message->setPalette(p);
|
||||
}
|
||||
|
||||
void OSDPretty::set_popup_duration(int msec) {
|
||||
timeout_->setInterval(msec);
|
||||
}
|
105
src/osdpretty.h
Normal file
105
src/osdpretty.h
Normal file
@ -0,0 +1,105 @@
|
||||
/* This file is part of Clementine.
|
||||
|
||||
Clementine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Clementine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OSDPRETTY_H
|
||||
#define OSDPRETTY_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "ui_osdpretty.h"
|
||||
|
||||
class OSDPretty : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OSDPretty(QWidget *parent = 0);
|
||||
|
||||
static const char* kSettingsGroup;
|
||||
|
||||
static const int kDropShadowSize;
|
||||
static const int kBorderRadius;
|
||||
static const int kMaxIconSize;
|
||||
|
||||
static const QRgb kPresetBlue;
|
||||
static const QRgb kPresetOrange;
|
||||
|
||||
enum Mode {
|
||||
Mode_Popup,
|
||||
Mode_Draggable,
|
||||
};
|
||||
|
||||
void SetMode(Mode mode);
|
||||
void SetMessage(const QString& summary,
|
||||
const QString& message,
|
||||
const QImage& image);
|
||||
|
||||
// Popup duration in seconds. Only used in Mode_Popup.
|
||||
void set_popup_duration(int msec);
|
||||
|
||||
// These will get overwritten when ReloadSettings() is called
|
||||
void set_foreground_color(QRgb color);
|
||||
void set_background_color(QRgb color);
|
||||
void set_background_opacity(qreal opacity);
|
||||
|
||||
QRgb foreground_color() const { return foreground_color_.rgb(); }
|
||||
QRgb background_color() const { return background_color_.rgb(); }
|
||||
qreal background_opacity() const { return background_opacity_; }
|
||||
|
||||
// When the user has been moving the popup, use these to get its current
|
||||
// position and screen
|
||||
int current_display() const;
|
||||
QPoint current_pos() const;
|
||||
|
||||
public slots:
|
||||
void ReloadSettings();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void showEvent(QShowEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
|
||||
private:
|
||||
void Reposition();
|
||||
void Load();
|
||||
|
||||
private:
|
||||
Ui::OSDPretty ui_;
|
||||
|
||||
Mode mode_;
|
||||
|
||||
// Settings loaded from QSettings
|
||||
QColor foreground_color_;
|
||||
QColor background_color_;
|
||||
float background_opacity_;
|
||||
int popup_display_; // -1 for default
|
||||
QPoint popup_pos_;
|
||||
|
||||
// Cached pixmaps
|
||||
QPixmap shadow_edge_[4];
|
||||
QPixmap shadow_corner_[4];
|
||||
|
||||
// For dragging the OSD
|
||||
QPoint original_window_pos_;
|
||||
QPoint drag_start_pos_;
|
||||
|
||||
// For timeout of notification
|
||||
QTimer* timeout_;
|
||||
};
|
||||
|
||||
#endif // OSDPRETTY_H
|
83
src/osdpretty.ui
Normal file
83
src/osdpretty.ui
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OSDPretty</class>
|
||||
<widget class="QWidget" name="OSDPretty">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>374</width>
|
||||
<height>89</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#summary {
|
||||
font-weight: bold;
|
||||
font-size: larger;
|
||||
}
|
||||
</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="icon"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="summary">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="message">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -17,13 +17,25 @@
|
||||
#include "settingsdialog.h"
|
||||
#include "enginebase.h"
|
||||
#include "osd.h"
|
||||
#include "osdpretty.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QColorDialog>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
: QDialog(parent),
|
||||
loading_settings_(false),
|
||||
pretty_popup_(new OSDPretty)
|
||||
{
|
||||
ui_.setupUi(this);
|
||||
pretty_popup_->SetMode(OSDPretty::Mode_Draggable);
|
||||
pretty_popup_->SetMessage(tr("OSD Preview"), tr("Drag to reposition"),
|
||||
QImage(":nocover.png"));
|
||||
|
||||
ui_.notifications_bg_preset->setItemData(0, QColor(OSDPretty::kPresetBlue), Qt::DecorationRole);
|
||||
ui_.notifications_bg_preset->setItemData(1, QColor(OSDPretty::kPresetOrange), Qt::DecorationRole);
|
||||
|
||||
// Last.fm
|
||||
connect(ui_.lastfm, SIGNAL(ValidationComplete(bool)), SLOT(LastFMValidationComplete(bool)));
|
||||
@ -36,11 +48,22 @@ SettingsDialog::SettingsDialog(QWidget* parent)
|
||||
connect(ui_.notifications_none, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||
connect(ui_.notifications_native, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||
connect(ui_.notifications_tray, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||
connect(ui_.notifications_pretty, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||
connect(ui_.notifications_opacity, SIGNAL(valueChanged(int)), SLOT(PrettyOpacityChanged(int)));
|
||||
connect(ui_.notifications_bg_preset, SIGNAL(activated(int)), SLOT(PrettyColorPresetChanged(int)));
|
||||
connect(ui_.notifications_fg_choose, SIGNAL(clicked()), SLOT(ChooseFgColor()));
|
||||
|
||||
if (!OSD::SupportsNativeNotifications())
|
||||
ui_.notifications_native->setEnabled(false);
|
||||
if (!OSD::SupportsTrayPopups())
|
||||
ui_.notifications_tray->setEnabled(false);
|
||||
|
||||
connect(ui_.stacked_widget, SIGNAL(currentChanged(int)), SLOT(UpdatePopupVisible()));
|
||||
connect(ui_.notifications_pretty, SIGNAL(toggled(bool)), SLOT(UpdatePopupVisible()));
|
||||
}
|
||||
|
||||
SettingsDialog::~SettingsDialog() {
|
||||
delete pretty_popup_;
|
||||
}
|
||||
|
||||
void SettingsDialog::CurrentTextChanged(const QString &text) {
|
||||
@ -80,6 +103,7 @@ void SettingsDialog::accept() {
|
||||
if (ui_.notifications_none->isChecked()) osd_behaviour = OSD::Disabled;
|
||||
else if (ui_.notifications_native->isChecked()) osd_behaviour = OSD::Native;
|
||||
else if (ui_.notifications_tray->isChecked()) osd_behaviour = OSD::TrayPopup;
|
||||
else if (ui_.notifications_pretty->isChecked()) osd_behaviour = OSD::Pretty;
|
||||
|
||||
s.beginGroup(OSD::kSettingsGroup);
|
||||
s.setValue("Behaviour", int(osd_behaviour));
|
||||
@ -88,11 +112,20 @@ void SettingsDialog::accept() {
|
||||
s.setValue("ShowArt", ui_.notifications_art->isChecked());
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup(OSDPretty::kSettingsGroup);
|
||||
s.setValue("foreground_color", pretty_popup_->foreground_color());
|
||||
s.setValue("background_color", pretty_popup_->background_color());
|
||||
s.setValue("background_opacity", pretty_popup_->background_opacity());
|
||||
s.setValue("popup_display", pretty_popup_->current_display());
|
||||
s.setValue("popup_pos", pretty_popup_->current_pos());
|
||||
s.endGroup();
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void SettingsDialog::showEvent(QShowEvent*) {
|
||||
QSettings s;
|
||||
loading_settings_ = true;
|
||||
|
||||
// Last.fm
|
||||
ui_.lastfm->Load();
|
||||
@ -124,6 +157,10 @@ void SettingsDialog::showEvent(QShowEvent*) {
|
||||
}
|
||||
// Fallthrough
|
||||
|
||||
case OSD::Pretty:
|
||||
ui_.notifications_pretty->setChecked(true);
|
||||
break;
|
||||
|
||||
case OSD::Disabled:
|
||||
default:
|
||||
ui_.notifications_none->setChecked(true);
|
||||
@ -133,11 +170,80 @@ void SettingsDialog::showEvent(QShowEvent*) {
|
||||
ui_.notifications_volume->setChecked(s.value("ShowOnVolumeChange", false).toBool());
|
||||
ui_.notifications_art->setChecked(s.value("ShowArt", true).toBool());
|
||||
s.endGroup();
|
||||
|
||||
// Pretty OSD
|
||||
pretty_popup_->ReloadSettings();
|
||||
ui_.notifications_opacity->setValue(pretty_popup_->background_opacity() * 100);
|
||||
|
||||
QRgb color = pretty_popup_->background_color();
|
||||
if (color == OSDPretty::kPresetBlue)
|
||||
ui_.notifications_bg_preset->setCurrentIndex(0);
|
||||
else if (color == OSDPretty::kPresetOrange)
|
||||
ui_.notifications_bg_preset->setCurrentIndex(1);
|
||||
else
|
||||
ui_.notifications_bg_preset->setCurrentIndex(2);
|
||||
ui_.notifications_bg_preset->setItemData(2, QColor(color), Qt::DecorationRole);
|
||||
UpdatePopupVisible();
|
||||
|
||||
loading_settings_ = false;
|
||||
}
|
||||
|
||||
void SettingsDialog::hideEvent(QHideEvent *) {
|
||||
pretty_popup_->hide();
|
||||
}
|
||||
|
||||
void SettingsDialog::NotificationTypeChanged() {
|
||||
bool enabled = !ui_.notifications_none->isChecked();
|
||||
ui_.notifications_options->setEnabled(enabled);
|
||||
ui_.notifications_volume->setEnabled(enabled);
|
||||
ui_.notifications_art->setEnabled(enabled);
|
||||
bool pretty = ui_.notifications_pretty->isChecked();
|
||||
|
||||
ui_.notifications_general->setEnabled(enabled);
|
||||
ui_.notifications_pretty_group->setEnabled(pretty);
|
||||
}
|
||||
|
||||
void SettingsDialog::PrettyOpacityChanged(int value) {
|
||||
pretty_popup_->set_background_opacity(qreal(value) / 100.0);
|
||||
}
|
||||
|
||||
void SettingsDialog::UpdatePopupVisible() {
|
||||
pretty_popup_->setVisible(
|
||||
isVisible() &&
|
||||
ui_.notifications_pretty->isChecked() &&
|
||||
ui_.stacked_widget->currentWidget() == ui_.notifications_page);
|
||||
}
|
||||
|
||||
void SettingsDialog::PrettyColorPresetChanged(int index) {
|
||||
if (loading_settings_)
|
||||
return;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
pretty_popup_->set_background_color(OSDPretty::kPresetBlue);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
pretty_popup_->set_background_color(OSDPretty::kPresetOrange);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
default:
|
||||
ChooseBgColor();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::ChooseBgColor() {
|
||||
QColor color = QColorDialog::getColor(pretty_popup_->background_color(), this);
|
||||
if (!color.isValid())
|
||||
return;
|
||||
|
||||
pretty_popup_->set_background_color(color.rgb());
|
||||
ui_.notifications_bg_preset->setItemData(2, color, Qt::DecorationRole);
|
||||
}
|
||||
|
||||
void SettingsDialog::ChooseFgColor() {
|
||||
QColor color = QColorDialog::getColor(pretty_popup_->foreground_color(), this);
|
||||
if (!color.isValid())
|
||||
return;
|
||||
|
||||
pretty_popup_->set_foreground_color(color.rgb());
|
||||
}
|
||||
|
@ -22,12 +22,14 @@
|
||||
#include "ui_settingsdialog.h"
|
||||
|
||||
class LibraryDirectoryModel;
|
||||
class OSDPretty;
|
||||
|
||||
class SettingsDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SettingsDialog(QWidget* parent = 0);
|
||||
~SettingsDialog();
|
||||
|
||||
void SetLibraryDirectoryModel(LibraryDirectoryModel* model);
|
||||
|
||||
@ -36,14 +38,25 @@ class SettingsDialog : public QDialog {
|
||||
|
||||
// QWidget
|
||||
void showEvent(QShowEvent* e);
|
||||
void hideEvent(QHideEvent *);
|
||||
|
||||
private slots:
|
||||
void CurrentTextChanged(const QString& text);
|
||||
void NotificationTypeChanged();
|
||||
void LastFMValidationComplete(bool success);
|
||||
|
||||
void PrettyOpacityChanged(int value);
|
||||
void PrettyColorPresetChanged(int index);
|
||||
void ChooseBgColor();
|
||||
void ChooseFgColor();
|
||||
|
||||
void UpdatePopupVisible();
|
||||
|
||||
private:
|
||||
Ui::SettingsDialog ui_;
|
||||
bool loading_settings_;
|
||||
|
||||
OSDPretty* pretty_popup_;
|
||||
};
|
||||
|
||||
#endif // SETTINGSDIALOG_H
|
||||
|
@ -97,7 +97,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<widget class="QStackedWidget" name="stacked_widget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
@ -192,13 +192,9 @@
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>groupBox</zorder>
|
||||
</widget>
|
||||
<widget class="QWidget" name="notifications_page">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
@ -207,65 +203,36 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="notifications_none">
|
||||
<property name="text">
|
||||
<string>Don't show notifications</string>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
<string>Notification type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="notifications_native">
|
||||
<property name="text">
|
||||
<string>Show a native desktop notification</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="notifications_tray">
|
||||
<property name="text">
|
||||
<string>Show a popup from the system tray</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>4</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="notifications_options" native="true">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="notifications_none">
|
||||
<property name="text">
|
||||
<string>Popup duration</string>
|
||||
<string>Disabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="notifications_duration">
|
||||
<property name="suffix">
|
||||
<string> seconds</string>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="notifications_native">
|
||||
<property name="text">
|
||||
<string>Show a native desktop notification</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="notifications_pretty">
|
||||
<property name="text">
|
||||
<string>Show a pretty OSD</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>5</number>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="notifications_tray">
|
||||
<property name="text">
|
||||
<string>Show a popup from the system tray</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -273,17 +240,121 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="notifications_volume">
|
||||
<property name="text">
|
||||
<string>Show a notification when I change the volume</string>
|
||||
<widget class="QGroupBox" name="notifications_general">
|
||||
<property name="title">
|
||||
<string>General settings</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QWidget" name="notifications_options" native="true">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Popup duration</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="notifications_duration">
|
||||
<property name="suffix">
|
||||
<string> seconds</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="notifications_volume">
|
||||
<property name="text">
|
||||
<string>Show a notification when I change the volume</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="notifications_art">
|
||||
<property name="text">
|
||||
<string>Include album art in the notification</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="notifications_art">
|
||||
<property name="text">
|
||||
<string>Include album art in the notification</string>
|
||||
<widget class="QGroupBox" name="notifications_pretty_group">
|
||||
<property name="title">
|
||||
<string>Pretty OSD options</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Background opacity</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSlider" name="notifications_opacity">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Background color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="notifications_bg_preset">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Basic Blue</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Clementine Orange</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Custom...</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Text color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="notifications_fg_choose">
|
||||
<property name="text">
|
||||
<string>Choose color...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -360,6 +431,16 @@
|
||||
<tabstop>no_fadeout</tabstop>
|
||||
<tabstop>fadeout</tabstop>
|
||||
<tabstop>fadeout_duration</tabstop>
|
||||
<tabstop>notifications_none</tabstop>
|
||||
<tabstop>notifications_native</tabstop>
|
||||
<tabstop>notifications_pretty</tabstop>
|
||||
<tabstop>notifications_tray</tabstop>
|
||||
<tabstop>notifications_duration</tabstop>
|
||||
<tabstop>notifications_volume</tabstop>
|
||||
<tabstop>notifications_art</tabstop>
|
||||
<tabstop>notifications_opacity</tabstop>
|
||||
<tabstop>notifications_bg_preset</tabstop>
|
||||
<tabstop>notifications_fg_choose</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
@ -367,7 +448,7 @@
|
||||
<connection>
|
||||
<sender>list</sender>
|
||||
<signal>currentRowChanged(int)</signal>
|
||||
<receiver>stackedWidget</receiver>
|
||||
<receiver>stacked_widget</receiver>
|
||||
<slot>setCurrentIndex(int)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
Loading…
x
Reference in New Issue
Block a user