qt-material-widgets/components/qtmaterialtoggle_internal.h

128 lines
2.5 KiB
C
Raw Normal View History

2017-09-29 16:52:33 +00:00
#ifndef QTMATERIALTOGGLE_INTERNAL_H
#define QTMATERIALTOGGLE_INTERNAL_H
#include <QtWidgets/QWidget>
#include <QtWidgets/QGraphicsDropShadowEffect>
#include <QPainter>
#include <QEvent>
2017-09-29 16:52:33 +00:00
#include "lib/qtmaterialrippleoverlay.h"
2022-02-17 03:12:00 +00:00
namespace md
{
2017-09-29 16:52:33 +00:00
2022-02-17 03:12:00 +00:00
class Toggle;
class ToggleThumb;
class ToggleTrack;
2017-09-29 16:52:33 +00:00
2022-02-17 03:12:00 +00:00
class ToggleRippleOverlay : public RippleOverlay
2017-09-29 16:52:33 +00:00
{
Q_OBJECT
public:
2022-02-17 03:12:00 +00:00
ToggleRippleOverlay(ToggleThumb *thumb,
ToggleTrack *track,
Toggle *parent);
~ToggleRippleOverlay();
2017-09-29 16:52:33 +00:00
protected slots:
void addToggleRipple();
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
QRect overlayGeometry() const Q_DECL_OVERRIDE;
private:
2022-02-17 03:12:00 +00:00
Q_DISABLE_COPY(ToggleRippleOverlay)
2017-09-29 16:52:33 +00:00
2022-02-17 03:12:00 +00:00
Toggle *const m_toggle;
ToggleThumb *const m_thumb;
ToggleTrack *const m_track;
2017-09-29 16:52:33 +00:00
};
2022-02-17 03:12:00 +00:00
class ToggleThumb : public QWidget
2017-09-29 16:52:33 +00:00
{
Q_OBJECT
Q_PROPERTY(qreal shift WRITE setShift READ shift)
Q_PROPERTY(QColor thumbColor WRITE setThumbColor READ thumbColor)
public:
2022-02-17 03:12:00 +00:00
ToggleThumb(Toggle *parent);
~ToggleThumb();
2017-09-29 16:52:33 +00:00
void setShift(qreal shift);
inline qreal shift() const;
inline qreal offset() const;
inline void setThumbColor(const QColor &color);
inline QColor thumbColor() const;
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
2022-02-17 03:12:00 +00:00
Q_DISABLE_COPY(ToggleThumb)
2017-09-29 16:52:33 +00:00
void updateOffset();
2022-02-17 03:12:00 +00:00
Toggle *const m_toggle;
2017-09-29 16:52:33 +00:00
QColor m_thumbColor;
qreal m_shift;
qreal m_offset;
};
2022-02-17 03:12:00 +00:00
inline qreal ToggleThumb::shift() const
2017-09-29 16:52:33 +00:00
{
return m_shift;
}
2022-02-17 03:12:00 +00:00
inline qreal ToggleThumb::offset() const
2017-09-29 16:52:33 +00:00
{
return m_offset;
}
2022-02-17 03:12:00 +00:00
inline void ToggleThumb::setThumbColor(const QColor &color)
2017-09-29 16:52:33 +00:00
{
m_thumbColor = color;
update();
}
2022-02-17 03:12:00 +00:00
inline QColor ToggleThumb::thumbColor() const
2017-09-29 16:52:33 +00:00
{
return m_thumbColor;
}
2022-02-17 03:12:00 +00:00
class ToggleTrack : public QWidget
2017-09-29 16:52:33 +00:00
{
Q_OBJECT
Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor)
public:
2022-02-17 03:12:00 +00:00
ToggleTrack(Toggle *parent);
~ToggleTrack();
2017-09-29 16:52:33 +00:00
void setTrackColor(const QColor &color);
inline QColor trackColor() const;
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
2022-02-17 03:12:00 +00:00
Q_DISABLE_COPY(ToggleTrack)
2017-09-29 16:52:33 +00:00
2022-02-17 03:12:00 +00:00
Toggle *const m_toggle;
2017-09-29 16:52:33 +00:00
QColor m_trackColor;
};
2022-02-17 03:12:00 +00:00
inline QColor ToggleTrack::trackColor() const
2017-09-29 16:52:33 +00:00
{
return m_trackColor;
}
2022-02-17 03:12:00 +00:00
}
2017-09-29 16:52:33 +00:00
#endif // QTMATERIALTOGGLE_INTERNAL_H