strawberry-audio-player-win.../src/osd/osdpretty.h

180 lines
4.6 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* Strawberry 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.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef OSDPRETTY_H
#define OSDPRETTY_H
#include "config.h"
#include <QtGlobal>
2020-02-09 02:29:35 +01:00
#include <QObject>
2018-02-27 18:06:05 +01:00
#include <QWidget>
2019-07-09 19:49:15 +02:00
#include <QMap>
#include <QString>
#include <QImage>
#include <QPixmap>
#include <QColor>
#include <QFont>
#include <QPoint>
#include <QRect>
2020-02-09 02:29:35 +01:00
#include <QRgb>
2020-02-09 02:29:35 +01:00
class QScreen;
2019-07-09 19:49:15 +02:00
class QTimer;
class QTimeLine;
class QEvent;
class QMouseEvent;
class QPaintEvent;
class QShowEvent;
2020-09-05 19:20:43 +02:00
class QEnterEvent;
2018-02-27 18:06:05 +01:00
class Ui_OSDPretty;
class OSDPretty : public QWidget {
Q_OBJECT
public:
enum Mode {
Mode_Popup,
Mode_Draggable,
};
2020-04-07 16:49:15 +02:00
explicit OSDPretty(Mode mode, QWidget *parent = nullptr);
2020-06-15 21:55:05 +02:00
~OSDPretty() override;
2018-02-27 18:06:05 +01:00
static const char *kSettingsGroup;
static const int kDropShadowSize;
static const int kBorderRadius;
static const int kMaxIconSize;
static const int kSnapProximity;
static const QRgb kPresetBlue;
2018-09-20 17:44:31 +02:00
static const QRgb kPresetRed;
2018-02-27 18:06:05 +01:00
bool IsTransparencyAvailable();
2018-02-27 18:06:05 +01:00
2021-06-12 20:53:23 +02:00
void SetMessage(const QString &summary, const QString &message, const QImage &image);
void ShowMessage(const QString &summary, const QString &message, const QImage &image);
2018-02-27 18:06:05 +01:00
// Popup duration in seconds. Only used in Mode_Popup.
2021-06-12 20:53:23 +02:00
void set_popup_duration(const int msec);
2018-02-27 18:06:05 +01:00
// These will get overwritten when ReloadSettings() is called
2021-06-12 20:53:23 +02:00
void set_foreground_color(const QRgb color);
void set_background_color(const QRgb color);
void set_background_opacity(const qreal opacity);
2021-06-20 19:04:08 +02:00
void set_font(const QFont &font);
2018-02-27 18:06:05 +01:00
QRgb foreground_color() const { return foreground_color_.rgb(); }
QRgb background_color() const { return background_color_.rgb(); }
qreal background_opacity() const { return background_opacity_; }
2019-07-09 19:49:15 +02:00
QString popup_screen() const { return popup_screen_name_; }
2018-02-27 18:06:05 +01:00
QPoint popup_pos() const { return popup_pos_; }
QFont font() const { return font_; }
bool disable_duration() const { return disable_duration_; }
2021-04-13 17:26:54 +02:00
bool fading() const { return fading_enabled_; }
2018-02-27 18:06:05 +01:00
// When the user has been moving the popup, use these to get its current position and screen.
// Note that these return invalid values if the popup is hidden.
2019-07-09 19:49:15 +02:00
QScreen *current_screen() const;
QScreen *current_screen(const QPoint pos) const;
2018-02-27 18:06:05 +01:00
QPoint current_pos() const;
// QWidget
2020-06-15 21:55:05 +02:00
void setVisible(bool visible) override;
2018-02-27 18:06:05 +01:00
bool toggle_mode() const { return toggle_mode_; }
2021-06-12 20:53:23 +02:00
void set_toggle_mode(const bool toggle_mode) { toggle_mode_ = toggle_mode; }
2018-02-27 18:06:05 +01:00
2020-06-05 23:46:07 +02:00
signals:
void PositionChanged();
2018-02-27 18:06:05 +01:00
public slots:
void ReloadSettings();
protected:
2020-06-15 21:55:05 +02:00
void paintEvent(QPaintEvent *e) override;
2020-09-05 19:20:43 +02:00
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEnterEvent*) override;
#else
void enterEvent(QEvent*) override;
#endif
void leaveEvent(QEvent*) override;
2020-06-15 21:55:05 +02:00
void mousePressEvent(QMouseEvent *e) override;
void showEvent(QShowEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
2018-02-27 18:06:05 +01:00
private:
void Reposition();
void Load();
QRect BoxBorder() const;
private slots:
2021-01-26 16:48:04 +01:00
void FaderValueChanged(const qreal value);
2018-02-27 18:06:05 +01:00
void FaderFinished();
2019-07-09 19:49:15 +02:00
void ScreenAdded(QScreen *screen);
void ScreenRemoved(QScreen *screen);
2018-02-27 18:06:05 +01:00
private:
Ui_OSDPretty *ui_;
Mode mode_;
// Settings loaded from QSettings
QColor foreground_color_;
QColor background_color_;
qreal background_opacity_;
2019-07-09 19:49:15 +02:00
QString popup_screen_name_;
2018-02-27 18:06:05 +01:00
QPoint popup_pos_;
2019-07-09 19:49:15 +02:00
QScreen *popup_screen_;
2018-02-27 18:06:05 +01:00
QFont font_;
// The OSD is kept always on top until you click (no timer)
bool disable_duration_;
// Cached pixmaps
QPixmap shadow_edge_[4];
QPixmap shadow_corner_[4];
QPixmap background_;
// For dragging the OSD
QPoint original_window_pos_;
QPoint drag_start_pos_;
// For timeout of notification
QTimer *timeout_;
// For fading
bool fading_enabled_;
QTimeLine *fader_;
// Toggling requested, we have to show or hide the OSD
bool toggle_mode_;
2019-07-09 19:49:15 +02:00
QMap<QString, QScreen*> screens_;
2018-02-27 18:06:05 +01:00
};
#endif // OSDPRETTY_H