Toggle
This commit is contained in:
parent
a910b39a2f
commit
803bce5281
|
@ -6,28 +6,30 @@
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include "qtmaterialtoggle_internal.h"
|
#include "qtmaterialtoggle_internal.h"
|
||||||
#include "lib/qtmaterialstyle.h"
|
#include "lib/qtmaterialstyle.h"
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialTogglePrivate
|
* \class QtMaterialTogglePrivate
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialTogglePrivate::QtMaterialTogglePrivate(QtMaterialToggle *q)
|
TogglePrivate::TogglePrivate(Toggle *q)
|
||||||
: q_ptr(q)
|
: q_ptr(q)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialTogglePrivate::~QtMaterialTogglePrivate()
|
TogglePrivate::~TogglePrivate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialTogglePrivate::init()
|
void TogglePrivate::init()
|
||||||
{
|
{
|
||||||
Q_Q(QtMaterialToggle);
|
Q_Q(Toggle);
|
||||||
|
|
||||||
track = new QtMaterialToggleTrack(q);
|
track = new ToggleTrack(q);
|
||||||
thumb = new QtMaterialToggleThumb(q);
|
thumb = new ToggleThumb(q);
|
||||||
rippleOverlay = new QtMaterialToggleRippleOverlay(thumb, track, q);
|
rippleOverlay = new ToggleRippleOverlay(thumb, track, q);
|
||||||
stateMachine = new QStateMachine(q);
|
stateMachine = new QStateMachine(q);
|
||||||
offState = new QState;
|
offState = new QState;
|
||||||
onState = new QState;
|
onState = new QState;
|
||||||
|
@ -106,9 +108,9 @@ void QtMaterialTogglePrivate::init()
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialTogglePrivate::setupProperties()
|
void TogglePrivate::setupProperties()
|
||||||
{
|
{
|
||||||
Q_Q(QtMaterialToggle);
|
Q_Q(Toggle);
|
||||||
|
|
||||||
if (q->isEnabled()) {
|
if (q->isEnabled()) {
|
||||||
const qreal shift = thumb->shift();
|
const qreal shift = thumb->shift();
|
||||||
|
@ -134,35 +136,35 @@ void QtMaterialTogglePrivate::setupProperties()
|
||||||
* \class QtMaterialToggle
|
* \class QtMaterialToggle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialToggle::QtMaterialToggle(QWidget *parent)
|
Toggle::Toggle(QWidget *parent)
|
||||||
: QAbstractButton(parent),
|
: QAbstractButton(parent),
|
||||||
d_ptr(new QtMaterialTogglePrivate(this))
|
d_ptr(new TogglePrivate(this))
|
||||||
{
|
{
|
||||||
d_func()->init();
|
d_func()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialToggle::~QtMaterialToggle()
|
Toggle::~Toggle()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggle::setUseThemeColors(bool value)
|
void Toggle::setUseThemeColors(bool value)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialToggle);
|
Q_D(Toggle);
|
||||||
|
|
||||||
d->useThemeColors = value;
|
d->useThemeColors = value;
|
||||||
d->setupProperties();
|
d->setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMaterialToggle::useThemeColors() const
|
bool Toggle::useThemeColors() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialToggle);
|
Q_D(const Toggle);
|
||||||
|
|
||||||
return d->useThemeColors;
|
return d->useThemeColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggle::setDisabledColor(const QColor &color)
|
void Toggle::setDisabledColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialToggle);
|
Q_D(Toggle);
|
||||||
|
|
||||||
d->disabledColor = color;
|
d->disabledColor = color;
|
||||||
|
|
||||||
|
@ -170,20 +172,20 @@ void QtMaterialToggle::setDisabledColor(const QColor &color)
|
||||||
d->setupProperties();
|
d->setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialToggle::disabledColor() const
|
QColor Toggle::disabledColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialToggle);
|
Q_D(const Toggle);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->disabledColor.isValid()) {
|
if (d->useThemeColors || !d->disabledColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("disabled");
|
return Style::instance().themeColor("disabled");
|
||||||
} else {
|
} else {
|
||||||
return d->disabledColor;
|
return d->disabledColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggle::setActiveColor(const QColor &color)
|
void Toggle::setActiveColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialToggle);
|
Q_D(Toggle);
|
||||||
|
|
||||||
d->activeColor = color;
|
d->activeColor = color;
|
||||||
|
|
||||||
|
@ -191,20 +193,20 @@ void QtMaterialToggle::setActiveColor(const QColor &color)
|
||||||
d->setupProperties();
|
d->setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialToggle::activeColor() const
|
QColor Toggle::activeColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialToggle);
|
Q_D(const Toggle);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->activeColor.isValid()) {
|
if (d->useThemeColors || !d->activeColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("primary1");
|
return Style::instance().themeColor("primary1");
|
||||||
} else {
|
} else {
|
||||||
return d->activeColor;
|
return d->activeColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggle::setInactiveColor(const QColor &color)
|
void Toggle::setInactiveColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialToggle);
|
Q_D(Toggle);
|
||||||
|
|
||||||
d->inactiveColor = color;
|
d->inactiveColor = color;
|
||||||
|
|
||||||
|
@ -212,20 +214,20 @@ void QtMaterialToggle::setInactiveColor(const QColor &color)
|
||||||
d->setupProperties();
|
d->setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialToggle::inactiveColor() const
|
QColor Toggle::inactiveColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialToggle);
|
Q_D(const Toggle);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->inactiveColor.isValid()) {
|
if (d->useThemeColors || !d->inactiveColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("canvas");
|
return Style::instance().themeColor("canvas");
|
||||||
} else {
|
} else {
|
||||||
return d->inactiveColor;
|
return d->inactiveColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggle::setTrackColor(const QColor &color)
|
void Toggle::setTrackColor(const QColor &color)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialToggle);
|
Q_D(Toggle);
|
||||||
|
|
||||||
d->trackColor = color;
|
d->trackColor = color;
|
||||||
|
|
||||||
|
@ -233,20 +235,20 @@ void QtMaterialToggle::setTrackColor(const QColor &color)
|
||||||
d->setupProperties();
|
d->setupProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QtMaterialToggle::trackColor() const
|
QColor Toggle::trackColor() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialToggle);
|
Q_D(const Toggle);
|
||||||
|
|
||||||
if (d->useThemeColors || !d->trackColor.isValid()) {
|
if (d->useThemeColors || !d->trackColor.isValid()) {
|
||||||
return QtMaterialStyle::instance().themeColor("accent3");
|
return Style::instance().themeColor("accent3");
|
||||||
} else {
|
} else {
|
||||||
return d->trackColor;
|
return d->trackColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggle::setOrientation(Qt::Orientation orientation)
|
void Toggle::setOrientation(Qt::Orientation orientation)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialToggle);
|
Q_D(Toggle);
|
||||||
|
|
||||||
if (d->orientation == orientation) {
|
if (d->orientation == orientation) {
|
||||||
return;
|
return;
|
||||||
|
@ -256,25 +258,25 @@ void QtMaterialToggle::setOrientation(Qt::Orientation orientation)
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::Orientation QtMaterialToggle::orientation() const
|
Qt::Orientation Toggle::orientation() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialToggle);
|
Q_D(const Toggle);
|
||||||
|
|
||||||
return d->orientation;
|
return d->orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize QtMaterialToggle::sizeHint() const
|
QSize Toggle::sizeHint() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialToggle);
|
Q_D(const Toggle);
|
||||||
|
|
||||||
return Qt::Horizontal == d->orientation
|
return Qt::Horizontal == d->orientation
|
||||||
? QSize(64, 48)
|
? QSize(64, 48)
|
||||||
: QSize(48, 64);
|
: QSize(48, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMaterialToggle::event(QEvent *event)
|
bool Toggle::event(QEvent *event)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialToggle);
|
Q_D(Toggle);
|
||||||
|
|
||||||
switch (event->type())
|
switch (event->type())
|
||||||
{
|
{
|
||||||
|
@ -292,7 +294,8 @@ bool QtMaterialToggle::event(QEvent *event)
|
||||||
return QAbstractButton::event(event);
|
return QAbstractButton::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggle::paintEvent(QPaintEvent *event)
|
void Toggle::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
#define QTMATERIALTOGGLE_H
|
#define QTMATERIALTOGGLE_H
|
||||||
|
|
||||||
#include <QtWidgets/QAbstractButton>
|
#include <QtWidgets/QAbstractButton>
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
|
|
||||||
class QtMaterialTogglePrivate;
|
class TogglePrivate;
|
||||||
|
|
||||||
class QtMaterialToggle : public QAbstractButton
|
class Toggle : public QAbstractButton
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -15,8 +17,8 @@ class QtMaterialToggle : public QAbstractButton
|
||||||
Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor)
|
Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QtMaterialToggle(QWidget *parent = 0);
|
explicit Toggle(QWidget *parent = 0);
|
||||||
~QtMaterialToggle();
|
~Toggle();
|
||||||
|
|
||||||
void setUseThemeColors(bool value);
|
void setUseThemeColors(bool value);
|
||||||
bool useThemeColors() const;
|
bool useThemeColors() const;
|
||||||
|
@ -42,11 +44,11 @@ protected:
|
||||||
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
const QScopedPointer<QtMaterialTogglePrivate> d_ptr;
|
const QScopedPointer<TogglePrivate> d_ptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialToggle)
|
Q_DISABLE_COPY(Toggle)
|
||||||
Q_DECLARE_PRIVATE(QtMaterialToggle)
|
Q_DECLARE_PRIVATE(Toggle)
|
||||||
};
|
};
|
||||||
|
}
|
||||||
#endif // QTMATERIALTOGGLE_H
|
#endif // QTMATERIALTOGGLE_H
|
||||||
|
|
|
@ -4,17 +4,19 @@
|
||||||
#include <QtWidgets/QGraphicsDropShadowEffect>
|
#include <QtWidgets/QGraphicsDropShadowEffect>
|
||||||
#include "qtmaterialtoggle.h"
|
#include "qtmaterialtoggle.h"
|
||||||
#include "lib/qtmaterialripple.h"
|
#include "lib/qtmaterialripple.h"
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialToggleRippleOverlay
|
* \class QtMaterialToggleRippleOverlay
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialToggleRippleOverlay::QtMaterialToggleRippleOverlay(
|
ToggleRippleOverlay::ToggleRippleOverlay(
|
||||||
QtMaterialToggleThumb *thumb,
|
ToggleThumb *thumb,
|
||||||
QtMaterialToggleTrack *track,
|
ToggleTrack *track,
|
||||||
QtMaterialToggle *parent)
|
Toggle *parent)
|
||||||
: QtMaterialRippleOverlay(parent->parentWidget()),
|
: RippleOverlay(parent->parentWidget()),
|
||||||
m_toggle(parent),
|
m_toggle(parent),
|
||||||
m_thumb(thumb),
|
m_thumb(thumb),
|
||||||
m_track(track)
|
m_track(track)
|
||||||
|
@ -24,11 +26,11 @@ QtMaterialToggleRippleOverlay::QtMaterialToggleRippleOverlay(
|
||||||
thumb->installEventFilter(this);
|
thumb->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialToggleRippleOverlay::~QtMaterialToggleRippleOverlay()
|
ToggleRippleOverlay::~ToggleRippleOverlay()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggleRippleOverlay::addToggleRipple()
|
void ToggleRippleOverlay::addToggleRipple()
|
||||||
{
|
{
|
||||||
if (!m_toggle->isEnabled()) {
|
if (!m_toggle->isEnabled()) {
|
||||||
return;
|
return;
|
||||||
|
@ -44,7 +46,7 @@ void QtMaterialToggleRippleOverlay::addToggleRipple()
|
||||||
w = m_thumb->width()/2+10;
|
w = m_thumb->width()/2+10;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialRipple *ripple = new QtMaterialRipple(QPoint(10+t, 20+t));
|
Ripple *ripple = new Ripple(QPoint(10+t, 20+t));
|
||||||
ripple->setColor(m_track->trackColor());
|
ripple->setColor(m_track->trackColor());
|
||||||
ripple->setRadiusEndValue(w);
|
ripple->setRadiusEndValue(w);
|
||||||
ripple->setOpacityStartValue(0.8);
|
ripple->setOpacityStartValue(0.8);
|
||||||
|
@ -52,21 +54,21 @@ void QtMaterialToggleRippleOverlay::addToggleRipple()
|
||||||
addRipple(ripple);
|
addRipple(ripple);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMaterialToggleRippleOverlay::eventFilter(QObject *obj, QEvent *event)
|
bool ToggleRippleOverlay::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if (QEvent::Paint == event->type()) {
|
if (QEvent::Paint == event->type()) {
|
||||||
setGeometry(overlayGeometry());
|
setGeometry(overlayGeometry());
|
||||||
QList<QtMaterialRipple *>::const_iterator i;
|
QList<Ripple *>::const_iterator i;
|
||||||
QList<QtMaterialRipple *> items = ripples();
|
QList<Ripple *> items = ripples();
|
||||||
QColor color = m_track->trackColor();
|
QColor color = m_track->trackColor();
|
||||||
for (i = items.begin(); i != items.end(); ++i) {
|
for (i = items.begin(); i != items.end(); ++i) {
|
||||||
(*i)->setColor(color);
|
(*i)->setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QtMaterialRippleOverlay::eventFilter(obj, event);
|
return RippleOverlay::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect QtMaterialToggleRippleOverlay::overlayGeometry() const
|
QRect ToggleRippleOverlay::overlayGeometry() const
|
||||||
{
|
{
|
||||||
const qreal offset = m_thumb->offset();
|
const qreal offset = m_thumb->offset();
|
||||||
if (Qt::Horizontal == m_toggle->orientation()) {
|
if (Qt::Horizontal == m_toggle->orientation()) {
|
||||||
|
@ -81,7 +83,7 @@ QRect QtMaterialToggleRippleOverlay::overlayGeometry() const
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialToggleThumb::QtMaterialToggleThumb(QtMaterialToggle *parent)
|
ToggleThumb::ToggleThumb(Toggle *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
m_toggle(parent),
|
m_toggle(parent),
|
||||||
m_shift(0),
|
m_shift(0),
|
||||||
|
@ -98,11 +100,11 @@ QtMaterialToggleThumb::QtMaterialToggleThumb(QtMaterialToggle *parent)
|
||||||
parent->installEventFilter(this);
|
parent->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialToggleThumb::~QtMaterialToggleThumb()
|
ToggleThumb::~ToggleThumb()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggleThumb::setShift(qreal shift)
|
void ToggleThumb::setShift(qreal shift)
|
||||||
{
|
{
|
||||||
if (m_shift == shift) {
|
if (m_shift == shift) {
|
||||||
return;
|
return;
|
||||||
|
@ -112,7 +114,7 @@ void QtMaterialToggleThumb::setShift(qreal shift)
|
||||||
updateOffset();
|
updateOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMaterialToggleThumb::eventFilter(QObject *obj, QEvent *event)
|
bool ToggleThumb::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
const QEvent::Type type = event->type();
|
const QEvent::Type type = event->type();
|
||||||
|
|
||||||
|
@ -124,7 +126,7 @@ bool QtMaterialToggleThumb::eventFilter(QObject *obj, QEvent *event)
|
||||||
return QWidget::eventFilter(obj, event);
|
return QWidget::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggleThumb::paintEvent(QPaintEvent *event)
|
void ToggleThumb::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
@ -158,7 +160,7 @@ void QtMaterialToggleThumb::paintEvent(QPaintEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggleThumb::updateOffset()
|
void ToggleThumb::updateOffset()
|
||||||
{
|
{
|
||||||
const QSize s(Qt::Horizontal == m_toggle->orientation()
|
const QSize s(Qt::Horizontal == m_toggle->orientation()
|
||||||
? size() : size().transposed());
|
? size() : size().transposed());
|
||||||
|
@ -171,7 +173,7 @@ void QtMaterialToggleThumb::updateOffset()
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialToggleTrack::QtMaterialToggleTrack(QtMaterialToggle *parent)
|
ToggleTrack::ToggleTrack(Toggle *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
m_toggle(parent)
|
m_toggle(parent)
|
||||||
{
|
{
|
||||||
|
@ -180,17 +182,17 @@ QtMaterialToggleTrack::QtMaterialToggleTrack(QtMaterialToggle *parent)
|
||||||
parent->installEventFilter(this);
|
parent->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialToggleTrack::~QtMaterialToggleTrack()
|
ToggleTrack::~ToggleTrack()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggleTrack::setTrackColor(const QColor &color)
|
void ToggleTrack::setTrackColor(const QColor &color)
|
||||||
{
|
{
|
||||||
m_trackColor = color;
|
m_trackColor = color;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMaterialToggleTrack::eventFilter(QObject *obj, QEvent *event)
|
bool ToggleTrack::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
const QEvent::Type type = event->type();
|
const QEvent::Type type = event->type();
|
||||||
|
|
||||||
|
@ -200,7 +202,7 @@ bool QtMaterialToggleTrack::eventFilter(QObject *obj, QEvent *event)
|
||||||
return QWidget::eventFilter(obj, event);
|
return QWidget::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialToggleTrack::paintEvent(QPaintEvent *event)
|
void ToggleTrack::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
@ -229,3 +231,4 @@ void QtMaterialToggleTrack::paintEvent(QPaintEvent *event)
|
||||||
painter.drawRoundedRect(r.adjusted(4, 14, -4, -14), w/2-4, w/2-4);
|
painter.drawRoundedRect(r.adjusted(4, 14, -4, -14), w/2-4, w/2-4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,20 +3,22 @@
|
||||||
|
|
||||||
#include <QtWidgets/QWidget>
|
#include <QtWidgets/QWidget>
|
||||||
#include "lib/qtmaterialrippleoverlay.h"
|
#include "lib/qtmaterialrippleoverlay.h"
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
|
|
||||||
class QtMaterialToggle;
|
class Toggle;
|
||||||
class QtMaterialToggleThumb;
|
class ToggleThumb;
|
||||||
class QtMaterialToggleTrack;
|
class ToggleTrack;
|
||||||
|
|
||||||
class QtMaterialToggleRippleOverlay : public QtMaterialRippleOverlay
|
class ToggleRippleOverlay : public RippleOverlay
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialToggleRippleOverlay(QtMaterialToggleThumb *thumb,
|
ToggleRippleOverlay(ToggleThumb *thumb,
|
||||||
QtMaterialToggleTrack *track,
|
ToggleTrack *track,
|
||||||
QtMaterialToggle *parent);
|
Toggle *parent);
|
||||||
~QtMaterialToggleRippleOverlay();
|
~ToggleRippleOverlay();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void addToggleRipple();
|
void addToggleRipple();
|
||||||
|
@ -26,14 +28,14 @@ protected:
|
||||||
QRect overlayGeometry() const Q_DECL_OVERRIDE;
|
QRect overlayGeometry() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialToggleRippleOverlay)
|
Q_DISABLE_COPY(ToggleRippleOverlay)
|
||||||
|
|
||||||
QtMaterialToggle *const m_toggle;
|
Toggle *const m_toggle;
|
||||||
QtMaterialToggleThumb *const m_thumb;
|
ToggleThumb *const m_thumb;
|
||||||
QtMaterialToggleTrack *const m_track;
|
ToggleTrack *const m_track;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QtMaterialToggleThumb : public QWidget
|
class ToggleThumb : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -41,8 +43,8 @@ class QtMaterialToggleThumb : public QWidget
|
||||||
Q_PROPERTY(QColor thumbColor WRITE setThumbColor READ thumbColor)
|
Q_PROPERTY(QColor thumbColor WRITE setThumbColor READ thumbColor)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialToggleThumb(QtMaterialToggle *parent);
|
ToggleThumb(Toggle *parent);
|
||||||
~QtMaterialToggleThumb();
|
~ToggleThumb();
|
||||||
|
|
||||||
void setShift(qreal shift);
|
void setShift(qreal shift);
|
||||||
inline qreal shift() const;
|
inline qreal shift() const;
|
||||||
|
@ -57,46 +59,46 @@ protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialToggleThumb)
|
Q_DISABLE_COPY(ToggleThumb)
|
||||||
|
|
||||||
void updateOffset();
|
void updateOffset();
|
||||||
|
|
||||||
QtMaterialToggle *const m_toggle;
|
Toggle *const m_toggle;
|
||||||
QColor m_thumbColor;
|
QColor m_thumbColor;
|
||||||
qreal m_shift;
|
qreal m_shift;
|
||||||
qreal m_offset;
|
qreal m_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline qreal QtMaterialToggleThumb::shift() const
|
inline qreal ToggleThumb::shift() const
|
||||||
{
|
{
|
||||||
return m_shift;
|
return m_shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline qreal QtMaterialToggleThumb::offset() const
|
inline qreal ToggleThumb::offset() const
|
||||||
{
|
{
|
||||||
return m_offset;
|
return m_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QtMaterialToggleThumb::setThumbColor(const QColor &color)
|
inline void ToggleThumb::setThumbColor(const QColor &color)
|
||||||
{
|
{
|
||||||
m_thumbColor = color;
|
m_thumbColor = color;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QColor QtMaterialToggleThumb::thumbColor() const
|
inline QColor ToggleThumb::thumbColor() const
|
||||||
{
|
{
|
||||||
return m_thumbColor;
|
return m_thumbColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
class QtMaterialToggleTrack : public QWidget
|
class ToggleTrack : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor)
|
Q_PROPERTY(QColor trackColor WRITE setTrackColor READ trackColor)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialToggleTrack(QtMaterialToggle *parent);
|
ToggleTrack(Toggle *parent);
|
||||||
~QtMaterialToggleTrack();
|
~ToggleTrack();
|
||||||
|
|
||||||
void setTrackColor(const QColor &color);
|
void setTrackColor(const QColor &color);
|
||||||
inline QColor trackColor() const;
|
inline QColor trackColor() const;
|
||||||
|
@ -106,15 +108,15 @@ protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QtMaterialToggleTrack)
|
Q_DISABLE_COPY(ToggleTrack)
|
||||||
|
|
||||||
QtMaterialToggle *const m_toggle;
|
Toggle *const m_toggle;
|
||||||
QColor m_trackColor;
|
QColor m_trackColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QColor QtMaterialToggleTrack::trackColor() const
|
inline QColor ToggleTrack::trackColor() const
|
||||||
{
|
{
|
||||||
return m_trackColor;
|
return m_trackColor;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif // QTMATERIALTOGGLE_INTERNAL_H
|
#endif // QTMATERIALTOGGLE_INTERNAL_H
|
||||||
|
|
|
@ -2,31 +2,33 @@
|
||||||
#define QTMATERIALTOGGLE_P_H
|
#define QTMATERIALTOGGLE_P_H
|
||||||
|
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
|
namespace md
|
||||||
|
{
|
||||||
|
|
||||||
class QStateMachine;
|
class QStateMachine;
|
||||||
class QState;
|
class QState;
|
||||||
class QColor;
|
class QColor;
|
||||||
class QtMaterialToggle;
|
class Toggle;
|
||||||
class QtMaterialToggleTrack;
|
class ToggleTrack;
|
||||||
class QtMaterialToggleThumb;
|
class ToggleThumb;
|
||||||
class QtMaterialToggleRippleOverlay;
|
class ToggleRippleOverlay;
|
||||||
|
|
||||||
class QtMaterialTogglePrivate
|
class TogglePrivate
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(QtMaterialTogglePrivate)
|
Q_DISABLE_COPY(TogglePrivate)
|
||||||
Q_DECLARE_PUBLIC(QtMaterialToggle)
|
Q_DECLARE_PUBLIC(Toggle)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtMaterialTogglePrivate(QtMaterialToggle *q);
|
TogglePrivate(Toggle *q);
|
||||||
~QtMaterialTogglePrivate();
|
~TogglePrivate();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void setupProperties();
|
void setupProperties();
|
||||||
|
|
||||||
QtMaterialToggle *const q_ptr;
|
Toggle *const q_ptr;
|
||||||
QtMaterialToggleTrack *track;
|
ToggleTrack *track;
|
||||||
QtMaterialToggleThumb *thumb;
|
ToggleThumb *thumb;
|
||||||
QtMaterialToggleRippleOverlay *rippleOverlay;
|
ToggleRippleOverlay *rippleOverlay;
|
||||||
QStateMachine *stateMachine;
|
QStateMachine *stateMachine;
|
||||||
QState *offState;
|
QState *offState;
|
||||||
QState *onState;
|
QState *onState;
|
||||||
|
@ -37,5 +39,5 @@ public:
|
||||||
QColor trackColor;
|
QColor trackColor;
|
||||||
bool useThemeColors;
|
bool useThemeColors;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
#endif // QTMATERIALTOGGLE_P_H
|
#endif // QTMATERIALTOGGLE_P_H
|
||||||
|
|
Loading…
Reference in New Issue