CuteLogger
Fast and simple logging solution for Qt based applications
colorwheelitem.h
1 /*
2  * Copyright (c) 2013-2018 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  * Author: Brian Matherly <code@brianmatherly.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
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  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef COLORWHEELITEM_H
21 #define COLORWHEELITEM_H
22 
23 #include <QQuickPaintedItem>
24 #include <QImage>
25 
26 class ColorWheelItem : public QQuickPaintedItem
27 {
28  Q_OBJECT
29  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
30  Q_PROPERTY(int red READ red WRITE setRed)
31  Q_PROPERTY(int green READ green WRITE setGreen)
32  Q_PROPERTY(int blue READ blue WRITE setBlue)
33  Q_PROPERTY(qreal redF READ redF WRITE setRedF)
34  Q_PROPERTY(qreal greenF READ greenF WRITE setGreenF)
35  Q_PROPERTY(qreal blueF READ blueF WRITE setBlueF)
36  Q_PROPERTY(qreal step READ step WRITE setStep)
37 public:
38  explicit ColorWheelItem(QQuickItem *parent = 0);
39  QColor color();
40  void setColor(const QColor &color);
41  int red();
42  void setRed(int red);
43  int green();
44  void setGreen(int green);
45  int blue();
46  void setBlue(int blue);
47  qreal redF();
48  void setRedF(qreal red);
49  qreal greenF();
50  void setGreenF(qreal green);
51  qreal blueF();
52  void setBlueF(qreal blue);
53  qreal step();
54  void setStep(qreal blue);
55 
56 
57 signals:
58  void colorChanged(const QColor &color);
59 
60 protected:
61  void mousePressEvent(QMouseEvent *event);
62  void mouseMoveEvent(QMouseEvent *event);
63  void mouseReleaseEvent(QMouseEvent *event);
64  void hoverMoveEvent(QHoverEvent * event);
65  void wheelEvent(QWheelEvent *event);
66  void paint(QPainter *painter);
67 
68 private:
69  QImage m_image;
70  bool m_isMouseDown;
71  QPoint m_lastPoint;
72  QSize m_size;
73  int m_margin;
74  QRegion m_wheelRegion;
75  QRegion m_sliderRegion;
76  QColor m_color;
77  bool m_isInWheel;
78  bool m_isInSquare;
79  qreal m_step;
80 
81  int wheelSize() const;
82  QColor colorForPoint(const QPoint &point);
83  void drawWheel();
84  void drawWheelDot(QPainter &painter);
85  void drawSliderBar(QPainter &painter);
86  void drawSlider();
87  void updateCursor(const QPoint &pos);
88 };
89 
90 #endif // COLORWHEELITEM_H