tahoma2d/toonz/sources/include/toonzqt/styleeditor.h

757 lines
21 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef STYLEEDITOR_H
#define STYLEEDITOR_H
// TnzCore includes
#include "tcommon.h"
#include "tfilepath.h"
#include "tpixel.h"
#include "tpalette.h"
#include "saveloadqsettings.h"
2016-03-19 06:57:51 +13:00
// TnzLib includes
#include "toonz/tpalettehandle.h"
#include "toonz/txshlevelhandle.h"
#include "toonz/txshlevel.h"
// TnzQt includes
#include "toonzqt/checkbox.h"
#include "toonzqt/intfield.h"
#include "toonzqt/doublefield.h"
#include "toonzqt/colorfield.h"
#include "toonzqt/tabbar.h"
2017-04-19 22:31:31 +12:00
#include "toonzqt/glwidget_for_highdpi.h"
2016-03-19 06:57:51 +13:00
// Qt includes
#include <QWidget>
#include <QFrame>
#include <QTabBar>
#include <QSlider>
#include <QToolButton>
#include <QScrollArea>
#include <QMouseEvent>
#include <QPointF>
#include <QSettings>
#include <QSplitter>
2016-03-19 06:57:51 +13:00
#undef DVAPI
#undef DVVAR
#ifdef TOONZQT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//=============================================
// Forward declarations
class TColorStyle;
class TPalette;
class TXshLevelHandle;
class PaletteController;
class QGridLayout;
class QLabel;
class QStackedWidget;
class QSlider;
class QRadioButton;
class QButtonGroup;
class QPushButton;
class QTabWidget;
class QToolBar;
2018-02-19 16:06:07 +13:00
class QOpenGLFramebufferObject;
2016-03-19 06:57:51 +13:00
class ColorSquaredWheel;
class TabBarContainter;
class StyleChooser;
class StyleEditor;
2018-03-14 19:32:28 +13:00
class LutCalibrator;
2016-03-19 06:57:51 +13:00
//=============================================
//=============================================================================
2016-06-15 18:43:10 +12:00
namespace StyleEditorGUI {
2016-03-19 06:57:51 +13:00
//=============================================================================
enum ColorChannel {
2016-06-15 18:43:10 +12:00
eRed = 0,
eGreen,
eBlue,
eAlpha,
eHue,
eSaturation,
eValue
2016-03-19 06:57:51 +13:00
};
//=============================================================================
/*! \brief The ColorModel provides an object to manage color change and
2016-06-15 18:43:10 +12:00
its transformation from rgb value to hsv value and vice versa.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
This object change color using its rgb channel or its hsv
channel;
if you change a color channel class assure you that other
channel not change.
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
class DVAPI ColorModel {
int m_channels[7];
void rgb2hsv();
void hsv2rgb();
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ColorModel();
void setTPixel(const TPixel32 &color);
TPixel32 getTPixel() const;
void setValue(ColorChannel channel, int value);
void setValues(ColorChannel channel, int u, int v);
int getValue(ColorChannel channel) const;
void getValues(ColorChannel channel, int &u, int &v);
inline int r() const { return m_channels[0]; }
inline int g() const { return m_channels[1]; }
inline int b() const { return m_channels[2]; }
inline int a() const { return m_channels[3]; }
inline int h() const { return m_channels[4]; }
inline int s() const { return m_channels[5]; }
inline int v() const { return m_channels[6]; }
bool operator==(const ColorModel &cm) {
int i;
for (i = 0; i < 7; i++)
if (m_channels[i] != cm.getValue(ColorChannel(i))) return false;
return true;
}
2016-03-19 06:57:51 +13:00
};
//=============================================
2016-06-15 18:43:10 +12:00
enum CurrentWheel { none, leftWheel, rightTriangle };
2016-03-19 06:57:51 +13:00
2017-04-19 22:31:31 +12:00
class DVAPI HexagonalColorWheel final : public GLWidgetForHighDpi {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// backgoround color (R160, G160, B160)
QColor m_bgColor;
Q_PROPERTY(QColor BGColor READ getBGColor WRITE setBGColor)
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ColorModel m_color;
QPointF m_wheelPosition;
float m_triEdgeLen;
float m_triHeight;
QPointF m_wp[7], m_leftp[3];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
CurrentWheel m_currentWheel;
2016-03-19 06:57:51 +13:00
2018-02-19 16:06:07 +13:00
// used for color calibration with 3DLUT
QOpenGLFramebufferObject *m_fbo = NULL;
2018-03-14 19:32:28 +13:00
LutCalibrator *m_lutCalibrator = NULL;
2016-03-19 06:57:51 +13:00
bool m_firstInitialized = true;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
void drawCurrentColorMark();
void clickLeftWheel(const QPoint &pos);
void clickRightTriangle(const QPoint &pos);
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
HexagonalColorWheel(QWidget *parent);
void setColor(const ColorModel &color) { m_color = color; };
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
~HexagonalColorWheel();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setBGColor(const QColor &color) { m_bgColor = color; }
QColor getBGColor() const { return m_bgColor; }
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void initializeGL() override;
void resizeGL(int width, int height) override;
void paintGL() override;
2016-06-15 18:43:10 +12:00
QSize SizeHint() const { return QSize(300, 200); };
2016-06-19 20:06:29 +12:00
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void colorChanged(const ColorModel &color, bool isDragging);
2018-03-14 19:32:28 +13:00
public slots:
void onContextAboutToBeDestroyed();
2016-03-19 06:57:51 +13:00
};
//=============================================================================
/*! \brief The SquaredColorWheel is a squared color to change color.
2016-06-15 18:43:10 +12:00
Inherits \b QWidget.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
This object show a square faded from one color channel to
another color channel,
the two channel represent x and y axis of square.
It's possible to choose viewed shade using \b setChannel().
Click in square change current SquaredColorWheel.
2016-03-19 06:57:51 +13:00
*/
class DVAPI SquaredColorWheel final : public QWidget {
2016-06-15 18:43:10 +12:00
Q_OBJECT
ColorChannel m_channel;
ColorModel m_color;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
SquaredColorWheel(QWidget *parent);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! Doesn't call update(). */
void setColor(const ColorModel &color);
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *event) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void click(const QPoint &pos);
2016-06-19 20:06:29 +12:00
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
2016-03-19 06:57:51 +13:00
public slots:
2016-06-15 18:43:10 +12:00
/*! Connect channels to the two square axes:
\li eRed : connect x-axis to eGreen and y-axis to eBlue;
\li eGreen : connect x-axis to eRed and y-axis to eBlue;
\li eBlue : connect x-axis to eRed and y-axis to eGreen;
\li eHue : connect x-axis to eSaturation and y-axis to eValue;
\li eSaturation : connect x-axis to eHue and y-axis to eValue;
\li eValue : connect x-axis to eHue and y-axis to eSaturation;
*/
void setChannel(int channel);
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void colorChanged(const ColorModel &color, bool isDragging);
2016-03-19 06:57:51 +13:00
};
//=============================================================================
/*! \brief The ColorSlider is used to set a color channel.
2016-06-15 18:43:10 +12:00
Inherits \b QSlider.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
This object show a bar which colors differ from minimum to
maximum channel color
value.
2016-03-19 06:57:51 +13:00
*/
class DVAPI ColorSlider final : public QSlider {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ColorSlider(Qt::Orientation orientation, QWidget *parent = 0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! set channel and color. doesn't call update(). */
void setChannel(ColorChannel channel);
void setColor(const ColorModel &color);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ColorChannel getChannel() const { return m_channel; }
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// QIcon getFirstArrowIcon();
// QIcon getLastArrowIcon();
// QRect getFirstArrowRect();
// QRect getLastArrowRect();
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
ColorChannel m_channel;
ColorModel m_color;
2016-03-19 06:57:51 +13:00
};
//=============================================================================
// ArrowButton
class ArrowButton final : public QToolButton {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Qt::Orientation m_orientaion;
bool m_isFirstArrow;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_timerId;
int m_firstTimerId;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ArrowButton(QWidget *parent = 0, Qt::Orientation orientation = Qt::Horizontal,
bool m_isFirstArrow = true);
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
void stopTime(int timerId);
2016-06-19 20:06:29 +12:00
void timerEvent(QTimerEvent *event) override;
2016-06-15 18:43:10 +12:00
void notifyChanged();
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onPressed();
void onRelease();
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void add();
void remove();
2016-03-19 06:57:51 +13:00
};
//=============================================================================
2016-06-15 18:43:10 +12:00
/*! \brief The ColorSliderBar is a colorSlider with two arrow to add or remove
one to current value.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Inherits \b QToolBar.
2016-03-19 06:57:51 +13:00
*/
class DVAPI ColorSliderBar final : public QWidget {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ColorSlider *m_colorSlider;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ColorSliderBar(QWidget *parent = 0,
Qt::Orientation orientation = Qt::Vertical);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setValue(int value) { m_colorSlider->setValue(value); }
void setRange(int minValue, int maxValue) {
m_colorSlider->setRange(minValue, maxValue);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setChannel(ColorChannel channel) {
return m_colorSlider->setChannel(channel);
}
void setColor(const ColorModel &color) {
return m_colorSlider->setColor(color);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ColorChannel getChannel() const { return m_colorSlider->getChannel(); }
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onRemove();
void onAdd();
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void valueChanged(int);
void valueChanged();
2016-03-19 06:57:51 +13:00
};
//=============================================================================
2016-06-15 18:43:10 +12:00
/*! \brief The ChannelLineEdit is a cutomized version of IntLineEdit for channel
value.
2016-03-19 06:57:51 +13:00
It calls selectAll() at the moment of the first click.
*/
class ChannelLineEdit final : public DVGui::IntLineEdit {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_isEditing;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ChannelLineEdit(QWidget *parent, int value, int minValue, int maxValue)
: IntLineEdit(parent, value, minValue, maxValue), m_isEditing(false) {}
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void mousePressEvent(QMouseEvent *) override;
void focusOutEvent(QFocusEvent *) override;
void paintEvent(QPaintEvent *) override;
2016-03-19 06:57:51 +13:00
};
//=============================================================================
/*! \brief ColorChannelControl is the widget used to show/edit a channel
2016-06-15 18:43:10 +12:00
Inherits \b QWidget.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
The ColorChannelControl is composed of three object: a label \b
QLabel
to show the channel name, and an \b IntLineEdit and a
ColorSlider to show/edit the
channel value.
2016-03-19 06:57:51 +13:00
*/
class DVAPI ColorChannelControl final : public QWidget {
2016-06-15 18:43:10 +12:00
Q_OBJECT
QLabel *m_label;
ChannelLineEdit *m_field;
ColorSlider *m_slider;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ColorChannel m_channel;
ColorModel m_color;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_value;
bool m_signalEnabled;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ColorChannelControl(ColorChannel channel, QWidget *parent = 0);
void setColor(const ColorModel &color);
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onFieldChanged();
void onSliderChanged(int value);
void onSliderReleased();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void onAddButtonClicked();
void onSubButtonClicked();
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void colorChanged(const ColorModel &color, bool isDragging);
2016-03-19 06:57:51 +13:00
};
//=============================================================================
/*! \brief The StyleEditorPage is the base class of StyleEditor pages.
2016-06-15 18:43:10 +12:00
Inherits \b QFrame.
Inherited by \b PlainColorPage and \b StyleChooserPage.
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
class StyleEditorPage : public QFrame {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
StyleEditorPage(QWidget *parent);
2016-03-19 06:57:51 +13:00
};
//=============================================================================
/*! \brief The ColorParameterSelector is used for styles having more
than one color parameter to select the current one.
2016-06-15 18:43:10 +12:00
Inherits \b QWidget.
2016-03-19 06:57:51 +13:00
*/
class ColorParameterSelector final : public QWidget {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::vector<QColor> m_colors;
int m_index;
const QSize m_chipSize;
const QPoint m_chipOrigin, m_chipDelta;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ColorParameterSelector(QWidget *parent);
int getSelected() const { return m_index; }
void setStyle(const TColorStyle &style);
void clear();
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void colorParamChanged();
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *) override;
void mousePressEvent(QMouseEvent *) override;
2016-03-19 06:57:51 +13:00
};
//=============================================================================
2016-06-15 18:43:10 +12:00
/*! \brief The PlainColorPage is used to control the color parameter.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Inherits \b StyleEditorPage.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
The PlainColorPage is made of a \b SquaredColorWheel and a \b
ColorSlider,
a collection of \b ColorChannelControl, and a number of radio
button (to control
the ColorWheel behaviour).
2016-03-19 06:57:51 +13:00
*/
class PlainColorPage final : public StyleEditorPage {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// ColorSliderBar *m_verticalSlider;
// QRadioButton *m_modeButtons[7];
ColorChannelControl *m_channelControls[7];
// SquaredColorWheel *m_squaredColorWheel; //iwsw not used
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
HexagonalColorWheel *m_hexagonalColorWheel;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ColorModel m_color;
bool m_signalEnabled;
bool m_isVertical = true;
int m_visibleParts;
2016-06-15 18:43:10 +12:00
void updateControls();
// QGridLayout *m_mainLayout;
QFrame *m_slidersContainer;
QSplitter *m_vSplitter;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
PlainColorPage(QWidget *parent = 0);
~PlainColorPage() {}
2016-03-19 06:57:51 +13:00
QFrame *m_wheelFrame;
QFrame *m_hsvFrame;
QFrame *m_alphaFrame;
QFrame *m_rgbFrame;
2016-06-15 18:43:10 +12:00
void setColor(const TColorStyle &style, int colorParameterIndex);
void setIsVertical(bool isVertical);
bool getIsVertical() { return m_isVertical; }
QByteArray getSplitterState();
void setSplitterState(QByteArray state);
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void resizeEvent(QResizeEvent *) override;
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void colorChanged(const ColorModel &, bool isDragging);
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onWheelChanged(const ColorModel &color, bool isDragging);
// void onWheelSliderChanged(int value);
// void onWheelSliderReleased();
2016-03-19 06:57:51 +13:00
public slots:
2016-06-15 18:43:10 +12:00
// void setWheelChannel(int channel);
void onControlChanged(const ColorModel &color, bool isDragging);
void toggleOrientation();
2016-03-19 06:57:51 +13:00
};
//=============================================================================
2016-06-15 18:43:10 +12:00
/*! \brief The StyleChooserPage is the base class of pages with texture,
special style and custom style. It features a collection of selectable
'chips'.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Inherits \b StyleEditorPage.
2016-03-19 06:57:51 +13:00
*/
2016-06-15 18:43:10 +12:00
class StyleChooserPage : public StyleEditorPage {
Q_OBJECT
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
QPoint m_chipOrigin;
QSize m_chipSize;
int m_chipPerRow;
static TFilePath m_rootPath;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
StyleChooserPage(QWidget *parent = 0);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QSize getChipSize() const { return m_chipSize; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual bool loadIfNeeded() = 0;
virtual int getChipCount() const = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void drawChip(QPainter &p, QRect rect, int index) = 0;
virtual void onSelect(int index) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! \see StyleEditor::setRootPath()
// TOGLIERE
static void setRootPath(const TFilePath &rootPath);
static TFilePath getRootPath() { return m_rootPath; }
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
int m_currentIndex;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int posToIndex(const QPoint &pos) const;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void paintEvent(QPaintEvent *) override;
void resizeEvent(QResizeEvent *) override { computeSize(); }
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override {}
void mouseReleaseEvent(QMouseEvent *event) override;
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void computeSize();
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void styleSelected(const TColorStyle &style);
2016-03-19 06:57:51 +13:00
};
//=============================================================================
/*!
\brief The SettingsPage is used to show/edit style parameters.
\details This class stores the GUI for editing a \a copy of the
current color style. Updates of the actual current color
style are \a not performed directly by this class.
*/
class SettingsPage final : public QScrollArea {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QGridLayout *m_paramsLayout;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QCheckBox *m_autoFillCheckBox;
QWidget *m_autopaintToggleBox;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TColorStyleP m_editedStyle; //!< A copy of the current style being edited by
2016-06-20 14:23:05 +12:00
//! the Style Editor.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool
m_updating; //!< Whether the page is copying style content to its widget,
//! to be displayed.
private:
int getParamIndex(const QWidget *widget);
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
SettingsPage(QWidget *parent);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setStyle(const TColorStyleP &editedStyle);
void updateValues();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void enableAutopaintToggle(bool enabled);
2016-03-19 06:57:51 +13:00
signals:
2016-06-15 18:43:10 +12:00
void paramStyleChanged(
bool isDragging); //!< Signals that the edited style has changed.
2016-03-19 06:57:51 +13:00
private slots:
2016-06-15 18:43:10 +12:00
void onAutofillChanged();
void onValueChanged(bool isDragging = false);
void onValueReset();
2016-03-19 06:57:51 +13:00
};
//=============================================================================
2016-06-15 18:43:10 +12:00
} // namespace StyleEditorGUI
2016-03-19 06:57:51 +13:00
//=============================================================================
using namespace StyleEditorGUI;
//=============================================================================
// StyleEditor
//-----------------------------------------------------------------------------
class DVAPI StyleEditor final : public QWidget, public SaveLoadQSettings {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PaletteController *m_paletteController;
TPaletteHandle *m_paletteHandle;
TPaletteHandle *m_cleanupPaletteHandle;
QWidget *m_parent;
2016-06-15 18:43:10 +12:00
TXshLevelHandle
*m_levelHandle; //!< for clearing the level cache when the color changed
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DVGui::TabBar *m_styleBar;
QStackedWidget *m_styleChooser;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DVGui::StyleSample
*m_newColor; //!< New style viewer (lower-right panel side).
DVGui::StyleSample
*m_oldColor; //!< Old style viewer (lower-right panel side).
QPushButton *m_toggleOrientationButton;
2016-06-15 18:43:10 +12:00
QPushButton
*m_autoButton; //!< "Auto Apply" checkbox on the right panel side.
QPushButton *m_applyButton; //!< "Apply" button on the right panel side.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QToolBar *m_toolBar; //!< Lower toolbar.
ColorParameterSelector *m_colorParameterSelector; //!< Secondary color
2016-06-20 14:23:05 +12:00
//! parameter selector in
//! the lower toolbar.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TabBarContainter *m_tabBarContainer; //!< Tabs container for style types.
2016-03-19 06:57:51 +13:00
// QLabel *m_statusLabel; //!< showing the information of the current palette
//! and style.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PlainColorPage *m_plainColorPage;
StyleChooserPage *m_textureStylePage;
StyleEditorPage *m_specialStylePage;
StyleChooserPage *m_customStylePage;
StyleChooserPage *m_vectorBrushesStylePage;
StyleChooserPage *m_mypaintBrushesStylePage;
2016-06-15 18:43:10 +12:00
SettingsPage *m_settingsPage;
QScrollArea *m_vectorArea;
QAction *m_wheelAction;
QAction *m_hsvAction;
QAction *m_alphaAction;
QAction *m_rgbAction;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TColorStyleP
m_oldStyle; //!< A copy of current style \a before the last change.
TColorStyleP m_editedStyle; //!< The currently edited style. Please observe
2016-06-20 14:23:05 +12:00
//! that this is
2016-06-15 18:43:10 +12:00
//! a \b copy of currently selected style, since style edits
//! may be not <I>automatically applied</I>.
bool m_enabled;
bool m_enabledOnlyFirstTab;
bool m_enabledFirstAndLastTab;
bool m_colorPageIsVertical = true;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
StyleEditor(PaletteController *, QWidget *parent = 0);
~StyleEditor();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setPaletteHandle(TPaletteHandle *paletteHandle);
TPaletteHandle *getPaletteHandle() const { return m_paletteHandle; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setLevelHandle(TXshLevelHandle *levelHandle) {
m_levelHandle = levelHandle;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPalette *getPalette() { return m_paletteHandle->getPalette(); }
int getStyleIndex() { return m_paletteHandle->getStyleIndex(); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! rootPath generally is STUFFDIR/Library. Contains directories 'textures'
and
'custom styles' */
// TOGLIERE
void setRootPath(const TFilePath &rootPath);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void enableAutopaintToggle(bool enabled) {
m_settingsPage->enableAutopaintToggle(enabled);
}
2016-03-19 06:57:51 +13:00
// SaveLoadQSettings
virtual void save(QSettings &settings) const override;
virtual void load(QSettings &settings) override;
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
/*! Return false if style is linked and style must be set to null.*/
bool setStyle(TColorStyle *currentStyle);
void setEditedStyleToStyle(const TColorStyle *style); //!< Clones the
2016-06-20 14:23:05 +12:00
//! supplied style and
//! considers that as
//! the edited one.
2016-06-15 18:43:10 +12:00
void setOldStyleToStyle(const TColorStyle *style); //!< Clones the supplied
2016-06-20 14:23:05 +12:00
//! style and considers
//! that as the previously
//! current one.
2016-06-15 18:43:10 +12:00
//! \todo Why is this not assimilated to setCurrentStyleToStyle()?
/*! Return style parameter index selected in \b ColorParameterSelector. */
int getColorParam() const { return m_colorParameterSelector->getSelected(); }
/*! Set StyleEditor view to \b enabled. If \b enabledOnlyFirstTab or if \b
enabledFirstAndLastTab
is true hide other tab, pay attention \b enabled must be true
or StyleEditor is disabled. */
void enable(bool enabled, bool enabledOnlyFirstTab = false,
bool enabledFirstAndLastTab = false);
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void showEvent(QShowEvent *) override;
void hideEvent(QHideEvent *) override;
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void onStyleSwitched();
2017-11-07 20:24:20 +13:00
void onStyleChanged(bool isDragging);
void onCleanupStyleChanged(bool isDragging);
2016-06-15 18:43:10 +12:00
void onOldStyleClicked(const TColorStyle &);
void updateOrientationButton();
2016-06-15 18:43:10 +12:00
// called (e.g.) by PaletteController when an other StyleEditor change the
// toggle
void enableColorAutoApply(bool enabled);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// when colorAutoApply==false this slot is called when the current color
// changes
void setColorSample(const TPixel32 &color);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// chiamato quando viene modificato uno slider o la color wheel
void onColorChanged(const ColorModel &, bool isDragging);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void selectStyle(const TColorStyle &style);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void applyButtonClicked();
void autoCheckChanged(bool value);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setPage(int index);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void onColorParamChanged();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void onParamStyleChanged(bool isDragging);
2016-03-19 06:57:51 +13:00
void onSpecialButtonToggled(bool on);
void onCustomButtonToggled(bool on);
void onVectorBrushButtonToggled(bool on);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
QFrame *createBottomWidget();
QFrame *createVectorPage();
2016-06-15 18:43:10 +12:00
void updateTabBar();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void copyEditedStyleToPalette(bool isDragging);
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // STYLEEDITOR_H