From 968a3c0f9f0365be61946783513214135532ba77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 27 Apr 2009 14:10:54 +0200 Subject: [PATCH] Added 'current line number' to color theme settings Recently it was made to highlight black or write, which isn't nice for everybody. Now it is dark gray by default, and can be customized. Bold and italic are also supported. --- src/plugins/texteditor/basetexteditor.cpp | 20 +++++++++---------- src/plugins/texteditor/basetexteditor_p.h | 1 + src/plugins/texteditor/fontsettingspage.cpp | 4 ++-- src/plugins/texteditor/texteditorconstants.h | 1 + src/plugins/texteditor/texteditorsettings.cpp | 1 + 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index bc474a5c8ea..ada99dc501c 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1513,7 +1513,7 @@ QRect BaseTextEditor::collapseBox() return QRect(); QTextBlock begin = document()->findBlockByNumber(d->m_highlightBlocksInfo.open.last()); - QTextBlock end= document()->findBlockByNumber(d->m_highlightBlocksInfo.close.first()); + QTextBlock end = document()->findBlockByNumber(d->m_highlightBlocksInfo.close.first()); if (!begin.isValid() || !end.isValid()) return QRect(); QRectF br = blockBoundingGeometry(begin).translated(contentOffset()); @@ -2349,7 +2349,11 @@ void BaseTextEditor::extraAreaPaintEvent(QPaintEvent *e) const QString &number = QString::number(blockNumber + 1); if (blockNumber == cursorBlockNumber) { painter.save(); - painter.setPen(pal.color(QPalette::Background).value() < 128 ? Qt::white : Qt::black); + QFont f = painter.font(); + f.setBold(d->m_currentLineNumberFormat.font().bold()); + f.setItalic(d->m_currentLineNumberFormat.font().italic()); + painter.setFont(f); + painter.setPen(d->m_currentLineNumberFormat.foreground().color()); } painter.drawText(markWidth, top, extraAreaWidth - markWidth - 4, fm.height(), Qt::AlignRight, number); if (blockNumber == cursorBlockNumber) @@ -3547,10 +3551,11 @@ void BaseTextEditor::setFontSettings(const TextEditor::FontSettings &fs) const QTextCharFormat selectionFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SELECTION)); const QTextCharFormat lineNumberFormat = fs.toTextCharFormat(QLatin1String(Constants::C_LINE_NUMBER)); const QTextCharFormat searchResultFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SEARCH_RESULT)); - const QTextCharFormat searchScopeFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SEARCH_SCOPE)); + d->m_searchScopeFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SEARCH_SCOPE)); const QTextCharFormat parenthesesFormat = fs.toTextCharFormat(QLatin1String(Constants::C_PARENTHESES)); - const QTextCharFormat currentLineFormat = fs.toTextCharFormat(QLatin1String(Constants::C_CURRENT_LINE)); - const QTextCharFormat ifdefedOutFormat = fs.toTextCharFormat(QLatin1String(Constants::C_DISABLED_CODE)); + d->m_currentLineFormat = fs.toTextCharFormat(QLatin1String(Constants::C_CURRENT_LINE)); + d->m_currentLineNumberFormat = fs.toTextCharFormat(QLatin1String(Constants::C_CURRENT_LINE_NUMBER)); + d->m_ifdefedOutFormat = fs.toTextCharFormat(QLatin1String(Constants::C_DISABLED_CODE)); QFont font(textFormat.font()); const QColor foreground = textFormat.foreground().color(); @@ -3578,16 +3583,11 @@ void BaseTextEditor::setFontSettings(const TextEditor::FontSettings &fs) // Search results d->m_searchResultFormat.setBackground(searchResultFormat.background()); - d->m_searchScopeFormat.setBackground(searchScopeFormat.background()); - d->m_currentLineFormat.setBackground(currentLineFormat.background()); // Matching braces d->m_matchFormat.setForeground(parenthesesFormat.foreground()); d->m_rangeFormat.setBackground(parenthesesFormat.background()); - // Disabled code - d->m_ifdefedOutFormat.setForeground(ifdefedOutFormat.foreground()); - slotUpdateExtraAreaWidth(); } diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 1372087f00d..27baa0851c0 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -207,6 +207,7 @@ public: QTextCharFormat m_searchResultFormat; QTextCharFormat m_searchScopeFormat; QTextCharFormat m_currentLineFormat; + QTextCharFormat m_currentLineNumberFormat; void highlightSearchResults(const QTextBlock &block, QVector *selections); diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp index 8f776f04b00..aec2acb241a 100644 --- a/src/plugins/texteditor/fontsettingspage.cpp +++ b/src/plugins/texteditor/fontsettingspage.cpp @@ -137,9 +137,9 @@ QString FormatDescription::trName() const QColor FormatDescription::foreground() const { - if (m_name == QLatin1String("LineNumber")) + if (m_name == QLatin1String(Constants::C_LINE_NUMBER)) return QApplication::palette().dark().color(); - if (m_name == QLatin1String("Parentheses")) + if (m_name == QLatin1String(Constants::C_PARENTHESES)) return QColor(Qt::red); return m_format.foreground(); } diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index e598a891148..a8dfac2b5c0 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -72,6 +72,7 @@ const char * const C_SEARCH_RESULT = "SearchResult"; const char * const C_SEARCH_SCOPE = "SearchScope"; const char * const C_PARENTHESES = "Parentheses"; const char * const C_CURRENT_LINE = "CurrentLine"; +const char * const C_CURRENT_LINE_NUMBER = "CurrentLineNumber"; const char * const C_NUMBER = "Number"; const char * const C_STRING = "String"; diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp index 31204648a1d..ca562d0df18 100644 --- a/src/plugins/texteditor/texteditorsettings.cpp +++ b/src/plugins/texteditor/texteditorsettings.cpp @@ -72,6 +72,7 @@ TextEditorSettings::TextEditorSettings(QObject *parent) formatDescriptions.push_back(FormatDescription(QLatin1String(C_SEARCH_SCOPE), tr("Search Scope"))); formatDescriptions.push_back(FormatDescription(QLatin1String(C_PARENTHESES), tr("Parentheses"))); formatDescriptions.push_back(FormatDescription(QLatin1String(C_CURRENT_LINE), tr("Current Line"))); + formatDescriptions.push_back(FormatDescription(QLatin1String(C_CURRENT_LINE_NUMBER), tr("Current Line Number"), Qt::darkGray)); // Standard categories formatDescriptions.push_back(FormatDescription(QLatin1String(C_NUMBER), tr("Number"), Qt::darkBlue));