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/logging.h"
|
||||
|
||||
#include <QContextMenuEvent>
|
||||
#include <QEvent>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
#include <QSlider>
|
||||
|
@ -34,13 +36,17 @@ const int MoodbarProxyStyle::kArrowHeight = 13;
|
|||
|
||||
MoodbarProxyStyle::MoodbarProxyStyle(Application* app, QSlider* slider)
|
||||
: QProxyStyle(slider->style()),
|
||||
app_(app),
|
||||
slider_(slider),
|
||||
enabled_(true),
|
||||
moodbar_style_(MoodbarRenderer::Style_Normal),
|
||||
state_(MoodbarOff),
|
||||
fade_timeline_(new QTimeLine(1000, this)),
|
||||
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->installEventFilter(this);
|
||||
|
@ -80,12 +86,22 @@ void MoodbarProxyStyle::SetMoodbarData(const QByteArray& data) {
|
|||
|
||||
void MoodbarProxyStyle::SetMoodbarEnabled(bool enabled) {
|
||||
enabled_ = enabled;
|
||||
NextState();
|
||||
|
||||
// Save the enabled setting.
|
||||
QSettings s;
|
||||
s.beginGroup("Moodbar");
|
||||
s.setValue("show", enabled);
|
||||
|
||||
app_->ReloadSettings();
|
||||
}
|
||||
|
||||
void MoodbarProxyStyle::NextState() {
|
||||
const bool visible = enabled_ && !data_.isEmpty();
|
||||
|
||||
if (show_moodbar_action_) {
|
||||
show_moodbar_action_->setChecked(enabled_);
|
||||
}
|
||||
|
||||
if ((visible && (state_ == MoodbarOn || state_ == FadingToOn)) ||
|
||||
(!visible && (state_ == MoodbarOff || state_ == FadingToOff))) {
|
||||
return;
|
||||
|
@ -117,9 +133,20 @@ void MoodbarProxyStyle::FaderValueChanged(qreal value) {
|
|||
}
|
||||
|
||||
bool MoodbarProxyStyle::eventFilter(QObject* object, QEvent* event) {
|
||||
if (object == slider_ && event->type() == QEvent::Resize) {
|
||||
// The widget was resized, we've got to render a new pixmap.
|
||||
moodbar_pixmap_dirty_ = true;
|
||||
if (object == slider_) {
|
||||
switch (event->type()) {
|
||||
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);
|
||||
|
@ -302,3 +329,48 @@ QPixmap MoodbarProxyStyle::MoodbarPixmap(const ColorVector& colors,
|
|||
|
||||
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 QActionGroup;
|
||||
class QMenu;
|
||||
class QSlider;
|
||||
class QStyleOptionSlider;
|
||||
class QTimeLine;
|
||||
|
@ -70,6 +72,7 @@ private:
|
|||
QPainter* painter, const QWidget* widget);
|
||||
void EnsureMoodbarRendered();
|
||||
void DrawArrow(const QStyleOptionSlider* option, QPainter* painter) const;
|
||||
void ShowContextMenu(const QPoint& pos);
|
||||
|
||||
static QPixmap MoodbarPixmap(const ColorVector& colors,
|
||||
const QSize& size, const QPalette& palette);
|
||||
|
@ -77,8 +80,10 @@ private:
|
|||
private slots:
|
||||
void ReloadSettings();
|
||||
void FaderValueChanged(qreal value);
|
||||
void ChangeStyle(QAction* action);
|
||||
|
||||
private:
|
||||
Application* app_;
|
||||
QSlider* slider_;
|
||||
|
||||
bool enabled_;
|
||||
|
@ -95,6 +100,10 @@ private:
|
|||
bool moodbar_pixmap_dirty_;
|
||||
ColorVector moodbar_colors_;
|
||||
QPixmap moodbar_pixmap_;
|
||||
|
||||
QMenu* context_menu_;
|
||||
QAction* show_moodbar_action_;
|
||||
QActionGroup* style_action_group_;
|
||||
};
|
||||
|
||||
#endif // MOODBARPROXYSTYLE_H
|
||||
|
|
|
@ -147,3 +147,15 @@ QImage MoodbarRenderer::RenderToImage(const ColorVector& colors, const QSize& si
|
|||
p.end();
|
||||
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_Frozen,
|
||||
Style_Happy,
|
||||
Style_SystemPalette
|
||||
Style_SystemPalette,
|
||||
|
||||
StyleCount
|
||||
};
|
||||
|
||||
static const int kNumHues;
|
||||
|
||||
static QString StyleName(MoodbarStyle style);
|
||||
|
||||
static ColorVector Colors(const QByteArray& data, MoodbarStyle style,
|
||||
const QPalette& palette);
|
||||
static void Render(const ColorVector& colors, QPainter* p, const QRect& rect);
|
||||
|
|
|
@ -248,15 +248,17 @@ void AppearanceSettingsPage::InitMoodbarPreviews() {
|
|||
QByteArray data(file.readAll());
|
||||
|
||||
// Render and set each preview
|
||||
for (int i=0 ; i<ui_->moodbar_style->count() ; ++i) {
|
||||
const ColorVector colors =
|
||||
MoodbarRenderer::Colors(data, MoodbarRenderer::MoodbarStyle(i), palette());
|
||||
for (int i=0 ; i<MoodbarRenderer::StyleCount ; ++i) {
|
||||
const MoodbarRenderer::MoodbarStyle style =
|
||||
MoodbarRenderer::MoodbarStyle(i);
|
||||
const ColorVector colors = MoodbarRenderer::Colors(data, style, palette());
|
||||
|
||||
QPixmap pixmap(preview_size);
|
||||
QPainter p(&pixmap);
|
||||
MoodbarRenderer::Render(colors, &p, pixmap.rect());
|
||||
p.end();
|
||||
|
||||
ui_->moodbar_style->addItem(MoodbarRenderer::StyleName(style));
|
||||
ui_->moodbar_style->setItemData(i, pixmap, Qt::DecorationRole);
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -174,38 +174,12 @@
|
|||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Moodbar style:</string>
|
||||
<string>Moodbar style</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<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>
|
||||
<widget class="QComboBox" name="moodbar_style"/>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="moodbar_save">
|
||||
|
|
Loading…
Reference in New Issue