forked from CE-Programming/CEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disasmwidget.cpp
57 lines (45 loc) · 1.68 KB
/
disasmwidget.cpp
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
#include <QtWidgets>
#include "disasmwidget.h"
/* extraHighlights (0) = current line selection */
DisasmWidget::DisasmWidget(QWidget *p) : QPlainTextEdit(p) {
connect(this, &QPlainTextEdit::cursorPositionChanged, this, &DisasmWidget::highlightCurrentLine);
}
void DisasmWidget::clearAllHighlights() {
while (!extraHighlights.isEmpty()) {
extraHighlights.removeFirst();
}
extraHighlights.clear();
updateAllHighlights();
}
void DisasmWidget::updateAllHighlights() {
setExtraSelections(extraHighlights);
}
QString DisasmWidget::getSelectedAddress() {
QTextCursor c = textCursor();
c.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
c.setPosition(c.position()+3, QTextCursor::MoveAnchor); // +3 == 3 debug symbols
c.setPosition(c.position()+6, QTextCursor::KeepAnchor); // +6 == size of the address
// See MainWindow::drawNextDisassembleLine() for details
return c.selectedText();
}
void DisasmWidget::addHighlight(QColor color) {
QTextEdit::ExtraSelection selection;
selection.format.setBackground(color);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.movePosition(QTextCursor::StartOfLine);
extraHighlights.append(selection);
}
void DisasmWidget::cursorState(bool moveable) {
cursor_state = moveable;
if (moveable) {
addHighlight(QColor(Qt::yellow).lighter(160));
}
}
void DisasmWidget::highlightCurrentLine() {
if(cursor_state == true) {
extraHighlights.removeLast();
addHighlight(QColor(Qt::yellow).lighter(160));
updateAllHighlights();
}
}