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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
#pragma once
#include <QtWidgets/QWidget>
#include "theme.h"
#include "viewframe.h"
#include "tabwidget.h"
#include "sidebar.h"
/*!
\defgroup globalarea GlobalArea
\ingroup uiapi
*/
/*!
\ingroup globalarea
\deprecated Use `SidebarWidget` with `SidebarContextSensitivity::Global` instead
*/
class BINARYNINJAUIAPI GlobalAreaWidget : public SidebarWidget
{
Q_OBJECT
public:
GlobalAreaWidget(const QString& title);
};
/*!
\ingroup globalarea
*/
class BINARYNINJAUIAPI GlobalAreaTabStyle : public DockableTabStyle
{
int closeButtonSize(const QWidget* widget) const;
public:
virtual QSize sizeForTab(
const QWidget* widget, const DockableTabInfo& info, int idx, int count, int active) const override;
virtual QRect closeButtonRect(
const QWidget* widget, const DockableTabInfo& info, int idx, int count, int active) const override;
virtual QRect closeIconRect(
const QWidget* widget, const DockableTabInfo& info, int idx, int count, int active) const override;
virtual void paintTab(const QWidget* widget, QStylePainter& p, const DockableTabInfo& info, int idx, int count,
int active, DockableTabInteractionState state, const QRect& rect) const override;
virtual DockableTabStyle* duplicate() override;
};
/*!
\ingroup globalarea
*/
class BINARYNINJAUIAPI CloseButton : public QWidget
{
Q_OBJECT
bool m_mouseInside = false;
bool m_buttonDown = false;
QTimer* m_timer;
public:
CloseButton();
virtual QSize sizeHint() const override;
protected:
virtual void paintEvent(QPaintEvent* event) override;
virtual void enterEvent(QEnterEvent* event) override;
virtual void leaveEvent(QEvent* event) override;
virtual void mouseMoveEvent(QMouseEvent* event) override;
virtual void mousePressEvent(QMouseEvent* event) override;
virtual void mouseReleaseEvent(QMouseEvent* event) override;
private Q_SLOTS:
void underMouseTimerEvent();
Q_SIGNALS:
void clicked();
};
/*!
\ingroup globalarea
*/
class BINARYNINJAUIAPI GlobalArea : public QObject
{
Q_OBJECT
Sidebar* m_sidebar;
static std::vector<std::function<GlobalAreaWidget*(UIContext*)>> m_widgetFactories;
QString actionNameForWidget(const QString& title);
public:
GlobalArea(QWidget* owner, Sidebar* sidebar);
void addWidget(GlobalAreaWidget* widget, bool canClose = false);
static void addWidget(const std::function<GlobalAreaWidget*(UIContext*)>& createWidget);
void initRegisteredWidgets(UIContext* context);
bool isWidgetVisible(const QString& title);
bool toggleVisible();
bool toggleWidgetVisible(const QString& title);
void focusWidget(const QString& title);
GlobalAreaWidget* widget(const QString& title);
void closeTab(QWidget* widget);
static GlobalArea* current()
{
UIContext* context = UIContext::activeContext();
if (!context)
return nullptr;
return context->globalArea();
}
template <class T>
static T* widget(const QString& title)
{
GlobalArea* globalArea = current();
if (!globalArea)
return (T*)nullptr;
GlobalAreaWidget* widget = globalArea->widget(title);
if (!widget)
return (T*)nullptr;
return qobject_cast<T*>(widget);
}
template <class T>
static UIAction globalAreaAction(const QString& title, const std::function<void(T* obj)>& activate)
{
return globalAreaAction<T>(
title, [=](T* obj, const UIActionContext&) { activate(obj); },
[=](T*, const UIActionContext&) { return true; });
}
template <class T>
static UIAction globalAreaAction(
const QString& title, const std::function<void(T* obj, const UIActionContext& ctxt)>& activate)
{
return globalAreaAction<T>(title, activate, [](T*, const UIActionContext&) { return true; });
}
template <class T>
static UIAction globalAreaAction(
const QString& title, const std::function<void(T* obj)>& activate, const std::function<bool(T* obj)>& isValid)
{
return globalAreaAction<T>(
title, [=](T* obj, const UIActionContext&) { activate(obj); },
[=](T* obj, const UIActionContext&) { return isValid(obj); });
}
template <class T>
static UIAction globalAreaAction(const QString& title,
const std::function<void(T* obj, const UIActionContext& ctxt)>& activate,
const std::function<bool(T* obj, const UIActionContext& ctxt)>& isValid)
{
std::function<T*(const UIActionContext& ctxt)> lookup = [=](const UIActionContext& ctxt) {
if (!ctxt.context)
return (T*)nullptr;
GlobalArea* globalArea = ctxt.context->globalArea();
if (!globalArea || !globalArea->isWidgetVisible(title))
return (T*)nullptr;
GlobalAreaWidget* widget = globalArea->widget(title);
if (!widget)
return (T*)nullptr;
return qobject_cast<T*>(widget);
};
return UIAction(
[=](const UIActionContext& ctxt) {
T* obj = lookup(ctxt);
if (obj)
activate(obj, ctxt);
},
[=](const UIActionContext& ctxt) {
T* obj = lookup(ctxt);
if (obj)
return isValid(obj, ctxt);
return false;
});
}
template <class T>
static std::function<bool(const UIActionContext&)> globalAreaActionChecked(
const QString& title, const std::function<bool(T* obj)>& isChecked)
{
return globalAreaActionChecked<T>(title, [=](T* obj, const UIActionContext&) { return isChecked(obj); });
}
template <class T>
static std::function<bool(const UIActionContext&)> globalAreaActionChecked(
const QString& title, const std::function<bool(T* obj, const UIActionContext& ctxt)>& isChecked)
{
return [=](const UIActionContext& ctxt) {
if (!ctxt.context)
return false;
GlobalArea* globalArea = ctxt.context->globalArea();
if (!globalArea || !globalArea->isWidgetVisible(title))
return false;
GlobalAreaWidget* widget = globalArea->widget(title);
if (!widget)
return false;
T* obj = qobject_cast<T*>(widget);
if (obj)
return isChecked(obj, ctxt);
return false;
};
}
};
/*!
\ingroup scriptingconsole
*/
class BINARYNINJAUIAPI GlobalAreaCompatibilitySidebarWidgetType : public SidebarWidgetType
{
public:
GlobalAreaCompatibilitySidebarWidgetType();
SidebarWidgetLocation defaultLocation() const override { return SidebarWidgetLocation::LeftBottom; }
SidebarContextSensitivity contextSensitivity() const override { return GlobalSidebarContext; }
bool alwaysShowTabs() const override { return true; }
SidebarIconVisibility defaultIconVisibility() const override { return InvisibleIfNoContent; }
SidebarContentClassifier* contentClassifier(ViewFrame*, BinaryViewRef) override;
};
|