Commits

zjes committed 93589ca

Add python highlighter and initialy add theme editor

Comments (0)

Files changed (26)

src/Core/ColorChooser.cpp

     if (isEnabled()){
         paint.fillRect(rect(), _color);
         paint.setPen(QColor(255 - _color.red(), 255 - _color.green(), 255 - _color.blue()));
-        paint.drawText(rect(), Qt::AlignCenter, _color.name());
+        paint.drawText(rect(), Qt::AlignCenter, _color.name().toUpper());
         paint.setPen(Qt::black);
     } else {
         QPalette pal = palette();

src/PythonEditor/CMakeLists.txt

     PythonCompliter.h
     ErrorModel.h
     ComplititionList.h
+    Highlighter.h
 )
 
 SET(moc
     PythonCompliter.cpp
     ErrorModel.cpp
     ComplititionList.cpp
+    Highlighter.cpp
 )
 
 SET(res

src/PythonEditor/Highlighter.cpp

+#include <QDebug>
+#include "Highlighter.h"
+#include "Settings.h"
+
+namespace PythonEditor {
+
+Highlighter::Highlighter(QTextDocument *parent, const QString &lexer):
+    TextEditor::Highlighter(parent, lexer)
+{
+
+}
+
+void Highlighter::init(const QString &themeName)
+{
+    Settings set;
+    Theme::ITheme *theme = themeName.isEmpty() ? set.theme() : set.themeByName(themeName);
+
+    TextEditor::Highlighter::init(themeName);
+    _formats.insert("Normal Text"           , theme->defFormat(_lexer, "NormalText", "dsNormal"));
+    _formats.insert("Definition Keyword"    , theme->defFormat(_lexer, "DefinitionKeyword", "dsKeyword", true));
+    _formats.insert("Operator"              , theme->defFormat(_lexer, "Operator", "dsKeyword", true));
+    _formats.insert("String Substitution"   , theme->format(_lexer, "StringSubstitution", QColor("#0057ae")));
+    _formats.insert("Command Keyword"       , theme->defFormat(_lexer, "CommandKeyword", "dsKeyword"));
+    _formats.insert("Flow Control Keyword"  , theme->defFormat(_lexer, "FlowControlKeyword", "dsKeyword"));
+    _formats.insert("Builtin Function"      , theme->defFormat(_lexer, "BuiltinFunction", "dsDataType"));
+    _formats.insert("Special Variable"      , theme->defFormat(_lexer, "SpecialVariable", "dsOthers"));
+    _formats.insert("Extensions"            , theme->format(_lexer, "Extensions", QColor("#0095ff"), true));
+    _formats.insert("Exceptions"            , theme->format(_lexer, "Exceptions", QColor("#054d00"), true));
+    _formats.insert("Overloaders"           , theme->format(_lexer, "Overloaders", QColor("#000e52"), true));
+    _formats.insert("Preprocessor"          , theme->defFormat(_lexer, "Preprocessor", "dsChar"));
+    _formats.insert("String Char"           , theme->defFormat(_lexer, "StringChar", "dsChar"));
+    _formats.insert("Float"                 , theme->defFormat(_lexer, "Number", "dsNumber"));
+    _formats.insert("Int"                   , theme->defFormat(_lexer, "Number", "dsNumber"));
+    _formats.insert("Hex"                   , theme->defFormat(_lexer, "Number", "dsNumber"));
+    _formats.insert("Octal"                 , theme->defFormat(_lexer, "Number", "dsNumber"));
+    _formats.insert("Complex"               , theme->defFormat(_lexer, "Complex", "dsOthers"));
+    _formats.insert("Comment"               , theme->defFormat(_lexer, "Comment", "dsComment"));
+    _formats.insert("String"                , theme->defFormat(_lexer, "String", "dsString"));
+    _formats.insert("Raw String"            , theme->defFormat(_lexer, "RawString", "dsString"));
+    _formats.insert("Decorator"             , theme->format(_lexer, "Decorator", QColor("#8f6b32")));
+    _formats.insert("BlockRegion"           , theme->defFormat(_lexer, "BlockRegion", "dsComment"));
+}
+
+}

src/PythonEditor/Highlighter.h

+#ifndef _PYHIGHLIGHTER_H_
+#define _PYHIGHLIGHTER_H_
+#include "TextEditor/Highlighter/Highlighter.h"
+
+namespace PythonEditor {
+
+class Highlighter: public TextEditor::Highlighter
+{
+    Q_OBJECT
+public:
+    Highlighter(QTextDocument *parent, const QString &lexer);
+    virtual void init(const QString &themeName = "");
+};
+
+}
+
+#endif

src/PythonEditor/PythonEditorWidget.cpp

 #include "ErrorModel.h"
 #include "Settings.h"
 #include "PythonDocumentLayout.h"
+#include "Highlighter.h"
 
 namespace PythonEditor {
 
 {
     setMouseTracking(true);
     document()->setDocumentLayout(new PythonDocumentLayout(document()));
-    _updateErrorsTimer.setSingleShot(true);
-    _updateErrorsTimer.setInterval(500);
-    _updateErrorsTimer.stop();
-    connect(&_updateErrorsTimer, SIGNAL(timeout()), SLOT(checkIssues()));
+    if (!_isSample){
+        _updateErrorsTimer.setSingleShot(true);
+        _updateErrorsTimer.setInterval(500);
+        _updateErrorsTimer.stop();
+        connect(&_updateErrorsTimer, SIGNAL(timeout()), SLOT(checkIssues()));
+    }
     Settings set;
     _showIdent = set.showIndentLine();
 }
         _compliter->checkErrors();
 }
 
-QString PythonEditorWidget::lexer()
+TextEditor::Highlighter* PythonEditorWidget::hightlighter()
 {
-    return "python";
+    return new PythonEditor::Highlighter(document(), "python");
 }
 
 void PythonEditorWidget::paintEvent(QPaintEvent *event)

src/PythonEditor/PythonEditorWidget.h

 namespace PythonEditor {
 
 class PythonCompliter;
-class PythonHightlighter;
+class Highlighter;
 
 class PythonEditorWidget: public TextEditor::TextEditorWidget
 {
 public:
     PythonEditorWidget(const QString& fileName, bool sample = false, QWidget* parent = NULL);
     virtual void editorLoaded();
-    virtual QString lexer();
+    virtual TextEditor::Highlighter* hightlighter();
     void setErrors(const QList<Python::IPython::ErrorItem>& items);
     QAbstractTableModel* errorListModel();
 public slots:
 private:
     void autoIndentNewLine();
 private:
-    PythonHightlighter * _hight;
     PythonCompliter * _compliter;
     QAbstractTableModel * _errorListModel;
     bool _showIdent;

src/TextEditor/Highlighter/Highlighter.cpp

     static const QLatin1Char kHash('#');
 }
 
-const Highlighter::KateFormatMap Highlighter::_kateFormats;
-
 Highlighter::Highlighter(QTextDocument *parent, const QString& lexer) :
     SyntaxHighlighter(parent),
     _regionDepth(0),
     Settings set;
     Theme::ITheme *theme = themeName.isEmpty() ? set.theme() : set.themeByName(themeName);
 
-    _creatorFormats[Highlighter::Normal] = createFormat(theme, _lexer, Theme::Default);
-    _creatorFormats[Highlighter::Keyword] = createFormat(theme, _lexer, Theme::Keyword);
-    _creatorFormats[Highlighter::DataType] = createFormat(theme, _lexer, Theme::DataType);
-    _creatorFormats[Highlighter::Decimal] = createFormat(theme, _lexer, Theme::Number);
-    _creatorFormats[Highlighter::BaseN] = createFormat(theme, _lexer, Theme::Number);
-    _creatorFormats[Highlighter::Float] = createFormat(theme, _lexer, Theme::Number);
-    _creatorFormats[Highlighter::Char] = createFormat(theme, _lexer, Theme::Char);
-    _creatorFormats[Highlighter::String] = createFormat(theme, _lexer, Theme::String);
-    _creatorFormats[Highlighter::Comment] = createFormat(theme, _lexer, Theme::Comment);
-    _creatorFormats[Highlighter::Others] = createFormat(theme, _lexer, Theme::Others);
-    _creatorFormats[Highlighter::Alert] = createFormat(theme, _lexer, Theme::Alert);
-    _creatorFormats[Highlighter::Function] = createFormat(theme, _lexer, Theme::Function);
-    _creatorFormats[Highlighter::Error] = createFormat(theme, _lexer, Theme::Error);
-    _creatorFormats[Highlighter::RegionMarker] = createFormat(theme, _lexer, Theme::String);
-}
-
-QTextCharFormat Highlighter::createFormat(Theme::ITheme * theme, const QString& lexer, Theme::Roles role)
-{
-    QTextCharFormat format;
-    format.setForeground(theme->color(lexer, role));
-    format.setFontItalic(theme->italic(lexer, role));
-    format.setFontUnderline(theme->underline(lexer, role));
-    format.setFontWeight(theme->bold(lexer, role) ? QFont::Bold: QFont::Normal);
-    return format;
+    _formats.insert("dsNormal"      , theme->format(_lexer, "dsNormal", QColor("#000000")));
+    _formats.insert("dsKeyword"     , theme->format(_lexer, "dsKeyword", QColor("#000000"), true));
+    _formats.insert("dsDataType"    , theme->format(_lexer, "dsDataType", QColor("#0057AE")));
+    _formats.insert("dsDecVal"      , theme->format(_lexer, "dsNumber", QColor("#B08000")));
+    _formats.insert("dsBaseN"       , theme->format(_lexer, "dsNumber", QColor("#B08000")));
+    _formats.insert("dsFloat"       , theme->format(_lexer, "dsNumber", QColor("#B08000")));
+    _formats.insert("dsChar"        , theme->format(_lexer, "dsChar", QColor("#FF80E0")));
+    _formats.insert("dsString"      , theme->format(_lexer, "dsString", QColor("#BF0303")));
+    _formats.insert("dsComment"     , theme->format(_lexer, "dsComment", QColor("#898887")));
+    _formats.insert("dsOthers"      , theme->format(_lexer, "dsOthers", QColor("#006E28")));
+    _formats.insert("dsAlert"       , theme->format(_lexer, "dsAlert", QColor("#BF0303")));
+    _formats.insert("dsFunction"    , theme->format(_lexer, "dsFunction", QColor("#644A9B")));
+    _formats.insert("dsRegionMarker", theme->format(_lexer, "dsRegionMarker", QColor("#DEDEDE")));
+    _formats.insert("dsError"       , theme->format(_lexer, "dsError", QColor("#BF0303")));
 }
 
 Highlighter::BlockData::BlockData():
 Highlighter::BlockData::~BlockData()
 {}
 
-Highlighter::KateFormatMap::KateFormatMap()
-{
-    _ids.insert(QLatin1String("dsNormal"), Highlighter::Normal);
-    _ids.insert(QLatin1String("dsKeyword"), Highlighter::Keyword);
-    _ids.insert(QLatin1String("dsDataType"), Highlighter::DataType);
-    _ids.insert(QLatin1String("dsDecVal"), Highlighter::Decimal);
-    _ids.insert(QLatin1String("dsBaseN"), Highlighter::BaseN);
-    _ids.insert(QLatin1String("dsFloat"), Highlighter::Float);
-    _ids.insert(QLatin1String("dsChar"), Highlighter::Char);
-    _ids.insert(QLatin1String("dsString"), Highlighter::String);
-    _ids.insert(QLatin1String("dsComment"), Highlighter::Comment);
-    _ids.insert(QLatin1String("dsOthers"), Highlighter::Others);
-    _ids.insert(QLatin1String("dsAlert"), Highlighter::Alert);
-    _ids.insert(QLatin1String("dsFunction"), Highlighter::Function);
-    _ids.insert(QLatin1String("dsRegionMarker"), Highlighter::RegionMarker);
-    _ids.insert(QLatin1String("dsError"), Highlighter::Error);
-}
-
-void Highlighter::configureFormat(TextFormatId id, const QTextCharFormat &format)
-{
-    _creatorFormats[id] = format;
-}
-
 void  Highlighter::setDefaultContext(const QSharedPointer<Context> &defaultContext)
 {
     _defaultContext = defaultContext;
         }
     }
 
