colorpicker: implemented color management
Also moves some items to ColorManager from Project for better accessibility and re-uses some widgets in ExportDialog for improved code.
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
|
||||
#include "dialog/color/colordialog.h"
|
||||
|
||||
ColorButton::ColorButton(QWidget *parent) :
|
||||
QPushButton(parent)
|
||||
ColorButton::ColorButton(ColorManager* color_manager, QWidget *parent) :
|
||||
QPushButton(parent),
|
||||
color_manager_(color_manager)
|
||||
{
|
||||
color_ = Color(1.0f, 1.0f, 1.0f);
|
||||
|
||||
@@ -14,7 +15,7 @@ ColorButton::ColorButton(QWidget *parent) :
|
||||
|
||||
void ColorButton::ShowColorDialog()
|
||||
{
|
||||
ColorDialog cd(nullptr, color_, this);
|
||||
ColorDialog cd(color_manager_, color_, this);
|
||||
|
||||
if (cd.exec() == QDialog::Accepted) {
|
||||
color_ = cd.GetSelectedColor();
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "render/color.h"
|
||||
#include "render/colormanager.h"
|
||||
|
||||
class ColorButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ColorButton(QWidget* parent = nullptr);
|
||||
ColorButton(ColorManager* color_manager, QWidget* parent = nullptr);
|
||||
|
||||
signals:
|
||||
void ColorChanged();
|
||||
@@ -20,6 +21,8 @@ private slots:
|
||||
private:
|
||||
void UpdateColor();
|
||||
|
||||
ColorManager* color_manager_;
|
||||
|
||||
Color color_;
|
||||
|
||||
};
|
||||
|
||||
@@ -40,8 +40,7 @@ void ColorGradientWidget::paintEvent(QPaintEvent *e)
|
||||
}
|
||||
|
||||
for (int i=0;i<max;i++) {
|
||||
Color c = LerpColor(start_, end_, i, max);
|
||||
p.setPen(c.toQColor());
|
||||
p.setPen(GetManagedColor(LerpColor(start_, end_, i, max)).toQColor());
|
||||
|
||||
if (orientation_ == Qt::Horizontal) {
|
||||
p.drawLine(i, 0, i, height());
|
||||
@@ -56,20 +55,22 @@ void ColorGradientWidget::paintEvent(QPaintEvent *e)
|
||||
p.setBrush(Qt::NoBrush);
|
||||
|
||||
if (orientation_ == Qt::Horizontal) {
|
||||
p.drawRect(qRound(width() * (1.0 - val_)) - selector_radius, 0, selector_radius * 2, height());
|
||||
p.drawRect(qRound(width() * (1.0 - val_)) - selector_radius, 0, selector_radius * 2, height() - 1);
|
||||
} else {
|
||||
p.drawRect(0, qRound(height() * (1.0 - val_)) - selector_radius, width(), selector_radius * 2);
|
||||
p.drawRect(0, qRound(height() * (1.0 - val_)) - selector_radius, width() - 1, selector_radius * 2);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorGradientWidget::SelectedColorChangedEvent(const Color &c)
|
||||
void ColorGradientWidget::SelectedColorChangedEvent(const Color &c, bool external)
|
||||
{
|
||||
float hue, sat;
|
||||
|
||||
c.toHsv(&hue, &sat, &val_);
|
||||
|
||||
start_ = Color::fromHsv(hue, sat, 1.0);
|
||||
end_ = Color::fromHsv(hue, sat, 0.0);
|
||||
if (external) {
|
||||
start_ = Color::fromHsv(hue, sat, 1.0);
|
||||
end_ = Color::fromHsv(hue, sat, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
Color ColorGradientWidget::LerpColor(const Color &a, const Color &b, int i, int max)
|
||||
|
||||
@@ -15,11 +15,13 @@ protected:
|
||||
|
||||
virtual void paintEvent(QPaintEvent* e) override;
|
||||
|
||||
virtual void SelectedColorChangedEvent(const Color& c) override;
|
||||
virtual void SelectedColorChangedEvent(const Color& c, bool external) override;
|
||||
|
||||
private:
|
||||
static Color LerpColor(const Color& a, const Color& b, int i, int max);
|
||||
|
||||
QPixmap cached_gradient_;
|
||||
|
||||
Qt::Orientation orientation_;
|
||||
|
||||
Color start_;
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include "render/backend/opengl/openglrenderfunctions.h"
|
||||
|
||||
ColorSwatchWidget::ColorSwatchWidget(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
QWidget(parent),
|
||||
to_linear_processor_(nullptr),
|
||||
to_display_processor_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,18 +16,26 @@ const Color &ColorSwatchWidget::GetSelectedColor() const
|
||||
return selected_color_;
|
||||
}
|
||||
|
||||
void ColorSwatchWidget::SetColorProcessor(ColorProcessorPtr to_linear, ColorProcessorPtr to_display)
|
||||
{
|
||||
to_linear_processor_ = to_linear;
|
||||
to_display_processor_ = to_display;
|
||||
|
||||
// Force full update
|
||||
SelectedColorChangedEvent(GetSelectedColor(), true);
|
||||
update();
|
||||
}
|
||||
|
||||
void ColorSwatchWidget::SetSelectedColor(const Color &c)
|
||||
{
|
||||
selected_color_ = c;
|
||||
SelectedColorChangedEvent(c);
|
||||
update();
|
||||
SetSelectedColorInternal(c, true);
|
||||
}
|
||||
|
||||
void ColorSwatchWidget::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
QWidget::mousePressEvent(e);
|
||||
|
||||
SetSelectedColor(GetColorFromScreenPos(e->pos()));
|
||||
SetSelectedColorInternal(GetColorFromScreenPos(e->pos()), false);
|
||||
emit SelectedColorChanged(GetSelectedColor());
|
||||
}
|
||||
|
||||
@@ -34,12 +44,12 @@ void ColorSwatchWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
QWidget::mouseMoveEvent(e);
|
||||
|
||||
if (e->buttons() & Qt::LeftButton) {
|
||||
SetSelectedColor(GetColorFromScreenPos(e->pos()));
|
||||
SetSelectedColorInternal(GetColorFromScreenPos(e->pos()), false);
|
||||
emit SelectedColorChanged(GetSelectedColor());
|
||||
}
|
||||
}
|
||||
|
||||
void ColorSwatchWidget::SelectedColorChangedEvent(const Color &)
|
||||
void ColorSwatchWidget::SelectedColorChangedEvent(const Color &, bool)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -53,3 +63,19 @@ Qt::GlobalColor ColorSwatchWidget::GetUISelectorColor() const
|
||||
return Qt::white;
|
||||
}
|
||||
}
|
||||
|
||||
Color ColorSwatchWidget::GetManagedColor(const Color &input) const
|
||||
{
|
||||
if (to_linear_processor_ && to_display_processor_) {
|
||||
return to_display_processor_->ConvertColor(to_linear_processor_->ConvertColor(input));
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
void ColorSwatchWidget::SetSelectedColorInternal(const Color &c, bool external)
|
||||
{
|
||||
selected_color_ = c;
|
||||
SelectedColorChangedEvent(c, external);
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "render/backend/opengl/openglshader.h"
|
||||
#include "render/color.h"
|
||||
#include "render/colorprocessor.h"
|
||||
|
||||
class ColorSwatchWidget : public QWidget
|
||||
{
|
||||
@@ -14,6 +15,8 @@ public:
|
||||
|
||||
const Color& GetSelectedColor() const;
|
||||
|
||||
void SetColorProcessor(ColorProcessorPtr to_linear, ColorProcessorPtr to_display);
|
||||
|
||||
public slots:
|
||||
void SetSelectedColor(const Color& c);
|
||||
|
||||
@@ -27,13 +30,21 @@ protected:
|
||||
|
||||
virtual Color GetColorFromScreenPos(const QPoint& p) const = 0;
|
||||
|
||||
virtual void SelectedColorChangedEvent(const Color& c);
|
||||
virtual void SelectedColorChangedEvent(const Color& c, bool external);
|
||||
|
||||
Qt::GlobalColor GetUISelectorColor() const;
|
||||
|
||||
Color GetManagedColor(const Color& input) const;
|
||||
|
||||
private:
|
||||
void SetSelectedColorInternal(const Color& c, bool external);
|
||||
|
||||
Color selected_color_;
|
||||
|
||||
ColorProcessorPtr to_linear_processor_;
|
||||
|
||||
ColorProcessorPtr to_display_processor_;
|
||||
|
||||
};
|
||||
|
||||
#endif // COLORSWATCHWIDGET_H
|
||||
|
||||
@@ -49,7 +49,7 @@ void ColorWheelWidget::paintEvent(QPaintEvent *e)
|
||||
Triangle tri = GetTriangleFromCoords(center, j, i);
|
||||
|
||||
if (tri.hypotenuse <= radius) {
|
||||
QColor c = GetColorFromTriangle(tri).toQColor();
|
||||
QColor c = GetManagedColor(GetColorFromTriangle(tri)).toQColor();
|
||||
|
||||
// Very basic antialiasing around the edges of the wheel
|
||||
qreal alpha = qMin(1.0, radius - tri.hypotenuse);
|
||||
@@ -93,10 +93,12 @@ void ColorWheelWidget::paintEvent(QPaintEvent *e)
|
||||
p.drawEllipse(GetCoordsFromColor(GetSelectedColor()), selector_radius, selector_radius);
|
||||
}
|
||||
|
||||
void ColorWheelWidget::SelectedColorChangedEvent(const Color &c)
|
||||
void ColorWheelWidget::SelectedColorChangedEvent(const Color &c, bool external)
|
||||
{
|
||||
force_redraw_ = true;
|
||||
val_ = c.value();
|
||||
if (external) {
|
||||
force_redraw_ = true;
|
||||
val_ = c.value();
|
||||
}
|
||||
}
|
||||
|
||||
int ColorWheelWidget::GetDiameter() const
|
||||
|
||||
@@ -23,7 +23,7 @@ protected:
|
||||
|
||||
virtual void paintEvent(QPaintEvent* e) override;
|
||||
|
||||
virtual void SelectedColorChangedEvent(const Color& c) override;
|
||||
virtual void SelectedColorChangedEvent(const Color& c, bool external) override;
|
||||
|
||||
private:
|
||||
int GetDiameter() const;
|
||||
|
||||
@@ -94,7 +94,8 @@ void NodeParamViewWidgetBridge::CreateWidgets()
|
||||
break;
|
||||
case NodeParam::kColor:
|
||||
{
|
||||
ColorButton* color_button = new ColorButton();
|
||||
// NOTE: Very convoluted way to get back to the project's color manager
|
||||
ColorButton* color_button = new ColorButton(static_cast<Sequence*>(input_->parentNode()->parent())->project()->color_manager());
|
||||
widgets_.append(color_button);
|
||||
connect(color_button, &ColorButton::ColorChanged, this, &NodeParamViewWidgetBridge::WidgetCallback);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user