summaryrefslogtreecommitdiff
path: root/ui/clickablelabel.h
blob: 4025d7c3a5e21626d3f34908f660a187b9517da6 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once

#include <QtGui/QColor>
#include <QtGui/QPainter>
#include <QtWidgets/QLabel>


class BINARYNINJAUIAPI ClickableLabel: public QLabel
{
	Q_OBJECT

public:
	ClickableLabel(QWidget* parent = nullptr, const QString& name = ""): QLabel(parent) { setText(name); }

Q_SIGNALS:
	void clicked();

protected:
	void mouseReleaseEvent(QMouseEvent* event) override { if (event->button() == Qt::LeftButton) Q_EMIT clicked(); }
};


class BINARYNINJAUIAPI ClickableStateLabel: public ClickableLabel
{
	Q_OBJECT

	QString m_name;
	QString m_altName;
	bool m_state = true;
	bool m_stateEffectEnabled = false;
	bool m_altStateEffect = false;
	QPalette::ColorRole m_altOverlayColorRole;
	int m_alpha;

public:
	ClickableStateLabel(QWidget* parent, const QString& name, const QString& altName): ClickableLabel(parent, name), m_name(name), m_altName(altName) { }

	bool getState() { return m_state; }

	void setDisplayState(bool state) {
		m_state = state;
		setText(m_state ? m_name : m_altName);
	}

	void setAlternateTransparency(QPalette::ColorRole colorRole, int alpha, bool state) {
		m_altOverlayColorRole = colorRole;
		m_alpha = alpha;
		m_altStateEffect = state;
		m_stateEffectEnabled = true;
	}

protected:
	void paintEvent(QPaintEvent* event) override {
		ClickableLabel::paintEvent(event);
		if (m_stateEffectEnabled && (m_state == m_altStateEffect))
		{
			QPainter p(this);
			QColor overlayColor = palette().color(m_altOverlayColorRole);
			overlayColor.setAlpha(m_alpha);
			p.fillRect(event->rect(), overlayColor);
		}
	}
};