sliders: implement color coding for clarity
This commit is contained in:
@@ -55,6 +55,11 @@ public:
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void SetColor(const QColor &c)
|
||||
{
|
||||
label_->SetColor(c);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void ShowEditor();
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
namespace olive {
|
||||
|
||||
SliderLabel::SliderLabel(QWidget *parent) :
|
||||
QLabel(parent)
|
||||
QLabel(parent),
|
||||
override_color_enabled_(false)
|
||||
{
|
||||
QPalette p = palette();
|
||||
|
||||
@@ -52,6 +53,26 @@ SliderLabel::SliderLabel(QWidget *parent) :
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
|
||||
void SliderLabel::SetColor(const QColor &c)
|
||||
{
|
||||
// Prevent infinite loop in changeEvent when we set the stylesheet
|
||||
override_color_enabled_ = false;
|
||||
override_color_ = c;
|
||||
|
||||
// Different colors will look different depending on the theme (light/dark mode). We abstract
|
||||
// that away here so that other classes can simply choose a color and we will handle making it
|
||||
// more legible based on the background
|
||||
QColor adjusted;
|
||||
if (palette().window().color().lightness() < 128) {
|
||||
adjusted = override_color_.lighter(150);
|
||||
} else {
|
||||
adjusted = override_color_.darker(150);
|
||||
}
|
||||
|
||||
setStyleSheet(QStringLiteral("color: %1").arg(adjusted.name()));
|
||||
override_color_enabled_ = true;
|
||||
}
|
||||
|
||||
void SliderLabel::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
@@ -81,4 +102,13 @@ void SliderLabel::focusInEvent(QFocusEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void SliderLabel::changeEvent(QEvent *event)
|
||||
{
|
||||
QWidget::changeEvent(event);
|
||||
|
||||
if (override_color_enabled_ && event->type() == QEvent::StyleChange) {
|
||||
SetColor(override_color_);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ class SliderLabel : public QLabel
|
||||
public:
|
||||
SliderLabel(QWidget* parent);
|
||||
|
||||
void SetColor(const QColor &c);
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent *e) override;
|
||||
|
||||
@@ -40,6 +42,8 @@ protected:
|
||||
|
||||
virtual void focusInEvent(QFocusEvent *event) override;
|
||||
|
||||
virtual void changeEvent(QEvent *event) override;
|
||||
|
||||
signals:
|
||||
void LabelPressed();
|
||||
|
||||
@@ -51,6 +55,10 @@ signals:
|
||||
|
||||
void ChangeSliderType();
|
||||
|
||||
private:
|
||||
bool override_color_enabled_;
|
||||
QColor override_color_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user