Chatterino
QColorPicker.hpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 #pragma once
40 
41 #include <QFrame>
42 #include <QSpinBox>
43 
44 namespace chatterino {
45 
46 /*
47  * These classes are literally copied from the Qt source.
48  * Unfortunately, they are private to the QColorDialog class so we cannot use
49  * them directly.
50  * If they become public at any point in the future, it should be possible to
51  * replace every include of this header with the respective includes for the
52  * QColorPicker, QColorLuminancePicker, and QColSpinBox classes.
53  */
54 class QColorPicker : public QFrame
55 {
56  Q_OBJECT
57 public:
58  QColorPicker(QWidget *parent);
59  ~QColorPicker();
60  void setCrossVisible(bool visible);
61 
62 public slots:
63  void setCol(int h, int s);
64 
65 signals:
66  void newCol(int h, int s);
67 
68 protected:
69  QSize sizeHint() const override;
70  void paintEvent(QPaintEvent *) override;
71  void mouseMoveEvent(QMouseEvent *) override;
72  void mousePressEvent(QMouseEvent *) override;
73  void resizeEvent(QResizeEvent *) override;
74 
75 private:
76  int hue;
77  int sat;
78  QPoint colPt();
79  int huePt(const QPoint &pt);
80  int satPt(const QPoint &pt);
81  void setCol(const QPoint &pt);
82  QPixmap pix;
83  bool crossVisible;
84 };
85 
86 static const int COLOR_PICKER_WIDTH = 220;
87 static const int COLOR_PICKER_HEIGHT = 200;
88 
89 class QColorLuminancePicker : public QWidget
90 {
91  Q_OBJECT
92 public:
93  QColorLuminancePicker(QWidget *parent = 0);
95 
96 public slots:
97  void setCol(int h, int s, int v);
98  void setCol(int h, int s);
99 
100 signals:
101  void newHsv(int h, int s, int v);
102 
103 protected:
104  QSize sizeHint() const override;
105  void paintEvent(QPaintEvent *) override;
106  void mouseMoveEvent(QMouseEvent *) override;
107  void mousePressEvent(QMouseEvent *) override;
108 
109 private:
110  enum { foff = 3, coff = 4 }; //frame and contents offset
111  int val;
112  int hue;
113  int sat;
114  int y2val(int y);
115  int val2y(int val);
116  void setVal(int v);
117  QPixmap *pix;
118 };
119 
120 static const int LUMINANCE_PICKER_WIDTH = 25;
121 static const int LUMINANCE_PICKER_HEIGHT = COLOR_PICKER_HEIGHT;
122 
123 class QColSpinBox : public QSpinBox
124 {
125 public:
126  QColSpinBox(QWidget *parent);
127 
128  void setValue(int i);
129 };
130 
131 } // namespace chatterino
QColorPicker(QWidget *parent)
Definition: QColorPicker.cpp:184
void resizeEvent(QResizeEvent *) override
Definition: QColorPicker.cpp:256
Definition: QColorPicker.hpp:54
Definition: QColorPicker.hpp:89
Definition: Application.cpp:48
void mouseMoveEvent(QMouseEvent *) override
Definition: QColorPicker.cpp:227
void setCol(int h, int s)
Definition: QColorPicker.cpp:213
void paintEvent(QPaintEvent *) override
Definition: QColorPicker.cpp:241
Definition: QColorPicker.hpp:123
void mousePressEvent(QMouseEvent *) override
Definition: QColorPicker.cpp:234
~QColorPicker()
Definition: QColorPicker.cpp:195
void newCol(int h, int s)
void setCrossVisible(bool visible)
Definition: QColorPicker.cpp:199
QSize sizeHint() const override
Definition: QColorPicker.cpp:208