From 62135f163f19d3362d0c95b5acd63837dab89a39 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 22 Jan 2021 20:54:32 -0500 Subject: Make status bar buttons full height + adjustable color --- examples/triage/files.cpp | 5 +++-- examples/triage/files.h | 2 +- ui/flowgraphwidget.h | 2 +- ui/hexeditor.h | 2 +- ui/linearview.h | 2 +- ui/menus.h | 29 ++++++++++++++++++++++++----- ui/tokenizedtextview.h | 2 +- ui/typeview.h | 2 +- 8 files changed, 33 insertions(+), 13 deletions(-) diff --git a/examples/triage/files.cpp b/examples/triage/files.cpp index ef640aa8..fcb71cd0 100644 --- a/examples/triage/files.cpp +++ b/examples/triage/files.cpp @@ -4,9 +4,10 @@ #include "files.h" -TriageFilePicker::TriageFilePicker(UIContext* context): m_contextMenuManager(this) +TriageFilePicker::TriageFilePicker(UIContext* context) { m_context = context; + m_contextMenuManager = new ContextMenuManager(this); m_actionHandler.setupActionHandler(this); QVBoxLayout* layout = new QVBoxLayout(); @@ -53,7 +54,7 @@ TriageFilePicker::TriageFilePicker(UIContext* context): m_contextMenuManager(thi void TriageFilePicker::contextMenuEvent(QContextMenuEvent*) { - m_contextMenuManager.show(&m_contextMenu, &m_actionHandler); + m_contextMenuManager->show(&m_contextMenu, &m_actionHandler); } diff --git a/examples/triage/files.h b/examples/triage/files.h index 9874691c..e371d869 100644 --- a/examples/triage/files.h +++ b/examples/triage/files.h @@ -16,7 +16,7 @@ class TriageFilePicker: public QWidget UIContext* m_context; UIActionHandler m_actionHandler; Menu m_contextMenu; - ContextMenuManager m_contextMenuManager; + ContextMenuManager* m_contextMenuManager; QFileSystemModel* m_model; QTreeView* m_tree; diff --git a/ui/flowgraphwidget.h b/ui/flowgraphwidget.h index 1a8774e2..ef2a4df7 100644 --- a/ui/flowgraphwidget.h +++ b/ui/flowgraphwidget.h @@ -107,7 +107,7 @@ class BINARYNINJAUIAPI FlowGraphWidget: public QAbstractScrollArea, public View, std::set m_relatedIndexHighlights; std::set m_relatedInstructionHighlights; - ContextMenuManager m_contextMenuManager; + ContextMenuManager* m_contextMenuManager; QPointer m_commentDialog; BinaryNinja::Ref m_pendingHistoryEntry, m_layoutHistoryEntry; diff --git a/ui/hexeditor.h b/ui/hexeditor.h index e571ca88..08baf21d 100644 --- a/ui/hexeditor.h +++ b/ui/hexeditor.h @@ -171,7 +171,7 @@ private: RenderContext m_render; HexEditorHighlightState m_highlightState; - ContextMenuManager m_contextMenuManager; + ContextMenuManager* m_contextMenuManager; protected: virtual void resizeEvent(QResizeEvent* event) override; diff --git a/ui/linearview.h b/ui/linearview.h index 7e616b35..2360df94 100644 --- a/ui/linearview.h +++ b/ui/linearview.h @@ -146,7 +146,7 @@ class BINARYNINJAUIAPI LinearView: public QAbstractScrollArea, public View, publ QTimer* m_updateTimer; - ContextMenuManager m_contextMenuManager; + ContextMenuManager* m_contextMenuManager; QPointer m_commentDialog; std::map m_analysisRequestors; diff --git a/ui/menus.h b/ui/menus.h index 4b0cc3a5..50b92785 100644 --- a/ui/menus.h +++ b/ui/menus.h @@ -12,8 +12,10 @@ #include "action.h" #include "viewframe.h" -class BINARYNINJAUIAPI ContextMenuManager +class BINARYNINJAUIAPI ContextMenuManager: public QObject { + Q_OBJECT + QWidget* m_parent; QPointer m_menu; MenuInstance* m_instance; @@ -24,8 +26,14 @@ public: ~ContextMenuManager(); QMenu* create(); MenuInstance* show(View* view); + MenuInstance* show(QPoint pos, View* view); MenuInstance* show(Menu* source, UIActionHandler* handler); + MenuInstance* show(QPoint pos, Menu* source, UIActionHandler* handler); bool isActive() { return !m_menu.isNull(); } + +Q_SIGNALS: + void onOpen(); + void onClose(); }; @@ -34,22 +42,30 @@ class BINARYNINJAUIAPI MenuHelper: public QLabel Q_OBJECT QPalette::ColorRole m_backgroundRole; + QPalette::ColorRole m_activeBackgroundRole; + QPalette::ColorRole m_pressedBackgroundRole; QPalette::ColorRole m_foregroundRole; QPalette::ColorRole m_activeForegroundRole; + QPalette::ColorRole m_pressedForegroundRole; protected: Menu m_menu; - ContextMenuManager m_contextMenuManager; + ContextMenuManager* m_contextMenuManager; QTimer* m_timer; bool m_activeOnHover = true; + bool m_active; + bool m_pressed; public: MenuHelper() { } MenuHelper(QWidget* parent, bool activeOnHover = true); - void setBackgroundColorRole(QPalette::ColorRole role = QPalette::Highlight); - void setForegroundColorRole(QPalette::ColorRole role = QPalette::WindowText); - void setActiveForegroundColorRole(QPalette::ColorRole role = QPalette::HighlightedText); + void setBackgroundColorRole(QPalette::ColorRole role); + void setActiveBackgroundColorRole(QPalette::ColorRole role); + void setPressedBackgroundColorRole(QPalette::ColorRole role); + void setForegroundColorRole(QPalette::ColorRole role); + void setActiveForegroundColorRole(QPalette::ColorRole role); + void setPressedForegroundColorRole(QPalette::ColorRole role); Q_SIGNALS: void clicked(); @@ -67,5 +83,8 @@ protected: void enterEvent(QEnterEvent* event) override; #endif void leaveEvent(QEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; + + void updateColors(); }; diff --git a/ui/tokenizedtextview.h b/ui/tokenizedtextview.h index 01174e82..fc718311 100644 --- a/ui/tokenizedtextview.h +++ b/ui/tokenizedtextview.h @@ -48,7 +48,7 @@ class BINARYNINJAUIAPI TokenizedTextView: public QAbstractScrollArea, public Vie QTimer* m_updateTimer; - ContextMenuManager m_contextMenuManager; + ContextMenuManager* m_contextMenuManager; QPointer m_commentDialog; void adjustSize(int width, int height); diff --git a/ui/typeview.h b/ui/typeview.h index 3c8e7a84..02ab1708 100644 --- a/ui/typeview.h +++ b/ui/typeview.h @@ -118,7 +118,7 @@ class BINARYNINJAUIAPI TypeView: public QAbstractScrollArea, public View, public Qt::KeyboardModifiers m_ctrl, m_command; - ContextMenuManager m_contextMenuManager; + ContextMenuManager* m_contextMenuManager; QAction* m_actionCopy; QAction* m_actionSelectAll; -- cgit v1.3.1