forked from qt-creator/qt-creator
Integrating highlighter formats with Creator's font settings.
This commit is contained in:
@@ -3838,8 +3838,8 @@
|
|||||||
<itemData name="Normal Text" defStyleNum="dsNormal"/>
|
<itemData name="Normal Text" defStyleNum="dsNormal"/>
|
||||||
<itemData name="Keyword" defStyleNum="dsKeyword"/>
|
<itemData name="Keyword" defStyleNum="dsKeyword"/>
|
||||||
<itemData name="Function" defStyleNum="dsFunction"/>
|
<itemData name="Function" defStyleNum="dsFunction"/>
|
||||||
<itemData name="StaticImports" defStyleNum="dsKeyword" color="#800080" selColor="#FFFFFF" bold="0" italic="0"/>
|
<itemData name="StaticImports" defStyleNum="dsKeyword" color="#B00080" selColor="#FFFFFF" bold="0" italic="0"/>
|
||||||
<itemData name="Imports" defStyleNum="dsKeyword" color="#808000" selColor="#FFFFFF" bold="0" italic="0"/>
|
<itemData name="Imports" defStyleNum="dsKeyword" color="#B00080" selColor="#FFFFFF" bold="0" italic="0"/>
|
||||||
<itemData name="Data Type" defStyleNum="dsDataType"/>
|
<itemData name="Data Type" defStyleNum="dsDataType"/>
|
||||||
<itemData name="Decimal" defStyleNum="dsDecVal"/>
|
<itemData name="Decimal" defStyleNum="dsDecVal"/>
|
||||||
<itemData name="Octal" defStyleNum="dsBaseN"/>
|
<itemData name="Octal" defStyleNum="dsBaseN"/>
|
||||||
|
|||||||
@@ -39,6 +39,8 @@
|
|||||||
#include <coreplugin/mimedatabase.h>
|
#include <coreplugin/mimedatabase.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <texteditor/basetextdocument.h>
|
#include <texteditor/basetextdocument.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
#include <texteditor/fontsettings.h>
|
||||||
|
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
@@ -64,6 +66,18 @@ TextEditor::BaseTextEditorEditable *Editor::createEditableInterface()
|
|||||||
return editable;
|
return editable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::setFontSettings(const TextEditor::FontSettings & fs)
|
||||||
|
{
|
||||||
|
TextEditor::BaseTextEditor::setFontSettings(fs);
|
||||||
|
|
||||||
|
Highlighter *highlighter = static_cast<Highlighter *>(baseTextDocument()->syntaxHighlighter());
|
||||||
|
if (!highlighter)
|
||||||
|
return;
|
||||||
|
|
||||||
|
highlighter->configureFormats(fs);
|
||||||
|
highlighter->rehighlight();
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::configure()
|
void Editor::configure()
|
||||||
{
|
{
|
||||||
const QString &mimeType = Core::ICore::instance()->mimeDatabase()->findByFile(
|
const QString &mimeType = Core::ICore::instance()->mimeDatabase()->findByFile(
|
||||||
@@ -76,7 +90,10 @@ void Editor::configure()
|
|||||||
QSharedPointer<HighlightDefinition> definition =
|
QSharedPointer<HighlightDefinition> definition =
|
||||||
GenericEditorPlugin::instance()->definition(definitionId);
|
GenericEditorPlugin::instance()->definition(definitionId);
|
||||||
|
|
||||||
baseTextDocument()->setSyntaxHighlighter(new Highlighter(definition->initialContext()));
|
Highlighter *highlighter = new Highlighter(definition->initialContext());
|
||||||
|
highlighter->configureFormats(TextEditor::TextEditorSettings::instance()->fontSettings());
|
||||||
|
|
||||||
|
baseTextDocument()->setSyntaxHighlighter(highlighter);
|
||||||
|
|
||||||
m_commentDefinition.setAfterWhiteSpaces(definition->isCommentAfterWhiteSpaces());
|
m_commentDefinition.setAfterWhiteSpaces(definition->isCommentAfterWhiteSpaces());
|
||||||
m_commentDefinition.setSingleLine(definition->singleLineComment());
|
m_commentDefinition.setSingleLine(definition->singleLineComment());
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual TextEditor::BaseTextEditorEditable *createEditableInterface();
|
virtual TextEditor::BaseTextEditorEditable *createEditableInterface();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void setFontSettings(const TextEditor::FontSettings &);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void configure();
|
void configure();
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/mimedatabase.h>
|
#include <coreplugin/mimedatabase.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
@@ -142,6 +143,7 @@ bool GenericEditorPlugin::initialize(const QStringList &arguments, QString *erro
|
|||||||
|
|
||||||
m_actionHandler = new TextEditor::TextEditorActionHandler(
|
m_actionHandler = new TextEditor::TextEditorActionHandler(
|
||||||
GenericEditor::Constants::GENERIC_EDITOR,
|
GenericEditor::Constants::GENERIC_EDITOR,
|
||||||
|
TextEditor::TextEditorActionHandler::Format |
|
||||||
TextEditor::TextEditorActionHandler::UnCommentSelection);
|
TextEditor::TextEditorActionHandler::UnCommentSelection);
|
||||||
m_actionHandler->initializeActions();
|
m_actionHandler->initializeActions();
|
||||||
|
|
||||||
@@ -154,6 +156,8 @@ void GenericEditorPlugin::extensionsInitialized()
|
|||||||
void GenericEditorPlugin::initializeEditor(Editor *editor)
|
void GenericEditorPlugin::initializeEditor(Editor *editor)
|
||||||
{
|
{
|
||||||
m_actionHandler->setupActions(editor);
|
m_actionHandler->setupActions(editor);
|
||||||
|
|
||||||
|
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GenericEditorPlugin::definitionIdByName(const QString &name) const
|
QString GenericEditorPlugin::definitionIdByName(const QString &name) const
|
||||||
|
|||||||
@@ -275,7 +275,6 @@ void HighlightDefinitionHandler::itemDataElementStarted(const QXmlAttributes &at
|
|||||||
itemData->setBold(atts.value(kBold));
|
itemData->setBold(atts.value(kBold));
|
||||||
itemData->setUnderlined(atts.value(kUnderline));
|
itemData->setUnderlined(atts.value(kUnderline));
|
||||||
itemData->setStrikedOut(atts.value(kStrikeout));
|
itemData->setStrikedOut(atts.value(kStrikeout));
|
||||||
itemData->configureFormat();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HighlightDefinitionHandler::commentElementStarted(const QXmlAttributes &atts) const
|
void HighlightDefinitionHandler::commentElementStarted(const QXmlAttributes &atts) const
|
||||||
@@ -434,8 +433,8 @@ void HighlightDefinitionHandler::processIncludeRules(const QSharedPointer<Contex
|
|||||||
const QString &sourceName = instruction.sourceContext();
|
const QString &sourceName = instruction.sourceContext();
|
||||||
if (sourceName.startsWith(kDoubleHash)) {
|
if (sourceName.startsWith(kDoubleHash)) {
|
||||||
// This refers to an external definition. The rules included are the ones from its
|
// This refers to an external definition. The rules included are the ones from its
|
||||||
// initial context. Others contexts and rules from the external definition will
|
// initial context. Others contexts and rules from the external definition will work
|
||||||
// transparently to the highlighter. This because contexts and rules know the
|
// transparently to the highlighter. This is because contexts and rules know the
|
||||||
// definition they are from.
|
// definition they are from.
|
||||||
QString externalName = QString::fromRawData(sourceName.unicode() + 2,
|
QString externalName = QString::fromRawData(sourceName.unicode() + 2,
|
||||||
sourceName.length() - 2);
|
sourceName.length() - 2);
|
||||||
|
|||||||
@@ -34,8 +34,13 @@
|
|||||||
#include "itemdata.h"
|
#include "itemdata.h"
|
||||||
#include "highlighterexception.h"
|
#include "highlighterexception.h"
|
||||||
#include "progressdata.h"
|
#include "progressdata.h"
|
||||||
|
#include "reuse.h"
|
||||||
|
|
||||||
#include <QtCore/QStringList>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
#include <texteditor/fontsettings.h>
|
||||||
|
|
||||||
|
#include <QtCore/QLatin1String>
|
||||||
|
#include <QtCore/QLatin1Char>
|
||||||
|
|
||||||
using namespace GenericEditor;
|
using namespace GenericEditor;
|
||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
@@ -91,11 +96,13 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
|
|
||||||
handleContextChange(m_currentContext->lineEndContext(), m_currentContext->definition(),
|
handleContextChange(m_currentContext->lineEndContext(), m_currentContext->definition(),
|
||||||
false);
|
false);
|
||||||
|
|
||||||
m_contexts.clear();
|
|
||||||
} catch (const HighlighterException &) {
|
} catch (const HighlighterException &) {
|
||||||
m_isBroken = true;
|
m_isBroken = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_contexts.clear();
|
||||||
|
applyVisualWhitespaceFormat(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Highlighter::setupDataForBlock(const QString &text)
|
void Highlighter::setupDataForBlock(const QString &text)
|
||||||
@@ -283,18 +290,53 @@ void Highlighter::handleContextChange(const QString &contextName,
|
|||||||
|
|
||||||
void Highlighter::applyFormat(int offset,
|
void Highlighter::applyFormat(int offset,
|
||||||
int count,
|
int count,
|
||||||
const QString &itemData,
|
const QString &itemDataName,
|
||||||
const QSharedPointer<HighlightDefinition> &definition)
|
const QSharedPointer<HighlightDefinition> &definition)
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
QSharedPointer<ItemData> itemData;
|
||||||
try {
|
try {
|
||||||
setFormat(offset, count, definition->itemData(itemData)->format());
|
itemData = definition->itemData(itemDataName);
|
||||||
} catch (const HighlighterException &) {
|
} catch (const HighlighterException &) {
|
||||||
// This case does not break the highlighter. In fact, currently there are broken xml
|
// Although the formatting is skipped this case does not break the highlighter. In fact,
|
||||||
// definition files which Kate can cope with. For instance, the Printf context in java.xml
|
// currently there are broken xml definition files which Kate can cope with. For instance,
|
||||||
// points to an inexistent Printf item data.
|
// the Printf context in java.xml points to an inexistent Printf item data.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextCharFormat format = m_genericFormats.value(itemData->style());
|
||||||
|
|
||||||
|
// Apply personalizations (if specified) for this particular item data from the current
|
||||||
|
// definition only.
|
||||||
|
if (itemData->color().isValid())
|
||||||
|
format.setForeground(itemData->color());
|
||||||
|
if (itemData->isItalicSpecified())
|
||||||
|
format.setFontItalic(itemData->isItalic());
|
||||||
|
if (itemData->isBoldSpecified())
|
||||||
|
format.setFontWeight(toFontWeight(itemData->isBold()));
|
||||||
|
if (itemData->isUnderlinedSpecified())
|
||||||
|
format.setFontUnderline(itemData->isUnderlined());
|
||||||
|
if (itemData->isStrikedOutSpecified())
|
||||||
|
format.setFontStrikeOut(itemData->isStrikedOut());
|
||||||
|
|
||||||
|
setFormat(offset, count, format);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Highlighter::applyVisualWhitespaceFormat(const QString &text)
|
||||||
|
{
|
||||||
|
int offset = 0;
|
||||||
|
const int length = text.length();
|
||||||
|
while (offset < length) {
|
||||||
|
if (text.at(offset).isSpace()) {
|
||||||
|
int start = offset++;
|
||||||
|
while (offset < length && text.at(offset).isSpace())
|
||||||
|
++offset;
|
||||||
|
setFormat(start, offset - start, m_visualWhitespaceFormat);
|
||||||
|
} else {
|
||||||
|
++offset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,3 +426,42 @@ void Highlighter::setCurrentContext()
|
|||||||
throw HighlighterException();
|
throw HighlighterException();
|
||||||
m_currentContext = m_contexts.back();
|
m_currentContext = m_contexts.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Highlighter::configureFormats(const TextEditor::FontSettings & fs)
|
||||||
|
{
|
||||||
|
m_visualWhitespaceFormat = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE));
|
||||||
|
|
||||||
|
m_genericFormats[ItemData::kDsNormal] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_TEXT));
|
||||||
|
m_genericFormats[ItemData::kDsKeyword] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_KEYWORD));
|
||||||
|
m_genericFormats[ItemData::kDsDataType] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_TYPE));
|
||||||
|
m_genericFormats[ItemData::kDsDecVal] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_NUMBER));
|
||||||
|
m_genericFormats[ItemData::kDsBaseN] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_NUMBER));
|
||||||
|
m_genericFormats[ItemData::kDsFloat] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_NUMBER));
|
||||||
|
m_genericFormats[ItemData::kDsChar] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_STRING));
|
||||||
|
m_genericFormats[ItemData::kDsString] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_STRING));
|
||||||
|
m_genericFormats[ItemData::kDsComment] = fs.toTextCharFormat(
|
||||||
|
QLatin1String(TextEditor::Constants::C_COMMENT));
|
||||||
|
|
||||||
|
// Currently Creator does not have corresponding formats for the following items. We can
|
||||||
|
// implement them... Just for now I will leave hardcoded colors.
|
||||||
|
QTextCharFormat format;
|
||||||
|
format.setForeground(Qt::blue);
|
||||||
|
m_genericFormats[ItemData::kDsOthers] = format;
|
||||||
|
format.setForeground(Qt::red);
|
||||||
|
m_genericFormats[ItemData::kDsAlert] = format;
|
||||||
|
format.setForeground(Qt::darkBlue);
|
||||||
|
m_genericFormats[ItemData::kDsFunction] = format;
|
||||||
|
format.setForeground(Qt::darkGray);
|
||||||
|
m_genericFormats[ItemData::kDsRegionMarker] = format;
|
||||||
|
format.setForeground(Qt::darkRed);
|
||||||
|
m_genericFormats[ItemData::kDsError] = format;
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#ifndef HIGHLIGHTER_H
|
#ifndef HIGHLIGHTER_H
|
||||||
#define HIGHLIGHTER_H
|
#define HIGHLIGHTER_H
|
||||||
|
|
||||||
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QVector>
|
#include <QtCore/QVector>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
@@ -39,6 +40,10 @@
|
|||||||
|
|
||||||
#include <texteditor/basetextdocumentlayout.h>
|
#include <texteditor/basetextdocumentlayout.h>
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
class FontSettings;
|
||||||
|
}
|
||||||
|
|
||||||
namespace GenericEditor {
|
namespace GenericEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -53,6 +58,8 @@ public:
|
|||||||
Highlighter(const QSharedPointer<Context> &defaultContext, QTextDocument *parent = 0);
|
Highlighter(const QSharedPointer<Context> &defaultContext, QTextDocument *parent = 0);
|
||||||
virtual ~Highlighter();
|
virtual ~Highlighter();
|
||||||
|
|
||||||
|
void configureFormats(const TextEditor::FontSettings & fs);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void highlightBlock(const QString &text);
|
virtual void highlightBlock(const QString &text);
|
||||||
|
|
||||||
@@ -80,8 +87,9 @@ private:
|
|||||||
|
|
||||||
void applyFormat(int offset,
|
void applyFormat(int offset,
|
||||||
int count,
|
int count,
|
||||||
const QString &itemData,
|
const QString &itemDataName,
|
||||||
const QSharedPointer<HighlightDefinition> &definition);
|
const QSharedPointer<HighlightDefinition> &definition);
|
||||||
|
void applyVisualWhitespaceFormat(const QString &text);
|
||||||
|
|
||||||
QString currentContextSequence() const;
|
QString currentContextSequence() const;
|
||||||
void mapContextSequence(const QString &contextSequence);
|
void mapContextSequence(const QString &contextSequence);
|
||||||
@@ -136,6 +144,9 @@ private:
|
|||||||
|
|
||||||
// Captures used in dynamic rules.
|
// Captures used in dynamic rules.
|
||||||
QStringList m_currentCaptures;
|
QStringList m_currentCaptures;
|
||||||
|
|
||||||
|
QTextCharFormat m_visualWhitespaceFormat;
|
||||||
|
QHash<QString, QTextCharFormat> m_genericFormats;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -33,95 +33,98 @@
|
|||||||
using namespace GenericEditor;
|
using namespace GenericEditor;
|
||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
|
|
||||||
namespace {
|
const QLatin1String ItemData::kDsNormal("dsNormal");
|
||||||
static const QLatin1String kDsNormal("dsNormal");
|
const QLatin1String ItemData::kDsKeyword("dsKeyword");
|
||||||
static const QLatin1String kDsKeyword("dsKeyword");
|
const QLatin1String ItemData::kDsDataType("dsDataType");
|
||||||
static const QLatin1String kDsDataType("dsDataType");
|
const QLatin1String ItemData::kDsDecVal("dsDecVal");
|
||||||
static const QLatin1String kDsDecVal("dsDecVal");
|
const QLatin1String ItemData::kDsBaseN("dsBaseN");
|
||||||
static const QLatin1String kDsBaseN("dsBaseN");
|
const QLatin1String ItemData::kDsFloat("dsFloat");
|
||||||
static const QLatin1String kDsFloat("dsFloat");
|
const QLatin1String ItemData::kDsChar("dsChar");
|
||||||
static const QLatin1String kDsChar("dsChar");
|
const QLatin1String ItemData::kDsString("dsString");
|
||||||
static const QLatin1String kDsString("dsString");
|
const QLatin1String ItemData::kDsComment("dsComment");
|
||||||
static const QLatin1String kDsComment("dsComment");
|
const QLatin1String ItemData::kDsOthers("dsOthers");
|
||||||
static const QLatin1String kDsOthers("dsOthers");
|
const QLatin1String ItemData::kDsAlert("dsAlert");
|
||||||
static const QLatin1String kDsAlert("dsAlert");
|
const QLatin1String ItemData::kDsFunction("dsFunction");
|
||||||
static const QLatin1String kDsFunction("dsFunction");
|
const QLatin1String ItemData::kDsRegionMarker("dsRegionMarker");
|
||||||
static const QLatin1String kDsRegionMarker("dsRegionMarker");
|
const QLatin1String ItemData::kDsError("dsError");
|
||||||
static const QLatin1String kDsError("dsError");
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemData::ItemData()
|
ItemData::ItemData() :
|
||||||
|
m_italicSpecified(false),
|
||||||
|
m_boldSpecified(false),
|
||||||
|
m_underlinedSpecified(false),
|
||||||
|
m_strikedOutSpecified(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void ItemData::setStyle(const QString &style)
|
void ItemData::setStyle(const QString &style)
|
||||||
{ m_style = style; }
|
{ m_style = style; }
|
||||||
|
|
||||||
|
const QString &ItemData::style() const
|
||||||
|
{ return m_style; }
|
||||||
|
|
||||||
void ItemData::setColor(const QString &color)
|
void ItemData::setColor(const QString &color)
|
||||||
{ m_color.setNamedColor(color); }
|
{ m_color.setNamedColor(color); }
|
||||||
|
|
||||||
|
const QColor &ItemData::color() const
|
||||||
|
{ return m_color; }
|
||||||
|
|
||||||
void ItemData::setSelectionColor(const QString &color)
|
void ItemData::setSelectionColor(const QString &color)
|
||||||
{ m_selectionColor.setNamedColor(color); }
|
{ m_selectionColor.setNamedColor(color); }
|
||||||
|
|
||||||
|
const QColor &ItemData::selectionColor() const
|
||||||
|
{ return m_selectionColor; }
|
||||||
|
|
||||||
void ItemData::setItalic(const QString &italic)
|
void ItemData::setItalic(const QString &italic)
|
||||||
{ m_font.setItalic(toBool(italic)); }
|
|
||||||
|
|
||||||
void ItemData::setBold(const QString &bold)
|
|
||||||
{ m_font.setBold(toBool(bold)); }
|
|
||||||
|
|
||||||
void ItemData::setUnderlined(const QString &underlined)
|
|
||||||
{ m_font.setUnderline(toBool(underlined)); }
|
|
||||||
|
|
||||||
void ItemData::setStrikedOut(const QString &striked)
|
|
||||||
{ m_font.setStrikeOut(toBool(striked)); }
|
|
||||||
|
|
||||||
void ItemData::configureFormat()
|
|
||||||
{
|
{
|
||||||
//Todo: Overwrite defaults when true?
|
if (!italic.isEmpty()) {
|
||||||
m_format.setFont(m_font);
|
m_italic = toBool(italic);
|
||||||
|
m_italicSpecified = true;
|
||||||
if (m_style == kDsNormal) {
|
|
||||||
m_format.setForeground(Qt::black);
|
|
||||||
} else if (m_style == kDsKeyword) {
|
|
||||||
m_format.setForeground(Qt::black);
|
|
||||||
m_format.setFontWeight(QFont::Bold);
|
|
||||||
} else if (m_style == kDsDataType) {
|
|
||||||
m_format.setForeground(Qt::blue);
|
|
||||||
} else if (m_style == kDsDecVal) {
|
|
||||||
m_format.setForeground(Qt::darkYellow);
|
|
||||||
} else if (m_style == kDsBaseN) {
|
|
||||||
m_format.setForeground(Qt::darkYellow);
|
|
||||||
m_format.setFontWeight(QFont::Bold);
|
|
||||||
} else if (m_style == kDsFloat) {
|
|
||||||
m_format.setForeground(Qt::darkYellow);
|
|
||||||
m_format.setFontUnderline(true);
|
|
||||||
} else if (m_style == kDsChar) {
|
|
||||||
m_format.setForeground(Qt::magenta);
|
|
||||||
} else if (m_style == kDsString) {
|
|
||||||
m_format.setForeground(Qt::red);
|
|
||||||
} else if (m_style == kDsComment) {
|
|
||||||
m_format.setForeground(Qt::darkGray);
|
|
||||||
m_format.setFontItalic(true);
|
|
||||||
m_format.setFontWeight(QFont::Bold);
|
|
||||||
} else if (m_style == kDsOthers) {
|
|
||||||
m_format.setForeground(Qt::darkGreen);
|
|
||||||
} else if (m_style == kDsAlert) {
|
|
||||||
m_format.setForeground(Qt::darkRed);
|
|
||||||
m_format.setFontWeight(QFont::Bold);
|
|
||||||
} else if (m_style == kDsFunction) {
|
|
||||||
m_format.setForeground(Qt::darkBlue);
|
|
||||||
m_format.setFontWeight(QFont::Bold);
|
|
||||||
} else if (m_style == kDsRegionMarker) {
|
|
||||||
m_format.setForeground(Qt::yellow);
|
|
||||||
} else if (m_style == kDsError) {
|
|
||||||
m_format.setForeground(Qt::darkRed);
|
|
||||||
m_format.setFontUnderline(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_color.isValid())
|
|
||||||
m_format.setForeground(QColor(m_color));
|
|
||||||
//if (m_selectionColor.isValid())
|
|
||||||
//m_format.setBackground(QColor(m_selectionColor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QTextCharFormat &ItemData::format() const
|
bool ItemData::isItalic() const
|
||||||
{ return m_format; }
|
{ return m_italic; }
|
||||||
|
|
||||||
|
bool ItemData::isItalicSpecified() const
|
||||||
|
{ return m_italicSpecified; }
|
||||||
|
|
||||||
|
void ItemData::setBold(const QString &bold)
|
||||||
|
{
|
||||||
|
if (!bold.isEmpty()) {
|
||||||
|
m_bold = toBool(bold);
|
||||||
|
m_boldSpecified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ItemData::isBold() const
|
||||||
|
{ return m_bold; }
|
||||||
|
|
||||||
|
bool ItemData::isBoldSpecified() const
|
||||||
|
{ return m_boldSpecified; }
|
||||||
|
|
||||||
|
void ItemData::setUnderlined(const QString &underlined)
|
||||||
|
{
|
||||||
|
if (!underlined.isEmpty()) {
|
||||||
|
m_underlined = toBool(underlined);
|
||||||
|
m_underlinedSpecified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ItemData::isUnderlined() const
|
||||||
|
{ return m_underlined; }
|
||||||
|
|
||||||
|
bool ItemData::isUnderlinedSpecified() const
|
||||||
|
{ return m_underlinedSpecified; }
|
||||||
|
|
||||||
|
void ItemData::setStrikedOut(const QString &striked)
|
||||||
|
{
|
||||||
|
if (!striked.isEmpty()) {
|
||||||
|
m_strikedOut = toBool(striked);
|
||||||
|
m_strikedOutSpecified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ItemData::isStrikedOut() const
|
||||||
|
{ return m_strikedOut; }
|
||||||
|
|
||||||
|
bool ItemData::isStrikedOutSpecified() const
|
||||||
|
{ return m_strikedOutSpecified; }
|
||||||
|
|||||||
@@ -45,22 +45,57 @@ public:
|
|||||||
ItemData();
|
ItemData();
|
||||||
|
|
||||||
void setStyle(const QString &style);
|
void setStyle(const QString &style);
|
||||||
void setColor(const QString &color);
|
const QString &style() const;
|
||||||
void setSelectionColor(const QString &color);
|
|
||||||
void setItalic(const QString &italic);
|
|
||||||
void setBold(const QString &bold);
|
|
||||||
void setUnderlined(const QString &underlined);
|
|
||||||
void setStrikedOut(const QString &striked);
|
|
||||||
void configureFormat();
|
|
||||||
|
|
||||||
const QTextCharFormat &format() const;
|
void setColor(const QString &color);
|
||||||
|
const QColor &color() const;
|
||||||
|
|
||||||
|
void setSelectionColor(const QString &color);
|
||||||
|
const QColor &selectionColor() const;
|
||||||
|
|
||||||
|
void setItalic(const QString &italic);
|
||||||
|
bool isItalic() const;
|
||||||
|
bool isItalicSpecified() const;
|
||||||
|
|
||||||
|
void setBold(const QString &bold);
|
||||||
|
bool isBold() const;
|
||||||
|
bool isBoldSpecified() const;
|
||||||
|
|
||||||
|
void setUnderlined(const QString &underlined);
|
||||||
|
bool isUnderlined() const;
|
||||||
|
bool isUnderlinedSpecified() const;
|
||||||
|
|
||||||
|
void setStrikedOut(const QString &striked);
|
||||||
|
bool isStrikedOut() const;
|
||||||
|
bool isStrikedOutSpecified() const;
|
||||||
|
|
||||||
|
static const QLatin1String kDsNormal;
|
||||||
|
static const QLatin1String kDsKeyword;
|
||||||
|
static const QLatin1String kDsDataType;
|
||||||
|
static const QLatin1String kDsDecVal;
|
||||||
|
static const QLatin1String kDsBaseN;
|
||||||
|
static const QLatin1String kDsFloat;
|
||||||
|
static const QLatin1String kDsChar;
|
||||||
|
static const QLatin1String kDsString;
|
||||||
|
static const QLatin1String kDsComment;
|
||||||
|
static const QLatin1String kDsOthers;
|
||||||
|
static const QLatin1String kDsAlert;
|
||||||
|
static const QLatin1String kDsFunction;
|
||||||
|
static const QLatin1String kDsRegionMarker;
|
||||||
|
static const QLatin1String kDsError;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_style;
|
QString m_style;
|
||||||
QColor m_color;
|
QColor m_color;
|
||||||
QColor m_selectionColor;
|
QColor m_selectionColor;
|
||||||
QFont m_font;
|
bool m_italic;
|
||||||
QTextCharFormat m_format;
|
bool m_italicSpecified;
|
||||||
|
bool m_bold;
|
||||||
|
bool m_boldSpecified;
|
||||||
|
bool m_underlined;
|
||||||
|
bool m_underlinedSpecified;
|
||||||
|
bool m_strikedOut;
|
||||||
|
bool m_strikedOutSpecified;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QLatin1String>
|
#include <QtCore/QLatin1String>
|
||||||
#include <QtCore/QChar>
|
#include <QtCore/QChar>
|
||||||
|
#include <QtGui/QFont>
|
||||||
|
|
||||||
namespace GenericEditor {
|
namespace GenericEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -56,6 +57,14 @@ inline Qt::CaseSensitivity toCaseSensitivity(const bool sensitive)
|
|||||||
return Qt::CaseInsensitive;
|
return Qt::CaseInsensitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QFont::Weight toFontWeight(const bool bold)
|
||||||
|
{
|
||||||
|
if (bold)
|
||||||
|
return QFont::Bold;
|
||||||
|
else
|
||||||
|
return QFont::Normal;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool isOctalDigit(const QChar &c)
|
inline bool isOctalDigit(const QChar &c)
|
||||||
{
|
{
|
||||||
static const QLatin1Char k0('0');
|
static const QLatin1Char k0('0');
|
||||||
|
|||||||
Reference in New Issue
Block a user