All Classes Namespaces Functions Variables Enumerations Properties Pages
colorslider.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #ifndef COLORSLIDER_H
18 #define COLORSLIDER_H
19 
20 #include <QWidget>
21 
22 
23 class ColorSlider : public QWidget
24 {
25  Q_OBJECT
26 public:
27 
28  enum ColorType {
29  HUE,
30  SAT,
31  VAL,
32  RED,
33  GREEN,
34  BLUE,
35  ALPHA
36  };
37  enum ColorSpecType {
38  RGB,
39  HSV,
40  HSL,
41  CMYK
42  };
43 
44  explicit ColorSlider(QWidget* parent);
45  ~ColorSlider() override;
46 
47  void init(ColorSpecType specType, ColorType type, const QColor &color, qreal min, qreal max);
48 
49  QLinearGradient setColorSpec(const QColor &color);
50 
51  QColor color() { return mColor; }
52 
53  void setHsv(const QColor& hsv) { mColor.setHsv(hsv.hsvHue(),
54  hsv.hsvSaturation(),
55  hsv.value(),
56  hsv.alpha());
57  }
58 
59  void setRgb(const QColor& rgb) { mColor.setRgb(rgb.red(),
60  rgb.green(),
61  rgb.blue(),
62  rgb.alpha());
63  }
64 
65  void setColorSpecType(ColorSpecType newType) { this->mSpecType = newType; }
66  void setColorType(ColorType newType) { this->mColorType = newType; }
67 
68  void setMin(qreal min) { mMin = min; }
69  void setMax(qreal max) { mMax = max; }
70 
71  QSize sizeHint() const override;
72 
73 protected:
74  void paintEvent(QPaintEvent* event) override;
75  void mouseMoveEvent(QMouseEvent* event) override;
76  void mousePressEvent(QMouseEvent* event) override;
77 
78 signals:
79  void valueChanged(QColor color);
80 
81 private:
82 
83  void drawColorBox(const QColor &color, QSize size);
84  void drawPicker(const QColor &color);
85  QLinearGradient hsvGradient(const QColor &color);
86  QLinearGradient rgbGradient(const QColor &color);
87 
88  void colorPicked(QPoint point);
89 
90  QPixmap mBoxPixmapSource;
91 
92  QColor mColor;
93  qreal mMin = 0.0;
94  qreal mMax = 0.0;
95 
96  ColorType mColorType = ColorType::HUE;
97  ColorSpecType mSpecType = ColorSpecType::RGB;
98 
99  QLinearGradient mGradient;
100 };
101 
102 #endif // COLORSLIDER_H
int value() const const
void setRgb(int r, int g, int b, int a)
QSize size() const const
Q_OBJECTQ_OBJECT
int red() const const
int alpha() const const
int green() const const
int blue() const const
void setHsv(int h, int s, int v, int a)
int hsvHue() const const
QObject * parent() const const
virtual bool event(QEvent *event) override
int hsvSaturation() const const