From 98cd461ccb286609e248aa5260cfaeb5e81d7387 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Thu, 18 Feb 2021 17:01:11 -0500 Subject: Improve write lock status state visibility. --- ui/clickablelabel.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'ui/clickablelabel.h') diff --git a/ui/clickablelabel.h b/ui/clickablelabel.h index 3e09c045..5f85c6bc 100644 --- a/ui/clickablelabel.h +++ b/ui/clickablelabel.h @@ -1,7 +1,10 @@ #pragma once +#include +#include #include + class BINARYNINJAUIAPI ClickableLabel: public QLabel { Q_OBJECT @@ -15,3 +18,44 @@ Q_SIGNALS: 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) { } + + 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); + } + } +}; -- cgit v1.3.1