-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.h
62 lines (49 loc) · 1.28 KB
/
switch.h
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
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#ifndef SWITCH_H
#define SWITCH_H
//#include <QPropertyAnimation>
#include <QBrush>
#include <QAbstractButton>
#include <QPainter>
#include <QMouseEvent>
#include <QtDebug>
class Switch : public QAbstractButton {
Q_OBJECT
//Q_PROPERTY(int offset READ offset WRITE setOffset)
public:
explicit Switch(QWidget *parent = nullptr);
explicit Switch(const QBrush &brush, QWidget *parent = nullptr);
QSize sizeHint() const override;
QBrush brush() const {
return _brush;
}
void setBrush(const QBrush &brsh) {
_brush = brsh;
}
int offset() const {
return _x;
}
void setOffset(int o) {
_x = o;
update();
}
public slots:
void setChecked(bool b);
bool isChecked();
protected:
void paintEvent(QPaintEvent *) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
private:
int _height;
qreal _opacity;
bool _switch;
int _margin;
int _x;
int _y;
QBrush _brush;
//QBrush _thumb, _track, _brush;
//QPropertyAnimation *_anim = nullptr;
};
#endif // SWITCH_H