Skip to content

Commit

Permalink
KnobGuiColor: replace QColorDialog with ColorSelector (#657)
Browse files Browse the repository at this point in the history
* Gui: Added QtColorTriangle from Qt Solutions

Maintained in Natron under the GNU Lesser General Public 2.1 license.

Updated to work in Qt4 and Qt5.

* Gui/ScaleSliderQWidget: support custom slider color

* Gui: added ColorSelectorWidget

* Gui/KnobGuiColor: replace QColorDialog with ColorSelectorWidget

* Gui/ColorSelectorWidget: added tooltips

* Gui/ColorSelectorWidget: added hsv sliders

* Gui/ColorSelectorWidget: minor ui

* Gui/ColorSelectorWidget: ui changes

* Gui/ColorSelectorWidget: hsv slider fix

forgot to set slider value when spinbox changed.
  • Loading branch information
rodlie authored Jul 20, 2021
1 parent f064207 commit b7d8a02
Show file tree
Hide file tree
Showing 10 changed files with 2,797 additions and 112 deletions.
886 changes: 886 additions & 0 deletions Gui/ColorSelectorWidget.cpp

Large diffs are not rendered by default.

156 changes: 156 additions & 0 deletions Gui/ColorSelectorWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of Natron <https://natrongithub.github.io/>,
* (C) 2018-2021 The Natron developers
* (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat
*
* Natron is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Natron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Natron. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */

#ifndef Gui_ColorSelectorWidget_h
#define Gui_ColorSelectorWidget_h

#include "Global/Macros.h"

CLANG_DIAG_OFF(deprecated)
CLANG_DIAG_OFF(uninitialized)
#include <QWidget>
#include <QColor>
#include "Gui/QtColorTriangle.h" // from Qt Solutions
#include <QMouseEvent>
#include <QEvent>
#include <QStackedWidget>
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)

#include "Gui/ScaleSliderQWidget.h"
#include "Gui/SpinBox.h"
#include "Gui/LineEdit.h"
#include "Gui/Button.h"

NATRON_NAMESPACE_ENTER

class ColorSelectorWidget : public QWidget
{
Q_OBJECT

public:

explicit ColorSelectorWidget(QWidget *parent = NULL);
void getColor(float *r, float *g, float *b, float *a);

Q_SIGNALS:

void colorChanged(float r, float g, float b, float a);
void updateColor();

public Q_SLOTS:

void setColor(float r, float g, float b, float a);

private:

SpinBox *_spinR;
SpinBox *_spinG;
SpinBox *_spinB;
SpinBox *_spinH;
SpinBox *_spinS;
SpinBox *_spinV;
SpinBox *_spinA;

ScaleSliderQWidget *_slideR;
ScaleSliderQWidget *_slideG;
ScaleSliderQWidget *_slideB;
ScaleSliderQWidget *_slideH;
ScaleSliderQWidget *_slideS;
ScaleSliderQWidget *_slideV;
ScaleSliderQWidget *_slideA;

QtColorTriangle *_triangle;

LineEdit *_hex;

Button *_button;

QStackedWidget *_stack;

void setRedChannel(float value);
void setGreenChannel(float value);
void setBlueChannel(float value);
void setHueChannel(float value);
void setSaturationChannel(float value);
void setValueChannel(float value);
void setAlphaChannel(float value);
void setTriangle(float r, float g, float b, float a);
void setHex(const QColor &color);

void announceColorChange();

void setTriangleSize();

private Q_SLOTS:

void handleTriangleColorChanged(const QColor &color, bool announce = true);

void manageColorRGBChanged(bool announce = true);
void manageColorHSVChanged(bool announce = true);
void manageColorAlphaChanged(bool announce = true);

void handleSpinRChanged(double value);
void handleSpinGChanged(double value);
void handleSpinBChanged(double value);
void handleSpinHChanged(double value);
void handleSpinSChanged(double value);
void handleSpinVChanged(double value);
void handleSpinAChanged(double value);

void handleHexChanged();

void handleSliderRMoved(double value);
void handleSliderGMoved(double value);
void handleSliderBMoved(double value);
void handleSliderHMoved(double value);
void handleSliderSMoved(double value);
void handleSliderVMoved(double value);
void handleSliderAMoved(double value);

void setSliderHColor();
void setSliderSColor();
void setSliderVColor();

void handleButtonClicked(bool checked);

// workaround for QToolButton+QWidgetAction
// triggered signal(s) are never emitted!?
bool event(QEvent*e) override
{
if (e->type() == QEvent::Show) {
Q_EMIT updateColor();
}
return QWidget::event(e);
}

// https://bugreports.qt.io/browse/QTBUG-47406
void mousePressEvent(QMouseEvent *e) override
{
e->accept();
}
void mouseReleaseEvent(QMouseEvent *e) override
{
e->accept();
}
};

NATRON_NAMESPACE_EXIT

#endif // Gui_ColorSelectorWidget_h
4 changes: 4 additions & 0 deletions Gui/Gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ SOURCES += \
ChannelsComboBox.cpp \
ClickableLabel.cpp \
ColoredFrame.cpp \
ColorSelectorWidget.cpp \
ComboBox.cpp \
CurveEditor.cpp \
CurveEditorUndoRedo.cpp \
Expand Down Expand Up @@ -183,6 +184,7 @@ SOURCES += \
PropertiesBinWrapper.cpp \
PyGuiApp.cpp \
PythonPanels.cpp \
QtColorTriangle.cpp \
QtEnumConvert.cpp \
RenderStatsDialog.cpp \
ResizableMessageBox.cpp \
Expand Down Expand Up @@ -235,6 +237,7 @@ HEADERS += \
ChannelsComboBox.h \
ClickableLabel.h \
ColoredFrame.h \
ColorSelectorWidget.h \
ComboBox.h \
CurveEditor.h \
CurveEditorUndoRedo.h \
Expand Down Expand Up @@ -324,6 +327,7 @@ HEADERS += \
PyGuiApp.h \
Pyside_Gui_Python.h \
PythonPanels.h \
QtColorTriangle.h \
QtEnumConvert.h \
RegisteredTabs.h \
RenderStatsDialog.h \
Expand Down
Loading

0 comments on commit b7d8a02

Please sign in to comment.