-    applyFormatToSpaces(text, _creatorFormats.value(VisualWhitespace));
+    //applyFormatToSpaces(text, _creatorFormats.value(VisualWhitespace));
 }
 
 void Highlighter::setupDataForBlock(const QString &text)
         return;
     }
 
-    TextFormatId formatId = _kateFormats._ids.value(itemData->style());
-    if (formatId != Normal) {
-        QHash<TextFormatId, QTextCharFormat>::const_iterator cit =
-            _creatorFormats.constFind(formatId);
-        if (cit != _creatorFormats.constEnd()) {
-            QTextCharFormat format = cit.value();
-            if (itemData->isCustomized()) {
-                // Please notice that the following are applied every time for item data which have
-                // customizations. The configureFormats method could be used to provide a "one time"
-                // configuration, but it would probably require to traverse all item data from all
-                // definitions available/loaded (either to set the values or for some "notifying"
-                // strategy). This is because the highlighter does not really know on which
-                // definition(s) it is working. Since not many item data specify customizations I
-                // think this approach would fit better. If there are other ideas...
-                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->isStrikeOutSpecified())
-                    format.setFontStrikeOut(itemData->isStrikeOut());
-            }
-
-            setFormat(offset, count, format);
+    const QString formatName = itemData->style();
+    if (formatName != "dsNormal"){
+        QTextCharFormat format = _formats.value(formatName, QTextCharFormat());
+        if (itemData->isCustomized()) {
+            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->isStrikeOutSpecified())
+                format.setFontStrikeOut(itemData->isStrikeOut());
         }
+        setFormat(offset, count, format);
     }
 }
 

src/TextEditor/Highlighter/Highlighter.h

 #include <QSyntaxHighlighter>
 #include <QTextCharFormat>
 #include "Include/ITheme.h"
