texteditor: use an enum instead of QString as color ids

Change-Id: I658412c18d5ccfe978ec444451c6417ffb18d71c
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
hjk
2012-04-26 14:17:42 +02:00
committed by hjk
parent a872c91c64
commit d006ca80a6
29 changed files with 381 additions and 275 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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));

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -43,6 +43,7 @@
#include <texteditor/basetextdocumentlayout.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/texteditorconstants.h>
namespace QmlJSEditor {

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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;
};

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);
tf.setFontItalic(f.italic());
@@ -195,7 +195,7 @@ QTextCharFormat FontSettings::toTextCharFormat(const QString &category) const
* Returns the list of QTextCharFormats that corresponds to the list of
* requested format categories.
*/
QVector<QTextCharFormat> FontSettings::toTextCharFormats(const QVector<QString> &categories) const
QVector<QTextCharFormat> FontSettings::toTextCharFormats(const QVector<TextStyle> &categories) const
{
QVector<QTextCharFormat> rc;
const int size = categories.size();
@@ -265,7 +265,7 @@ void FontSettings::setAntialias(bool antialias)
/**
* Returns the format for the given font category.
*/
Format &FontSettings::formatFor(const QString &category)
Format &FontSettings::formatFor(TextStyle category)
{
return m_scheme.formatFor(category);
}
@@ -301,7 +301,7 @@ bool FontSettings::loadColorScheme(const QString &fileName,
// Apply default formats to undefined categories
foreach (const FormatDescription &desc, descriptions) {
const QString id = desc.id();
const TextStyle id = desc.id();
if (!m_scheme.contains(id)) {
Format format;
format.setForeground(desc.foreground());

View File

@@ -70,8 +70,8 @@ public:
const FormatDescriptions &descriptions,
const QSettings *s);
QVector<QTextCharFormat> toTextCharFormats(const QVector<QString> &categories) const;
QTextCharFormat toTextCharFormat(const QString &category) const;
QVector<QTextCharFormat> toTextCharFormats(const QVector<TextStyle> &categories) const;
QTextCharFormat toTextCharFormat(TextStyle category) const;
QString family() const;
void setFamily(const QString &family);
@@ -87,7 +87,7 @@ public:
bool antialias() const;
void setAntialias(bool antialias);
Format &formatFor(const QString &category);
Format &formatFor(TextStyle category);
QString colorSchemeFileName() const;
void setColorSchemeFileName(const QString &fileName);

View File

@@ -195,22 +195,21 @@ FontSettingsPagePrivate::FontSettingsPagePrivate(const TextEditor::FormatDescrip
if (!settingsFound) { // Apply defaults
foreach (const FormatDescription &f, m_descriptions) {
const QString fid = f.id();
m_value.formatFor(fid).setForeground(f.foreground());
m_value.formatFor(fid).setBackground(f.background());
m_value.formatFor(fid).setBold(f.format().bold());
m_value.formatFor(fid).setItalic(f.format().italic());
Format &format = m_value.formatFor(f.id());
format.setForeground(f.foreground());
format.setBackground(f.background());
format.setBold(f.format().bold());
format.setItalic(f.format().italic());
}
} else if (m_value.colorSchemeFileName().isEmpty()) {
// No color scheme was loaded, but one might be imported from the ini file
ColorScheme defaultScheme;
foreach (const FormatDescription &f, m_descriptions) {
const QString fid = f.id();
defaultScheme.formatFor(fid).setForeground(f.foreground());
defaultScheme.formatFor(fid).setBackground(f.background());
defaultScheme.formatFor(fid).setBold(f.format().bold());
defaultScheme.formatFor(fid).setItalic(f.format().italic());
Format &format = defaultScheme.formatFor(f.id());
format.setForeground(f.foreground());
format.setBackground(f.background());
format.setBold(f.format().bold());
format.setItalic(f.format().italic());
}
if (m_value.colorScheme() != defaultScheme) {
// Save it as a color scheme file
@@ -232,14 +231,14 @@ FontSettingsPagePrivate::~FontSettingsPagePrivate()
// ------- FormatDescription
FormatDescription::FormatDescription(const QString &id, const QString &displayName, const QColor &color) :
FormatDescription::FormatDescription(TextStyle id, const QString &displayName, const QColor &color) :
m_id(id),
m_displayName(displayName)
{
m_format.setForeground(color);
}
FormatDescription::FormatDescription(const QString &id, const QString &displayName, const Format &format) :
FormatDescription::FormatDescription(TextStyle id, const QString &displayName, const Format &format) :
m_id(id),
m_displayName(displayName),
m_format(format)
@@ -248,23 +247,23 @@ FormatDescription::FormatDescription(const QString &id, const QString &displayNa
QColor FormatDescription::foreground() const
{
if (m_id == QLatin1String(Constants::C_LINE_NUMBER)) {
if (m_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 == QLatin1String(Constants::C_CURRENT_LINE_NUMBER)) {
} else if (m_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 == QLatin1String(Constants::C_OCCURRENCES_UNUSED)) {
} else if (m_id == C_OCCURRENCES_UNUSED) {
return Qt::darkYellow;
} else if (m_id == QLatin1String(Constants::C_PARENTHESES)) {
} else if (m_id == C_PARENTHESES) {
return QColor(Qt::red);
}
return m_format.foreground();
@@ -272,23 +271,22 @@ QColor FormatDescription::foreground() const
QColor FormatDescription::background() const
{
if (m_id == QLatin1String(Constants::C_TEXT))
if (m_id == C_TEXT)
return Qt::white;
else if (m_id == QLatin1String(Constants::C_LINE_NUMBER))
else if (m_id == C_LINE_NUMBER)
return QApplication::palette().background().color();
else if (m_id == QLatin1String(Constants::C_SEARCH_RESULT))
else if (m_id == C_SEARCH_RESULT)
return QColor(0xffef0b);
else if (m_id == QLatin1String(Constants::C_PARENTHESES))
else if (m_id == C_PARENTHESES)
return QColor(0xb4, 0xee, 0xb4);
else if (m_id == QLatin1String(Constants::C_CURRENT_LINE)
|| m_id == QLatin1String(Constants::C_SEARCH_SCOPE)) {
else if (m_id == C_CURRENT_LINE || m_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 == QLatin1String(Constants::C_CURRENT_LINE)) {
if (m_id == C_CURRENT_LINE) {
smallRatio = .3;
largeRatio = .6;
} else {
@@ -302,14 +300,14 @@ QColor FormatDescription::background() const
fg.greenF() * ratio + bg.greenF() * (1 - ratio),
fg.blueF() * ratio + bg.blueF() * (1 - ratio));
return col;
} else if (m_id == QLatin1String(Constants::C_SELECTION)) {
} else if (m_id == C_SELECTION) {
const QPalette palette = QApplication::palette();
return palette.color(QPalette::Highlight);
} else if (m_id == QLatin1String(Constants::C_OCCURRENCES)) {
} else if (m_id == C_OCCURRENCES) {
return QColor(180, 180, 180);
} else if (m_id == QLatin1String(Constants::C_OCCURRENCES_RENAME)) {
} else if (m_id == C_OCCURRENCES_RENAME) {
return QColor(255, 100, 100);
} else if (m_id == QLatin1String(Constants::C_DISABLED_CODE)) {
} else if (m_id == C_DISABLED_CODE) {
return QColor(239, 239, 239);
}
return QColor(); // invalid color

View File

@@ -58,13 +58,12 @@ class FontSettingsPagePrivate;
class TEXTEDITOR_EXPORT FormatDescription
{
public:
FormatDescription(const QString &id, const QString &displayName,
FormatDescription(TextStyle id, const QString &displayName,
const QColor &foreground = Qt::black);
FormatDescription(const QString &id, const QString &displayName,
FormatDescription(TextStyle id, const QString &displayName,
const Format &format);
QString id() const
{ return m_id; }
TextStyle id() const { return m_id; }
QString displayName() const
{ return m_displayName; }
@@ -76,7 +75,7 @@ public:
Format &format() { return m_format; }
private:
QString m_id; // Name of the category
TextStyle m_id; // Name of the category
QString m_displayName; // Displayed name of the category
Format m_format; // Default format
};

View File

@@ -110,26 +110,17 @@ void PlainTextEditorWidget::setFontSettings(const FontSettings &fs)
Highlighter *highlighter =
static_cast<Highlighter *>(baseTextDocument()->syntaxHighlighter());
highlighter->configureFormat(Highlighter::VisualWhitespace, fs.toTextCharFormat(
QLatin1String(Constants::C_VISUAL_WHITESPACE)));
highlighter->configureFormat(Highlighter::Keyword, fs.toTextCharFormat(
QLatin1String(Constants::C_KEYWORD)));
highlighter->configureFormat(Highlighter::DataType, fs.toTextCharFormat(
QLatin1String(Constants::C_TYPE)));
highlighter->configureFormat(Highlighter::Comment, fs.toTextCharFormat(
QLatin1String(Constants::C_COMMENT)));
highlighter->configureFormat(Highlighter::VisualWhitespace, fs.toTextCharFormat(C_VISUAL_WHITESPACE));
highlighter->configureFormat(Highlighter::Keyword, fs.toTextCharFormat(C_KEYWORD));
highlighter->configureFormat(Highlighter::DataType, fs.toTextCharFormat(C_TYPE));
highlighter->configureFormat(Highlighter::Comment, fs.toTextCharFormat(C_COMMENT));
// Using C_NUMBER for all kinds of numbers.
highlighter->configureFormat(Highlighter::Decimal, fs.toTextCharFormat(
QLatin1String(Constants::C_NUMBER)));
highlighter->configureFormat(Highlighter::BaseN, fs.toTextCharFormat(
QLatin1String(Constants::C_NUMBER)));
highlighter->configureFormat(Highlighter::Float, fs.toTextCharFormat(
QLatin1String(Constants::C_NUMBER)));
highlighter->configureFormat(Highlighter::Decimal, fs.toTextCharFormat(C_NUMBER));
highlighter->configureFormat(Highlighter::BaseN, fs.toTextCharFormat(C_NUMBER));
highlighter->configureFormat(Highlighter::Float, fs.toTextCharFormat(C_NUMBER));
// Using C_STRING for strings and chars.
highlighter->configureFormat(Highlighter::Char, fs.toTextCharFormat(
QLatin1String(Constants::C_STRING)));
highlighter->configureFormat(Highlighter::String, fs.toTextCharFormat(
QLatin1String(Constants::C_STRING)));
highlighter->configureFormat(Highlighter::Char, fs.toTextCharFormat(C_STRING));
highlighter->configureFormat(Highlighter::String, fs.toTextCharFormat(C_STRING));
highlighter->rehighlight();
}

View File

@@ -19,6 +19,7 @@ SOURCES += texteditorplugin.cpp \
behaviorsettingspage.cpp \
texteditoractionhandler.cpp \
fontsettingspage.cpp \
texteditorconstants.cpp \
tabsettings.cpp \
storagesettings.cpp \
displaysettings.cpp \

View File

@@ -130,6 +130,7 @@ QtcPlugin {
"texteditor_global.h",
"texteditoractionhandler.cpp",
"texteditoractionhandler.h",
"texteditorconstants.cpp",
"texteditorconstants.h",
"texteditoroptionspage.cpp",
"texteditoroptionspage.h",

View File

@@ -0,0 +1,106 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "texteditorconstants.h"
#include <QByteArray>>
namespace TextEditor {
namespace Constants {
const char *nameForStyle(TextStyle style)
{
switch (style) {
case C_TEXT: return "Text";
case C_LINK: return "Link";
case C_SELECTION: return "Selection";
case C_LINE_NUMBER: return "LineNumber";
case C_SEARCH_RESULT: return "SearchResult";
case C_SEARCH_SCOPE: return "SearchScope";
case C_PARENTHESES: return "Parentheses";
case C_CURRENT_LINE: return "CurrentLine";
case C_CURRENT_LINE_NUMBER: return "CurrentLineNumber";
case C_OCCURRENCES: return "Occurrences";
case C_OCCURRENCES_UNUSED: return "Occurrences.Unused";
case C_OCCURRENCES_RENAME: return "Occurrences.Rename";
case C_NUMBER: return "Number";
case C_STRING: return "String";
case C_TYPE: return "Type";
case C_LOCAL: return "Local";
case C_FIELD: return "Field";
case C_STATIC: return "Static";
case C_VIRTUAL_METHOD: return "VirtualMethod";
case C_KEYWORD: return "Keyword";
case C_OPERATOR: return "Operator";
case C_PREPROCESSOR: return "Preprocessor";
case C_LABEL: return "Label";
case C_COMMENT: return "Comment";
case C_DOXYGEN_COMMENT: return "Doxygen.Comment";
case C_DOXYGEN_TAG: return "Doxygen.Tag";
case C_VISUAL_WHITESPACE: return "VisualWhitespace";
case C_QML_LOCAL_ID: return "QmlLocalId";
case C_QML_EXTERNAL_ID: return "QmlExternalId";
case C_QML_TYPE_ID: return "QmlTypeId";
case C_QML_ROOT_OBJECT_PROPERTY: return "QmlRootObjectProperty";
case C_QML_SCOPE_OBJECT_PROPERTY: return "QmlScopeObjectProperty";
case C_QML_EXTERNAL_OBJECT_PROPERTY: return "QmlExternalObjectProperty";
case C_JS_SCOPE_VAR: return "JsScopeVar";
case C_JS_IMPORT_VAR: return "JsImportVar";
case C_JS_GLOBAL_VAR: return "JsGlobalVar";
case C_QML_STATE_NAME: return "QmlStateName";
case C_BINDING: return "Binding";
case C_DISABLED_CODE: return "DisabledCode";
case C_ADDED_LINE: return "AddedLine";
case C_REMOVED_LINE: return "RemovedLine";
case C_DIFF_FILE: return "DiffFile";
case C_DIFF_LOCATION: return "DiffLocation";
case C_LAST_STYLE_SENTINEL: return "LastStyleSentinel";
}
return "Unknown Style";
}
TextStyle styleFromName(const char *name)
{
for (int i = 0; i < C_LAST_STYLE_SENTINEL; ++i) {
if (qstrcmp(name, nameForStyle(TextStyle(i))) == 0)
return TextStyle(i);
}
return TextStyle();
}
} // namespace Constants
} // namespace TextEditor

View File

@@ -36,6 +36,61 @@
#include <QtGlobal>
namespace TextEditor {
// Text color and style categories
enum TextStyle {
C_TEXT,
C_LINK,
C_SELECTION,
C_LINE_NUMBER,
C_SEARCH_RESULT,
C_SEARCH_SCOPE,
C_PARENTHESES,
C_CURRENT_LINE,
C_CURRENT_LINE_NUMBER,
C_OCCURRENCES,
C_OCCURRENCES_UNUSED,
C_OCCURRENCES_RENAME,
C_NUMBER,
C_STRING,
C_TYPE,
C_LOCAL,
C_FIELD,
C_STATIC,
C_VIRTUAL_METHOD,
C_KEYWORD,
C_OPERATOR,
C_PREPROCESSOR,
C_LABEL,
C_COMMENT,
C_DOXYGEN_COMMENT,
C_DOXYGEN_TAG,
C_VISUAL_WHITESPACE,
C_QML_LOCAL_ID,
C_QML_EXTERNAL_ID,
C_QML_TYPE_ID,
C_QML_ROOT_OBJECT_PROPERTY,
C_QML_SCOPE_OBJECT_PROPERTY,
C_QML_EXTERNAL_OBJECT_PROPERTY,
C_JS_SCOPE_VAR,
C_JS_IMPORT_VAR,
C_JS_GLOBAL_VAR,
C_QML_STATE_NAME,
C_BINDING,
C_DISABLED_CODE,
C_ADDED_LINE,
C_REMOVED_LINE,
C_DIFF_FILE,
C_DIFF_LOCATION,
C_LAST_STYLE_SENTINEL
};
namespace Constants {
const char C_TEXTEDITOR[] = "Text Editor";
@@ -108,55 +163,8 @@ const char UNINDENT[] = "TextEditor.Unindent";
const char FOLLOW_SYMBOL_UNDER_CURSOR[] = "TextEditor.FollowSymbolUnderCursor";
const char JUMP_TO_FILE_UNDER_CURSOR[] = "TextEditor.JumpToFileUnderCursor";
// Text color and style categories
const char C_TEXT[] = "Text";
const char C_LINK[] = "Link";
const char C_SELECTION[] = "Selection";
const char C_LINE_NUMBER[] = "LineNumber";
const char C_SEARCH_RESULT[] = "SearchResult";
const char C_SEARCH_SCOPE[] = "SearchScope";
const char C_PARENTHESES[] = "Parentheses";
const char C_CURRENT_LINE[] = "CurrentLine";
const char C_CURRENT_LINE_NUMBER[] = "CurrentLineNumber";
const char C_OCCURRENCES[] = "Occurrences";
const char C_OCCURRENCES_UNUSED[] = "Occurrences.Unused";
const char C_OCCURRENCES_RENAME[] = "Occurrences.Rename";
const char C_NUMBER[] = "Number";
const char C_STRING[] = "String";
const char C_TYPE[] = "Type";
const char C_LOCAL[] = "Local";
const char C_FIELD[] = "Field";
const char C_STATIC[] = "Static";
const char C_VIRTUAL_METHOD[] = "VirtualMethod";
const char C_KEYWORD[] = "Keyword";
const char C_OPERATOR[] = "Operator";
const char C_PREPROCESSOR[] = "Preprocessor";
const char C_LABEL[] = "Label";
const char C_COMMENT[] = "Comment";
const char C_DOXYGEN_COMMENT[] = "Doxygen.Comment";
const char C_DOXYGEN_TAG[] = "Doxygen.Tag";
const char C_VISUAL_WHITESPACE[] = "VisualWhitespace";
const char C_QML_LOCAL_ID[] = "QmlLocalId";
const char C_QML_EXTERNAL_ID[] = "QmlExternalId";
const char C_QML_TYPE_ID[] = "QmlTypeId";
const char C_QML_ROOT_OBJECT_PROPERTY[] = "QmlRootObjectProperty";
const char C_QML_SCOPE_OBJECT_PROPERTY[] = "QmlScopeObjectProperty";
const char C_QML_EXTERNAL_OBJECT_PROPERTY[] = "QmlExternalObjectProperty";
const char C_JS_SCOPE_VAR[] = "JsScopeVar";
const char C_JS_IMPORT_VAR[] = "JsImportVar";
const char C_JS_GLOBAL_VAR[] = "JsGlobalVar";
const char C_QML_STATE_NAME[] = "QmlStateName";
const char C_BINDING[] = "Binding";
const char C_DISABLED_CODE[] = "DisabledCode";
const char C_ADDED_LINE[] = "AddedLine";
const char C_REMOVED_LINE[] = "RemovedLine";
const char C_DIFF_FILE[] = "DiffFile";
const char C_DIFF_LOCATION[] = "DiffLocation";
const char *nameForStyle(TextStyle style);
TextStyle styleFromName(const char *name);
const char TEXT_EDITOR_SETTINGS_CATEGORY[] = "C.TextEditor";
const char TEXT_EDITOR_SETTINGS_CATEGORY_ICON[] = ":/core/images/category_texteditor.png";

View File

@@ -117,80 +117,80 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
// Add font preference page
FormatDescriptions formatDescriptions;
formatDescriptions.append(FormatDescription(QLatin1String(C_TEXT), tr("Text")));
formatDescriptions.append(FormatDescription(C_TEXT, tr("Text")));
// Special categories
const QPalette p = QApplication::palette();
formatDescriptions.append(FormatDescription(QLatin1String(C_LINK), tr("Link"), Qt::blue));
formatDescriptions.append(FormatDescription(QLatin1String(C_SELECTION), tr("Selection"), p.color(QPalette::HighlightedText)));
formatDescriptions.append(FormatDescription(QLatin1String(C_LINE_NUMBER), tr("Line Number")));
formatDescriptions.append(FormatDescription(QLatin1String(C_SEARCH_RESULT), tr("Search Result")));
formatDescriptions.append(FormatDescription(QLatin1String(C_SEARCH_SCOPE), tr("Search Scope")));
formatDescriptions.append(FormatDescription(QLatin1String(C_PARENTHESES), tr("Parentheses")));
formatDescriptions.append(FormatDescription(QLatin1String(C_CURRENT_LINE), tr("Current Line")));
formatDescriptions.append(FormatDescription(C_LINK, tr("Link"), Qt::blue));
formatDescriptions.append(FormatDescription(C_SELECTION, tr("Selection"), p.color(QPalette::HighlightedText)));
formatDescriptions.append(FormatDescription(C_LINE_NUMBER, tr("Line Number")));
formatDescriptions.append(FormatDescription(C_SEARCH_RESULT, tr("Search Result")));
formatDescriptions.append(FormatDescription(C_SEARCH_SCOPE, tr("Search Scope")));
formatDescriptions.append(FormatDescription(C_PARENTHESES, tr("Parentheses")));
formatDescriptions.append(FormatDescription(C_CURRENT_LINE, tr("Current Line")));
FormatDescription currentLineNumber = FormatDescription(QLatin1String(C_CURRENT_LINE_NUMBER), tr("Current Line Number"), Qt::darkGray);
FormatDescription currentLineNumber = FormatDescription(C_CURRENT_LINE_NUMBER, tr("Current Line Number"), Qt::darkGray);
currentLineNumber.format().setBold(true);
formatDescriptions.append(currentLineNumber);
formatDescriptions.append(FormatDescription(QLatin1String(C_OCCURRENCES), tr("Occurrences")));
formatDescriptions.append(FormatDescription(QLatin1String(C_OCCURRENCES_UNUSED), tr("Unused Occurrence")));
formatDescriptions.append(FormatDescription(QLatin1String(C_OCCURRENCES_RENAME), tr("Renaming Occurrence")));
formatDescriptions.append(FormatDescription(C_OCCURRENCES, tr("Occurrences")));
formatDescriptions.append(FormatDescription(C_OCCURRENCES_UNUSED, tr("Unused Occurrence")));
formatDescriptions.append(FormatDescription(C_OCCURRENCES_RENAME, tr("Renaming Occurrence")));
// Standard categories
formatDescriptions.append(FormatDescription(QLatin1String(C_NUMBER), tr("Number"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(QLatin1String(C_STRING), tr("String"), Qt::darkGreen));
formatDescriptions.append(FormatDescription(QLatin1String(C_TYPE), tr("Type"), Qt::darkMagenta));
formatDescriptions.append(FormatDescription(QLatin1String(C_LOCAL), tr("Local")));
formatDescriptions.append(FormatDescription(QLatin1String(C_FIELD), tr("Field"), Qt::darkRed));
formatDescriptions.append(FormatDescription(QLatin1String(C_STATIC), tr("Static"), Qt::darkMagenta));
formatDescriptions.append(FormatDescription(C_NUMBER, tr("Number"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(C_STRING, tr("String"), Qt::darkGreen));
formatDescriptions.append(FormatDescription(C_TYPE, tr("Type"), Qt::darkMagenta));
formatDescriptions.append(FormatDescription(C_LOCAL, tr("Local")));
formatDescriptions.append(FormatDescription(C_FIELD, tr("Field"), Qt::darkRed));
formatDescriptions.append(FormatDescription(C_STATIC, tr("Static"), Qt::darkMagenta));
FormatDescription virtualMethodFormatDescriptor(QLatin1String(C_VIRTUAL_METHOD), tr("Virtual Method"));
FormatDescription virtualMethodFormatDescriptor(C_VIRTUAL_METHOD, tr("Virtual Method"));
virtualMethodFormatDescriptor.format().setItalic(true);
formatDescriptions.append(virtualMethodFormatDescriptor);
formatDescriptions.append(FormatDescription(QLatin1String(C_BINDING), tr("QML Binding"), Qt::darkRed));
formatDescriptions.append(FormatDescription(C_BINDING, tr("QML Binding"), Qt::darkRed));
Format qmlLocalNameFormat;
qmlLocalNameFormat.setItalic(true);
formatDescriptions.append(FormatDescription(QLatin1String(C_QML_LOCAL_ID), tr("QML Local Id"), qmlLocalNameFormat));
formatDescriptions.append(FormatDescription(QLatin1String(C_QML_ROOT_OBJECT_PROPERTY), tr("QML Root Object Property"), qmlLocalNameFormat));
formatDescriptions.append(FormatDescription(QLatin1String(C_QML_SCOPE_OBJECT_PROPERTY), tr("QML Scope Object Property"), qmlLocalNameFormat));
formatDescriptions.append(FormatDescription(QLatin1String(C_QML_STATE_NAME), tr("QML State Name"), qmlLocalNameFormat));
formatDescriptions.append(FormatDescription(C_QML_LOCAL_ID, tr("QML Local Id"), qmlLocalNameFormat));
formatDescriptions.append(FormatDescription(C_QML_ROOT_OBJECT_PROPERTY, tr("QML Root Object Property"), qmlLocalNameFormat));
formatDescriptions.append(FormatDescription(C_QML_SCOPE_OBJECT_PROPERTY, tr("QML Scope Object Property"), qmlLocalNameFormat));
formatDescriptions.append(FormatDescription(C_QML_STATE_NAME, tr("QML State Name"), qmlLocalNameFormat));
formatDescriptions.append(FormatDescription(QLatin1String(C_QML_TYPE_ID), tr("QML Type Name"), Qt::darkMagenta));
formatDescriptions.append(FormatDescription(C_QML_TYPE_ID, tr("QML Type Name"), Qt::darkMagenta));
Format qmlExternalNameFormat = qmlLocalNameFormat;
qmlExternalNameFormat.setForeground(Qt::darkBlue);
formatDescriptions.append(FormatDescription(QLatin1String(C_QML_EXTERNAL_ID), tr("QML External Id"), qmlExternalNameFormat));
formatDescriptions.append(FormatDescription(QLatin1String(C_QML_EXTERNAL_OBJECT_PROPERTY), tr("QML External Object Property"), qmlExternalNameFormat));
formatDescriptions.append(FormatDescription(C_QML_EXTERNAL_ID, tr("QML External Id"), qmlExternalNameFormat));
formatDescriptions.append(FormatDescription(C_QML_EXTERNAL_OBJECT_PROPERTY, tr("QML External Object Property"), qmlExternalNameFormat));
Format jsLocalFormat;
jsLocalFormat.setForeground(QColor(41, 133, 199)); // very light blue
jsLocalFormat.setItalic(true);
formatDescriptions.append(FormatDescription(QLatin1String(C_JS_SCOPE_VAR), tr("JavaScript Scope Var"), jsLocalFormat));
formatDescriptions.append(FormatDescription(C_JS_SCOPE_VAR, tr("JavaScript Scope Var"), jsLocalFormat));
Format jsGlobalFormat;
jsGlobalFormat.setForeground(QColor(0, 85, 175)); // light blue
jsGlobalFormat.setItalic(true);
formatDescriptions.append(FormatDescription(QLatin1String(C_JS_IMPORT_VAR), tr("JavaScript Import"), jsGlobalFormat));
formatDescriptions.append(FormatDescription(QLatin1String(C_JS_GLOBAL_VAR), tr("JavaScript Global Variable"), jsGlobalFormat));
formatDescriptions.append(FormatDescription(C_JS_IMPORT_VAR, tr("JavaScript Import"), jsGlobalFormat));
formatDescriptions.append(FormatDescription(C_JS_GLOBAL_VAR, tr("JavaScript Global Variable"), jsGlobalFormat));
formatDescriptions.append(FormatDescription(QLatin1String(C_KEYWORD), tr("Keyword"), Qt::darkYellow));
formatDescriptions.append(FormatDescription(QLatin1String(C_OPERATOR), tr("Operator")));
formatDescriptions.append(FormatDescription(QLatin1String(C_PREPROCESSOR), tr("Preprocessor"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(QLatin1String(C_LABEL), tr("Label"), Qt::darkRed));
formatDescriptions.append(FormatDescription(QLatin1String(C_COMMENT), tr("Comment"), Qt::darkGreen));
formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_COMMENT), tr("Doxygen Comment"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_TAG), tr("Doxygen Tag"), Qt::blue));
formatDescriptions.append(FormatDescription(QLatin1String(C_VISUAL_WHITESPACE), tr("Visual Whitespace"), Qt::lightGray));
formatDescriptions.append(FormatDescription(QLatin1String(C_DISABLED_CODE), tr("Disabled Code")));
formatDescriptions.append(FormatDescription(C_KEYWORD, tr("Keyword"), Qt::darkYellow));
formatDescriptions.append(FormatDescription(C_OPERATOR, tr("Operator")));
formatDescriptions.append(FormatDescription(C_PREPROCESSOR, tr("Preprocessor"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(C_LABEL, tr("Label"), Qt::darkRed));
formatDescriptions.append(FormatDescription(C_COMMENT, tr("Comment"), Qt::darkGreen));
formatDescriptions.append(FormatDescription(C_DOXYGEN_COMMENT, tr("Doxygen Comment"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(C_DOXYGEN_TAG, tr("Doxygen Tag"), Qt::blue));
formatDescriptions.append(FormatDescription(C_VISUAL_WHITESPACE, tr("Visual Whitespace"), Qt::lightGray));
formatDescriptions.append(FormatDescription(C_DISABLED_CODE, tr("Disabled Code")));
// Diff categories
formatDescriptions.append(FormatDescription(QLatin1String(C_ADDED_LINE), tr("Added Line"), QColor(0, 170, 0)));
formatDescriptions.append(FormatDescription(QLatin1String(C_REMOVED_LINE), tr("Removed Line"), Qt::red));
formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_FILE), tr("Diff File"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_LOCATION), tr("Diff Location"), Qt::blue));
formatDescriptions.append(FormatDescription(C_ADDED_LINE, tr("Added Line"), QColor(0, 170, 0)));
formatDescriptions.append(FormatDescription(C_REMOVED_LINE, tr("Removed Line"), Qt::red));
formatDescriptions.append(FormatDescription(C_DIFF_FILE, tr("Diff File"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(C_DIFF_LOCATION, tr("Diff Location"), Qt::blue));
m_d->m_fontSettingsPage = new FontSettingsPage(formatDescriptions,
QLatin1String(Constants::TEXT_EDITOR_FONT_SETTINGS),

View File

@@ -1153,18 +1153,18 @@ void VcsBaseEditorWidget::setPlainTextData(const QByteArray &data)
void VcsBaseEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
{
TextEditor::BaseTextEditorWidget::setFontSettings(fs);
d->m_backgroundColor = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_TEXT))
d->m_backgroundColor = fs.toTextCharFormat(TextEditor::C_TEXT)
.brushProperty(QTextFormat::BackgroundBrush).color();
if (d->m_parameters->type == DiffOutput) {
if (DiffHighlighter *highlighter = qobject_cast<DiffHighlighter*>(baseTextDocument()->syntaxHighlighter())) {
static QVector<QString> categories;
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << QLatin1String(TextEditor::Constants::C_TEXT)
<< QLatin1String(TextEditor::Constants::C_ADDED_LINE)
<< QLatin1String(TextEditor::Constants::C_REMOVED_LINE)
<< QLatin1String(TextEditor::Constants::C_DIFF_FILE)
<< QLatin1String(TextEditor::Constants::C_DIFF_LOCATION);
categories << TextEditor::C_TEXT
<< TextEditor::C_ADDED_LINE
<< TextEditor::C_REMOVED_LINE
<< TextEditor::C_DIFF_FILE
<< TextEditor::C_DIFF_LOCATION;
}
highlighter->setFormats(fs.toTextCharFormats(categories));
highlighter->rehighlight();