Files
dragonpilot/selfdrive/ui/qt/widgets/toggle.h

45 lines
932 B
C
Raw Normal View History

#pragma once
#include <QAbstractButton>
#include <QMouseEvent>
#include <QPropertyAnimation>
class Toggle : public QAbstractButton {
2020-11-27 09:33:52 -08:00
Q_OBJECT
Q_PROPERTY(int offset_circle READ offset_circle WRITE set_offset_circle CONSTANT)
public:
2020-11-27 09:33:52 -08:00
Toggle(QWidget* parent = nullptr);
void togglePosition();
2021-01-27 12:07:17 +01:00
bool on;
int animation_duration = 150;
2021-01-27 12:07:17 +01:00
int immediateOffset = 0;
2020-11-27 09:33:52 -08:00
int offset_circle() const {
return _x_circle;
}
void set_offset_circle(int o) {
_x_circle = o;
update();
}
bool getEnabled();
void setEnabled(bool value);
2021-01-27 12:07:17 +01:00
protected:
2020-11-27 09:33:52 -08:00
void paintEvent(QPaintEvent*) override;
void mouseReleaseEvent(QMouseEvent*) override;
void enterEvent(QEvent*) override;
private:
QColor circleColor;
QColor green;
bool enabled = true;
2020-11-27 09:33:52 -08:00
int _x_circle, _y_circle;
int _height, _radius;
int _height_rect, _y_rect;
QPropertyAnimation *_anim = nullptr;
signals:
void stateChanged(bool new_state);
};