-#include "BaseDocumentLayout.h"
+#include "TextEditor/BaseDocumentLayout.h"
 
 namespace TextEditor {
 
     Highlighter(QTextDocument *parent, const QString& lexer);
     virtual ~Highlighter();
 
-    void init(const QString& themeName = "");
-
-    enum TextFormatId {
-        Normal,
-        VisualWhitespace,
-        Keyword,
-        DataType,
-        Decimal,
-        BaseN,
-        Float,
-        Char,
-        String,
-        Comment,
-        Alert,
-        Error,
-        Function,
-        RegionMarker,
-        Others
-    };
+    virtual void init(const QString& themeName = "");
 
-    void configureFormat(TextFormatId id, const QTextCharFormat &format);
     void setTabSettings(const TabSettings &ts);
     void setDefaultContext(const QSharedPointer<Context> &defaultContext);
 protected:
     virtual void highlightBlock(const QString &text);
-    QTextCharFormat createFormat(Theme::ITheme * theme, const QString& lexer, Theme::Roles role);
-
 private:
 
     void setupDataForBlock(const QString &text);
     void applyIndentationBasedFolding(const QString &text) const;
     int neighbouringNonEmptyBlockIndent(QTextBlock block, const bool previous) const;
 
-    // Mapping from Kate format strings to format ids.
-    struct KateFormatMap
-    {
-        KateFormatMap();
-        QHash<QString, TextFormatId> _ids;
-    };
-    static const KateFormatMap _kateFormats;
-    QHash<TextFormatId, QTextCharFormat> _creatorFormats;
-
     struct BlockData : TextBlockData
     {
         BlockData();
 
     // Captures used in dynamic rules.
     QStringList _currentCaptures;
+protected:
     QString _lexer;
+    QHash<QString, QTextCharFormat> _formats;
 };
 
 }

src/TextEditor/TextEditorMargine.cpp

 {
     Settings set;
     Theme::ITheme *theme = set.themeByName(name.isEmpty() ? set.themeName() : name);
-    _background = theme->background("common", Theme::Margine);
-    _foreground = theme->color("common", Theme::Margine);
+    QPalette pal = QApplication::palette();
+    _background = theme->background("common", "dsMargine", pal.color(QPalette::Window));
+    _foreground = theme->color("common", "dsMargine", pal.color(QPalette::Text));
     update();
 }
 

src/TextEditor/TextEditorWidget.cpp

 #include "TextEditorMargine.h"
 #include "Settings.h"
 #include "TabSettings.h"
-//#include "GenericHightlighter.h"
 #include "TextEditorHeader.h"
 #include "CustomMenu.h"
 #include "Editors/FileProperty.h"
     }
     connect(_margine, SIGNAL(foldingOpenClosed(int,bool)), SLOT(onFoldingOpenClosed(int,bool)));
     connect(Aux::app(), SIGNAL(preferencesChanged(QString)), SLOT(preferencesChanged(QString)));
-    _updateTimer.setInterval(500);
+    _updateTimer.setInterval(100);
     _updateTimer.setSingleShot(true);
     _updateTimer.stop();
     connect(&_updateTimer, SIGNAL(timeout()), SLOT(validateFolding()));
         editorLoaded();
         connect(this, SIGNAL(textChanged()), SLOT(editorTextChanged()));
         emit contentLoaded();
-        _highlighter = new Highlighter(document(), lexer());
+        _highlighter = hightlighter();
         _highlighter->init();
         QSharedPointer<HighlightDefinition> def = Manager::instance()->definition(_fileName);
         if (!def.isNull()){
             _highlighter->setDefaultContext(def->initialContext());
             _highlighter->rehighlight();
-            QTimer::singleShot(100, this, SLOT(restoreState()));
+            QTimer::singleShot(10, this, SLOT(restoreState()));
         }
         return true;
     }
     return false;
 }
 
+Highlighter* TextEditorWidget::hightlighter()
+{
+    return new Highlighter(document(), "default");
+}
+
 void TextEditorWidget::editorLoaded()
 {
 }
     _fileName = fileName;
 }
 
-QString TextEditorWidget::lexer()
-{
-    return "default";
-}
-
 void TextEditorWidget::startIncrementalFind()
 {
     _incFindCursor = textCursor();
         _incFindCursor = textCursor();
 
     QTextCursor fc = document()->find(text, _incFindCursor, forward ? (QTextDocument::FindFlag)0 : QTextDocument::FindBackward);
-    setTextCursor(fc);
+    if (!fc.isNull())
+        setTextCursor(fc);
+    else
+        setTextCursor(_incFindCursor);
 }
 
 void TextEditorWidget::replace(const QString& text, const QString& repl, bool findNext, bool forward)
     Settings set;
     Theme::ITheme *theme = set.themeByName(name.isEmpty() ? set.themeName() : name);
     QPalette pal = palette();
-    qDebug() << theme->background("common", Theme::Default).name();
-    pal.setColor(QPalette::Base, theme->background("common", Theme::Default));
-    pal.setColor(QPalette::Text, theme->color("common", Theme::Default));
+    QPalette apal = QApplication::palette();
+    pal.setColor(QPalette::Base, theme->background("common", "dsNormal", apal.color(QPalette::Base)));
+    pal.setColor(QPalette::Text, theme->color("common", "dsNormal", apal.color(QPalette::WindowText)));
     setPalette(pal);
