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 public:
37  explicit ColorWheelItem(QQuickItem *parent = 0);
38  QColor color();
39  void setColor(const QColor &color);
40  int red();
41  void setRed(int red);
42  int green();
43  void setGreen(int green);
44  int blue();
45  void setBlue(int blue);
46  qreal redF();
47  void setRedF(qreal red);
48  qreal greenF();
49  void setGreenF(qreal green);
50  qreal blueF();
51  void setBlueF(qreal blue);
52 
53 signals:
54  void colorChanged(const QColor &color);
55 
56 protected:
57  void mousePressEvent(QMouseEvent *event);
58  void mouseMoveEvent(QMouseEvent *event);
59  void mouseReleaseEvent(QMouseEvent *event);
60  void hoverMoveEvent(QHoverEvent * event);
61  void paint(QPainter *painter);
62 
63 private:
64  QImage m_image;
65  bool m_isMouseDown;
66  QPoint m_lastPoint;
67  QSize m_size;
68  int m_margin;
69  QRegion m_wheelRegion;
70  QRegion m_sliderRegion;
71  QColor m_color;
72  bool m_isInWheel;
73  bool m_isInSquare;
74 
75  int wheelSize() const;
76  QColor colorForPoint(const QPoint &point);
77  void drawWheel();
78  void drawWheelDot(QPainter &painter);
79  void drawSliderBar(QPainter &painter);
80  void drawSlider();
81  void updateCursor(const QPoint &pos);
82 };
83 
84 #endif // COLORWHEELITEM_H