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 <QImage>
24#include <QQuickPaintedItem>
25
26class 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)
37public:
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
56signals:
57 void colorChanged(const QColor &color);
58
59protected:
60 void mousePressEvent(QMouseEvent *event);
61 void mouseMoveEvent(QMouseEvent *event);
62 void mouseReleaseEvent(QMouseEvent *event);
63 void hoverMoveEvent(QHoverEvent *event);
64 void wheelEvent(QWheelEvent *event);
65 void paint(QPainter *painter);
66
67private:
68 QImage m_image;
69 bool m_isMouseDown;
70 QPoint m_lastPoint;
71 QSize m_size;
72 int m_margin;
73 QRegion m_wheelRegion;
74 QRegion m_sliderRegion;
75 QColor m_color;
76 bool m_isInWheel;
77 bool m_isInSquare;
78 qreal m_step;
79
80 int wheelSize() const;
81 QColor colorForPoint(const QPoint &point);
82 void drawWheel();
83 void drawWheelDot(QPainter &painter);
84 void drawSliderBar(QPainter &painter);
85 void drawSlider();
86 void updateCursor(const QPoint &pos);
87};
88
89#endif // COLORWHEELITEM_H