qt-material-widgets/components/toggle.h

56 lines
1.1 KiB
C
Raw Normal View History

2016-03-25 21:57:51 +00:00
#ifndef TOGGLE_H
#define TOGGLE_H
2016-03-26 10:37:48 +00:00
#include <QAbstractButton>
2016-03-27 14:06:22 +00:00
class QPropertyAnimation;
2016-03-26 10:37:48 +00:00
class RippleOverlay;
class Toggle;
2016-03-26 10:37:48 +00:00
2016-03-26 12:42:21 +00:00
class Thumb : public QWidget
{
Q_OBJECT
2016-03-27 14:06:22 +00:00
Q_PROPERTY(qreal progress WRITE setProgress READ progress)
2016-03-26 12:42:21 +00:00
public:
explicit Thumb(Toggle *parent);
2016-03-26 12:42:21 +00:00
~Thumb();
2016-03-26 12:58:01 +00:00
2016-03-27 14:12:57 +00:00
inline void setProgress(qreal p) { _progress = p; update(); }
2016-03-27 14:06:22 +00:00
inline qreal progress() const { return _progress; }
signals:
void clicked();
2016-03-26 12:58:01 +00:00
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
2016-03-27 14:06:22 +00:00
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
2016-03-26 12:58:01 +00:00
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
2016-03-27 14:06:22 +00:00
private:
Toggle *const _toggle;
QPropertyAnimation *const _animation;
2016-03-27 14:12:57 +00:00
qreal _progress;
2016-03-26 12:42:21 +00:00
};
2016-03-26 10:37:48 +00:00
class Toggle : public QAbstractButton
{
Q_OBJECT
public:
explicit Toggle(QWidget *parent = 0);
~Toggle();
2016-03-27 14:06:22 +00:00
QSize sizeHint() const { return QSize(132, 64); }
2016-03-26 10:37:48 +00:00
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
RippleOverlay *const _overlay;
2016-03-26 12:58:01 +00:00
Thumb *const _thumb;
2016-03-26 10:37:48 +00:00
};
2016-03-25 21:57:51 +00:00
#endif // TOGGLE_H