-    _lineColor = theme->background("common", Theme::HightlightLine);
+    _lineColor = theme->background("common", "dsHightlight", QColor("#F8F7F6"));
 
     if (_highlighter){
         _highlighter->init(name);
 
 void TextEditorWidget::editorTextChanged()
 {
-    qDebug() << "text changed";
     _updateTimer.start();
 }
 
 void TextEditorWidget::validateFolding()
 {
-    qDebug() << "update folding";
     QMap<int, FoldInfo> lst;
     QTextBlock block = document()->firstBlock();
     while(block.isValid()){

src/TextEditor/TextEditorWidget.h

     QString selectedText();
     virtual void editorLoaded();
     virtual QWidget * header();
-    virtual QString lexer();
+    virtual Highlighter* hightlighter();
     QString fileName();
     void setFileName(const QString& fileName);
     int visibleBlockCount();

src/Theme/CMakeLists.txt

     ThemePlugin.h
     Theme.h
     ThemeEditor.h
+    CommonModel.h
+    DefaultModel.h
+    LexerModel.h
+    PythonModel.h
 )
 
 SET(moc
     ThemePlugin.cpp
     Theme.cpp
     ThemeEditor.cpp
+    CommonModel.cpp
+    DefaultModel.cpp
+    LexerModel.cpp
+    PythonModel.cpp
 )
 
 SET(res

src/Theme/CommonModel.cpp

+#include <QApplication>
+#include <QPalette>
+#include "CommonModel.h"
+#include "Include/ITheme.h"
+
+namespace Theme {
+
+CommonModel::CommonModel(ITheme* theme, QObject* parent):
+    QAbstractListModel(parent),
+    _theme(theme)
+{
+    _names << "dsNormal" << "dsMargine" << "dsHightlight";
+
+    QPalette pal = QApplication::palette();
+
+    _colors << _theme->color("common", "dsNormal", pal.color(QPalette::WindowText))
+            << _theme->color("common", "dsMargine", pal.color(QPalette::Text))
+            << _theme->color("common", "dsHightlight", pal.color(QPalette::WindowText));
+
+    _backgrounds << _theme->background("common", "dsNormal", pal.color(QPalette::Base))
+                 << _theme->background("common", "dsMargine", pal.color(QPalette::Window))
+                 << _theme->background("common", "dsHightlight", pal.color(QPalette::AlternateBase));
+}
+
+int CommonModel::rowCount(const QModelIndex &) const
+{
+    return 3;
+}
+
+QVariant CommonModel::data(const QModelIndex & index, int role) const
+{
+    if (!index.isValid())
+        return QVariant();
+
+    QPalette pal = QApplication::palette();
+    switch(role) {
+    case Qt::BackgroundRole:
+        return _backgrounds[index.row()];
+    case Qt::ForegroundRole:
+        return _colors[index.row()];
+    case Qt::DisplayRole:
+        switch(index.row()){
+        case 0: return tr("Text");
+        case 1: return tr("Margine");
+        case 2: return tr("Current line");
+        }
+    }
+    return QVariant();
+}
+
+void CommonModel::setColor(const QModelIndex& index, int role, const QColor& color)
+{
+    if (role == Qt::ForegroundRole && index.row() != 2){
+        _colors[index.row()] = color;
+        _theme->setColor("common", _names[index.row()], color);
+    } else if (role == Qt::BackgroundRole) {
+        _backgrounds[index.row()] = color;
+        _theme->setBackground("common", _names[index.row()], color);
+    }
+}
+
+}

src/Theme/CommonModel.h

+#ifndef _COMMONMODEL_H_
+#define _COMMONMODEL_H_
+#include <QAbstractListModel>
+#include <QStringList>
+#include <QColor>
+
+namespace Theme {
+class ITheme;
+
+class CommonModel : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    CommonModel(ITheme* theme, QObject* parent = NULL);
+    virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
+    virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+
+    void setColor(const QModelIndex& index, int role, const QColor& color);
+private:
+    ITheme* _theme;
+    QStringList _names;
+    QList<QColor> _colors;
+    QList<QColor> _backgrounds;
+};
+
+}
+
+#endif

src/Theme/DefaultModel.cpp

+#include <QApplication>
+#include <QPalette>
+#include "DefaultModel.h"
+#include "Include/ITheme.h"
+
+namespace Theme {
+
+DefaultModel::DefaultModel(ITheme* theme, QObject* parent):
+    LexerModel(theme, "default", parent)
+{
+    _names << "dsKeyword" << "dsDataType" << "dsNumber" << "dsChar"
+           << "dsString" << "dsComment" << "dsOthers" << "dsAlert"
+           << "dsFunction" << "dsRegionMarker" << "dsError";
+
+    _titles << tr("Keyword") << tr("Data type") << tr("Number")
+            << tr("Char") << tr("String") << tr("Comment")
+            << tr("Others") << tr("Alert") << tr("Function")
+            << tr("Region marker") << tr("Error");
+
+    _colors << _theme->color("default", "dsKeyword"     , QColor("#000000"))
+            << _theme->color("default", "dsDataType"    , QColor("#0057AE"))
+            << _theme->color("default", "dsNumber"      , QColor("#B08000"))
+            << _theme->color("default", "dsChar"        , QColor("#FF80E0"))
+            << _theme->color("default", "dsString"      , QColor("#BF0303"))
+            << _theme->color("default", "dsComment"     , QColor("#898887"))
+            << _theme->color("default", "dsOthers"      , QColor("#006E28"))
+            << _theme->color("default", "dsAlert"       , QColor("#BF0303"))
+            << _theme->color("default", "dsFunction"    , QColor("#644A9B"))
+            << _theme->color("default", "dsRegionMarker", QColor("#DEDEDE"))
+            << _theme->color("default", "dsError"       , QColor("#BF0303"));
+
+    foreach(QString name, _names){
+        _backgrounds << _theme->background("default", name);
+        _bold << _theme->bold("default", name, name == "dsKeyword" ? true : false);
+        _italic << _theme->italic("default", name);
+        _underline << _theme->italic("default", name);
+    }
+}
+
+
+}

src/Theme/DefaultModel.h

+#ifndef _DEFAULTMODEL_H_
+#define _DEFAULTMODEL_H_
+#include "LexerModel.h"
+
+namespace Theme {
+class ITheme;
+
+class DefaultModel : public LexerModel
+{
+    Q_OBJECT
+public:
+    DefaultModel(ITheme* theme, QObject* parent = NULL);
+};
+
+}
+
+#endif

src/Theme/ITheme.h

 #define _ITHEME_H_
 #include <QObject>
 #include <QColor>
+#include <QTextCharFormat>
 
 namespace Theme {
 
-enum Roles {
-    Default,
-    Margine,
-    HightlightLine,
-
-    //Normal,
-    Keyword,
-    DataType,
-    Number,
-    Char,
-    String,
-    Comment,
-    Others,
-    Alert,
-    Function,
-    Error,
-
-    Operand,
-    SpecialVariable,
-    Class,
-    Decorator,
-    Preprocessor
-};
-
 class ITheme: public QObject
 {
     Q_OBJECT
 public:
     virtual ~ITheme(){}
 
-    virtual QColor color(const QString& lexer, Roles role) = 0;
-    virtual QColor background(const QString& lexer, Roles role) = 0;
+    virtual QTextCharFormat format(const QString& lexer, const QString& role, const QColor& defColor = Qt::black, bool bold = false) = 0;
+    virtual QTextCharFormat defFormat(const QString& lexer, const QString& role, const QString& defRole = "dsNormal", bool bold = false) = 0;
+
+    virtual QColor color(const QString& lexer, const QString& role, const QColor& def = Qt::black) = 0;
+    virtual QColor background(const QString& lexer, const QString& role, const QColor& def = Qt::transparent) = 0;
+
+    virtual void setColor(const QString& lexer, const QString& role, const QColor& color) = 0;
+    virtual void setBackground(const QString& lexer, const QString& role, const QColor& color) = 0;
 
-    virtual void setColor(const QString& lexer, Roles role, const QColor& color) = 0;
-    virtual void setBackground(const QString& lexer, Roles role, const QColor& color) = 0;
+    virtual bool italic(const QString& lexer, const QString& role, bool def = false) = 0;
+    virtual bool bold(const QString& lexer, const QString& role, bool def = false) = 0;
+    virtual bool underline(const QString& lexer, const QString& role, bool def = false) = 0;
 
-    virtual bool italic(const QString& lexer, Roles role) = 0;
-    virtual bool bold(const QString& lexer, Roles role) = 0;
-    virtual bool underline(const QString& lexer, Roles role) = 0;
+    virtual void setItalic(const QString& lexer, const QString& role, bool on) = 0;
+    virtual void setBold(const QString& lexer, const QString& role, bool on) = 0;
+    virtual void setUnderline(const QString& lexer, const QString& role, bool on) = 0;
 };
 
 }

src/Theme/LexerModel.cpp

+#include <QApplication>
+#include <QPalette>
+#include "LexerModel.h"
+#include "Include/ITheme.h"
+
+namespace Theme {
+
+LexerModel::LexerModel(ITheme* theme, const QString& lexer, QObject* parent):
+    QAbstractListModel(parent),
+    _theme(theme),
+    _lexer(lexer)
+{
+}
+
+int LexerModel::rowCount(const QModelIndex &) const
+{
+    return _names.length();
+}
+
+QVariant LexerModel::data(const QModelIndex & index, int role) const
+{
+    if (!index.isValid())
+        return QVariant();
+
+    switch(role) {
+    case BackgroundRole:
+        return _backgrounds[index.row()];
+    case ForegroundRole:
+        return _colors[index.row()];
+    case FontRole: {
+        QFont font(QApplication::font());
+        font.setBold(_bold[index.row()]);
+        font.setItalic(_italic[index.row()]);
+        font.setUnderline(_underline[index.row()]);
+        return font;
+    }
+    case DisplayRole:
+        return _titles[index.row()];
+    case BoldRole:
+        return _bold[index.row()];
+    case ItalicRole:
+        return _italic[index.row()];
+    case UnderscoreRole:
+        return _underline[index.row()];
+    case BTransparentRole:
+        return _backgrounds[index.row()].alpha() == 0;
+    }
+    return QVariant();
+}
+
+void LexerModel::setColor(const QModelIndex& index, const QColor& color)
+{
+    _colors[index.row()] = color;
+    _theme->setColor(_lexer, _names[index.row()], color);
+    emit dataChanged(index, index);
+}
+
+void LexerModel::setBackground(const QModelIndex& index, const QColor& color)
+{
+    _backgrounds[index.row()] = color;
+    _theme->setBackground(_lexer, _names[index.row()], color);
+    emit dataChanged(index, index);
+}
+
+void LexerModel::setTransparent(const QModelIndex& index, bool on)
+{
+    if (on)
+        setBackground(index, Qt::transparent);
+}
+
+void LexerModel::setBold(const QModelIndex& index, bool on)
+{
+    _bold[index.row()] = on;
+    _theme->setBold(_lexer, _names[index.row()], on);
+    emit dataChanged(index, index);
+}
+
+void LexerModel::setItalic(const QModelIndex& index, bool on)
+{
+    _italic[index.row()] = on;
+    _theme->setItalic(_lexer, _names[index.row()], on);
+    emit dataChanged(index, index);
+}
+
+void LexerModel::setUnderline(const QModelIndex& index, bool on)
+{
+    _underline[index.row()] = on;
+    _theme->setUnderline(_lexer, _names[index.row()], on);
+    emit dataChanged(index, index);
+}
+
+}

src/Theme/LexerModel.h

+#ifndef _LEXERMODEL_H_
+#define _LEXERMODEL_H_
+#include <QAbstractListModel>
+#include <QStringList>
+#include <QColor>
+
+namespace Theme {
+class ITheme;
+
+enum LexerRoles {
+    DisplayRole = Qt::DisplayRole,
+    BackgroundRole = Qt::BackgroundRole,
+    ForegroundRole = Qt::ForegroundRole,
+    FontRole = Qt::FontRole,
+    BTransparentRole = Qt::UserRole + 1,
+    BoldRole = Qt::UserRole + 2,
+    ItalicRole = Qt::UserRole + 3,
+    UnderscoreRole = Qt::UserRole + 4
+};
+
+class LexerModel : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    LexerModel(ITheme* theme, const QString& lexer, QObject* parent = NULL);
+    virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
+    virtual QVariant data(const QModelIndex & index, int role = DisplayRole) const;
+
+    void setColor(const QModelIndex& index, const QColor& color);
+    void setBackground(const QModelIndex& index, const QColor& color);
+
+    void setTransparent(const QModelIndex& index, bool on);
+    void setBold(const QModelIndex& index, bool on);
+    void setItalic(const QModelIndex& index, bool on);
+    void setUnderline(const QModelIndex& index, bool on);
+protected:
+    ITheme* _theme;
+    QString _lexer;
+    QStringList _names;
+    QStringList _titles;
+    QList<QColor> _colors;
+    QList<QColor> _backgrounds;
+    QList<bool> _bold;
+    QList<bool> _italic;
+    QList<bool> _underline;
+};
+
+}
+
+#endif

src/Theme/PythonModel.cpp

+#include <QApplication>
+#include <QPalette>
+#include "PythonModel.h"
+#include "Include/ITheme.h"
+
+namespace Theme {
+
+PythonModel::PythonModel(ITheme* theme, QObject* parent):
+    LexerModel(theme, "python", parent)
+{
+    _names << "DefinitionKeyword" << "Operator" << "StringSubstitution"
+           << "CommandKeyword" << "FlowControlKeyword"
+           << "BuiltinFunction" << "SpecialVariable" << "Extensions"
+           << "Exceptions" << "Overloaders" << "Preprocessor" << "StringChar"
+           << "Number" << "Complex" << "Comment" << "String" << "RawString"
+           << "Decorator" << "BlockRegion";
+
+    _titles << tr("Definition Keyword") << tr("Operator") << tr("String Substitution")
+            << tr("Command Keyword") << tr("Flow Control Keyword")
+            << tr("Builtin Function") << tr("Special Variable") << tr("Extensions")
+            << tr("Exceptions") << tr("Overloaders") << tr("Preprocessor") << tr("String Char")
+            << tr("Number") << tr("Complex") << tr("Comment") << tr("String") << tr("Raw String")
+            << tr("Decorator") << tr("BlockRegion");
+
+    _colors << _theme->color("python", "DefinitionKeyword"  , QColor("#000000"))
+            << _theme->color("python", "Operator"           , QColor("#000000"))
+            << _theme->color("python", "StringSubstitution" , QColor("#0057ae"))
+            << _theme->color("python", "CommandKeyword"     , QColor("#000000"))
+            << _theme->color("python", "FlowControlKeyword" , QColor("#000000"))
+            << _theme->color("python", "BuiltinFunction"    , QColor("#0057AE"))
+            << _theme->color("python", "SpecialVariable"    , QColor("#006E28"))
+            << _theme->color("python", "Extensions"         , QColor("#0095ff"))
+            << _theme->color("python", "Exceptions"         , QColor("#054d00"))
+            << _theme->color("python", "Overloaders"        , QColor("#000e52"))
+            << _theme->color("python", "Preprocessor"       , QColor("#FF80E0"))
+            << _theme->color("python", "StringChar"         , QColor("#FF80E0"))
+            << _theme->color("python", "Number"             , QColor("#B08000"))
+            << _theme->color("python", "Complex"            , QColor("#006E28"))
+            << _theme->color("python", "Comment"            , QColor("#898887"))
+            << _theme->color("python", "String"             , QColor("#BF0303"))
+            << _theme->color("python", "RawString"          , QColor("#BF0303"))
+            << _theme->color("python", "Decorator"          , QColor("#8f6b32"))
+            << _theme->color("python", "BlockRegion"        , QColor("#DEDEDE"));
+
+    QStringList bold;
+    bold << "DefinitionKeyword" << "Operator" << "Extensions" << "Exceptions" << "Overloaders";
+    foreach(QString name, _names){
+        _backgrounds << _theme->background("python", name);
+        _bold << _theme->bold("python", name, bold.contains(name));
+        _italic << _theme->italic("python", name);
+        _underline << _theme->italic("python", name);
+    }
+}
+
+
+}

src/Theme/PythonModel.h

+#ifndef _PYTHONMODEL_H_
+#define _PYTHONMODEL_H_
+#include "LexerModel.h"
+
+namespace Theme {
+class ITheme;
+
+class PythonModel : public LexerModel
+{
+    Q_OBJECT
+public:
+    PythonModel(ITheme* theme, QObject* parent = NULL);
+};
+
+}
+
+#endif

src/Theme/Theme.cpp

 #include <QApplication>
 #include <QPalette>
 #include <QDir>
+#include <QStringBuilder>
 #include "Theme.h"
 
 namespace Theme {
     dir.cd("themes");
     _themePath = dir.filePath(name+".conf"+(temp ? "~" : ""));
     _theme = new QSettings(_themePath, QSettings::IniFormat);
-
-    QPalette pal = QApplication::palette();
-    _default.insert(Default,        ThemeData("dsNormal"        , QColor("#000000"), QColor("#FFFFFF")));
-    _default.insert(Margine,        ThemeData("margine"         , QColor("#000000"), pal.color(QPalette::Window)));
-    _default.insert(HightlightLine, ThemeData("hightlightLine"  , Qt::transparent, QColor("#101000")));
-
-    //_default.insert(Normal,         ThemeData("dsKeyword"       , QColor("#000000")));
-    _default.insert(Keyword,        ThemeData("dsKeyword"       , QColor("#000000"), true));
-    _default.insert(DataType,       ThemeData("dsDataType"      , QColor("#0057AE")));
-    _default.insert(Number,         ThemeData("dsNumber"        , QColor("#B08000")));
-    _default.insert(Char,           ThemeData("dsChar"          , QColor("#FF80E0")));
-    _default.insert(String,         ThemeData("dsString"        , QColor("#BF0303")));
-    _default.insert(Comment,        ThemeData("dsComment"       , QColor("#898887"), false, true));
-    _default.insert(Others,         ThemeData("dsOthers"        , QColor("#006E28")));
-    _default.insert(Alert,          ThemeData("dsAlert"         , QColor("#BF0303"), true));
-    _default.insert(Function,       ThemeData("dsFunction"      , QColor("#644A9B")));
-    _default.insert(Error,          ThemeData("dsError"         , QColor("#BF0303"), false, false, true));
-
-    _default.insert(Operand,        ThemeData("dsOperand"       , QColor("#000000"), true));
-    _default.insert(SpecialVariable,ThemeData("dsSpecialVariable", QColor("#006E28"), true));
-    _default.insert(Class,          ThemeData("dsClass"         , QColor("#00316E"), true));
-    _default.insert(Decorator,      ThemeData("dsDecorator"     , QColor("#8F6B32")));
-    _default.insert(Preprocessor,   ThemeData("dsPreprocessor"  , QColor("#FF80E0"), true));
 }
 
 Theme::~Theme()
     delete _theme;
 }
 
