sliders: implement color coding for clarity

This commit is contained in:
itsmattkc
2022-05-05 17:29:40 -07:00
parent d1c0734ff0
commit 6286b7091c
6 changed files with 75 additions and 1 deletions
@@ -42,10 +42,13 @@ OCIOGradingTransformLinearNode::OCIOGradingTransformLinearNode()
{
AddInput(kContrastInput, NodeValue::kVec4, QVector4D{1.0, 1.0, 1.0, 1.0});
SetInputProperty(kContrastInput, QStringLiteral("min"), QVector4D{0.001f, 0.001f, 0.001f, 0.001f});
SetVec4InputColors(kContrastInput);
AddInput(kOffsetInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0});
SetVec4InputColors(kOffsetInput);
AddInput(kExposureInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0});
SetVec4InputColors(kExposureInput);
AddInput(kSaturationInput, NodeValue::kFloat, 1.0);
SetInputProperty(kSaturationInput, QStringLiteral("min"), 0.0);
@@ -124,4 +127,12 @@ void OCIOGradingTransformLinearNode::ConfigChanged()
GenerateProcessor();
}
void OCIOGradingTransformLinearNode::SetVec4InputColors(const QString &input)
{
SetInputProperty(input, QStringLiteral("color0"), QColor(255, 0, 0).name());
SetInputProperty(input, QStringLiteral("color1"), QColor(0, 255, 0).name());
SetInputProperty(input, QStringLiteral("color2"), QColor(0, 0, 255).name());
SetInputProperty(input, QStringLiteral("color3"), QColor(192, 192, 192).name());
}
}
@@ -55,6 +55,9 @@ class OCIOGradingTransformLinearNode : public OCIOBaseNode
protected slots:
virtual void ConfigChanged() override;
private:
void SetVec4InputColors(const QString &input);
};
} // olive
@@ -654,6 +654,23 @@ void NodeParamViewWidgetBridge::SetProperty(const QString &key, const QVariant &
}
UpdateWidgetValues();
} else if (key.startsWith(QStringLiteral("color"))) {
QColor c(value.toString());
int tracks = NodeValue::get_number_of_keyframe_tracks(data_type);
if (key.size() == 5) {
// Set for all tracks
for (int i=0; i<tracks; i++) {
static_cast<SliderBase*>(widgets_.at(i))->SetColor(c);
}
} else {
bool ok;
int element = key.mid(5).toInt(&ok);
if (ok && element >= 0 && element < tracks) {
static_cast<SliderBase*>(widgets_.at(element))->SetColor(c);
}
}
}
}
+5
View File
@@ -55,6 +55,11 @@ public:
UpdateLabel();
}
void SetColor(const QColor &c)
{
label_->SetColor(c);
}
public slots:
void ShowEditor();
+31 -1
View File
@@ -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_);
}
}
}
+8
View File
@@ -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_;
};
}