-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtogglebutton.h
More file actions
85 lines (71 loc) · 1.77 KB
/
togglebutton.h
File metadata and controls
85 lines (71 loc) · 1.77 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
#ifndef ANTTOGGLEBUTTON_H
#define ANTTOGGLEBUTTON_H
#include <QColor>
#include <QParallelAnimationGroup>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
#include <QWidget>
class ToggleButton : public QWidget
{
Q_OBJECT
Q_PROPERTY(int m_circleX READ circleX WRITE setCircleX)
Q_PROPERTY(int m_circleWidth READ circleWidth WRITE setCircleWidth)
Q_PROPERTY(QColor m_bgColor READ bgColor WRITE setBgColor)
public:
ToggleButton(QWidget *parent = nullptr);
~ToggleButton();
void setChecked(bool checked);
bool isChecked() const
{
return m_checked;
}
int circleX() const
{
return m_circleX;
}
void setCircleX(int x)
{
m_circleX = x;
update();
}
int circleWidth() const
{
return m_circleWidth;
}
void setCircleWidth(int w)
{
m_circleWidth = w;
update();
}
QColor bgColor() const
{
return m_bgColor;
}
void setBgColor(const QColor &color)
{
m_bgColor = color;
update();
}
void setShowText(bool show);
signals:
void toggled(bool checked);
protected:
void paintEvent(QPaintEvent *) override;
void mousePressEvent(QMouseEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private:
bool m_checked;
bool m_showText = true;
int m_circleX;
int m_circleWidth;
QSize m_size;
QColor m_bgColor;
QColor m_toggleButtonColor;
QColor m_textColor;
QColor m_checkedBgColor;
QColor m_uncheckedBgColor;
QPropertyAnimation *posAnim;
QPropertyAnimation *colorAnim;
QParallelAnimationGroup *groupAnim;
};
#endif // ANTTOGGLEBUTTON_H