-QColor Theme::color(const QString& lexer, Roles role)
+QTextCharFormat Theme::format(const QString& lexer, const QString& role, const QColor& defColor, bool isbold)
+{
+    QTextCharFormat fmt;
+    fmt.setForeground(color(lexer, role, defColor));
+    fmt.setBackground(background(lexer, role));
+    fmt.setFontWeight(bold(lexer, role) ? QFont::Bold: QFont::Normal);
+    fmt.setFontItalic(italic(lexer, role));
+    fmt.setFontUnderline(underline(lexer, role));
+    return fmt;
+}
+
+QTextCharFormat Theme::defFormat(const QString& lexer, const QString& role, const QString& defRole, bool isbold)
+{
+    QTextCharFormat def = format(lexer, defRole, Qt::black);
+    QTextCharFormat fmt;
+    fmt.setForeground(color(lexer, role, def.foreground().color()));
+    fmt.setBackground(background(lexer, role, def.background().color()));
+    fmt.setFontWeight(bold(lexer, role, isbold) ? QFont::Bold: QFont::Normal);
+    fmt.setFontItalic(italic(lexer, role, def.fontItalic()));
+    fmt.setFontUnderline(underline(lexer, role, def.fontUnderline()));
+    return fmt;
+}
+
+QColor Theme::color(const QString& lexer, const QString& role, const QColor& def)
+{
+    return QColor(_theme->value(lexer % "/" % role % "/color", colorName(def)).toString());
+}
+
+QColor Theme::background(const QString& lexer, const QString& role, const QColor& def)
+{
+    return QColor(_theme->value(lexer % "/" % role % "/background", colorName(def)).toString());
+}
+
+QString Theme::colorName(const QColor& color)
+{
+    if (color.alpha() == 0)
+        return "transparent";
+    return color.name();
+}
+
+void Theme::setColor(const QString& lexer, const QString& role, const QColor& color)
+{
+    _theme->setValue(lexer % "/" % role % "/color", colorName(color));
+}
+
+void Theme::setBackground(const QString& lexer, const QString& role, const QColor& color)
 {
-    return QColor(_theme->value(lexer+"/"+_default[role].roleName+"/color", _default[role].color).toString());
+    _theme->setValue(lexer % "/" % role % "/background", colorName(color));
 }
 
