qt-material-widgets/components/toggle.h

71 lines
1.5 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 19:48:32 +00:00
Q_PROPERTY(qreal progress WRITE setProgress READ progress NOTIFY progressChanged)
2016-03-27 14:06:22 +00:00
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-28 08:51:24 +00:00
void setProgress(qreal progress);
2016-03-27 14:06:22 +00:00
inline qreal progress() const { return _progress; }
2016-03-29 20:28:40 +00:00
inline void setOffset(int offset) { _offset = offset; }
2016-03-27 19:48:32 +00:00
inline int offset() const { return _offset; }
2016-03-27 14:06:22 +00:00
signals:
void clicked();
2016-03-27 19:48:32 +00:00
void progressChanged(qreal);
2016-03-27 14:06:22 +00:00
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-27 19:48:32 +00:00
int _offset;
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-28 08:51:24 +00:00
QSize sizeHint() const;
inline Qt::Orientation orientation() const { return _orientation; }
void setOrientation(Qt::Orientation orientation);
2016-03-27 19:48:32 +00:00
protected slots:
2016-03-29 20:46:50 +00:00
void addRipple();
void updateOverlayGeometry();
2016-03-26 10:37:48 +00:00
protected:
2016-03-27 19:48:32 +00:00
bool event(QEvent *event) Q_DECL_OVERRIDE;
2016-03-26 10:37:48 +00:00
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
2016-03-26 12:58:01 +00:00
Thumb *const _thumb;
2016-03-27 19:48:32 +00:00
RippleOverlay *const _overlay;
2016-03-28 08:51:24 +00:00
Qt::Orientation _orientation;
2016-03-26 10:37:48 +00:00
};
2016-03-25 21:57:51 +00:00
#endif // TOGGLE_H