Skip to content

Commit c56f0d4

Browse files
committed
GUI: Cache some values in dissassembler; standardize config updates (signals/vtable)
1 parent 5ae3315 commit c56f0d4

File tree

12 files changed

+170
-84
lines changed

12 files changed

+170
-84
lines changed

src/gui/Src/BasicView/AbstractTableView.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ AbstractTableView::AbstractTableView(QWidget* parent) : QAbstractScrollArea(pare
1313
data.activeButtonIndex = -1;
1414
mHeader = data;
1515

16-
fontsUpdated();
17-
colorsUpdated();
18-
1916
// Paint cell content only when debugger is running
2017
setDrawDebugOnly(true);
2118

@@ -41,18 +38,32 @@ AbstractTableView::AbstractTableView(QWidget* parent) : QAbstractScrollArea(pare
4138
mMouseWheelScrollDelta = 4;
4239
setMouseTracking(true);
4340

44-
// Signals/Slots Connections
41+
// Slots
4542
connect(verticalScrollBar(), SIGNAL(actionTriggered(int)), this, SLOT(vertSliderActionSlot(int)));
46-
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
47-
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
43+
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(slot_updateColors()));
44+
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(slot_updateFonts()));
45+
connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(slot_updateShortcuts()));
46+
47+
// todo: try Qt::QueuedConnection to init
48+
Initialize();
4849
}
4950

50-
void AbstractTableView::colorsUpdatedSlot()
51+
/************************************************************************************
52+
Configuration
53+
************************************************************************************/
54+
55+
void AbstractTableView::Initialize()
5156
{
52-
colorsUpdated();
57+
// Required to be called by each constructor because
58+
// of VTable changes
59+
//
60+
// Init all other updates once
61+
updateColors();
62+
updateFonts();
63+
updateShortcuts();
5364
}
5465

55-
void AbstractTableView::colorsUpdated()
66+
void AbstractTableView::updateColors()
5667
{
5768
backgroundColor = ConfigColor("AbstractTableViewBackgroundColor");
5869
textColor = ConfigColor("AbstractTableViewTextColor");
@@ -61,14 +72,28 @@ void AbstractTableView::colorsUpdated()
6172
selectionColor = ConfigColor("AbstractTableViewSelectionColor");
6273
}
6374

64-
void AbstractTableView::fontsUpdatedSlot()
75+
void AbstractTableView::updateFonts()
6576
{
66-
fontsUpdated();
77+
setFont(ConfigFont("AbstractTableView"));
6778
}
6879

69-
void AbstractTableView::fontsUpdated()
80+
void AbstractTableView::updateShortcuts()
7081
{
71-
setFont(ConfigFont("AbstractTableView"));
82+
}
83+
84+
void AbstractTableView::slot_updateColors()
85+
{
86+
updateColors();
87+
}
88+
89+
void AbstractTableView::slot_updateFonts()
90+
{
91+
updateFonts();
92+
}
93+
94+
void AbstractTableView::slot_updateShortcuts()
95+
{
96+
updateShortcuts();
7297
}
7398