-QColor Theme::background(const QString& lexer, Roles role)
+bool Theme::italic(const QString& lexer, const QString& role, bool def)
 {
-    return QColor(_theme->value(lexer+"/"+_default[role].roleName+"/background", _default[role].background).toString());
+    return _theme->value(lexer % "/" % role % "/italic", def).toBool();
 }
 
-void Theme::setColor(const QString& lexer, Roles role, const QColor& color)
+bool Theme::bold(const QString& lexer, const QString& role, bool def)
 {
-    if (!color.alpha()){
-        _theme->remove(lexer+_default[role].roleName+"/color");
-    } else {
-        _theme->setValue(lexer+_default[role].roleName+"/color", color.name());
-    }
+    return _theme->value(lexer % "/" % role % "/bold", def).toBool();
 }
 
-void Theme::setBackground(const QString& lexer, Roles role, const QColor& color)
+bool Theme::underline(const QString& lexer, const QString& role, bool def)
 {
-    if (!color.alpha()){
-        _theme->remove(lexer+"/"+_default[role].roleName+"/background");
-    } else {
-        _theme->setValue(lexer+"/"+_default[role].roleName+"/background", color.name());
-    }
+    return _theme->value(lexer % "/" % role % "/underline", def).toBool();
 }
 
-bool Theme::italic(const QString& lexer, Roles role)
+void Theme::setItalic(const QString& lexer, const QString& role, bool on)
 {
-    return _theme->value(lexer+"/"+_default[role].roleName+"/italic", _default[role].italic).toBool();
+    _theme->setValue(lexer % "/" % role % "/italic", on);
 }
 
-bool Theme::bold(const QString& lexer, Roles role)
+void Theme::setBold(const QString& lexer, const QString& role, bool on)
 {
-    return _theme->value(lexer+"/"+_default[role].roleName+"/bold", _default[role].bold).toBool();
+    _theme->setValue(lexer % "/" % role % "/bold", on);
 }
 
