mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 04:16:12 +00:00
Enhance DisassemblyWidget highlighting
This commit is contained in:
parent
65ec19ddbf
commit
5fb0527acf
@ -29,6 +29,8 @@ void Configuration::loadDefaultTheme()
|
|||||||
QColor color8 = QColor(108, 108, 108);
|
QColor color8 = QColor(108, 108, 108);
|
||||||
QColor color9 = QColor(128, 64, 0);
|
QColor color9 = QColor(128, 64, 0);
|
||||||
|
|
||||||
|
QColor highlightColor = QColor(210, 210, 255);
|
||||||
|
|
||||||
// Instructions
|
// Instructions
|
||||||
setColor("comment", color4);
|
setColor("comment", color4);
|
||||||
setColor("usrcmt", color2);
|
setColor("usrcmt", color2);
|
||||||
@ -90,7 +92,7 @@ void Configuration::loadDefaultTheme()
|
|||||||
setColor("gui.cflow", color0);
|
setColor("gui.cflow", color0);
|
||||||
setColor("gui.dataoffset", color0);
|
setColor("gui.dataoffset", color0);
|
||||||
setColor("gui.border", color0);
|
setColor("gui.border", color0);
|
||||||
setColor("highlight", color0);
|
setColor("highlight", highlightColor);
|
||||||
// Windows background
|
// Windows background
|
||||||
setColor("gui.background", QColor(255, 255, 255));
|
setColor("gui.background", QColor(255, 255, 255));
|
||||||
// Disassembly nodes background
|
// Disassembly nodes background
|
||||||
@ -111,6 +113,8 @@ void Configuration::loadDarkTheme()
|
|||||||
QColor color8 = QColor(108, 108, 108);
|
QColor color8 = QColor(108, 108, 108);
|
||||||
QColor color9 = QColor(255, 128, 0);
|
QColor color9 = QColor(255, 128, 0);
|
||||||
|
|
||||||
|
QColor highlightColor = QColor(64, 115, 115);
|
||||||
|
|
||||||
// Instructions
|
// Instructions
|
||||||
setColor("comment", color4);
|
setColor("comment", color4);
|
||||||
setColor("usrcmt", color2);
|
setColor("usrcmt", color2);
|
||||||
@ -172,7 +176,7 @@ void Configuration::loadDarkTheme()
|
|||||||
setColor("gui.cflow", color0);
|
setColor("gui.cflow", color0);
|
||||||
setColor("gui.dataoffset", color0);
|
setColor("gui.dataoffset", color0);
|
||||||
setColor("gui.border", color0);
|
setColor("gui.border", color0);
|
||||||
setColor("highlight", color0);
|
setColor("highlight", highlightColor);
|
||||||
// Windows background
|
// Windows background
|
||||||
setColor("gui.background", QColor(36, 66, 79));
|
setColor("gui.background", QColor(36, 66, 79));
|
||||||
// Disassembly nodes background
|
// Disassembly nodes background
|
||||||
|
@ -229,57 +229,56 @@ void DisassemblyWidget::highlightCurrentLine()
|
|||||||
{
|
{
|
||||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||||
|
|
||||||
|
QColor highlightColor = ConfigColor("highlight");
|
||||||
|
QColor highlightWordColor = ConfigColor("highlight");
|
||||||
|
highlightWordColor.setAlpha(128);
|
||||||
|
QColor highlightWordCurrentLineColor = ConfigColor("gui.background");
|
||||||
|
highlightWordCurrentLineColor.setAlpha(128);
|
||||||
|
|
||||||
// Highlight the current line
|
// Highlight the current line
|
||||||
if (mDisasTextEdit->isReadOnly())
|
QTextEdit::ExtraSelection selection;
|
||||||
{
|
selection.format.setBackground(highlightColor);
|
||||||
QTextEdit::ExtraSelection selection;
|
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||||
QColor lineColor = ConfigColor("gui.highlight");
|
selection.cursor = mDisasTextEdit->textCursor();
|
||||||
lineColor.setAlpha(128);
|
selection.cursor.clearSelection();
|
||||||
selection.format.setBackground(lineColor);
|
extraSelections.append(selection);
|
||||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
|
||||||
selection.cursor = mDisasTextEdit->textCursor();
|
|
||||||
selection.cursor.clearSelection();
|
|
||||||
extraSelections.append(selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Highlight the current word
|
// Highlight the current word
|
||||||
QTextCursor cursor = mDisasTextEdit->textCursor();
|
QTextCursor cursor = mDisasTextEdit->textCursor();
|
||||||
cursor.select(QTextCursor::WordUnderCursor);
|
cursor.select(QTextCursor::WordUnderCursor);
|
||||||
|
|
||||||
QTextEdit::ExtraSelection currentWord;
|
|
||||||
|
|
||||||
QColor highlightColor = ConfigColor("comment");
|
|
||||||
highlightColor.setAlpha(128);
|
|
||||||
currentWord.format.setBackground(highlightColor);
|
|
||||||
|
|
||||||
currentWord.cursor = cursor;
|
|
||||||
extraSelections.append(currentWord);
|
|
||||||
currentWord.cursor.clearSelection();
|
|
||||||
|
|
||||||
// Highlight all the words in the document same as the actual one
|
|
||||||
QString searchString = cursor.selectedText();
|
QString searchString = cursor.selectedText();
|
||||||
|
|
||||||
|
cursor.movePosition(QTextCursor::StartOfLine);
|
||||||
|
int listStartPos = cursor.position();
|
||||||
|
cursor.movePosition(QTextCursor::EndOfLine);
|
||||||
|
int lineEndPos = cursor.position();
|
||||||
|
|
||||||
|
// Highlight all the words in the document same as the current one
|
||||||
QTextDocument *document = mDisasTextEdit->document();
|
QTextDocument *document = mDisasTextEdit->document();
|
||||||
|
|
||||||
//QTextCursor highlightCursor(document);
|
|
||||||
QTextEdit::ExtraSelection highlightSelection;
|
QTextEdit::ExtraSelection highlightSelection;
|
||||||
highlightSelection.cursor = cursor;
|
highlightSelection.cursor = cursor;
|
||||||
highlightSelection.format.setBackground(highlightColor);
|
|
||||||
QTextCursor cursor2(document);
|
|
||||||
|
|
||||||
cursor2.beginEditBlock();
|
|
||||||
|
|
||||||
highlightSelection.cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
|
highlightSelection.cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
|
||||||
|
|
||||||
while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd())
|
while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd())
|
||||||
{
|
{
|
||||||
highlightSelection.cursor = document->find(searchString, highlightSelection.cursor, QTextDocument::FindWholeWords);
|
highlightSelection.cursor = document->find(searchString, highlightSelection.cursor, QTextDocument::FindWholeWords);
|
||||||
|
|
||||||
if (!highlightSelection.cursor.isNull())
|
if (!highlightSelection.cursor.isNull())
|
||||||
{
|
{
|
||||||
|
if (highlightSelection.cursor.position() >= listStartPos && highlightSelection.cursor.position() <= lineEndPos)
|
||||||
|
{
|
||||||
|
highlightSelection.format.setBackground(highlightWordCurrentLineColor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
highlightSelection.format.setBackground(highlightWordColor);
|
||||||
|
}
|
||||||
|
|
||||||
highlightSelection.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
highlightSelection.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||||
extraSelections.append(highlightSelection);
|
extraSelections.append(highlightSelection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor2.endEditBlock();
|
|
||||||
|
|
||||||
mDisasTextEdit->setExtraSelections(extraSelections);
|
mDisasTextEdit->setExtraSelections(extraSelections);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user