QCodeEdit dark theme test

This commit is contained in:
2024-01-18 17:38:02 +03:00
parent b9dea57200
commit e0134b3b5e
2 changed files with 17 additions and 2 deletions

View File

@@ -584,6 +584,7 @@ void QCodeEdit::changeEvent(QEvent * e) {
ui->retranslateUi(this); ui->retranslateUi(this);
lbl_help[lhF1]->setText(tr("Press F1 for details")); lbl_help[lhF1]->setText(tr("Press F1 for details"));
break; break;
case QEvent::PaletteChange: is_dark_theme = palette().color(QPalette::Window).valueF() < 0.5; break;
default: break; default: break;
} }
} }
@@ -876,8 +877,21 @@ void QCodeEdit::highlightBrackets() {
void QCodeEdit::applyExtraSelection() { void QCodeEdit::applyExtraSelection() {
ui->textCode->setExtraSelections(QList<QTextEdit::ExtraSelection>() << es_line << es_selected << es_custom << es_brackets auto inverseColorValue = [](const QColor & c) {
<< es_search_list << es_cursor << es_link << es_blockselection); qreal hsv[4];
c.getHsvF(&hsv[0], &hsv[1], &hsv[2], &hsv[3]);
return QColor::fromHsvF(hsv[0], hsv[1], 1. - hsv[2], hsv[3]);
};
QList<QTextEdit::ExtraSelection> esl;
esl << es_line << es_selected << es_custom << es_brackets << es_search_list << es_cursor << es_link;
if (is_dark_theme) {
for (auto & e: esl) {
e.format.foreground().setColor(inverseColorValue(e.format.foreground().color()));
e.format.background().setColor(inverseColorValue(e.format.background().color()));
}
}
esl << es_blockselection;
ui->textCode->setExtraSelections(esl);
} }

View File

@@ -245,6 +245,7 @@ private:
QTextCursor block_start_cursor, drag_cursor; QTextCursor block_start_cursor, drag_cursor;
int prev_lc, auto_comp_pl, timer_parse, timer_blink, cur_search_ind, pos_press, pos_el_press; int prev_lc, auto_comp_pl, timer_parse, timer_blink, cur_search_ind, pos_press, pos_el_press;
int cursor_width; int cursor_width;
bool is_dark_theme = false;
bool spaces_, _ignore_focus_out, _first, _destructor, _replacing; bool spaces_, _ignore_focus_out, _first, _destructor, _replacing;
bool word_complete, help_visible, cursor_state, block_sel_state; bool word_complete, help_visible, cursor_state, block_sel_state;
}; };