-bool Theme::underline(const QString& lexer, Roles role)
+void Theme::setUnderline(const QString& lexer, const QString& role, bool on)
 {
-    return _theme->value(lexer+"/"+_default[role].roleName+"/underline", _default[role].underline).toBool();
+    _theme->setValue(lexer % "/" % role % "/underline", on);
 }
 
 }

src/Theme/Theme.h

     Theme(const QString& name, bool temp = false);
     virtual ~Theme();
 
-    virtual QColor color(const QString& lexer, Roles role);
-    virtual QColor background(const QString& lexer, Roles role);
+    virtual QTextCharFormat format(const QString& lexer, const QString& role, const QColor& defColor = Qt::black, bool bold = false);
+    virtual QTextCharFormat defFormat(const QString& lexer, const QString& role, const QString& defRole = "dsNormal", bool bold = false);
 
-    virtual void setColor(const QString& lexer, Roles role, const QColor& color);
-    virtual void setBackground(const QString& lexer, Roles role, const QColor& color);
+    virtual QColor color(const QString& lexer, const QString& role, const QColor& def = Qt::black);
+    virtual QColor background(const QString& lexer, const QString& role, const QColor& def = Qt::transparent);
 
-    virtual bool italic(const QString& lexer, Roles role);
-    virtual bool bold(const QString& lexer, Roles role);
-    virtual bool underline(const QString& lexer, Roles role);
+    virtual void setColor(const QString& lexer, const QString& role, const QColor& color);
+    virtual void setBackground(const QString& lexer, const QString& role, const QColor& color);
+
+    virtual bool italic(const QString& lexer, const QString& role, bool def = false);
+    virtual bool bold(const QString& lexer, const QString& role, bool def = false);
+    virtual bool underline(const QString& lexer, const QString& role, bool def = false);
+
+    virtual void setItalic(const QString& lexer, const QString& role, bool on);
+    virtual void setBold(const QString& lexer, const QString& role, bool on);
+    virtual void setUnderline(const QString& lexer, const QString& role, bool on);
 
     QString themePath()
     { return _themePath; }
         {}
     };
 
-    QMap<Roles, ThemeData> _default;
-
-    /*QMap <Roles, QString> _rolesNames;
-    QMap <Roles, QString> _defaultColor;
-    QMap <Roles, QString> _defaultBackground;*/
+    inline QString colorName(const QColor& color);
     QString _themePath;
 };
 

src/Theme/ThemeEditor.cpp

 #include "ThemeEditor.h"
 #include "ITheme.h"
 #include "ui_ThemeEditor.h"
+#include "CommonModel.h"
+#include "DefaultModel.h"
+#include "PythonModel.h"
 
 namespace Theme {
 
-#define TransparentRole Qt::UserRole + 1
-
 ThemeEditor::ThemeEditor(ITheme* theme, QWidget* parent):
     QDialog(parent),
     _theme(theme),
     _ui(new Ui::ThemeEditor)
 {
     _ui->setupUi(this);
-    _ui->common->setModel(new CommonModel(_theme, this));
+
+    _ui->lexerView->setAlternatingRowColors(false);
+
+    _lexers.insert(tr("Default"), new DefaultModel(_theme, this));
+    _lexers.insert(tr("Python"), new PythonModel(_theme, this));
+    foreach(QString lex, _lexers.keys()){
+        _ui->lstLexers->addItem(lex);
+    }
+    connect(_ui->lstLexers, SIGNAL(activated(QString)), SLOT(onLexerActivated(QString)));
+    _ui->lstLexers->setCurrentIndex(0);
 
     _ui->common->setItemDelegate(new ColorItemDelegate(this));
+    _ui->lexerView->setItemDelegate(new ColorItemDelegate(this));
+
     _ui->ceditGroup->setEnabled(false);
+    _ui->editGroup->setEnabled(false);
+
+    _ui->common->setModel(new CommonModel(_theme, this));
+    _ui->lexerView->setModel(new DefaultModel(_theme, this));
 
     connect(_ui->common, SIGNAL(activated(QModelIndex)), SLOT(onCommonActivated(QModelIndex)));
+    connect(_ui->lexerView, SIGNAL(activated(QModelIndex)), SLOT(onLexerActivated(QModelIndex)));
+
     connect(_ui->cforeground, SIGNAL(changed(QColor)), SLOT(onCommonForeChanged(QColor)));
     connect(_ui->cbackground, SIGNAL(changed(QColor)), SLOT(onCommonBackChanged(QColor)));
+
+    connect(_ui->foreground, SIGNAL(changed(QColor)), SLOT(onLexerForeChanged(QColor)));
+    connect(_ui->background, SIGNAL(changed(QColor)), SLOT(onLexerBackChanged(QColor)));
+    connect(_ui->transparent, SIGNAL(clicked(bool)), SLOT(onTransparentChanged(bool)));
+    connect(_ui->bold, SIGNAL(clicked(bool)), SLOT(onBoldChanged(bool)));
+    connect(_ui->italic, SIGNAL(clicked(bool)), SLOT(onItalicChanged(bool)));
+    connect(_ui->underline, SIGNAL(clicked(bool)), SLOT(onUnderlineChanged(bool)));
 }
 
 ThemeEditor::~ThemeEditor()
     delete _ui;
 }
 
+void ThemeEditor::onLexerActivated(const QString& name)
+{
+    _ui->lexerView->setModel(_lexers[name]);
+}
+
 void ThemeEditor::onCommonActivated(const QModelIndex& index)
 {
     _ui->ceditGroup->setEnabled(index.isValid());
     qobject_cast<CommonModel*>(_ui->common->model())->setColor(_ui->common->currentIndex(), Qt::BackgroundRole, color);
 }
 
-// -------------------------------------------------------------------
+void ThemeEditor::onLexerActivated(const QModelIndex& index)
+{
+    _ui->editGroup->setEnabled(index.isValid());
+    _ui->foreground->setColor(index.data(ForegroundRole).value<QColor>());
+    _ui->background->setColor(index.data(BackgroundRole).value<QColor>());
+    _ui->transparent->setChecked(index.data(BTransparentRole).toBool());
+    _ui->bold->setChecked(index.data(BoldRole).toBool());
+    _ui->italic->setChecked(index.data(ItalicRole).toBool());
+    _ui->underline->setChecked(index.data(UnderscoreRole).toBool());
+
+    _ui->background->setEnabled(!index.data(BTransparentRole).toBool());
+    _ui->backgroundLabel->setEnabled(!index.data(BTransparentRole).toBool());
+}
 
-CommonModel::CommonModel(ITheme* theme, QObject* parent):
-    QAbstractListModel(parent),
-    _theme(theme)
+void ThemeEditor::onLexerForeChanged(const QColor& color)
 {
+    qobject_cast<LexerModel*>(_ui->lexerView->model())->setColor(_ui->lexerView->currentIndex(), color);
 }
 
-int CommonModel::rowCount(const QModelIndex &) const
+void ThemeEditor::onLexerBackChanged(const QColor& color)
 {
-    return 3;
+    qobject_cast<LexerModel*>(_ui->lexerView->model())->setBackground(_ui->lexerView->currentIndex(), color);
 }
 
