File: toggleswitch.h

package info (click to toggle)
openterface-qt 0.1.0%2Bds-1
  • links: PTS
  • area: main
  • in suites: experimental
  • size: 1,444 kB
  • sloc: cpp: 9,552; sh: 127; python: 57; ansic: 4; makefile: 4
file content (52 lines) | stat: -rw-r--r-- 1,445 bytes parent folder | download
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
#ifndef TOGGLESWITCH_H
#define TOGGLESWITCH_H

#include <QCheckBox>
#include <QPainter>
#include <QPropertyAnimation>

class ToggleSwitch : public QCheckBox
{
    Q_OBJECT
    Q_PROPERTY(float handlePosition READ handlePosition WRITE setHandlePosition NOTIFY handlePositionChanged)

public:
    explicit ToggleSwitch(QWidget *parent = nullptr,
                          QColor barColor = QColor(242, 145, 58),      // Replace "#F2913A"
                          QColor checkedColor = QColor(242, 145, 58),      // Replace "#F2913A"
                          QColor handleColor = QColor(252, 241, 230),
                          float hScale = 1.0f,
                          float vScale = 1.1f,
                          int fontSize = 9);

    QSize sizeHint() const override;
    bool hitButton(const QPoint &pos) const override;

    float handlePosition() const { return m_handlePosition; }
    void setHandlePosition(float pos);

    void setHScale(float value);
    void setVScale(float value);
    void setFontSize(int value);

signals:
    void handlePositionChanged(float position);

protected:
    void paintEvent(QPaintEvent *e) override;

private slots:
    void handleStateChange(int value);

private:
    QBrush m_barBrush;
    QBrush m_barCheckedBrush;
    QBrush m_handleBrush;
    QBrush m_handleCheckedBrush;
    float m_handlePosition;
    float m_hScale;
    float m_vScale;
    int m_fontSize;
};

#endif // TOGGLESWITCH_H