summaryrefslogtreecommitdiff
path: root/util/coreboot-configurator/src/application/ToggleSwitch.cpp
blob: b0a399e01cb6137ee7793abab3db189a9006858f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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();
}