2019-04-18 15:03:01 +02:00
|
|
|
/* This file was part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MOODBARPROXYSTYLE_H
|
|
|
|
#define MOODBARPROXYSTYLE_H
|
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QObject>
|
2019-04-18 15:03:01 +02:00
|
|
|
#include <QProxyStyle>
|
|
|
|
#include <QByteArray>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QString>
|
2019-04-18 15:03:01 +02:00
|
|
|
#include <QPixmap>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QPalette>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QStyle>
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
#include "moodbarrenderer.h"
|
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
class QAction;
|
|
|
|
class QActionGroup;
|
|
|
|
class QMenu;
|
|
|
|
class QPainter;
|
|
|
|
class QSlider;
|
|
|
|
class QStyleOptionComplex;
|
|
|
|
class QStyleOptionSlider;
|
|
|
|
class QTimeLine;
|
|
|
|
class QWidget;
|
|
|
|
class QEvent;
|
|
|
|
|
2019-04-18 15:03:01 +02:00
|
|
|
class Application;
|
|
|
|
|
|
|
|
class MoodbarProxyStyle : public QProxyStyle {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-06-20 19:04:08 +02:00
|
|
|
explicit MoodbarProxyStyle(Application *app, QSlider *slider, QObject *parent = nullptr);
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
// QProxyStyle
|
2021-01-26 16:48:04 +01:00
|
|
|
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const override;
|
|
|
|
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override;
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
// QObject
|
2021-01-26 16:48:04 +01:00
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
// An empty byte array means there's no moodbar, so just show a normal slider.
|
2021-01-26 16:48:04 +01:00
|
|
|
void SetMoodbarData(const QByteArray &data);
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
// If the moodbar is disabled then a normal slider will always be shown.
|
2021-01-26 16:48:04 +01:00
|
|
|
void SetMoodbarEnabled(const bool enabled);
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kMarginSize;
|
|
|
|
static const int kBorderSize;
|
|
|
|
static const int kArrowWidth;
|
|
|
|
static const int kArrowHeight;
|
|
|
|
|
2023-02-18 14:09:27 +01:00
|
|
|
enum class State {
|
|
|
|
MoodbarOn,
|
|
|
|
MoodbarOff,
|
|
|
|
FadingToOn,
|
|
|
|
FadingToOff
|
|
|
|
};
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void NextState();
|
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
void Render(ComplexControl control, const QStyleOptionSlider *option, QPainter *painter, const QWidget *widget);
|
|
|
|
void EnsureMoodbarRendered(const QStyleOptionSlider *opt);
|
|
|
|
void DrawArrow(const QStyleOptionSlider *option, QPainter *painter) const;
|
2021-06-20 19:04:08 +02:00
|
|
|
void ShowContextMenu(const QPoint pos);
|
2019-04-18 15:03:01 +02:00
|
|
|
|
2021-06-22 13:41:38 +02:00
|
|
|
static QPixmap MoodbarPixmap(const ColorVector &colors, const QSize size, const QPalette &palette, const QStyleOptionSlider *opt);
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void ReloadSettings();
|
|
|
|
void FaderValueChanged(qreal value);
|
2021-01-26 16:48:04 +01:00
|
|
|
void ChangeStyle(QAction *action);
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
private:
|
2021-01-26 16:48:04 +01:00
|
|
|
Application *app_;
|
|
|
|
QSlider *slider_;
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
bool enabled_;
|
|
|
|
QByteArray data_;
|
|
|
|
MoodbarRenderer::MoodbarStyle moodbar_style_;
|
|
|
|
|
|
|
|
State state_;
|
2021-01-26 16:48:04 +01:00
|
|
|
QTimeLine *fade_timeline_;
|
2019-04-18 15:03:01 +02:00
|
|
|
|
|
|
|
QPixmap fade_source_;
|
|
|
|
QPixmap fade_target_;
|
|
|
|
|
|
|
|
bool moodbar_colors_dirty_;
|
|
|
|
bool moodbar_pixmap_dirty_;
|
|
|
|
ColorVector moodbar_colors_;
|
|
|
|
QPixmap moodbar_pixmap_;
|
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
QMenu *context_menu_;
|
|
|
|
QAction *show_moodbar_action_;
|
|
|
|
QActionGroup *style_action_group_;
|
2019-04-18 15:03:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MOODBARPROXYSTYLE_H
|