DtkWidget
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#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
59 void enterEvent(QEvent *e);
60#else
61 void enterEvent(QEnterEvent *e);
62#endif
63 void leaveEvent(QEvent *e);
64 void mousePressEvent(QMouseEvent *e);
65 void mouseMoveEvent(QMouseEvent *e);
66 void mouseReleaseEvent(QMouseEvent *e);
67
68private:
69 QCursor m_lastCursor;
70 int m_hue = 0;
71 bool m_pressed;
72 QColor m_pickedColor;
73 QPoint m_clickedPos;
74 QPoint m_tipPoint;
75};
76class ColorSlider : public QSlider
77{
78 Q_OBJECT
79public:
80 ColorSlider(QWidget *parent = nullptr);
82
83 //h∈(0, 360), s∈(0, 1), v∈(0, 1)
84 QColor getColor(qreal h, qreal s, qreal v);
85
86protected:
87 void paintEvent(QPaintEvent *ev);
88
89private:
90 int m_value;
91 QImage m_backgroundImage;
92};
93class DPrintPickColorWidget : public DWidget
94{
95 Q_OBJECT
96public:
97 DPrintPickColorWidget(QWidget *parent = nullptr);
99 void initUI();
100 void initConnection();
101 void setRgbEdit(QColor color, bool btnColor = false);
102 void convertColor(QColor color, bool btnColor = false);
103Q_SIGNALS:
104 void selectColorButton(QColor color);
105 void signalColorChanged(QColor color);
106public Q_SLOTS:
107 void slotColorPick(QString uuid, QString colorName);
108 void slotEditColor(QString str);
109
110private:
111 QList<ColorButton *> btnlist;
112 QList<QColor> colorList;
113 QButtonGroup *btnGroup;
114 DLineEdit *valueLineEdit;
115 DIconButton *pickColorBtn;
116 QDBusInterface *pinterface;
117 DLineEdit *rEdit;
118 DLineEdit *gEdit;
119 DLineEdit *bEdit;
120 ColorLabel *colorLabel;
121 ColorSlider *colorSlider;
122};
123DWIDGET_END_NAMESPACE
124#endif // DPRINTPICKCOLORWIDGET_H
Definition dprintpickcolorwidget.h:22
Definition dprintpickcolorwidget.h:39
Definition dprintpickcolorwidget.h:77
按钮的图标
Definition diconbutton.h:24
DLabel一个重新实现的 QLabel。
Definition dlabel.h:18
DLineEdit一个聚合 QLineEdit 的输入框.
Definition dlineedit.h:20
Definition dprintpickcolorwidget.h:94