DtkWidget 5.6.0.2
DTK Widget module
dprintpickcolorwidget.h
1// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DPRINTPICKCOLORWIDGET_H
6#define DPRINTPICKCOLORWIDGET_H
7#include "qdbusinterface.h"
8#include <DFloatingWidget>
9#include <DLabel>
10
11#include <DWidget>
12#include <DPushButton>
13
14class QVBoxLayout;
15DWIDGET_BEGIN_NAMESPACE
16class DIconButton;
17class DLineEdit;
18class DLabel;
19class DSlider;
20
21class ColorButton : public DPushButton
22{
23 Q_OBJECT
24public:
25 ColorButton(QColor color, QWidget *parent = nullptr);
26Q_SIGNALS:
27 void selectColorButton(QColor color);
28 void btnIsChecked(bool checked);
29
30protected:
31 void paintEvent(QPaintEvent *) override;
32
33private:
34 QColor m_color;
35 bool m_flag = false;
36 bool m_checked = false;
37};
38class ColorLabel : public DLabel
39{
40 Q_OBJECT
41public:
42 ColorLabel(DWidget *parent = nullptr);
44
45 //h∈(0, 360), s∈(0, 1), v∈(0, 1)
46 QColor getColor(qreal h, qreal s, qreal v);
47 void setHue(int hue);
48
49 void pickColor(QPoint pos);
50 QCursor pickColorCursor();
51
52Q_SIGNALS:
53 void clicked();
54 void pickedColor(QColor color);
55
56protected:
57 void paintEvent(QPaintEvent *);
58 void enterEvent(QEvent *e);
59 void leaveEvent(QEvent *e);
60 void mousePressEvent(QMouseEvent *e);
61 void mouseMoveEvent(QMouseEvent *e);
62 void mouseReleaseEvent(QMouseEvent *e);
63
64private:
65 QCursor m_lastCursor;
66 int m_hue = 0;
67 bool m_pressed;
68 QColor m_pickedColor;
69 QPoint m_clickedPos;
70 QPoint m_tipPoint;
71};
72class ColorSlider : public QSlider
73{
74 Q_OBJECT
75public:
76 ColorSlider(QWidget *parent = nullptr);
78
79 //h∈(0, 360), s∈(0, 1), v∈(0, 1)
80 QColor getColor(qreal h, qreal s, qreal v);
81
82protected:
83 void paintEvent(QPaintEvent *ev);
84
85private:
86 int m_value;
87 QImage m_backgroundImage;
88};
89class DPrintPickColorWidget : public DWidget
90{
91 Q_OBJECT
92public:
93 DPrintPickColorWidget(QWidget *parent = nullptr);
95 void initUI();
96 void initConnection();
97 void setRgbEdit(QColor color, bool btnColor = false);
98 void convertColor(QColor color, bool btnColor = false);
99Q_SIGNALS:
100 void selectColorButton(QColor color);
101 void signalColorChanged(QColor color);
102public Q_SLOTS:
103 void slotColorPick(QString uuid, QString colorName);
104 void slotEditColor(QString str);
105
106private:
107 QList<ColorButton *> btnlist;
108 QList<QColor> colorList;
109 QButtonGroup *btnGroup;
110 DLineEdit *valueLineEdit;
111 DIconButton *pickColorBtn;
112 QDBusInterface *pinterface;
113 DLineEdit *rEdit;
114 DLineEdit *gEdit;
115 DLineEdit *bEdit;
116 ColorLabel *colorLabel;
117 ColorSlider *colorSlider;
118};
119DWIDGET_END_NAMESPACE
120#endif // DPRINTPICKCOLORWIDGET_H
Definition: dprintpickcolorwidget.h:22
Definition: dprintpickcolorwidget.h:39
Definition: dprintpickcolorwidget.h:73
Definition: diconbutton.h:24
DLabel一个重新实现的 QLabel.
Definition: dlabel.h:18
DLineEdit一个聚合 QLineEdit 的输入框.
Definition: dlineedit.h:20
Definition: dprintpickcolorwidget.h:90