From 7d5673930dfc24d682a478a448ef961d75ed20b8 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Thu, 25 Mar 2010 19:30:10 +0000 Subject: [PATCH] Pretty OSD. --- data/data.qrc | 2 + data/osd_shadow_corner.png | Bin 0 -> 421 bytes data/osd_shadow_edge.png | Bin 0 -> 208 bytes src/CMakeLists.txt | 3 + src/osd.cpp | 17 ++- src/osd.h | 6 + src/osdpretty.cpp | 277 +++++++++++++++++++++++++++++++++++++ src/osdpretty.h | 105 ++++++++++++++ src/osdpretty.ui | 83 +++++++++++ src/settingsdialog.cpp | 114 ++++++++++++++- src/settingsdialog.h | 13 ++ src/settingsdialog.ui | 209 +++++++++++++++++++--------- 12 files changed, 759 insertions(+), 70 deletions(-) create mode 100644 data/osd_shadow_corner.png create mode 100644 data/osd_shadow_edge.png create mode 100644 src/osdpretty.cpp create mode 100644 src/osdpretty.h create mode 100644 src/osdpretty.ui diff --git a/data/data.qrc b/data/data.qrc index 151cc428a..15ead2ad5 100644 --- a/data/data.qrc +++ b/data/data.qrc @@ -73,5 +73,7 @@ media-playlist-shuffle-off.png schema-4.sql schema-5.sql + osd_shadow_corner.png + osd_shadow_edge.png diff --git a/data/osd_shadow_corner.png b/data/osd_shadow_corner.png new file mode 100644 index 0000000000000000000000000000000000000000..d236ed2823f82bddb59312e72a4778baf87073b4 GIT binary patch literal 421 zcmeAS@N?(olHy`uVBq!ia0vp^;vmey1|%P7U0DF67>k44ofy`glX(f`uqAoByDx`7I;J!GcfR50kII{sg%+TpdfpRr>`sfEoMmpQKN4yk52%FBuiW)N}Tg^ zb5rw57@Uhz6H8K46v{J8G8EiBeFMT9`G6KPGI+W;hIkxbJ0*~>MS;g!hlu;AE!wJV%~^z3HgNJP{{p5Dr;>$Ud)6_U*QFR7;5;zr_1xDC8$3D8F9}Xn z4Gyzljwq^ST%+3h=0s^o-10Rgj2{>`MBD3H6rE*_ezvA!eeR@yn^P}MoAhaG>8-0% zf)(4+pYWXzl&6h2cL4 zF4((#GEjuGz$3Dlfq~x&h=mwWrIcm>1=&kHeO=jaF-r=FNUzoPdI}VhEOCt}an8@p zP0cG|a4t$sEJ;mKD9q{Ku3ER+I%*geEp-=UZwm(oCgQu&X%Q~loCIFMNJyrk! literal 0 HcmV?d00001 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e79396a7..65dbce5c8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/osd.cpp b/src/osd.cpp index b4866614b..e7da55f25 100644 --- a/src/osd.cpp +++ b/src/osd.cpp @@ -15,6 +15,7 @@ */ #include "osd.h" +#include "osdpretty.h" #include #include @@ -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; diff --git a/src/osd.h b/src/osd.h index f6b2decd0..8794fbf1e 100644 --- a/src/osd.h +++ b/src/osd.h @@ -24,6 +24,8 @@ #include "engine_fwd.h" #include "song.h" +class OSDPretty; + #ifdef Q_WS_X11 #include #include @@ -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_; diff --git a/src/osdpretty.cpp b/src/osdpretty.cpp new file mode 100644 index 000000000..acc609bac --- /dev/null +++ b/src/osdpretty.cpp @@ -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 . +*/ + +#include "osdpretty.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +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); +} diff --git a/src/osdpretty.h b/src/osdpretty.h new file mode 100644 index 000000000..dafad4c47 --- /dev/null +++ b/src/osdpretty.h @@ -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 . +*/ + +#ifndef OSDPRETTY_H +#define OSDPRETTY_H + +#include + +#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 diff --git a/src/osdpretty.ui b/src/osdpretty.ui new file mode 100644 index 000000000..43bd38e47 --- /dev/null +++ b/src/osdpretty.ui @@ -0,0 +1,83 @@ + + + OSDPretty + + + + 0 + 0 + 374 + 89 + + + + + 200 + 0 + + + + #summary { + font-weight: bold; + font-size: larger; +} + + + + + 12 + + + + + + + + 4 + + + + + + 400 + 16777215 + + + + true + + + + + + + + 400 + 16777215 + + + + true + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + + diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 33b7d8bd8..bb1249316 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -17,13 +17,25 @@ #include "settingsdialog.h" #include "enginebase.h" #include "osd.h" +#include "osdpretty.h" #include +#include + +#include 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()); } diff --git a/src/settingsdialog.h b/src/settingsdialog.h index fb8a4dff7..d65c89938 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -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 diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 323d17f9a..1d7dd272d 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -97,7 +97,7 @@ - + 1 @@ -192,13 +192,9 @@ - groupBox - - 0 - @@ -207,65 +203,36 @@ - - - Don't show notifications + + + Notification type - - - - - - Show a native desktop notification - - - - - - - Show a popup from the system tray - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 4 - - - - - - - - - + + + - Popup duration + Disabled - - - - seconds + + + + Show a native desktop notification - - 1 + + + + + + Show a pretty OSD - - 20 - - - 5 + + + + + + Show a popup from the system tray @@ -273,17 +240,121 @@ - - - Show a notification when I change the volume + + + General settings + + + + + + 0 + + + + + Popup duration + + + + + + + seconds + + + 1 + + + 20 + + + 5 + + + + + + + + + + Show a notification when I change the volume + + + + + + + Include album art in the notification + + + + - - - Include album art in the notification + + + Pretty OSD options + + + + + Background opacity + + + + + + + Qt::Horizontal + + + + + + + Background color + + + + + + + + Basic Blue + + + + + Clementine Orange + + + + + Custom... + + + + + + + + Text color + + + + + + + Choose color... + + + + @@ -360,6 +431,16 @@ no_fadeout fadeout fadeout_duration + notifications_none + notifications_native + notifications_pretty + notifications_tray + notifications_duration + notifications_volume + notifications_art + notifications_opacity + notifications_bg_preset + notifications_fg_choose buttonBox @@ -367,7 +448,7 @@ list currentRowChanged(int) - stackedWidget + stacked_widget setCurrentIndex(int)