Add moodbar settings to the track slider's context menu
This commit is contained in:
parent
972b6a233c
commit
24ea8d3e05
BIN
data/sample.mood
BIN
data/sample.mood
Binary file not shown.
@ -19,7 +19,9 @@
|
|||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
|
|
||||||
|
#include <QContextMenuEvent>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
#include <QMenu>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
@ -34,13 +36,17 @@ const int MoodbarProxyStyle::kArrowHeight = 13;
|
|||||||
|
|
||||||
MoodbarProxyStyle::MoodbarProxyStyle(Application* app, QSlider* slider)
|
MoodbarProxyStyle::MoodbarProxyStyle(Application* app, QSlider* slider)
|
||||||
: QProxyStyle(slider->style()),
|
: QProxyStyle(slider->style()),
|
||||||
|
app_(app),
|
||||||
slider_(slider),
|
slider_(slider),
|
||||||
enabled_(true),
|
enabled_(true),
|
||||||
moodbar_style_(MoodbarRenderer::Style_Normal),
|
moodbar_style_(MoodbarRenderer::Style_Normal),
|
||||||
state_(MoodbarOff),
|
state_(MoodbarOff),
|
||||||
fade_timeline_(new QTimeLine(1000, this)),
|
fade_timeline_(new QTimeLine(1000, this)),
|
||||||
moodbar_colors_dirty_(true),
|
moodbar_colors_dirty_(true),
|
||||||
moodbar_pixmap_dirty_(true)
|
moodbar_pixmap_dirty_(true),
|
||||||
|
context_menu_(NULL),
|
||||||
|
show_moodbar_action_(NULL),
|
||||||
|
style_action_group_(NULL)
|
||||||
{
|
{
|
||||||
slider->setStyle(this);
|
slider->setStyle(this);
|
||||||
slider->installEventFilter(this);
|
slider->installEventFilter(this);
|
||||||
@ -80,12 +86,22 @@ void MoodbarProxyStyle::SetMoodbarData(const QByteArray& data) {
|
|||||||
|
|
||||||
void MoodbarProxyStyle::SetMoodbarEnabled(bool enabled) {
|
void MoodbarProxyStyle::SetMoodbarEnabled(bool enabled) {
|
||||||
enabled_ = enabled;
|
enabled_ = enabled;
|
||||||
NextState();
|
|
||||||
|
// Save the enabled setting.
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup("Moodbar");
|
||||||
|
s.setValue("show", enabled);
|
||||||
|
|
||||||
|
app_->ReloadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoodbarProxyStyle::NextState() {
|
void MoodbarProxyStyle::NextState() {
|
||||||
const bool visible = enabled_ && !data_.isEmpty();
|
const bool visible = enabled_ && !data_.isEmpty();
|
||||||
|
|
||||||
|
if (show_moodbar_action_) {
|
||||||
|
show_moodbar_action_->setChecked(enabled_);
|
||||||
|
}
|
||||||
|
|
||||||
if ((visible && (state_ == MoodbarOn || state_ == FadingToOn)) ||
|
if ((visible && (state_ == MoodbarOn || state_ == FadingToOn)) ||
|
||||||
(!visible && (state_ == MoodbarOff || state_ == FadingToOff))) {
|
(!visible && (state_ == MoodbarOff || state_ == FadingToOff))) {
|
||||||
return;
|
return;
|
||||||
@ -117,9 +133,20 @@ void MoodbarProxyStyle::FaderValueChanged(qreal value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MoodbarProxyStyle::eventFilter(QObject* object, QEvent* event) {
|
bool MoodbarProxyStyle::eventFilter(QObject* object, QEvent* event) {
|
||||||
if (object == slider_ && event->type() == QEvent::Resize) {
|
if (object == slider_) {
|
||||||
// The widget was resized, we've got to render a new pixmap.
|
switch (event->type()) {
|
||||||
moodbar_pixmap_dirty_ = true;
|
case QEvent::Resize:
|
||||||
|
// The widget was resized, we've got to render a new pixmap.
|
||||||
|
moodbar_pixmap_dirty_ = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QEvent::ContextMenu:
|
||||||
|
ShowContextMenu(static_cast<QContextMenuEvent*>(event)->globalPos());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QProxyStyle::eventFilter(object, event);
|
return QProxyStyle::eventFilter(object, event);
|
||||||
@ -302,3 +329,48 @@ QPixmap MoodbarProxyStyle::MoodbarPixmap(const ColorVector& colors,
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MoodbarProxyStyle::ShowContextMenu(const QPoint& pos) {
|
||||||
|
if (!context_menu_) {
|
||||||
|
context_menu_ = new QMenu(slider_);
|
||||||
|
show_moodbar_action_ = context_menu_->addAction(
|
||||||
|
tr("Show moodbar"), this, SLOT(SetMoodbarEnabled(bool)));
|
||||||
|
|
||||||
|
show_moodbar_action_->setCheckable(true);
|
||||||
|
show_moodbar_action_->setChecked(enabled_);
|
||||||
|
|
||||||
|
QMenu* styles_menu = context_menu_->addMenu(tr("Moodbar style"));
|
||||||
|
style_action_group_ = new QActionGroup(styles_menu);
|
||||||
|
|
||||||
|
for (int i=0 ; i<MoodbarRenderer::StyleCount ; ++i) {
|
||||||
|
const MoodbarRenderer::MoodbarStyle style =
|
||||||
|
MoodbarRenderer::MoodbarStyle(i);
|
||||||
|
|
||||||
|
QAction* action = style_action_group_->addAction(MoodbarRenderer::StyleName(style));
|
||||||
|
action->setCheckable(true);
|
||||||
|
action->setData(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
styles_menu->addActions(style_action_group_->actions());
|
||||||
|
|
||||||
|
connect(styles_menu, SIGNAL(triggered(QAction*)), SLOT(ChangeStyle(QAction*)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the currently selected style
|
||||||
|
foreach (QAction* action, style_action_group_->actions()) {
|
||||||
|
if (MoodbarRenderer::MoodbarStyle(action->data().toInt()) == moodbar_style_) {
|
||||||
|
action->setChecked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context_menu_->popup(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MoodbarProxyStyle::ChangeStyle(QAction* action) {
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup("Moodbar");
|
||||||
|
s.setValue("style", action->data().toInt());
|
||||||
|
|
||||||
|
app_->ReloadSettings();
|
||||||
|
}
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
class Application;
|
class Application;
|
||||||
|
|
||||||
|
class QActionGroup;
|
||||||
|
class QMenu;
|
||||||
class QSlider;
|
class QSlider;
|
||||||
class QStyleOptionSlider;
|
class QStyleOptionSlider;
|
||||||
class QTimeLine;
|
class QTimeLine;
|
||||||
@ -70,6 +72,7 @@ private:
|
|||||||
QPainter* painter, const QWidget* widget);
|
QPainter* painter, const QWidget* widget);
|
||||||
void EnsureMoodbarRendered();
|
void EnsureMoodbarRendered();
|
||||||
void DrawArrow(const QStyleOptionSlider* option, QPainter* painter) const;
|
void DrawArrow(const QStyleOptionSlider* option, QPainter* painter) const;
|
||||||
|
void ShowContextMenu(const QPoint& pos);
|
||||||
|
|
||||||
static QPixmap MoodbarPixmap(const ColorVector& colors,
|
static QPixmap MoodbarPixmap(const ColorVector& colors,
|
||||||
const QSize& size, const QPalette& palette);
|
const QSize& size, const QPalette& palette);
|
||||||
@ -77,8 +80,10 @@ private:
|
|||||||
private slots:
|
private slots:
|
||||||
void ReloadSettings();
|
void ReloadSettings();
|
||||||
void FaderValueChanged(qreal value);
|
void FaderValueChanged(qreal value);
|
||||||
|
void ChangeStyle(QAction* action);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Application* app_;
|
||||||
QSlider* slider_;
|
QSlider* slider_;
|
||||||
|
|
||||||
bool enabled_;
|
bool enabled_;
|
||||||
@ -95,6 +100,10 @@ private:
|
|||||||
bool moodbar_pixmap_dirty_;
|
bool moodbar_pixmap_dirty_;
|
||||||
ColorVector moodbar_colors_;
|
ColorVector moodbar_colors_;
|
||||||
QPixmap moodbar_pixmap_;
|
QPixmap moodbar_pixmap_;
|
||||||
|
|
||||||
|
QMenu* context_menu_;
|
||||||
|
QAction* show_moodbar_action_;
|
||||||
|
QActionGroup* style_action_group_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MOODBARPROXYSTYLE_H
|
#endif // MOODBARPROXYSTYLE_H
|
||||||
|
@ -147,3 +147,15 @@ QImage MoodbarRenderer::RenderToImage(const ColorVector& colors, const QSize& si
|
|||||||
p.end();
|
p.end();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString MoodbarRenderer::StyleName(MoodbarStyle style) {
|
||||||
|
switch (style) {
|
||||||
|
case Style_Normal: return QObject::tr("Normal");
|
||||||
|
case Style_Angry: return QObject::tr("Angry");
|
||||||
|
case Style_Frozen: return QObject::tr("Frozen");
|
||||||
|
case Style_Happy: return QObject::tr("Happy");
|
||||||
|
case Style_SystemPalette: return QObject::tr("System colors");
|
||||||
|
|
||||||
|
default: return QString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,11 +35,15 @@ public:
|
|||||||
Style_Angry,
|
Style_Angry,
|
||||||
Style_Frozen,
|
Style_Frozen,
|
||||||
Style_Happy,
|
Style_Happy,
|
||||||
Style_SystemPalette
|
Style_SystemPalette,
|
||||||
|
|
||||||
|
StyleCount
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int kNumHues;
|
static const int kNumHues;
|
||||||
|
|
||||||
|
static QString StyleName(MoodbarStyle style);
|
||||||
|
|
||||||
static ColorVector Colors(const QByteArray& data, MoodbarStyle style,
|
static ColorVector Colors(const QByteArray& data, MoodbarStyle style,
|
||||||
const QPalette& palette);
|
const QPalette& palette);
|
||||||
static void Render(const ColorVector& colors, QPainter* p, const QRect& rect);
|
static void Render(const ColorVector& colors, QPainter* p, const QRect& rect);
|
||||||
|
@ -248,15 +248,17 @@ void AppearanceSettingsPage::InitMoodbarPreviews() {
|
|||||||
QByteArray data(file.readAll());
|
QByteArray data(file.readAll());
|
||||||
|
|
||||||
// Render and set each preview
|
// Render and set each preview
|
||||||
for (int i=0 ; i<ui_->moodbar_style->count() ; ++i) {
|
for (int i=0 ; i<MoodbarRenderer::StyleCount ; ++i) {
|
||||||
const ColorVector colors =
|
const MoodbarRenderer::MoodbarStyle style =
|
||||||
MoodbarRenderer::Colors(data, MoodbarRenderer::MoodbarStyle(i), palette());
|
MoodbarRenderer::MoodbarStyle(i);
|
||||||
|
const ColorVector colors = MoodbarRenderer::Colors(data, style, palette());
|
||||||
|
|
||||||
QPixmap pixmap(preview_size);
|
QPixmap pixmap(preview_size);
|
||||||
QPainter p(&pixmap);
|
QPainter p(&pixmap);
|
||||||
MoodbarRenderer::Render(colors, &p, pixmap.rect());
|
MoodbarRenderer::Render(colors, &p, pixmap.rect());
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
|
ui_->moodbar_style->addItem(MoodbarRenderer::StyleName(style));
|
||||||
ui_->moodbar_style->setItemData(i, pixmap, Qt::DecorationRole);
|
ui_->moodbar_style->setItemData(i, pixmap, Qt::DecorationRole);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -174,38 +174,12 @@
|
|||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Moodbar style:</string>
|
<string>Moodbar style</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="moodbar_style">
|
<widget class="QComboBox" name="moodbar_style"/>
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Normal</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Angry</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Frozen</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Happy</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>System colors</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="moodbar_save">
|
<widget class="QCheckBox" name="moodbar_save">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user