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 | |
| parent | ab38220c60d59f7bc164c76bde72201746a53da9 (diff) | |
Improve write lock status state visibility.
| -rw-r--r-- | ui/clickablelabel.h | 44 | ||||
| -rw-r--r-- | ui/viewframe.h | 6 |
2 files changed, 47 insertions, 3 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); + } + } +}; diff --git a/ui/viewframe.h b/ui/viewframe.h index 162dac11..466051d3 100644 --- a/ui/viewframe.h +++ b/ui/viewframe.h @@ -36,7 +36,7 @@ struct SelectionInfoForXref FunctionRef func; ArchitectureRef arch; - bool operator== (const SelectionInfoForXref& other) const + bool operator== (const SelectionInfoForXref& other) const { if (addrValid && other.addrValid) return (start == other.start) && (end == other.end) && @@ -67,7 +67,7 @@ public: class AssembleDialog; -class ClickableLabel; +class ClickableStateLabel; class CompileDialog; class DockHandler; class FeatureMap; @@ -265,7 +265,7 @@ private: FileContext* m_context; bool m_fileContentsLock = true; // file contents protection from accidental modification in the UI - ClickableLabel* m_fileContentsLockStatus; + ClickableStateLabel* m_fileContentsLockStatus; BinaryViewRef m_data; DockHandler* m_docks; QWidget* m_view; |
