1 /* This file is part of Clementine. 2 Copyright 2010, David Sansome <me@davidsansome.com> 3 4 Clementine is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 Clementine is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with Clementine. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef OSDPRETTY_H 19 #define OSDPRETTY_H 20 21 #include <QWidget> 22 23 class Ui_OSDPretty; 24 25 class QTimeLine; 26 27 class OSDPretty : public QWidget { 28 Q_OBJECT 29 30 public: 31 enum Mode { Mode_Popup, Mode_Draggable, }; 32 33 OSDPretty(Mode mode, QWidget* parent = nullptr); 34 ~OSDPretty(); 35 36 static const char* kSettingsGroup; 37 38 static const int kDropShadowSize; 39 static const int kBorderRadius; 40 static const int kMaxIconSize; 41 42 static const int kSnapProximity; 43 44 static const QRgb kPresetBlue; 45 static const QRgb kPresetOrange; 46 47 static bool IsTransparencyAvailable(); 48 49 void SetMessage(const QString& summary, const QString& message, 50 const QImage& image); 51 void ShowMessage(const QString& summary, const QString& message, 52 const QImage& image); 53 54 // Controls the fader. This is enabled by default on Windows. set_fading_enabled(bool enabled)55 void set_fading_enabled(bool enabled) { fading_enabled_ = enabled; } 56 57 // Popup duration in seconds. Only used in Mode_Popup. 58 void set_popup_duration(int msec); 59 60 // These will get overwritten when ReloadSettings() is called 61 void set_foreground_color(QRgb color); 62 void set_background_color(QRgb color); 63 void set_background_opacity(qreal opacity); 64 void set_font(QFont font); 65 foreground_color()66 QRgb foreground_color() const { return foreground_color_.rgb(); } background_color()67 QRgb background_color() const { return background_color_.rgb(); } background_opacity()68 qreal background_opacity() const { return background_opacity_; } popup_display()69 int popup_display() const { return popup_display_; } popup_pos()70 QPoint popup_pos() const { return popup_pos_; } font()71 QFont font() const { return font_; } disable_duration()72 bool disable_duration() const { return disable_duration_; } 73 74 // When the user has been moving the popup, use these to get its current 75 // position and screen. Note that these return invalid values if the popup 76 // is hidden. 77 int current_display() const; 78 QPoint current_pos() const; 79 80 // QWidget 81 void setVisible(bool visible); 82 toggle_mode()83 bool toggle_mode() const { return toggle_mode_; } set_toggle_mode(bool toggle_mode)84 void set_toggle_mode(bool toggle_mode) { toggle_mode_ = toggle_mode; } 85 86 public slots: 87 void ReloadSettings(); 88 89 protected: 90 void paintEvent(QPaintEvent*); 91 void enterEvent(QEvent*); 92 void leaveEvent(QEvent*); 93 void mousePressEvent(QMouseEvent*); 94 void showEvent(QShowEvent*); 95 void mouseMoveEvent(QMouseEvent*); 96 void mouseReleaseEvent(QMouseEvent*); 97 98 private: 99 void Reposition(); 100 void Load(); 101 102 QRect BoxBorder() const; 103 104 private slots: 105 void FaderValueChanged(qreal value); 106 void FaderFinished(); 107 108 private: 109 Ui_OSDPretty* ui_; 110 111 Mode mode_; 112 113 // Settings loaded from QSettings 114 QColor foreground_color_; 115 QColor background_color_; 116 float background_opacity_; 117 int popup_display_; // -1 for default 118 QPoint popup_pos_; 119 QFont font_; 120 // The OSD is kept always on top until you click (no timer) 121 bool disable_duration_; 122 123 // Cached pixmaps 124 QPixmap shadow_edge_[4]; 125 QPixmap shadow_corner_[4]; 126 QPixmap background_; 127 128 // For dragging the OSD 129 QPoint original_window_pos_; 130 QPoint drag_start_pos_; 131 132 // For timeout of notification 133 QTimer* timeout_; 134 135 // For fading 136 bool fading_enabled_; 137 QTimeLine* fader_; 138 139 // Toggling requested, we have to show or hide the OSD 140 bool toggle_mode_; 141 }; 142 143 #endif // OSDPRETTY_H 144