-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_button.h
More file actions
122 lines (92 loc) · 3.73 KB
/
switch_button.h
File metadata and controls
122 lines (92 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef SWITCHBUTTON_H
#define SWITCHBUTTON_H
#include <QWidget>
#include <QTimer>
#include <QColor>
class SwitchButton : public QWidget
{
Q_OBJECT
// Q_PROPERTY(int m_space READ space WRITE setSpace)
// Q_PROPERTY(int m_radius READ radius WRITE setRadius)
// Q_PROPERTY(bool m_checked READ checked WRITE setChecked)
// Q_PROPERTY(bool m_showText READ showText WRITE setShowText)
// Q_PROPERTY(bool m_showCircle READ showCircel WRITE setShowCircle)
// Q_PROPERTY(bool m_animation READ animation WRITE setAnimation)
// Q_PROPERTY(QColor m_bgColorOn READ bgColorOn WRITE setBgColorOn)
// Q_PROPERTY(QColor m_bgColorOff READ bgColorOff WRITE setBgColorOff)
// Q_PROPERTY(QColor m_sliderColorOn READ sliderColorOn WRITE setSliderColorOn)
// Q_PROPERTY(QColor m_sliderColorOff READ sliderColorOff WRITE setSliderColorOff)
// Q_PROPERTY(QColor m_textColor READ textColor WRITE setTextColor)
// Q_PROPERTY(QString m_textOn READ textOn WRITE setTextOn)
// Q_PROPERTY(QString m_textOff READ textOff WRITE setTextOff)
// Q_PROPERTY(int m_step READ step WRITE setStep)
// Q_PROPERTY(int m_startX READ startX WRITE setStartX)
// Q_PROPERTY(int m_endX READ endX WRITE setEndX)
public:
explicit SwitchButton(QWidget *parent = 0);
~SwitchButton(){}
signals:
void statusChanged(bool checked);
public slots:
private slots:
void updateValue();
private:
void drawBackGround(QPainter *painter);
void drawSlider(QPainter *painter);
protected:
void paintEvent(QPaintEvent *ev);
void mousePressEvent(QMouseEvent *ev);
private:
int m_space; //滑块距离边界距离
int m_radius; //圆角角度
bool m_checked; //是否选中
bool m_showText; //是否显示文字
bool m_showCircle; //是否显示圆圈
bool m_animation; //是否使用动画
QColor m_bgColorOn; //打开时候的背景色
QColor m_bgColorOff; //关闭时候的背景色
QColor m_sliderColorOn; //打开时候滑块颜色
QColor m_sliderColorOff; //关闭时候滑块颜色
QColor m_textColor; //文字颜色
QString m_textOn; //打开时候的文字
QString m_textOff; //关闭时候的文字
QTimer *m_timer; //动画定时器
int m_step; //动画步长
int m_startX; //滑块开始X轴坐标
int m_endX; //滑块结束X轴坐标
public:
int space() const;
int radius() const;
bool checked() const;
bool showText() const;
bool showCircel() const;
bool animation() const;
QColor bgColorOn() const;
QColor bgColorOff() const;
QColor sliderColorOn() const;
QColor sliderColorOff() const;
QColor textColor() const;
QString textOn() const;
QString textOff() const;
int step() const;
int startX() const;
int endX() const;
public Q_SLOTS:
void setSpace(int space);
void setRadius(int radius);
void setChecked(bool checked);
void setShowText(bool show);
void setShowCircle(bool show);
void setAnimation(bool ok);
void setBgColorOn(const QColor &color);
void setBgColorOff(const QColor &color);
void setSliderColorOn(const QColor &color);
void setSliderColorOff(const QColor &color);
void setTextColor(const QColor &color);
void setTextOn(const QString &text);
void setTextOff(const QString &text);
// void setStep(int step);
// void setStartX(int startX);
// void setEndX(int endX);
};
#endif // SWITCHBUTTON_H