diff options
| author | Brian Potchik <brian@vector35.com> | 2021-02-18 17:01:11 -0500 |
|---|---|---|
| committer | Brian Potchik <brian@vector35.com> | 2021-02-18 17:01:11 -0500 |
| commit | 98cd461ccb286609e248aa5260cfaeb5e81d7387 (patch) | |
| tree | 81bc476460d53ceef52cbe64b2c693e6fe989428 /ui/clickablelabel.h | |
| parent | ab38220c60d59f7bc164c76bde72201746a53da9 (diff) | |
Improve write lock status state visibility.
Diffstat (limited to 'ui/clickablelabel.h')
| -rw-r--r-- | ui/clickablelabel.h | 44 |
1 files changed, 44 insertions, 0 deletions
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 <QtGui/QColor> +#include <QtGui/QPainter> #include <QtWidgets/QLabel> + 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); + } + } +}; |
