xref: /aosp_15_r20/external/coreboot/util/coreboot-configurator/src/application/ToggleSwitch.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #pragma once
4 
5 #include <QCheckBox>
6 #include <QFile>
7 #include <QObject>
8 #include <QSvgRenderer>
9 
10 
11 /*
12  * The ToggleSwitch class represents Toggle Switch widget based on QCheckBox and toggles svg with colorscheme support
13  */
14 class ToggleSwitch : public QCheckBox {
15 	Q_OBJECT
16 public:
17 	explicit ToggleSwitch(QWidget* parent = nullptr);
18 
19 private:
20 	QSvgRenderer m_svgr;
21 
22 	static const QByteArray s_toggleOnSvgContent;
23 	static const QByteArray s_toggleOffSvgContent;
24 	static const int s_colorPosInToggleOn;
25 
26 	QByteArray m_toggleOnSvgContentColored;
27 
28 	/* QWidget interface */
29 protected:
30 	void paintEvent(QPaintEvent *event) override;
31 
32 	/* QAbstractButton interface */
33 protected:
hitButton(const QPoint & pos)34 	bool hitButton(const QPoint &pos) const override
35 	{
36 		/* needs to be clickable on */
37 		return rect().contains(pos);
38 	}
39 };
40