qt-material-widgets/components/qtmaterialslider_internal.h

225 lines
4.9 KiB
C
Raw Normal View History

2017-09-29 13:53:18 +00:00
#ifndef QTMATERIALSLIDER_INTERNAL_H
#define QTMATERIALSLIDER_INTERNAL_H
#include <QStateMachine>
#include "lib/qtmaterialoverlaywidget.h"
2022-02-17 02:51:42 +00:00
namespace md
{
2017-09-29 13:53:18 +00:00
2022-02-17 02:51:42 +00:00
class Slider;
class SliderThumb;
class SliderTrack;
2017-09-29 13:53:18 +00:00
2022-02-17 02:51:42 +00:00
class SliderStateMachine : public QStateMachine
2017-09-29 13:53:18 +00:00
{
Q_OBJECT
public:
2022-02-17 02:51:42 +00:00
SliderStateMachine(Slider *slider,
SliderThumb *thumb,
SliderTrack *track);
~SliderStateMachine();
2017-09-29 13:53:18 +00:00
void setupProperties();
private:
2022-02-17 02:51:42 +00:00
Q_DISABLE_COPY(SliderStateMachine)
2017-09-29 13:53:18 +00:00
2022-02-17 02:51:42 +00:00
Slider *const m_slider;
SliderThumb *const m_thumb;
SliderTrack *const m_track;
2017-09-29 13:53:18 +00:00
QState *const m_topState;
QState *const m_fstState;
QState *const m_sndState;
QState *const m_inactiveState;
QState *const m_focusState;
QState *const m_slidingState;
QState *const m_pulseOutState;
QState *const m_pulseInState;
QState *const m_minState;
QState *const m_normalState;
};
2022-02-17 02:51:42 +00:00
class SliderThumb : public OverlayWidget
2017-09-29 13:53:18 +00:00
{
Q_OBJECT
Q_PROPERTY(qreal diameter WRITE setDiameter READ diameter)
Q_PROPERTY(qreal borderWidth WRITE setBorderWidth READ borderWidth)
Q_PROPERTY(QColor borderColor WRITE setBorderColor READ borderColor)
Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize)
Q_PROPERTY(QColor haloColor WRITE setHaloColor READ haloColor)
public:
2022-02-17 02:51:42 +00:00
explicit SliderThumb(Slider *slider);
~SliderThumb();
2017-09-29 13:53:18 +00:00
inline void setDiameter(qreal diameter);
inline qreal diameter() const;
inline void setBorderWidth(qreal width);
inline qreal borderWidth() const;
inline void setBorderColor(const QColor &color);
inline QColor borderColor() const;
inline void setFillColor(const QColor &color);
inline QColor fillColor() const;
inline void setHaloSize(qreal size);
inline qreal haloSize() const;
inline void setHaloColor(const QColor &color);
inline QColor haloColor() const;
inline void setOffset(int offset);
inline int offset() const;
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
2022-02-17 02:51:42 +00:00
Q_DISABLE_COPY(SliderThumb)
2017-09-29 13:53:18 +00:00
2022-02-17 02:51:42 +00:00
const Slider *const m_slider;
2017-09-29 13:53:18 +00:00
QColor m_borderColor;
QColor m_fillColor;
QColor m_haloColor;
qreal m_diameter;
qreal m_borderWidth;
qreal m_haloSize;
int m_offset;
};
2022-02-17 02:51:42 +00:00
inline void SliderThumb::setDiameter(qreal diameter)
2017-09-29 13:53:18 +00:00
{
m_diameter = diameter;
update();
}
2022-02-17 02:51:42 +00:00
inline qreal SliderThumb::diameter() const
2017-09-29 13:53:18 +00:00
{
return m_diameter;
}
2022-02-17 02:51:42 +00:00
inline void SliderThumb::setBorderWidth(qreal width)
2017-09-29 13:53:18 +00:00
{
m_borderWidth = width;
update();
}
2022-02-17 02:51:42 +00:00
inline qreal SliderThumb::borderWidth() const
2017-09-29 13:53:18 +00:00
{
return m_borderWidth;
}
2022-02-17 02:51:42 +00:00
inline void SliderThumb::setBorderColor(const QColor &color)
2017-09-29 13:53:18 +00:00
{
m_borderColor = color;
update();
}
2022-02-17 02:51:42 +00:00
inline QColor SliderThumb::borderColor() const
2017-09-29 13:53:18 +00:00
{
return m_borderColor;
}
2022-02-17 02:51:42 +00:00
inline void SliderThumb::setFillColor(const QColor &color)
2017-09-29 13:53:18 +00:00
{
m_fillColor = color;
update();
}
2022-02-17 02:51:42 +00:00
inline QColor SliderThumb::fillColor() const
2017-09-29 13:53:18 +00:00
{
return m_fillColor;
}
2022-02-17 02:51:42 +00:00
inline void SliderThumb::setHaloSize(qreal size)
2017-09-29 13:53:18 +00:00
{
m_haloSize = size;
update();
}
2022-02-17 02:51:42 +00:00
inline qreal SliderThumb::haloSize() const
2017-09-29 13:53:18 +00:00
{
return m_haloSize;
}
2022-02-17 02:51:42 +00:00
inline void SliderThumb::setHaloColor(const QColor &color)
2017-09-29 13:53:18 +00:00
{
m_haloColor = color;
update();
}
2022-02-17 02:51:42 +00:00
inline QColor SliderThumb::haloColor() const
2017-09-29 13:53:18 +00:00
{
return m_haloColor;
}
2022-02-17 02:51:42 +00:00
inline void SliderThumb::setOffset(int offset)
2017-09-29 13:53:18 +00:00
{
m_offset = offset;
update();
}
2022-02-17 02:51:42 +00:00
inline int SliderThumb::offset() const
2017-09-29 13:53:18 +00:00
{
return m_offset;
}
2022-02-17 02:51:42 +00:00
class SliderTrack : public OverlayWidget
2017-09-29 13:53:18 +00:00
{
Q_OBJECT
Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
public:
2022-02-17 02:51:42 +00:00
explicit SliderTrack(SliderThumb *thumb, Slider *slider);
~SliderTrack();
2017-09-29 13:53:18 +00:00
inline void setFillColor(const QColor &color);
inline QColor fillColor() const;
inline void setTrackWidth(int width);
inline int trackWidth() const;
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
2022-02-17 02:51:42 +00:00
Q_DISABLE_COPY(SliderTrack)
2017-09-29 13:53:18 +00:00
2022-02-17 02:51:42 +00:00
const Slider *const m_slider;
SliderThumb *const m_thumb;
2017-09-29 13:53:18 +00:00
QColor m_fillColor;
int m_trackWidth;
};
2022-02-17 02:51:42 +00:00
inline void SliderTrack::setFillColor(const QColor &color)
2017-09-29 13:53:18 +00:00
{
m_fillColor = color;
update();
}
2022-02-17 02:51:42 +00:00
inline QColor SliderTrack::fillColor() const
2017-09-29 13:53:18 +00:00
{
return m_fillColor;
}
2022-02-17 02:51:42 +00:00
void SliderTrack::setTrackWidth(int width)
2017-09-29 13:53:18 +00:00
{
m_trackWidth = width;
update();
}
2022-02-17 02:51:42 +00:00
int SliderTrack::trackWidth() const
2017-09-29 13:53:18 +00:00
{
return m_trackWidth;
}
2022-02-17 02:51:42 +00:00
}
2017-09-29 13:53:18 +00:00
#endif // QTMATERIALSLIDER_INTERNAL_H