mirror of
https://github.com/rizinorg/cutter
synced 2026-08-11 16:23:06 -04:00
Fix word highlight color issues (#3560)
* Remove custom foreground color option * Reduce transparency of word highlight slightly
This commit is contained in:
parent
1e0c17243b
commit
1685f70286
7 changed files with 67 additions and 80 deletions
|
|
@ -11,19 +11,31 @@
|
|||
#include "common/Configuration.h"
|
||||
|
||||
const QStringList ColorThemeWorker::cutterSpecificOptions = {
|
||||
"wordHighlightBg", "wordHighlightFg",
|
||||
"lineHighlight", "searchCurrent",
|
||||
"searchHighlight", "gui.main",
|
||||
"gui.imports", "highlightPC",
|
||||
"gui.navbar.err", "gui.navbar.seek",
|
||||
"gui.navbar.pc", "gui.navbar.sym",
|
||||
"gui.dataoffset", "gui.navbar.code",
|
||||
"gui.navbar.unexplored", "gui.navbar.str",
|
||||
"gui.navbar.import", "gui.navbar.signature",
|
||||
"gui.navbar.data", "gui.breakpoint_background",
|
||||
"gui.overview.node", "gui.overview.fill",
|
||||
"gui.overview.border", "gui.border",
|
||||
"gui.background", "gui.alt_background",
|
||||
"wordHighlight",
|
||||
"lineHighlight",
|
||||
"searchCurrent",
|
||||
"searchHighlight",
|
||||
"gui.main",
|
||||
"gui.imports",
|
||||
"highlightPC",
|
||||
"gui.navbar.err",
|
||||
"gui.navbar.seek",
|
||||
"gui.navbar.pc",
|
||||
"gui.navbar.sym",
|
||||
"gui.dataoffset",
|
||||
"gui.navbar.code",
|
||||
"gui.navbar.unexplored",
|
||||
"gui.navbar.str",
|
||||
"gui.navbar.import",
|
||||
"gui.navbar.signature",
|
||||
"gui.navbar.data",
|
||||
"gui.breakpoint_background",
|
||||
"gui.overview.node",
|
||||
"gui.overview.fill",
|
||||
"gui.overview.border",
|
||||
"gui.border",
|
||||
"gui.background",
|
||||
"gui.alt_background",
|
||||
"gui.disass_selected",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -92,12 +92,9 @@ const QHash<QString, QHash<ColorFlags, QColor>> Configuration::cutterOptionColor
|
|||
{ "lineHighlight",
|
||||
{ { DarkFlag, QColor(0x15, 0x1d, 0x1d, 0x96) },
|
||||
{ LightFlag, QColor(0xd2, 0xd2, 0xff, 0x96) } } },
|
||||
{ "wordHighlightBg",
|
||||
{ { DarkFlag, QColor(0x3a, 0x41, 0x50, 0xff) },
|
||||
{ LightFlag, QColor(0xb3, 0x77, 0xd6, 0x50) } } },
|
||||
{ "wordHighlightFg",
|
||||
{ { DarkFlag, QColor(0x00, 0x00, 0x00, 0x00) },
|
||||
{ LightFlag, QColor(0x00, 0x00, 0x00, 0x00) } } },
|
||||
{ "wordHighlight",
|
||||
{ { DarkFlag, QColor(0x37, 0x3d, 0x4b, 0xff) },
|
||||
{ LightFlag, QColor(0xb3, 0x77, 0xd6, 0x46) } } },
|
||||
{ "highlightPC",
|
||||
{ { DarkFlag, QColor(0x57, 0x1a, 0x07) }, { LightFlag, QColor(0xd6, 0xff, 0xd2) } } },
|
||||
{ "gui.overview.fill",
|
||||
|
|
|
|||
|
|
@ -16,15 +16,7 @@ QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textE
|
|||
QList<QTextEdit::ExtraSelection> selections;
|
||||
QTextEdit::ExtraSelection highlightSelection;
|
||||
QTextDocument *document = textEdit->document();
|
||||
QColor highlightWordBgColor = ConfigColor("wordHighlightBg");
|
||||
QColor highlightWordFgColor = ConfigColor("wordHighlightFg");
|
||||
|
||||
auto applyHighlight = [&] {
|
||||
QColor originalColor = highlightSelection.cursor.charFormat().foreground().color();
|
||||
highlightSelection.format.setForeground(
|
||||
Colors::overlayColor(originalColor, highlightWordFgColor));
|
||||
highlightSelection.format.setBackground(highlightWordBgColor);
|
||||
};
|
||||
QColor highlightWordColor = ConfigColor("wordHighlight");
|
||||
|
||||
if (word.isEmpty()) {
|
||||
return QList<QTextEdit::ExtraSelection>();
|
||||
|
|
@ -58,7 +50,7 @@ QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textE
|
|||
val--;
|
||||
}
|
||||
if (val == 0) {
|
||||
applyHighlight();
|
||||
highlightSelection.format.setBackground(highlightWordColor);
|
||||
selections.append(highlightSelection);
|
||||
break;
|
||||
}
|
||||
|
|
@ -74,7 +66,7 @@ QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textE
|
|||
document->find(word, highlightSelection.cursor, QTextDocument::FindWholeWords);
|
||||
|
||||
if (!highlightSelection.cursor.isNull()) {
|
||||
applyHighlight();
|
||||
highlightSelection.format.setBackground(highlightWordColor);
|
||||
selections.append(highlightSelection);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,7 +223,6 @@ static void syncCustomThemes()
|
|||
// in config, unless changed by the user
|
||||
QHash<QString, QString> renames = {
|
||||
{ "angui.navbar.str", "gui.navbar.str" },
|
||||
{ "wordHighlight", "wordHighlightBg" },
|
||||
{ "gui.navbar.empty", "gui.navbar.unexplored" },
|
||||
};
|
||||
const QStringList forceDefaultKeys = { "gui.navbar.signature", "gui.navbar.data" };
|
||||
|
|
|
|||
|
|
@ -18,9 +18,8 @@ ColorThemeEditDialog::ColorThemeEditDialog(QWidget *parent)
|
|||
Config()), // Blocks signals from Config to avoid updating of widgets during editing
|
||||
colorTheme(Config()->getColorTheme())
|
||||
{
|
||||
showAlphaOptions = { "gui.overview.border", "gui.overview.fill", "wordHighlightBg",
|
||||
"wordHighlightFg", "lineHighlight", "searchCurrent",
|
||||
"searchHighlight" };
|
||||
showAlphaOptions = { "gui.overview.border", "gui.overview.fill", "wordHighlight",
|
||||
"lineHighlight", "searchCurrent", "searchHighlight" };
|
||||
ui->setupUi(this);
|
||||
ui->colorComboBox->setShowOnlyCustom(true);
|
||||
|
||||
|
|
|
|||
|
|
@ -627,12 +627,9 @@ const QMap<QString, OptionInfo> OPTION_INFO_MAP = {
|
|||
{ "lineHighlight",
|
||||
{ QT_TRANSLATE_NOOP("ColorTheme", "Color for highlighted line"),
|
||||
QT_TRANSLATE_NOOP("ColorTheme", "Line Highlight") } },
|
||||
{ "wordHighlightBg",
|
||||
{ "wordHighlight",
|
||||
{ QT_TRANSLATE_NOOP("ColorTheme", "Background color for highlighted word"),
|
||||
QT_TRANSLATE_NOOP("ColorTheme", "Word Highlight Background") } },
|
||||
{ "wordHighlightFg",
|
||||
{ QT_TRANSLATE_NOOP("ColorTheme", "Foreground color for highlighted word"),
|
||||
QT_TRANSLATE_NOOP("ColorTheme", "Word Highlight Foreground") } },
|
||||
{ "searchCurrent",
|
||||
{ QT_TRANSLATE_NOOP("ColorTheme", "Background color for the currently selected search match"),
|
||||
QT_TRANSLATE_NOOP("ColorTheme", "Current Search Highlight") } },
|
||||
|
|
|
|||
|
|
@ -424,8 +424,6 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block,
|
|||
p.drawRect(blockRect);
|
||||
}
|
||||
|
||||
const int firstInstructionY = block.y + getInstructionOffset(db, 0).y();
|
||||
|
||||
// Stop rendering text when it's too small
|
||||
auto transform = p.combinedTransform();
|
||||
QRect screenChar = transform.mapRect(QRect(0, 0, ACharWidth, charHeight));
|
||||
|
|
@ -436,45 +434,6 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block,
|
|||
|
||||
qreal indent = ACharWidth;
|
||||
|
||||
// Highlight selected tokens
|
||||
if (interactive && highlight_token != nullptr) {
|
||||
int y = firstInstructionY;
|
||||
qreal tokenWidth = mFontMetrics->width(highlight_token->content);
|
||||
|
||||
for (const Instr &instr : db.instrs) {
|
||||
int pos = -1;
|
||||
|
||||
while ((pos = instr.plainText.indexOf(highlight_token->content, pos + 1)) != -1) {
|
||||
int tokenEnd = pos + highlight_token->content.length();
|
||||
|
||||
if ((pos > 0 && instr.plainText[pos - 1].isLetterOrNumber())
|
||||
|| (tokenEnd < instr.plainText.length()
|
||||
&& instr.plainText[tokenEnd].isLetterOrNumber())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qreal widthBefore = mFontMetrics->width(instr.plainText.left(pos));
|
||||
qreal textOffset = padding + indent;
|
||||
if (textOffset + widthBefore > block.width - (10 + padding)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qreal highlightWidth = tokenWidth;
|
||||
if (textOffset + widthBefore + tokenWidth >= block.width - (10 + padding)) {
|
||||
highlightWidth = block.width - widthBefore - (10 + 2 * padding);
|
||||
}
|
||||
|
||||
QColor selectionColor = ConfigColor("wordHighlight");
|
||||
|
||||
p.fillRect(
|
||||
QRectF(block.x + textOffset + widthBefore, y, highlightWidth, charHeight),
|
||||
selectionColor);
|
||||
}
|
||||
|
||||
y += int(instr.text.lines.size()) * charHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Render node text
|
||||
auto x = block.x + padding;
|
||||
int y = block.y + getTextOffset(0).y();
|
||||
|
|
@ -485,6 +444,8 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block,
|
|||
}
|
||||
|
||||
auto bih = Core()->getBIHighlighter();
|
||||
QColor selectionColor = ConfigColor("wordHighlight");
|
||||
|
||||
for (const Instr &instr : db.instrs) {
|
||||
const QRect instrRect = QRect(static_cast<int>(block.x + indent), y,
|
||||
static_cast<int>(block.width - (10 + padding)),
|
||||
|
|
@ -507,8 +468,38 @@ void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block,
|
|||
p.fillRect(instrRect, disassemblySelectionColor);
|
||||
}
|
||||
|
||||
for (auto &line : instr.text.lines) {
|
||||
// Highlight selected tokens
|
||||
if (interactive && highlight_token != nullptr) {
|
||||
int pos = -1;
|
||||
qreal tokenWidth = mFontMetrics->width(highlight_token->content);
|
||||
while ((pos = instr.plainText.indexOf(highlight_token->content, pos + 1)) != -1) {
|
||||
int tokenEnd = pos + highlight_token->content.length();
|
||||
|
||||
if ((pos > 0 && instr.plainText[pos - 1].isLetterOrNumber())
|
||||
|| (tokenEnd < instr.plainText.length()
|
||||
&& instr.plainText[tokenEnd].isLetterOrNumber())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qreal widthBefore = mFontMetrics->width(instr.plainText.left(pos));
|
||||
qreal textOffset = padding + indent;
|
||||
|
||||
if (textOffset + widthBefore > block.width - (10 + padding)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qreal highlightWidth = tokenWidth;
|
||||
if (textOffset + widthBefore + tokenWidth >= block.width - (10 + padding)) {
|
||||
highlightWidth = block.width - widthBefore - (10 + 2 * padding);
|
||||
}
|
||||
|
||||
p.fillRect(
|
||||
QRectF(block.x + textOffset + widthBefore, y, highlightWidth, charHeight),
|
||||
selectionColor);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &line : instr.text.lines) {
|
||||
RichTextPainter::paintRichText<qreal>(&p, x + indent, y, block.width - padding,
|
||||
charHeight, 0, line, mFontMetrics.get());
|
||||
y += charHeight;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue