diff --git a/libs/widgets/qcodeedit.cpp b/libs/widgets/qcodeedit.cpp index 4a5a5ed..a99d45a 100644 --- a/libs/widgets/qcodeedit.cpp +++ b/libs/widgets/qcodeedit.cpp @@ -584,6 +584,7 @@ void QCodeEdit::changeEvent(QEvent * e) { ui->retranslateUi(this); lbl_help[lhF1]->setText(tr("Press F1 for details")); break; + case QEvent::PaletteChange: is_dark_theme = palette().color(QPalette::Window).valueF() < 0.5; break; default: break; } } @@ -876,8 +877,21 @@ void QCodeEdit::highlightBrackets() { void QCodeEdit::applyExtraSelection() { - ui->textCode->setExtraSelections(QList() << es_line << es_selected << es_custom << es_brackets - << es_search_list << es_cursor << es_link << es_blockselection); + auto inverseColorValue = [](const QColor & c) { + 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 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); } diff --git a/libs/widgets/qcodeedit.h b/libs/widgets/qcodeedit.h index c5bdae9..64ad940 100644 --- a/libs/widgets/qcodeedit.h +++ b/libs/widgets/qcodeedit.h @@ -245,6 +245,7 @@ private: 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 cursor_width; + bool is_dark_theme = false; bool spaces_, _ignore_focus_out, _first, _destructor, _replacing; bool word_complete, help_visible, cursor_state, block_sel_state; };