Commit d006ca80 authored by hjk's avatar hjk Committed by hjk
Browse files

texteditor: use an enum instead of QString as color ids



Change-Id: I658412c18d5ccfe978ec444451c6417ffb18d71c
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent a872c91c
......@@ -55,7 +55,7 @@ namespace Internal {
static QTextCharFormat commentFormat()
{
const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings();
return settings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_COMMENT));
return settings.toTextCharFormat(TextEditor::C_COMMENT);
}
// Highlighter for Bazaar submit messages. Make the first line bold, indicates
......
......@@ -256,7 +256,7 @@ QByteArray BinEditor::blockData(int block, bool old) const
void BinEditor::setFontSettings(const TextEditor::FontSettings &fs)
{
setFont(fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_TEXT)).font());
setFont(fs.toTextCharFormat(TextEditor::C_TEXT).font());
}
void BinEditor::setBlinkingCursorEnabled(bool enable)
......
......@@ -166,13 +166,13 @@ void CMakeEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
if (!highlighter)
return;
static QVector<QString> categories;
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << QLatin1String(TextEditor::Constants::C_LABEL) // variables
<< QLatin1String(TextEditor::Constants::C_KEYWORD) // functions
<< QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_STRING)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
categories << TextEditor::C_LABEL // variables
<< TextEditor::C_KEYWORD // functions
<< TextEditor::C_COMMENT
<< TextEditor::C_STRING
<< TextEditor::C_VISUAL_WHITESPACE;
}
const QVector<QTextCharFormat> formats = fs.toTextCharFormats(categories);
......
......@@ -1724,28 +1724,28 @@ void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
const QVector<QTextCharFormat> formats = fs.toTextCharFormats(highlighterFormatCategories());
highlighter->setFormats(formats.constBegin(), formats.constEnd());
m_occurrencesFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES));
m_occurrencesUnusedFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES_UNUSED));
m_occurrencesFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES);
m_occurrencesUnusedFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_UNUSED);
m_occurrencesUnusedFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
m_occurrencesUnusedFormat.setUnderlineColor(m_occurrencesUnusedFormat.foreground().color());
m_occurrencesUnusedFormat.clearForeground();
m_occurrencesUnusedFormat.setToolTip(tr("Unused variable"));
m_occurrenceRenameFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES_RENAME));
m_occurrenceRenameFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_RENAME);
m_semanticHighlightFormatMap[SemanticInfo::TypeUse] =
fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_TYPE));
fs.toTextCharFormat(TextEditor::C_TYPE);
m_semanticHighlightFormatMap[SemanticInfo::LocalUse] =
fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_LOCAL));
fs.toTextCharFormat(TextEditor::C_LOCAL);
m_semanticHighlightFormatMap[SemanticInfo::FieldUse] =
fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_FIELD));
fs.toTextCharFormat(TextEditor::C_FIELD);
m_semanticHighlightFormatMap[SemanticInfo::StaticUse] =
fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_STATIC));
fs.toTextCharFormat(TextEditor::C_STATIC);
m_semanticHighlightFormatMap[SemanticInfo::VirtualMethodUse] =
fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_VIRTUAL_METHOD));
fs.toTextCharFormat(TextEditor::C_VIRTUAL_METHOD);
m_semanticHighlightFormatMap[SemanticInfo::LabelUse] =
fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_LABEL));
fs.toTextCharFormat(TextEditor::C_LABEL);
m_semanticHighlightFormatMap[SemanticInfo::MacroUse] =
fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_PREPROCESSOR));
m_keywordFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_KEYWORD));
fs.toTextCharFormat(TextEditor::C_PREPROCESSOR);
m_keywordFormat = fs.toTextCharFormat(TextEditor::C_KEYWORD);
// only set the background, we do not want to modify foreground properties set by the syntax highlighter or the link
m_occurrencesFormat.clearForeground();
......@@ -2151,21 +2151,21 @@ QModelIndex CPPEditorWidget::indexForPosition(int line, int column, const QModel
return lastIndex;
}
QVector<QString> CPPEditorWidget::highlighterFormatCategories()
QVector<TextEditor::TextStyle> CPPEditorWidget::highlighterFormatCategories()
{
static QVector<QString> categories;
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << QLatin1String(TextEditor::Constants::C_NUMBER)
<< QLatin1String(TextEditor::Constants::C_STRING)
<< QLatin1String(TextEditor::Constants::C_TYPE)
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
<< QLatin1String(TextEditor::Constants::C_OPERATOR)
<< QLatin1String(TextEditor::Constants::C_PREPROCESSOR)
<< QLatin1String(TextEditor::Constants::C_LABEL)
<< QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_COMMENT)
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_TAG)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
categories << TextEditor::C_NUMBER
<< TextEditor::C_STRING
<< TextEditor::C_TYPE
<< TextEditor::C_KEYWORD
<< TextEditor::C_OPERATOR
<< TextEditor::C_PREPROCESSOR
<< TextEditor::C_LABEL
<< TextEditor::C_COMMENT
<< TextEditor::C_DOXYGEN_COMMENT
<< TextEditor::C_DOXYGEN_TAG
<< TextEditor::C_VISUAL_WHITESPACE;
}
return categories;
}
......
......@@ -41,6 +41,7 @@
#include <cplusplus/LookupContext.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/quickfix.h>
#include <texteditor/texteditorconstants.h>
#include <cpptools/commentssettings.h>
#include <cpptools/cppsemanticinfo.h>
......@@ -192,7 +193,7 @@ public:
static Link linkToSymbol(CPlusPlus::Symbol *symbol);
static QVector<QString> highlighterFormatCategories();
static QVector<TextEditor::TextStyle> highlighterFormatCategories();
virtual TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind kind,
TextEditor::AssistReason reason) const;
......
......@@ -54,7 +54,7 @@ namespace Internal {
static QTextCharFormat commentFormat()
{
const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings();
return settings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_COMMENT));
return settings.toTextCharFormat(TextEditor::C_COMMENT);
}
// Highlighter for git submit messages. Make the first line bold, indicates
......
......@@ -229,20 +229,20 @@ void GLSLTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
CommentFormat,
VisualWhitespace,
*/
static QVector<QString> categories;
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << QLatin1String(TextEditor::Constants::C_NUMBER)
<< QLatin1String(TextEditor::Constants::C_STRING)
<< QLatin1String(TextEditor::Constants::C_TYPE)
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
<< QLatin1String(TextEditor::Constants::C_OPERATOR)
<< QLatin1String(TextEditor::Constants::C_PREPROCESSOR)
<< QLatin1String(TextEditor::Constants::C_LABEL)
<< QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_COMMENT)
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_TAG)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE)
<< QLatin1String(TextEditor::Constants::C_REMOVED_LINE);
categories << TextEditor::C_NUMBER
<< TextEditor::C_STRING
<< TextEditor::C_TYPE
<< TextEditor::C_KEYWORD
<< TextEditor::C_OPERATOR
<< TextEditor::C_PREPROCESSOR
<< TextEditor::C_LABEL
<< TextEditor::C_COMMENT
<< TextEditor::C_DOXYGEN_COMMENT
<< TextEditor::C_DOXYGEN_TAG
<< TextEditor::C_VISUAL_WHITESPACE
<< TextEditor::C_REMOVED_LINE;
}
highlighter->setFormats(fs.toTextCharFormats(categories));
......
......@@ -54,7 +54,7 @@ namespace Internal {
static QTextCharFormat commentFormat()
{
const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings();
return settings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_COMMENT));
return settings.toTextCharFormat(TextEditor::C_COMMENT);
}
// Highlighter for Mercurial submit messages. Make the first line bold, indicates
......
......@@ -1015,13 +1015,13 @@ void QmlJSTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->setFormats(fs.toTextCharFormats(highlighterFormatCategories()));
highlighter->rehighlight();
m_occurrencesFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES));
m_occurrencesUnusedFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES_UNUSED));
m_occurrencesFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES);
m_occurrencesUnusedFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_UNUSED);
m_occurrencesUnusedFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
m_occurrencesUnusedFormat.setUnderlineColor(m_occurrencesUnusedFormat.foreground().color());
m_occurrencesUnusedFormat.clearForeground();
m_occurrencesUnusedFormat.setToolTip(tr("Unused variable"));
m_occurrenceRenameFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES_RENAME));
m_occurrenceRenameFormat = fs.toTextCharFormat(TextEditor::C_OCCURRENCES_RENAME);
// only set the background, we do not want to modify foreground properties set by the syntax highlighter or the link
m_occurrencesFormat.clearForeground();
......@@ -1429,7 +1429,7 @@ bool QmlJSTextEditorWidget::hideContextPane()
return b;
}
QVector<QString> QmlJSTextEditorWidget::highlighterFormatCategories()
QVector<TextEditor::TextStyle> QmlJSTextEditorWidget::highlighterFormatCategories()
{
/*
NumberFormat,
......@@ -1440,15 +1440,15 @@ QVector<QString> QmlJSTextEditorWidget::highlighterFormatCategories()
CommentFormat,
VisualWhitespace,
*/
static QVector<QString> categories;
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << QLatin1String(TextEditor::Constants::C_NUMBER)
<< QLatin1String(TextEditor::Constants::C_STRING)
<< QLatin1String(TextEditor::Constants::C_TYPE)
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
<< QLatin1String(TextEditor::Constants::C_FIELD)
<< QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
categories << TextEditor::C_NUMBER
<< TextEditor::C_STRING
<< TextEditor::C_TYPE
<< TextEditor::C_KEYWORD
<< TextEditor::C_FIELD
<< TextEditor::C_COMMENT
<< TextEditor::C_VISUAL_WHITESPACE;
}
return categories;
}
......
......@@ -39,6 +39,7 @@
#include <qmljstools/qmljssemanticinfo.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/quickfix.h>
#include <texteditor/texteditorconstants.h>
#include <QSharedPointer>
#include <QModelIndex>
......@@ -108,7 +109,7 @@ public:
Internal::QmlOutlineModel *outlineModel() const;
QModelIndex outlineModelIndex();
static QVector<QString> highlighterFormatCategories();
static QVector<TextEditor::TextStyle> highlighterFormatCategories();
TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const;
......
......@@ -43,6 +43,7 @@
#include <texteditor/basetextdocumentlayout.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/texteditorconstants.h>
namespace QmlJSEditor {
......
......@@ -468,18 +468,18 @@ void SemanticHighlighter::finished()
void SemanticHighlighter::updateFontSettings(const TextEditor::FontSettings &fontSettings)
{
m_formats[LocalIdType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_LOCAL_ID));
m_formats[ExternalIdType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_EXTERNAL_ID));
m_formats[QmlTypeType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_TYPE_ID));
m_formats[RootObjectPropertyType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_ROOT_OBJECT_PROPERTY));
m_formats[ScopeObjectPropertyType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_SCOPE_OBJECT_PROPERTY));
m_formats[ExternalObjectPropertyType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_EXTERNAL_OBJECT_PROPERTY));
m_formats[JsScopeType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_JS_SCOPE_VAR));
m_formats[JsImportType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_JS_IMPORT_VAR));
m_formats[JsGlobalType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_JS_GLOBAL_VAR));
m_formats[LocalStateNameType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_QML_STATE_NAME));
m_formats[BindingNameType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_BINDING));
m_formats[FieldType] = fontSettings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_FIELD));
m_formats[LocalIdType] = fontSettings.toTextCharFormat(TextEditor::C_QML_LOCAL_ID);
m_formats[ExternalIdType] = fontSettings.toTextCharFormat(TextEditor::C_QML_EXTERNAL_ID);
m_formats[QmlTypeType] = fontSettings.toTextCharFormat(TextEditor::C_QML_TYPE_ID);
m_formats[RootObjectPropertyType] = fontSettings.toTextCharFormat(TextEditor::C_QML_ROOT_OBJECT_PROPERTY);
m_formats[ScopeObjectPropertyType] = fontSettings.toTextCharFormat(TextEditor::C_QML_SCOPE_OBJECT_PROPERTY);
m_formats[ExternalObjectPropertyType] = fontSettings.toTextCharFormat(TextEditor::C_QML_EXTERNAL_OBJECT_PROPERTY);
m_formats[JsScopeType] = fontSettings.toTextCharFormat(TextEditor::C_JS_SCOPE_VAR);
m_formats[JsImportType] = fontSettings.toTextCharFormat(TextEditor::C_JS_IMPORT_VAR);
m_formats[JsGlobalType] = fontSettings.toTextCharFormat(TextEditor::C_JS_GLOBAL_VAR);
m_formats[LocalStateNameType] = fontSettings.toTextCharFormat(TextEditor::C_QML_STATE_NAME);
m_formats[BindingNameType] = fontSettings.toTextCharFormat(TextEditor::C_BINDING);
m_formats[FieldType] = fontSettings.toTextCharFormat(TextEditor::C_FIELD);
}
int SemanticHighlighter::startRevision() const
......
......@@ -220,12 +220,12 @@ void ProFileEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
if (!highlighter)
return;
static QVector<QString> categories;
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << QLatin1String(TextEditor::Constants::C_TYPE)
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
<< QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
categories << TextEditor::C_TYPE
<< TextEditor::C_KEYWORD
<< TextEditor::C_COMMENT
<< TextEditor::C_VISUAL_WHITESPACE;
}
const QVector<QTextCharFormat> formats = fs.toTextCharFormats(categories);
......
......@@ -5570,16 +5570,16 @@ void BaseTextEditorWidget::setFontSettingsIfVisible(const TextEditor::FontSettin
void BaseTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
{
const QTextCharFormat textFormat = fs.toTextCharFormat(QLatin1String(Constants::C_TEXT));
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));
d->m_searchScopeFormat = fs.toTextCharFormat(QLatin1String(Constants::C_SEARCH_SCOPE));
const QTextCharFormat parenthesesFormat = fs.toTextCharFormat(QLatin1String(Constants::C_PARENTHESES));
d->m_currentLineFormat = fs.toTextCharFormat(QLatin1String(Constants::C_CURRENT_LINE));
d->m_currentLineNumberFormat = fs.toTextCharFormat(QLatin1String(Constants::C_CURRENT_LINE_NUMBER));
d->m_linkFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_LINK));
d->m_ifdefedOutFormat = fs.toTextCharFormat(QLatin1String(Constants::C_DISABLED_CODE));
const QTextCharFormat textFormat = fs.toTextCharFormat(C_TEXT);
const QTextCharFormat selectionFormat = fs.toTextCharFormat(C_SELECTION);
const QTextCharFormat lineNumberFormat = fs.toTextCharFormat(C_LINE_NUMBER);
const QTextCharFormat searchResultFormat = fs.toTextCharFormat(C_SEARCH_RESULT);
d->m_searchScopeFormat = fs.toTextCharFormat(C_SEARCH_SCOPE);
const QTextCharFormat parenthesesFormat = fs.toTextCharFormat(C_PARENTHESES);
d->m_currentLineFormat = fs.toTextCharFormat(C_CURRENT_LINE);
d->m_currentLineNumberFormat = fs.toTextCharFormat(C_CURRENT_LINE_NUMBER);
d->m_linkFormat = fs.toTextCharFormat(C_LINK);
d->m_ifdefedOutFormat = fs.toTextCharFormat(C_DISABLED_CODE);
QFont font(textFormat.font());
const QColor foreground = textFormat.foreground().color();
......@@ -5616,9 +5616,9 @@ void BaseTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
// snippests
d->m_occurrencesFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES));
d->m_occurrencesFormat = fs.toTextCharFormat(C_OCCURRENCES);
d->m_occurrencesFormat.clearForeground();
d->m_occurrenceRenameFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES_RENAME));
d->m_occurrenceRenameFormat = fs.toTextCharFormat(C_OCCURRENCES_RENAME);
d->m_occurrenceRenameFormat.clearForeground();
slotUpdateExtraAreaWidth(); // Adjust to new font width
......
......@@ -109,22 +109,22 @@ ColorScheme::ColorScheme()
{
}
bool ColorScheme::contains(const QString &category) const
bool ColorScheme::contains(TextStyle category) const
{
return m_formats.contains(category);
}
Format &ColorScheme::formatFor(const QString &category)
Format &ColorScheme::formatFor(TextStyle category)
{
return m_formats[category];
}
Format ColorScheme::formatFor(const QString &category) const
Format ColorScheme::formatFor(TextStyle category) const
{
return m_formats.value(category);
}
void ColorScheme::setFormatFor(const QString &category, const Format &format)
void ColorScheme::setFormatFor(TextStyle category, const Format &format)
{
m_formats[category] = format;
}
......@@ -148,11 +148,11 @@ bool ColorScheme::save(const QString &fileName, QWidget *parent) const
if (!m_displayName.isEmpty())
w.writeAttribute(QLatin1String("name"), m_displayName);
QMapIterator<QString, Format> i(m_formats);
QMapIterator<TextStyle, Format> i(m_formats);
while (i.hasNext()) {
const Format &format = i.next().value();
w.writeStartElement(QLatin1String("style"));
w.writeAttribute(QLatin1String("name"), i.key());
w.writeAttribute(QLatin1String("name"), QString::fromLatin1(Constants::nameForStyle(i.key())));
if (format.foreground().isValid())
w.writeAttribute(QLatin1String("foreground"), format.foreground().name().toLower());
if (format.background().isValid())
......@@ -263,7 +263,7 @@ void ColorSchemeReader::readStyle()
Q_ASSERT(isStartElement() && name() == QLatin1String("style"));
const QXmlStreamAttributes attr = attributes();
QString name = attr.value(QLatin1String("name")).toString();
QByteArray name = attr.value(QLatin1String("name")).toString().toLatin1();
QString foreground = attr.value(QLatin1String("foreground")).toString();
QString background = attr.value(QLatin1String("background")).toString();
bool bold = attr.value(QLatin1String("bold")) == QLatin1String(trueString);
......@@ -284,7 +284,7 @@ void ColorSchemeReader::readStyle()
format.setBold(bold);
format.setItalic(italic);
m_scheme->setFormatFor(name, format);
m_scheme->setFormatFor(Constants::styleFromName(name), format);
skipCurrentElement();
}
......
......@@ -34,6 +34,7 @@
#define COLORSCHEME_H
#include "texteditor_global.h"
#include "texteditorconstants.h"
#include <QMap>
#include <QString>
......@@ -96,12 +97,12 @@ public:
inline bool isEmpty() const
{ return m_formats.isEmpty(); }
bool contains(const QString &category) const;
bool contains(TextStyle category) const;
Format &formatFor(const QString &category);
Format formatFor(const QString &category) const;
Format &formatFor(TextStyle category);
Format formatFor(TextStyle category) const;
void setFormatFor(const QString &category, const Format &format);
void setFormatFor(TextStyle category, const Format &format);
void clear();
......@@ -117,7 +118,7 @@ public:
static QString readNameOfScheme(const QString &fileName);
private:
QMap<QString, Format> m_formats;
QMap<TextStyle, Format> m_formats;
QString m_displayName;
};
......
......@@ -33,8 +33,6 @@
#include "colorschemeedit.h"
#include "ui_colorschemeedit.h"
#include "texteditorconstants.h"
#include <QAbstractListModel>
#include <QColorDialog>
......@@ -104,7 +102,7 @@ public:
if (foreground.isValid())
return foreground;
else
return m_scheme->formatFor(QLatin1String(TextEditor::Constants::C_TEXT)).foreground();
return m_scheme->formatFor(C_TEXT).foreground();
}
case Qt::BackgroundRole: {
QColor background = m_scheme->formatFor(description.id()).background();
......@@ -205,7 +203,7 @@ void ColorSchemeEdit::setColorScheme(const ColorScheme &colorScheme)
{
m_scheme = colorScheme;
m_formatsModel->setColorScheme(&m_scheme);
setItemListBackground(m_scheme.formatFor(QLatin1String(TextEditor::Constants::C_TEXT)).background());
setItemListBackground(m_scheme.formatFor(C_TEXT).background());
updateControls();
}
......@@ -258,7 +256,7 @@ void ColorSchemeEdit::changeForeColor()
m_ui->eraseForegroundToolButton->setEnabled(true);
foreach (const QModelIndex &index, m_ui->itemList->selectionModel()->selectedRows()) {
const QString category = m_descriptions[index.row()].id();
const TextStyle category = m_descriptions[index.row()].id();
m_scheme.formatFor(category).setForeground(newColor);
m_formatsModel->emitDataChanged(index);
}
......@@ -276,7 +274,7 @@ void ColorSchemeEdit::changeBackColor()
m_ui->eraseBackgroundToolButton->setEnabled(true);
foreach (const QModelIndex &index, m_ui->itemList->selectionModel()->selectedRows()) {
const QString category = m_descriptions[index.row()].id();
const TextStyle category = m_descriptions[index.row()].id();
m_scheme.formatFor(category).setBackground(newColor);
m_formatsModel->emitDataChanged(index);
// Synchronize item list background with text background
......@@ -294,7 +292,7 @@ void ColorSchemeEdit::eraseBackColor()
m_ui->eraseBackgroundToolButton->setEnabled(false);
foreach (const QModelIndex &index, m_ui->itemList->selectionModel()->selectedRows()) {
const QString category = m_descriptions[index.row()].id();
const TextStyle category = m_descriptions[index.row()].id();
m_scheme.formatFor(category).setBackground(newColor);
m_formatsModel->emitDataChanged(index);
}
......@@ -309,7 +307,7 @@ void ColorSchemeEdit::eraseForeColor()
m_ui->eraseForegroundToolButton->setEnabled(false);
foreach (const QModelIndex &index, m_ui->itemList->selectionModel()->selectedRows()) {
const QString category = m_descriptions[index.row()].id();
const TextStyle category = m_descriptions[index.row()].id();
m_scheme.formatFor(category).setForeground(newColor);
m_formatsModel->emitDataChanged(index);
}
......@@ -321,7 +319,7 @@ void ColorSchemeEdit::checkCheckBoxes()
return;
foreach (const QModelIndex &index, m_ui->itemList->selectionModel()->selectedRows()) {
const QString category = m_descriptions[index.row()].id();
const TextStyle category = m_descriptions[index.row()].id();
m_scheme.formatFor(category).setBold(m_ui->boldCheckBox->isChecked());
m_scheme.formatFor(category).setItalic(m_ui->italicCheckBox->isChecked());
m_formatsModel->emitDataChanged(index);
......
......@@ -81,7 +81,7 @@ private:
void updateControls();
void setItemListBackground(const QColor &color);
TextEditor::FormatDescriptions m_descriptions;
FormatDescriptions m_descriptions;
ColorScheme m_scheme;
int m_curItem;
Ui::ColorSchemeEdit *m_ui;
......
......@@ -32,6 +32,7 @@
#include "fontsettings.h"
#include "fontsettingspage.h"
#include "texteditorconstants.h"
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
......@@ -136,8 +137,8 @@ bool FontSettings::fromSettings(const QString &category,
} else {
// Load color scheme from ini file
foreach (const FormatDescription &desc, descriptions) {
const QString id = desc.id();
const QString fmt = s->value(group + id, QString()).toString();
const TextStyle id = desc.id();
const QString fmt = s->value(group + Constants::nameForStyle(id), QString()).toString();
Format format;
if (fmt.isEmpty()) {
format.setForeground(desc.foreground());
......@@ -169,14 +170,13 @@ bool FontSettings::equals(const FontSettings &f) const
/**
* Returns the QTextCharFormat of the given format category.
*/
QTextCharFormat FontSettings::toTextCharFormat(const QString &category) const
QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
{
const Format &f = m_scheme.formatFor(category);
const QLatin1String textCategory("Text");
QTextCharFormat tf;
if (category == textCategory) {
if (category == C_TEXT) {
tf.setFontFamily(m_family);
tf.setFontPointSize(m_fontSize * m_fontZoom / 100.);
tf.setFontStyleStrategy(m_antialias ? QFont::PreferAntialias : QFont::NoAntialias);
......@@ -184,7 +184,7 @@ QTextCharFormat FontSettings::toTextCharFormat(const QString &category) const
if (f.foreground().isValid())
tf.setForeground(f.foreground());
if (f.background().isValid() && (category == textCategory || f.background() != m_scheme.formatFor(textCategory).background()))
if (f.background().isValid() && (category == C_TEXT || f.background() != m_scheme.formatFor(C_TEXT).background()))
tf.setBackground(f.background());
tf.setFontWeight(f.bold() ? QFont::Bold : QFont::Normal);