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 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef COLORWHEELITEM_H
20#define COLORWHEELITEM_H
21
22#include <QImage>
23#include <QQuickPaintedItem>
24
25class ColorWheelItem : public QQuickPaintedItem
26{
27 Q_OBJECT
28 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
29 Q_PROPERTY(int red READ red WRITE setRed)
30 Q_PROPERTY(int green READ green WRITE setGreen)
31 Q_PROPERTY(int blue READ blue WRITE setBlue)
32 Q_PROPERTY(qreal redF READ redF WRITE setRedF)
33 Q_PROPERTY(qreal greenF READ greenF WRITE setGreenF)
34 Q_PROPERTY(qreal blueF READ blueF WRITE setBlueF)
35 Q_PROPERTY(qreal step READ step WRITE setStep)
36public:
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 qreal step();
53 void setStep(qreal blue);
54
55signals:
56 void colorChanged(const QColor &color);
57
58protected:
59 void mousePressEvent(QMouseEvent *event);
60 void mouseMoveEvent(QMouseEvent *event);
61 void mouseReleaseEvent(QMouseEvent *event);
62 void hoverMoveEvent(QHoverEvent *event);
63 void wheelEvent(QWheelEvent *event);
64 void paint(QPainter *painter);
65
66private:
67 QImage m_image;
68 bool m_isMouseDown;
69 QPoint m_lastPoint;
70 QSize m_size;
71 int m_margin;
72 QRegion m_wheelRegion;
73 QRegion m_sliderRegion;
74 QColor m_color;
75 bool m_isInWheel;
76 bool m_isInSquare;
77 qreal m_step;
78
79 int wheelSize() const;
80 QColor colorForPoint(const QPoint &point);
81 void drawWheel();
82 void drawWheelDot(QPainter &painter);
83 void drawSliderBar(QPainter &painter);
84 void drawSlider();
85 void updateCursor(const QPoint &pos);
86};
87
88#endif // COLORWHEELITEM_H