Debian Codegraph @

util/coreboot-configurator/src/application/ToggleSwitch.cpp

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <QEvent>
4 #include <QGuiApplication>
5 #include <QPainter>
6 #include <QPalette>
7 #include <QTimer>
8
9 #include "ToggleSwitch.h"
10 #include "ToggleSwitch.svg.h"
11
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");
15
16 ToggleSwitch::ToggleSwitch(QWidget *parent) : QCheckBox(parent){
17
18 setFixedWidth(50);
19 setFixedHeight(width()/2);
20
21 m_toggleOnSvgContentColored = s_toggleOnSvgContent;
22 }
23
24 void ToggleSwitch::paintEvent(QPaintEvent *event){
25 QPainter p(this);
26
27 if(isChecked()){
28 auto accent = palette().highlight().color();
29 m_toggleOnSvgContentColored = m_toggleOnSvgContentColored.replace(s_colorPosInToggleOn, 7, accent.name().toLatin1());
30
31 m_svgr.load(m_toggleOnSvgContentColored);
32 } else {
33 m_svgr.load(s_toggleOffSvgContent);
34 }
35
36 m_svgr.render(&p, this->rect());
37 p.end();
38 }