7499
/************************************************************************************

src/gui/Src/BasicView/AbstractTableView.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ class AbstractTableScrollBar : public QScrollBar
3636
class AbstractTableView : public QAbstractScrollArea
3737
{
3838
Q_OBJECT
39+
3940
public:
4041
enum GuiState_t {NoState, ReadyToResize, ResizeColumnState, HeaderButtonPressed};
4142

4243
// Constructor
4344
explicit AbstractTableView(QWidget* parent = 0);
4445

45-
// Config updates
46-
virtual void colorsUpdated();
47-
virtual void fontsUpdated();
46+
// Configuration
47+
virtual void Initialize();
48+
virtual void updateColors();
49+
virtual void updateFonts();
50+
virtual void updateShortcuts();
4851

4952
// Pure Virtual Methods
5053
virtual QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h) = 0;
@@ -116,8 +119,10 @@ class AbstractTableView : public QAbstractScrollArea
116119
void repainted();
117120

118121
public slots:
119-
void colorsUpdatedSlot();
120-
void fontsUpdatedSlot();
122+
// Configuration
123+
void slot_updateColors();
124+
void slot_updateFonts();
125+
void slot_updateShortcuts();
121126

122127
// Update/Reload/Refresh/Repaint
123128
virtual void reloadData();
@@ -185,13 +190,15 @@ public slots:
185190
ScrollBar64_t mScrollBarAttributes;
186191

187192
protected:
193+
bool mAllowPainting;
194+
bool mDrawDebugOnly;
195+
196+
// Configuration
188197
QColor backgroundColor;
189198
QColor textColor;
190199
QColor separatorColor;
191200
QColor headerTextColor;
192201
QColor selectionColor;
193-
bool mAllowPainting;
194-
bool mDrawDebugOnly;
195202
};
196203

197204
#endif // ABSTRACTTABLEVIEW_H

src/gui/Src/BasicView/Disassembly.cpp

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#include "Configuration.h"
33
#include "Bridge.h"
44

5-
Disassembly::Disassembly(QWidget* parent)
6-
: AbstractTableView(parent)
5+
Disassembly::Disassembly(QWidget* parent) : AbstractTableView(parent)
76
{
8-
fontsUpdated();
97
mMemPage = new MemoryPage(0, 0);
108

119
mInstBuffer.clear();
@@ -32,6 +30,9 @@ Disassembly::Disassembly(QWidget* parent)
3230

3331
mGuiState = Disassembly::NoState;
3432

33+
// Update fonts immediately because they are used in calculations
34+
updateFonts();
35+
3536
setRowCount(mMemPage->getSize());
3637

3738
addColumnAt(getCharWidth() * 2 * sizeof(dsint) + 8, "", false); //address
@@ -43,18 +44,41 @@ Disassembly::Disassembly(QWidget* parent)
4344

4445
backgroundColor = ConfigColor("DisassemblyBackgroundColor");
4546

47+
// Slots
4648
connect(Bridge::getBridge(), SIGNAL(repaintGui()), this, SLOT(reloadData()));
49+
connect(Bridge::getBridge(), SIGNAL(updateDump()), this, SLOT(reloadData()));
50+
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(debugStateChanged(DBGSTATE)));
51+
52+
Initialize();
4753
}
4854

49-
void Disassembly::colorsUpdated()
55+
void Disassembly::updateColors()
5056
{
51-
AbstractTableView::colorsUpdated();
57+
AbstractTableView::updateColors();
5258
backgroundColor = ConfigColor("DisassemblyBackgroundColor");
59+
60+
mInstructionHighlightColor = ConfigColor("InstructionHighlightColor");
61+
mSelectionColor = ConfigColor("DisassemblySelectionColor");
62+
mCipBackgroundColor = ConfigColor("DisassemblyCipBackgroundColor");
63+
mBreakpointBackgroundColor = ConfigColor("DisassemblyBreakpointBackgroundColor");
64+
mBreakpointColor = ConfigColor("DisassemblyBreakpointColor");
65+
mCipColor = ConfigColor("DisassemblyCipColor");
66+
mHardwareBreakpointBackgroundColor = ConfigColor("DisassemblyHardwareBreakpointBackgroundColor");
67+
mHardwareBreakpointColor = ConfigColor("DisassemblyHardwareBreakpointColor");
68+
mBookmarkBackgroundColor = ConfigColor("DisassemblyBookmarkBackgroundColor");
69+
mBookmarkColor = ConfigColor("DisassemblyBookmarkColor");
70+
mLabelColor = ConfigColor("DisassemblyLabelColor");
71+
mLabelBackgroundColor = ConfigColor("DisassemblyLabelBackgroundColor");
72+
mSelectedAddressBackgroundColor = ConfigColor("DisassemblySelectedAddressBackgroundColor");
73+
mSelectedAddressColor = ConfigColor("DisassemblySelectedAddressColor");
74+
mAddressBackgroundColor = ConfigColor("DisassemblyAddressBackgroundColor");
75+
mAddressColor = ConfigColor("DisassemblyAddressColor");
76+
5377
CapstoneTokenizer::UpdateColors();
5478
mDisasm->UpdateConfig();
5579
}
5680

57-
void Disassembly::fontsUpdated()
81+
void Disassembly::updateFonts()
5882
{
5983
setFont(ConfigFont("Disassembly"));
6084
}
@@ -83,7 +107,7 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
83107

84108
if(mHighlightingMode)
85109
{
86-
QPen pen(ConfigColor("InstructionHighlightColor"));
110+
QPen pen(mInstructionHighlightColor);
87111
pen.setWidth(2);
88112
painter->setPen(pen);
89113
QRect rect = viewport()->rect();
@@ -95,7 +119,7 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
95119

96120
// Highlight if selected
97121
if(wIsSelected)
98-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblySelectionColor")));
122+
painter->fillRect(QRect(x, y, w, h), QBrush(mSelectionColor));
99123

100124
switch(col)
101125
{
@@ -108,39 +132,39 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
108132
bool isbookmark = DbgGetBookmarkAt(cur_addr);
109133
if(mInstBuffer.at(rowOffset).rva == mCipRva && !mIsRunning) //cip + not running
110134
{
111-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyCipBackgroundColor")));
135+
painter->fillRect(QRect(x, y, w, h), QBrush(mCipBackgroundColor));
112136
if(!isbookmark) //no bookmark
113137
{
114138
if(bpxtype & bp_normal) //normal breakpoint
115139
{
116-
QColor bpColor = ConfigColor("DisassemblyBreakpointBackgroundColor");
140+
QColor& bpColor = mBreakpointBackgroundColor;
117141
if(!bpColor.alpha()) //we don't want transparent text
118-
bpColor = ConfigColor("DisassemblyBreakpointColor");
119-
if(bpColor == ConfigColor("DisassemblyCipBackgroundColor"))
120-
bpColor = ConfigColor("DisassemblyCipColor");
142+
bpColor = mBreakpointColor;
143+
if(bpColor == mCipBackgroundColor)
144+
bpColor = mCipColor;
121145
painter->setPen(QPen(bpColor));
122146
}
123147
else if(bpxtype & bp_hardware) //hardware breakpoint only
124148
{
125-
QColor hwbpColor = ConfigColor("DisassemblyHardwareBreakpointBackgroundColor");
149+
QColor hwbpColor = mHardwareBreakpointBackgroundColor;
126150
if(!hwbpColor.alpha()) //we don't want transparent text
127-
hwbpColor = ConfigColor("DisassemblyHardwareBreakpointColor");
128-
if(hwbpColor == ConfigColor("DisassemblyCipBackgroundColor"))
129-
hwbpColor = ConfigColor("DisassemblyCipColor");
151+
hwbpColor = mHardwareBreakpointColor;
152+
if(hwbpColor == mCipBackgroundColor)
153+
hwbpColor = mCipColor;
130154
painter->setPen(hwbpColor);
131155
}
132156
else //no breakpoint
133157
{
134-
painter->setPen(QPen(ConfigColor("DisassemblyCipColor")));
158+
painter->setPen(QPen(mCipColor));
135159
}
136160
}
137161
else //bookmark
138162
{
139-
QColor bookmarkColor = ConfigColor("DisassemblyBookmarkBackgroundColor");
163+
QColor bookmarkColor = mBookmarkBackgroundColor;
140164
if(!bookmarkColor.alpha()) //we don't want transparent text
141-
bookmarkColor = ConfigColor("DisassemblyBookmarkColor");
142-
if(bookmarkColor == ConfigColor("DisassemblyCipBackgroundColor"))
143-
bookmarkColor = ConfigColor("DisassemblyCipColor");
165+
bookmarkColor = mBookmarkColor;
166+
if(bookmarkColor == mCipBackgroundColor)
167+
bookmarkColor = mCipColor;
144168
painter->setPen(QPen(bookmarkColor));
145169
}
146170
}
@@ -152,25 +176,25 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
152176
{
153177
if(bpxtype == bp_none) //label only
154178
{
155-
painter->setPen(QPen(ConfigColor("DisassemblyLabelColor"))); //red -> address + label text
156-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyLabelBackgroundColor"))); //fill label background
179+
painter->setPen(QPen(mLabelColor)); //red -> address + label text
180+
painter->fillRect(QRect(x, y, w, h), QBrush(mLabelBackgroundColor)); //fill label background
157181
}
158182
else //label+breakpoint
159183
{
160184
if(bpxtype & bp_normal) //label + normal breakpoint
161185
{
162-
painter->setPen(QPen(ConfigColor("DisassemblyBreakpointColor")));
163-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyBreakpointBackgroundColor"))); //fill red
186+
painter->setPen(QPen(mBreakpointColor));
187+
painter->fillRect(QRect(x, y, w, h), QBrush(mBreakpointBackgroundColor)); //fill red
164188
}
165189
else if(bpxtype & bp_hardware) //label + hardware breakpoint only
166190
{
167-
painter->setPen(QPen(ConfigColor("DisassemblyHardwareBreakpointColor")));
168-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyHardwareBreakpointBackgroundColor"))); //fill ?
191+
painter->setPen(QPen(mHardwareBreakpointColor));
192+
painter->fillRect(QRect(x, y, w, h), QBrush(mHardwareBreakpointBackgroundColor)); //fill ?
169193
}
170194
else //other cases -> do as normal
171195
{
172-
painter->setPen(QPen(ConfigColor("DisassemblyLabelColor"))); //red -> address + label text
173-
painter->fillRect(QRect(x, y, w, h), QBrush(ConfigColor("DisassemblyLabelBackgroundColor"))); //fill label background
196+
painter->setPen(QPen(mLabelColor)); //red -> address + label text
197+
painter->fillRect(QRect(x, y, w, h), QBrush(mLabelBackgroundColor)); //fill label background
174198
}
175199
}
176200
}
@@ -181,13 +205,13 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
181205
QColor background;
182206
if(wIsSelected)
183207
{
184-
background = ConfigColor("DisassemblySelectedAddressBackgroundColor");
185-
painter->setPen(QPen(ConfigColor("DisassemblySelectedAddressColor"))); //black address (DisassemblySelectedAddressColor)
208+
background = mSelectedAddressBackgroundColor;
209+
painter->setPen(QPen(mSelectedAddressColor)); //black address (DisassemblySelectedAddressColor)
186210
}
187211
else
188212
{
189-
background = ConfigColor("DisassemblyAddressBackgroundColor");
190-
painter->setPen(QPen(ConfigColor("DisassemblyAddressColor"))); //DisassemblyAddressColor
213+
background = mAddressBackgroundColor;
214+
painter->setPen(QPen(mAddressColor)); //DisassemblyAddressColor
191215
}
192216
if(background.alpha())
193217
painter->fillRect(QRect(x, y, w, h), QBrush(background)); //fill background

src/gui/Src/BasicView/Disassembly.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ class Disassembly : public AbstractTableView
1010
Q_OBJECT
1111
public:
1212
explicit Disassembly(QWidget* parent = 0);
13-
void colorsUpdated();
14-
void fontsUpdated();
13+
14+
// Configuration
15+
virtual void updateColors();
16+
virtual void updateFonts();
1517

1618
// Reimplemented Functions
1719
QString paintContent(QPainter* painter, dsint rowBase, int rowOffset, int col, int x, int y, int w, int h);
@@ -135,6 +137,24 @@ public slots:
135137
CapstoneTokenizer::SingleToken mHighlightToken;
136138

137139
protected:
140+
// Configuration
141+
QColor mInstructionHighlightColor;
142+
QColor mSelectionColor;
143+
QColor mCipBackgroundColor;
144+
QColor mBreakpointBackgroundColor;
145+
QColor mBreakpointColor;
146+
QColor mCipColor;
147+
QColor mHardwareBreakpointBackgroundColor;
148+
QColor mHardwareBreakpointColor;
149+
QColor mBookmarkBackgroundColor;
150+
QColor mBookmarkColor;
151+
QColor mLabelColor;
152+
QColor mLabelBackgroundColor;
153+
QColor mSelectedAddressBackgroundColor;
154+
QColor mSelectedAddressColor;
155+
QColor mAddressBackgroundColor;
156+
QColor mAddressColor;
157+
138158
bool mRvaDisplayEnabled;
139159
duint mRvaDisplayBase;
140160
dsint mRvaDisplayPageBase;

src/gui/Src/BasicView/HexDump.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
HexDump::HexDump(QWidget* parent) : AbstractTableView(parent)
77
{
8-
fontsUpdated();
98
SelectionData_t data;
109
memset(&data, 0, sizeof(SelectionData_t));
1110
mSelection = data;
@@ -25,20 +24,24 @@ HexDump::HexDump(QWidget* parent) : AbstractTableView(parent)
2524

2625
mRvaDisplayEnabled = false;
2726

27+
// Slots
2828
connect(Bridge::getBridge(), SIGNAL(updateDump()), this, SLOT(reloadData()));
2929
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(debugStateChanged(DBGSTATE)));
30+
31+
Initialize();
3032
}
3133

32-
void HexDump::colorsUpdated()
34+
void HexDump::updateColors()
3335
{
34-
AbstractTableView::colorsUpdated();
36+
AbstractTableView::updateColors();
37+
3538
backgroundColor = ConfigColor("HexDumpBackgroundColor");
3639
textColor = ConfigColor("HexDumpTextColor");
3740
selectionColor = ConfigColor("HexDumpSelectionColor");
3841
reloadData();
3942
}
4043

41-
void HexDump::fontsUpdated()
44+
void HexDump::updateFonts()
4245
{
4346
setFont(ConfigFont("HexDump"));
4447
}

0 commit comments

Comments
 (0)