Navigator2Go  2.0
Manage your local Ocean Navigator installation.
switchwidget.h
1 #ifndef SWITCH_H
2 #define SWITCH_H
3 
4 #include "nodiscard.h"
5 
6 #include <QAbstractButton>
7 
8 /***********************************************************************************/
9 // Forward Declarations
10 class QPropertyAnimation;
11 
12 /***********************************************************************************/
14 class SwitchWidget : public QAbstractButton {
15  Q_OBJECT
16  Q_PROPERTY(int offset READ offset WRITE setOffset)
17  Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
18 
19 public:
20  explicit SwitchWidget(QWidget* parent = nullptr);
21 
22  QSize sizeHint() const override;
23 
24  void setBrush(const QBrush& brsh) {
25  m_brush = brsh;
26  }
27 
28  NODISCARD auto brush() const noexcept {
29  return m_brush;
30  }
31 
32  NODISCARD auto offset() const noexcept {
33  return m_x;
34  }
35 
36  void setOffset(const int o);
37 
38 signals:
39  void toggled(const bool checked);
40 
41 protected:
42  void paintEvent(QPaintEvent* e) override;
43  void mouseReleaseEvent(QMouseEvent* e) override;
44  void enterEvent(QEvent* e) override;
45 
46 private:
47  bool m_switch{true};
48  qreal m_opacity{0.0};
49  int m_x, m_y, m_width{50}, m_height{16}, m_margin{3};
50  QBrush m_thumb{"#d5d5d5"}, m_track, m_brush;
51  QPropertyAnimation* m_anim{nullptr};
52 };
53 
54 #endif // SWITCH_H
A toggleable switch widget.
Definition: switchwidget.h:14