CuteLogger
Fast and simple logging solution for Qt based applications
colorwheelitem.h
1 /*
2  * Copyright (c) 2013-2014 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  * Author: Brian Matherly <pez4brian@yahoo.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 public:
34  explicit ColorWheelItem(QQuickItem *parent = 0);
35  QColor color();
36  void setColor(const QColor &color);
37  int red();
38  void setRed(int red);
39  int green();
40  void setGreen(int green);
41  int blue();
42  void setBlue(int blue);
43 
44 signals:
45  void colorChanged(const QColor &color);
46 
47 protected:
48  void mousePressEvent(QMouseEvent *event);
49  void mouseMoveEvent(QMouseEvent *event);
50  void mouseReleaseEvent(QMouseEvent *event);
51  void hoverMoveEvent(QHoverEvent * event);
52  void paint(QPainter *painter);
53 
54 private:
55  QImage m_image;
56  bool m_isMouseDown;
57  QPoint m_lastPoint;
58  QSize m_size;
59  int m_margin;
60  QRegion m_wheelRegion;
61  QRegion m_sliderRegion;
62  QColor m_color;
63  bool m_isInWheel;
64  bool m_isInSquare;
65 
66  int wheelSize() const;
67  QColor colorForPoint(const QPoint &point);
68  void drawWheel();
69  void drawWheelDot(QPainter &painter);
70  void drawSliderBar(QPainter &painter);
71  void drawSlider();
72  void updateCursor(const QPoint &pos);
73 };
74 
75 #endif // COLORWHEELITEM_H