1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <QGuiApplication>
9 #include "ToggleSwitch.h"
10 #include "ToggleSwitch.svg.h"
12 const QByteArray
ToggleSwitch::s_toggleOffSvgContent
= ToggleSwitchSVG::s_toggledOffContent
;
13 const QByteArray
ToggleSwitch::s_toggleOnSvgContent
= ToggleSwitchSVG::s_toggledOnContent
;
14 const int ToggleSwitch::s_colorPosInToggleOn
= ToggleSwitch::s_toggleOnSvgContent
.indexOf("#1a73e8");
16 ToggleSwitch::ToggleSwitch(QWidget
*parent
) : QCheckBox(parent
){
19 setFixedHeight(width()/2);
21 m_toggleOnSvgContentColored
= s_toggleOnSvgContent
;
24 void ToggleSwitch::paintEvent(QPaintEvent
*event
){
28 auto accent
= palette().highlight().color();
29 m_toggleOnSvgContentColored
= m_toggleOnSvgContentColored
.replace(s_colorPosInToggleOn
, 7, accent
.name().toLatin1());
31 m_svgr
.load(m_toggleOnSvgContentColored
);
33 m_svgr
.load(s_toggleOffSvgContent
);
36 m_svgr
.render(&p
, this->rect());