diff options
Diffstat (limited to 'util/coreboot-configurator/src/application/ToggleSwitch.cpp')
-rw-r--r-- | util/coreboot-configurator/src/application/ToggleSwitch.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/util/coreboot-configurator/src/application/ToggleSwitch.cpp b/util/coreboot-configurator/src/application/ToggleSwitch.cpp new file mode 100644 index 0000000000..b0a399e01c --- /dev/null +++ b/util/coreboot-configurator/src/application/ToggleSwitch.cpp @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <QEvent> +#include <QGuiApplication> +#include <QPainter> +#include <QPalette> +#include <QTimer> + +#include "ToggleSwitch.h" +#include "ToggleSwitch.svg.h" + +const QByteArray ToggleSwitch::s_toggleOffSvgContent = ToggleSwitchSVG::s_toggledOffContent; +const QByteArray ToggleSwitch::s_toggleOnSvgContent = ToggleSwitchSVG::s_toggledOnContent; +const int ToggleSwitch::s_colorPosInToggleOn = ToggleSwitch::s_toggleOnSvgContent.indexOf("#1a73e8"); + +ToggleSwitch::ToggleSwitch(QWidget *parent) : QCheckBox(parent){ + + setFixedWidth(50); + setFixedHeight(width()/2); + + m_toggleOnSvgContentColored = s_toggleOnSvgContent; +} + +void ToggleSwitch::paintEvent(QPaintEvent *event){ + QPainter p(this); + + if(isChecked()){ + auto accent = palette().highlight().color(); + m_toggleOnSvgContentColored = m_toggleOnSvgContentColored.replace(s_colorPosInToggleOn, 7, accent.name().toLatin1()); + + m_svgr.load(m_toggleOnSvgContentColored); + } else { + m_svgr.load(s_toggleOffSvgContent); + } + + m_svgr.render(&p, this->rect()); + p.end(); +} |