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;
|
2016-03-26 16:26:39 +00:00
|
|
|
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:
|
2016-03-26 16:26:39 +00:00
|
|
|
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-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:
|
2016-03-26 16:26:39 +00:00
|
|
|
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
|
2016-03-28 08:51:24 +00:00
|
|
|
//void mousePressEvent(QMouseEvent *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:
|
|
|
|
void xx();
|
|
|
|
void yy();
|
2016-03-26 12:17:46 +00:00
|
|
|
|
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
|