implement basic Thumb widget painting
This commit is contained in:
parent
c86ebb1c7d
commit
0a637bf140
|
@ -3,6 +3,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "toggle.h"
|
#include "toggle.h"
|
||||||
#include "../lib/rippleoverlay.h"
|
#include "../lib/rippleoverlay.h"
|
||||||
|
#include "../lib/customshadoweffect.h"
|
||||||
|
|
||||||
Thumb::Thumb(QWidget *parent)
|
Thumb::Thumb(QWidget *parent)
|
||||||
: 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)
|
Toggle::Toggle(QWidget *parent)
|
||||||
: QAbstractButton(parent),
|
: QAbstractButton(parent),
|
||||||
_overlay(new RippleOverlay(this))
|
_overlay(new RippleOverlay(this)),
|
||||||
|
_thumb(new Thumb(this))
|
||||||
{
|
{
|
||||||
|
CustomShadowEffect *effect = new CustomShadowEffect;
|
||||||
|
_thumb->setGraphicsEffect(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
Toggle::~Toggle()
|
Toggle::~Toggle()
|
||||||
|
@ -28,6 +45,9 @@ void Toggle::paintEvent(QPaintEvent *event)
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
|
painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
||||||
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
const int h = height()/2;
|
const int h = height()/2;
|
||||||
|
@ -40,5 +60,4 @@ void Toggle::paintEvent(QPaintEvent *event)
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
|
|
||||||
painter.drawRoundedRect(QRect(0, h-h/2, width(), h+h/2), h, h);
|
painter.drawRoundedRect(QRect(0, h-h/2, width(), h+h/2), h, h);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@ class Thumb : public QWidget
|
||||||
public:
|
public:
|
||||||
explicit Thumb(QWidget *parent = 0);
|
explicit Thumb(QWidget *parent = 0);
|
||||||
~Thumb();
|
~Thumb();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Toggle : public QAbstractButton
|
class Toggle : public QAbstractButton
|
||||||
|
@ -29,6 +32,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RippleOverlay *const _overlay;
|
RippleOverlay *const _overlay;
|
||||||
|
Thumb *const _thumb;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOGGLE_H
|
#endif // TOGGLE_H
|
||||||
|
|
Loading…
Reference in New Issue