-QVariant CommonModel::data(const QModelIndex & index, int role) const
+void ThemeEditor::onTransparentChanged(bool on)
 {
-    if (!index.isValid())
-        return QVariant();
-    switch(role) {
-    case Qt::BackgroundRole:{
-        switch(index.row()){
-        case 0: return _theme->background("common", Theme::Default);
-        case 1: return _theme->background("common", Theme::Margine);
-        case 2: return _theme->background("common", Theme::HightlightLine);
-        }
-    }
-    case Qt::ForegroundRole: {
-        switch(index.row()){
-        case 0: return _theme->color("common", Theme::Default);
-        case 1: return _theme->color("common", Theme::Margine);
-        case 2: return _theme->color("common", Theme::Default);
-        }
-    }
-    case Qt::DisplayRole: {
-        switch(index.row()){
-        case 0: return tr("Text");
-        case 1: return tr("Margine");
-        case 2: return tr("Current line");
-        }
-    }
+    qobject_cast<LexerModel*>(_ui->lexerView->model())->setTransparent(_ui->lexerView->currentIndex(), on);
+
+    _ui->background->setEnabled(!on);
+    _ui->backgroundLabel->setEnabled(!on);
+
+    if (!on){
+        _ui->background->setColor(QColor("#dedede"));
+        onLexerBackChanged(QColor("#dedede"));
     }
-    return QVariant();
 }
 
-void CommonModel::setColor(const QModelIndex& index, int role, const QColor& color)
+void ThemeEditor::onBoldChanged(bool on)
 {
-    switch(index.row()){
-    case 0:
-        if (role == Qt::ForegroundRole)
-            _theme->setColor("common", Theme::Default, color);
-        else
-            _theme->setBackground("common", Theme::Default, color);
-        break;
-    case 1:
-        if (role == Qt::ForegroundRole)
-            _theme->setColor("common", Theme::Margine, color);
-        else
-            _theme->setBackground("common", Theme::Margine, color);
-        break;
-    case 2:
-        _theme->setColor("common", Theme::HightlightLine, color);
-        break;
-    }
+    qobject_cast<LexerModel*>(_ui->lexerView->model())->setBold(_ui->lexerView->currentIndex(), on);
+}
+
+void ThemeEditor::onItalicChanged(bool on)
+{
+    qobject_cast<LexerModel*>(_ui->lexerView->model())->setItalic(_ui->lexerView->currentIndex(), on);
+}
+
+void ThemeEditor::onUnderlineChanged(bool on)
+{
+    qobject_cast<LexerModel*>(_ui->lexerView->model())->setUnderline(_ui->lexerView->currentIndex(), on);
 }
 
 }

src/Theme/ThemeEditor.h

 
 namespace Theme {
 class ITheme;
+class LexerModel;
 
 class ThemeEditor: public QDialog
 {
     void onCommonActivated(const QModelIndex&);
     void onCommonForeChanged(const QColor&);
     void onCommonBackChanged(const QColor&);
+
+    void onLexerActivated(const QModelIndex&);
+    void onLexerForeChanged(const QColor&);
+    void onLexerBackChanged(const QColor&);
+
+    void onTransparentChanged(bool);
+    void onBoldChanged(bool);
+    void onItalicChanged(bool);
+    void onUnderlineChanged(bool);
+
+    void onLexerActivated(const QString&);
 private:
     ITheme * _theme;
     Ui::ThemeEditor * _ui;
+    QMap<QString, LexerModel*> _lexers;
 };
 
 class ColorItemDelegate : public QStyledItemDelegate
     { return QSize(100, 25); }
 };
 
-class CommonModel : public QAbstractListModel
-{
-    Q_OBJECT
-public:
-    CommonModel(ITheme* theme, QObject* parent = NULL);
-    virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
-    virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
-
-    void setColor(const QModelIndex& index, int role, const QColor& color);
-private:
-    ITheme* _theme;
-};
 
 }
 #endif

src/Theme/ThemeEditor.ui

    <rect>
     <x>0</x>
     <y>0</y>
-    <width>654</width>
-    <height>511</height>
+    <width>652</width>
+    <height>509</height>
    </rect>
   </property>
   <property name="windowTitle">
            <bool>false</bool>
           </property>
           <property name="alternatingRowColors">
-           <bool>false</bool>
+           <bool>true</bool>
           </property>
           <property name="selectionRectVisible">
            <bool>true</bool>
                </property>
               </widget>
              </item>
-             <item row="0" column="1">
-              <widget class="ColorChooser" name="cforeground" native="true">
+             <item row="1" column="1">
+              <widget class="ColorChooser" name="cbackground" native="true">
                <property name="minimumSize">
                 <size>
                  <width>60</width>
                </property>
               </widget>
              </item>
-             <item row="1" column="1">
-              <widget class="ColorChooser" name="cbackground" native="true">
+             <item row="0" column="1">
+              <widget class="ColorChooser" name="cforeground" native="true">
                <property name="minimumSize">
                 <size>
                  <width>60</width>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout_3">
         <item>
-         <widget class="QListView" name="listView_2">
+         <widget class="QListView" name="lexerView">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
             <horstretch>0</horstretch>
             <verstretch>0</verstretch>
            </sizepolicy>
           </property>
+          <property name="editTriggers">
+           <set>QAbstractItemView::NoEditTriggers</set>
+          </property>
+          <property name="showDropIndicator" stdset="0">
+           <bool>false</bool>
+          </property>
+          <property name="alternatingRowColors">
+           <bool>false</bool>
+          </property>
          </widget>
         </item>
         <item>
            <item>
             <layout class="QGridLayout" name="gridLayout_2">
              <item row="1" column="0">
-              <widget class="QLabel" name="label_9">
+              <widget class="QLabel" name="backgroundLabel">
                <property name="text">
                 <string>Background:</string>
                </property>
               </widget>
              </item>
              <item row="0" column="1">
-              <widget class="ColorChooser" name="foreground_3" native="true">
+              <widget class="ColorChooser" name="foreground" native="true">
                <property name="minimumSize">
                 <size>
                  <width>60</width>
               </widget>
              </item>
              <item row="1" column="1">
-              <widget class="ColorChooser" name="backgound_2" native="true">
+              <widget class="ColorChooser" name="background" native="true">
                <property name="minimumSize">
                 <size>
                  <width>60</width>
               </widget>
              </item>
              <item row="1" column="2">
-              <widget class="QCheckBox" name="checkBox_4">
+              <widget class="QCheckBox" name="transparent">
                <property name="text">
                 <string>Transparent</string>
                </property>
             </layout>
            </item>
            <item>
-            <widget class="QCheckBox" name="bold_2">
+            <widget class="QCheckBox" name="bold">
              <property name="text">
               <string>Bold</string>
              </property>
             </widget>
            </item>
            <item>
-            <widget class="QCheckBox" name="checkBox_5">
+            <widget class="QCheckBox" name="italic">
              <property name="text">
               <string>Italic</string>
              </property>
             </widget>
            </item>
            <item>
-            <widget class="QCheckBox" name="checkBox_6">
+            <widget class="QCheckBox" name="underline">
              <property name="text">
               <string>Underline</string>
              </property>