qt-material-widgets/components/slider.h

68 lines
1.7 KiB
C
Raw Normal View History

2016-03-22 14:16:49 +00:00
#ifndef SLIDER_H
#define SLIDER_H
#include <QWidget>
2016-03-23 05:35:41 +00:00
#include <QPoint>
class Slider;
2016-03-22 14:16:49 +00:00
2016-03-22 15:05:02 +00:00
class Handle : public QWidget
{
Q_OBJECT
public:
2016-03-23 05:35:41 +00:00
explicit Handle(Slider *slider);
2016-03-22 15:05:02 +00:00
~Handle();
2016-03-26 10:37:26 +00:00
Q_DECL_OVERRIDE
2016-03-23 05:35:41 +00:00
inline QSize sizeHint() const { return QSize(16, 16); }
2016-03-25 20:37:59 +00:00
inline void setRelativePosition(const QPoint &pos) { setPosition(_offset + pos); }
2016-03-25 20:30:28 +00:00
inline void setPosition(const QPoint &pos) { _position = pos; refreshGeometry(); }
inline const QPoint &position() const { return _position; }
2016-03-25 20:37:59 +00:00
2016-03-25 20:30:28 +00:00
inline void setOffset(const QPoint &offset) { _offset = offset; update(); }
inline const QPoint &offset() const { return _offset; }
2016-03-25 20:37:59 +00:00
void refreshGeometry();
2016-03-23 05:35:41 +00:00
2016-03-22 15:05:02 +00:00
protected:
2016-03-26 10:37:26 +00:00
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
2016-03-23 05:35:41 +00:00
private:
Slider *const _slider;
QPoint _position;
2016-03-23 05:35:41 +00:00
QPoint _eventPos;
QPoint _offset;
2016-03-22 15:05:02 +00:00
};
2016-03-22 14:16:49 +00:00
class Slider : public QWidget
{
Q_OBJECT
public:
explicit Slider(QWidget *parent = 0);
~Slider();
2016-03-22 15:05:02 +00:00
2016-03-23 05:35:41 +00:00
inline void setOrientation(Qt::Orientation orientation) { _orientation = orientation; }
inline Qt::Orientation orientation() const { return _orientation; }
2016-03-22 15:05:02 +00:00
protected:
2016-03-26 10:37:26 +00:00
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
2016-03-22 15:05:02 +00:00
private:
2016-03-25 21:27:49 +00:00
inline bool touchesRail(int p, int x) const { return (p >= x-2 && p < x+2); }
2016-03-25 20:30:28 +00:00
bool _drag;
2016-03-23 05:35:41 +00:00
Handle *const _handle;
Qt::Orientation _orientation;
2016-03-22 14:16:49 +00:00
};
#endif // SLIDER_H