diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2016-06-19 10:46:49 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2016-06-20 11:57:57 +0000 |
commit | ac931e19d5cef37d235d3885770e475a0d07fdda (patch) | |
tree | d023fc9d774164c90263551fee2d00087c1ad791 | |
parent | 9577eb72b49df64828e6ebbd8082e66e094eac36 (diff) | |
download | qt-creator-ac931e19d5cef37d235d3885770e475a0d07fdda.tar.gz |
TextEditor: Improve default color mechanism in FormatDescription
Required for providing defaults for non-existent entries that should
fall-back to text.
Change-Id: I8ce33257a55cf173a5e9b904b7da6326163b4261
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
-rw-r--r-- | src/plugins/texteditor/fontsettings.cpp | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettingspage.cpp | 54 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettingspage.h | 4 |
3 files changed, 29 insertions, 33 deletions
diff --git a/src/plugins/texteditor/fontsettings.cpp b/src/plugins/texteditor/fontsettings.cpp index 1af2bfcd52..565dd690f6 100644 --- a/src/plugins/texteditor/fontsettings.cpp +++ b/src/plugins/texteditor/fontsettings.cpp @@ -363,8 +363,8 @@ bool FontSettings::loadColorScheme(const QString &fileName, if (!m_scheme.contains(id)) { Format format; const Format &descFormat = desc.format(); - format.setForeground(desc.foreground()); - format.setBackground(desc.background()); + format.setForeground(descFormat.foreground()); + format.setBackground(descFormat.background()); format.setBold(descFormat.bold()); format.setItalic(descFormat.italic()); format.setUnderlineColor(descFormat.underlineColor()); diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp index 0fb6dcbb54..97865a404a 100644 --- a/src/plugins/texteditor/fontsettingspage.cpp +++ b/src/plugins/texteditor/fontsettingspage.cpp @@ -204,6 +204,7 @@ FormatDescription::FormatDescription(TextStyle id, m_showControls(showControls) { m_format.setForeground(foreground); + m_format.setBackground(defaultBackground(id)); } FormatDescription::FormatDescription(TextStyle id, @@ -230,8 +231,8 @@ FormatDescription::FormatDescription(TextStyle id, m_tooltipText(tooltipText), m_showControls(showControls) { - m_format.setForeground(QColor()); - m_format.setBackground(QColor()); + m_format.setForeground(defaultForeground(id)); + m_format.setBackground(defaultBackground(id)); m_format.setUnderlineColor(underlineColor); m_format.setUnderlineStyle(underlineStyle); } @@ -245,52 +246,54 @@ FormatDescription::FormatDescription(TextStyle id, m_tooltipText(tooltipText), m_showControls(showControls) { + m_format.setForeground(defaultForeground(id)); + m_format.setBackground(defaultBackground(id)); } -QColor FormatDescription::foreground() const +QColor FormatDescription::defaultForeground(TextStyle id) { - if (m_id == C_LINE_NUMBER) { + if (id == C_LINE_NUMBER) { const QColor bg = QApplication::palette().background().color(); if (bg.value() < 128) return QApplication::palette().foreground().color(); else return QApplication::palette().dark().color(); - } else if (m_id == C_CURRENT_LINE_NUMBER) { + } else if (id == C_CURRENT_LINE_NUMBER) { const QColor bg = QApplication::palette().background().color(); if (bg.value() < 128) return QApplication::palette().foreground().color(); else - return m_format.foreground(); - } else if (m_id == C_PARENTHESES) { + return QColor(); + } else if (id == C_PARENTHESES) { return QColor(Qt::red); - } else if (m_id == C_AUTOCOMPLETE) { + } else if (id == C_AUTOCOMPLETE) { return QColor(Qt::darkBlue); } - return m_format.foreground(); + return QColor(); } -QColor FormatDescription::background() const +QColor FormatDescription::defaultBackground(TextStyle id) { - if (m_id == C_TEXT) { + if (id == C_TEXT) { return Qt::white; - } else if (m_id == C_LINE_NUMBER) { + } else if (id == C_LINE_NUMBER) { return QApplication::palette().background().color(); - } else if (m_id == C_SEARCH_RESULT) { + } else if (id == C_SEARCH_RESULT) { return QColor(0xffef0b); - } else if (m_id == C_PARENTHESES) { + } else if (id == C_PARENTHESES) { return QColor(0xb4, 0xee, 0xb4); - } else if (m_id == C_PARENTHESES_MISMATCH) { + } else if (id == C_PARENTHESES_MISMATCH) { return QColor(Qt::magenta); - } else if (m_id == C_AUTOCOMPLETE) { + } else if (id == C_AUTOCOMPLETE) { return QColor(192, 192, 255); - } else if (m_id == C_CURRENT_LINE || m_id == C_SEARCH_SCOPE) { + } else if (id == C_CURRENT_LINE || id == C_SEARCH_SCOPE) { const QPalette palette = QApplication::palette(); const QColor &fg = palette.color(QPalette::Highlight); const QColor &bg = palette.color(QPalette::Base); qreal smallRatio; qreal largeRatio; - if (m_id == C_CURRENT_LINE) { + if (id == C_CURRENT_LINE) { smallRatio = .3; largeRatio = .6; } else { @@ -304,22 +307,15 @@ QColor FormatDescription::background() const fg.greenF() * ratio + bg.greenF() * (1 - ratio), fg.blueF() * ratio + bg.blueF() * (1 - ratio)); return col; - } else if (m_id == C_SELECTION) { + } else if (id == C_SELECTION) { const QPalette palette = QApplication::palette(); return palette.color(QPalette::Highlight); - } else if (m_id == C_OCCURRENCES) { + } else if (id == C_OCCURRENCES) { return QColor(180, 180, 180); - } else if (m_id == C_OCCURRENCES_RENAME) { + } else if (id == C_OCCURRENCES_RENAME) { return QColor(255, 100, 100); - } else if (m_id == C_DISABLED_CODE) { + } else if (id == C_DISABLED_CODE) { return QColor(239, 239, 239); - } else if (m_id == C_DIFF_FILE_LINE - || m_id == C_DIFF_CONTEXT_LINE - || m_id == C_DIFF_SOURCE_LINE - || m_id == C_DIFF_SOURCE_CHAR - || m_id == C_DIFF_DEST_LINE - || m_id == C_DIFF_DEST_CHAR) { - return m_format.background(); } return QColor(); // invalid color } diff --git a/src/plugins/texteditor/fontsettingspage.h b/src/plugins/texteditor/fontsettingspage.h index fccc072e48..6dfb5f1da7 100644 --- a/src/plugins/texteditor/fontsettingspage.h +++ b/src/plugins/texteditor/fontsettingspage.h @@ -89,8 +89,8 @@ public: QString displayName() const { return m_displayName; } - QColor foreground() const; - QColor background() const; + static QColor defaultForeground(TextStyle id); + static QColor defaultBackground(TextStyle id); const Format &format() const { return m_format; } Format &format() { return m_format; } |