Added toggle switch
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
|
||||
#include "bctoggleswitch.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QEasingCurve>
|
||||
#include <QEnterEvent>
|
||||
#include <QEvent>
|
||||
|
||||
#include <bctoggleswitch.h>
|
||||
|
||||
BCToggleSwitch::BCToggleSwitch(QWidget *parent)
|
||||
: QAbstractButton(parent)
|
||||
, m_position(0.0f)
|
||||
@@ -34,7 +34,8 @@ float BCToggleSwitch::position() const
|
||||
return m_position;
|
||||
}
|
||||
|
||||
void BCToggleSwitch::setPosition(float pos) {
|
||||
void BCToggleSwitch::setPosition(float pos)
|
||||
{
|
||||
m_position = pos;
|
||||
update(); // Trigger Repaint
|
||||
}
|
||||
@@ -52,9 +53,9 @@ void BCToggleSwitch::paintEvent(QPaintEvent *)
|
||||
// --- Farben ---
|
||||
// Tipp: In einem echten Projekt diese Farben als const statics
|
||||
// oder aus der QPalette laden.
|
||||
QColor offBorderColor = QColor("#8D8D8D");
|
||||
QColor offKnobColor = QColor("#5D5D5D");
|
||||
QColor onColor = QColor("#0078D4"); // Fluent Blue
|
||||
QColor offBorderColor = QColor(0x8D8D8D);
|
||||
QColor offKnobColor = QColor(0x5D5D5D);
|
||||
QColor onColor = QColor(0x0078D4); // Fluent Blue
|
||||
QColor white = Qt::white;
|
||||
|
||||
QRectF rect = this->rect();
|
||||
@@ -95,11 +96,16 @@ void BCToggleSwitch::paintEvent(QPaintEvent *)
|
||||
|
||||
QRectF knobRect(currentX, padding, knobDiameter, knobDiameter);
|
||||
|
||||
if (isChecked() || m_position > 0.5f) {
|
||||
if (isChecked() || m_position > 0.5f)
|
||||
{
|
||||
p.setBrush(white);
|
||||
} else {
|
||||
if (underMouse()) p.setBrush(offKnobColor.darker(110));
|
||||
else p.setBrush(offKnobColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (underMouse())
|
||||
p.setBrush(offKnobColor.darker(110));
|
||||
else
|
||||
p.setBrush(offKnobColor);
|
||||
}
|
||||
|
||||
p.setPen(Qt::NoPen);
|
||||
|
||||
Reference in New Issue
Block a user