diff --git a/components/toggle.cpp b/components/toggle.cpp index ce82a4a..87f12d2 100644 --- a/components/toggle.cpp +++ b/components/toggle.cpp @@ -3,6 +3,7 @@ #include #include "toggle.h" #include "../lib/rippleoverlay.h" +#include "../lib/customshadoweffect.h" Thumb::Thumb(QWidget *parent) : QWidget(parent) @@ -13,10 +14,26 @@ Thumb::~Thumb() { } +void Thumb::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + + QPainter painter(this); + + painter.drawRect(rect()); + + const int d = qMin(width(), height()); + + painter.drawEllipse(d, d, d/2, d/2); +} + Toggle::Toggle(QWidget *parent) : QAbstractButton(parent), - _overlay(new RippleOverlay(this)) + _overlay(new RippleOverlay(this)), + _thumb(new Thumb(this)) { + CustomShadowEffect *effect = new CustomShadowEffect; + _thumb->setGraphicsEffect(effect); } Toggle::~Toggle() @@ -28,6 +45,9 @@ void Toggle::paintEvent(QPaintEvent *event) Q_UNUSED(event) QPainter painter(this); + + painter.drawRect(rect().adjusted(0, 0, -1, -1)); + painter.setRenderHint(QPainter::Antialiasing); const int h = height()/2; @@ -40,5 +60,4 @@ void Toggle::paintEvent(QPaintEvent *event) painter.setPen(Qt::NoPen); painter.drawRoundedRect(QRect(0, h-h/2, width(), h+h/2), h, h); - } diff --git a/components/toggle.h b/components/toggle.h index 19c3f0f..3b594a7 100644 --- a/components/toggle.h +++ b/components/toggle.h @@ -12,6 +12,9 @@ class Thumb : public QWidget public: explicit Thumb(QWidget *parent = 0); ~Thumb(); + +protected: + void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; }; class Toggle : public QAbstractButton @@ -29,6 +32,7 @@ protected: private: RippleOverlay *const _overlay; + Thumb *const _thumb; }; #endif // TOGGLE_H