diff --git a/src/PreferencesDialog.cpp b/src/PreferencesDialog.cpp index 481d4b91..36c3eae4 100644 --- a/src/PreferencesDialog.cpp +++ b/src/PreferencesDialog.cpp @@ -13,6 +13,7 @@ PreferencesDialog::PreferencesDialog(QWidget* parent) ui(new Ui::PreferencesDialog) { ui->setupUi(this); + ui->treeSyntaxHighlighting->setColumnHidden(0, true); loadSettings(); } @@ -45,17 +46,11 @@ void PreferencesDialog::loadSettings() for(int i=0;itreeSyntaxHighlighting->topLevelItemCount();i++) { - QString name; - if(i == 0) name = "keyword"; - else if(i == 1) name = "table"; - else if(i == 2) name = "comment"; - else if(i == 3) name = "identifier"; - else if(i == 4) name = "string"; - - ui->treeSyntaxHighlighting->topLevelItem(i)->setText(1, getSettingsValue("syntaxhighlighter", name + "_colour").toString()); - ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(2, getSettingsValue("syntaxhighlighter", name + "_bold").toBool() ? Qt::Checked : Qt::Unchecked); - ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(3, getSettingsValue("syntaxhighlighter", name + "_italic").toBool() ? Qt::Checked : Qt::Unchecked); - ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(4, getSettingsValue("syntaxhighlighter", name + "_underline").toBool() ? Qt::Checked : Qt::Unchecked); + QString name = ui->treeSyntaxHighlighting->topLevelItem(i)->text(0); + ui->treeSyntaxHighlighting->topLevelItem(i)->setText(2, getSettingsValue("syntaxhighlighter", name + "_colour").toString()); + ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(3, getSettingsValue("syntaxhighlighter", name + "_bold").toBool() ? Qt::Checked : Qt::Unchecked); + ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(4, getSettingsValue("syntaxhighlighter", name + "_italic").toBool() ? Qt::Checked : Qt::Unchecked); + ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(5, getSettingsValue("syntaxhighlighter", name + "_underline").toBool() ? Qt::Checked : Qt::Unchecked); } } @@ -67,17 +62,11 @@ void PreferencesDialog::saveSettings() for(int i=0;itreeSyntaxHighlighting->topLevelItemCount();i++) { - QString name; - if(i == 0) name = "keyword"; - else if(i == 1) name = "table"; - else if(i == 2) name = "comment"; - else if(i == 3) name = "identifier"; - else if(i == 4) name = "string"; - - setSettingsValue("syntaxhighlighter", name + "_colour", ui->treeSyntaxHighlighting->topLevelItem(i)->text(1)); - setSettingsValue("syntaxhighlighter", name + "_bold", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(2) == Qt::Checked); - setSettingsValue("syntaxhighlighter", name + "_italic", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(3) == Qt::Checked); - setSettingsValue("syntaxhighlighter", name + "_underline", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(4) == Qt::Checked); + QString name = ui->treeSyntaxHighlighting->topLevelItem(i)->text(0); + setSettingsValue("syntaxhighlighter", name + "_colour", ui->treeSyntaxHighlighting->topLevelItem(i)->text(2)); + setSettingsValue("syntaxhighlighter", name + "_bold", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(3) == Qt::Checked); + setSettingsValue("syntaxhighlighter", name + "_italic", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(4) == Qt::Checked); + setSettingsValue("syntaxhighlighter", name + "_underline", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(5) == Qt::Checked); } accept(); diff --git a/src/PreferencesDialog.ui b/src/PreferencesDialog.ui index dd45d4d5..0b8e9e3c 100644 --- a/src/PreferencesDialog.ui +++ b/src/PreferencesDialog.ui @@ -117,6 +117,11 @@ false + + + Settings name + + Context @@ -143,6 +148,9 @@ + + keyword + Keyword @@ -152,26 +160,92 @@ + + + + + + + + table + Table + + + + + + + + + + + + + + comment + Comment - - - Identifier + + + + + + + + + + + + identifier + + + Identifier + + + + + + + + + + + + + + + + + string + String + + + + + + + + + + + + diff --git a/src/SQLiteSyntaxHighlighter.cpp b/src/SQLiteSyntaxHighlighter.cpp index 18f313ee..c6492828 100644 --- a/src/SQLiteSyntaxHighlighter.cpp +++ b/src/SQLiteSyntaxHighlighter.cpp @@ -6,15 +6,12 @@ SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) : { HighlightingRule rule; - tableFormat.setForeground(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "table_colour").toString())); - tableFormat.setFontWeight(PreferencesDialog::getSettingsValue("syntaxhighlighter", "table_bold").toBool() ? QFont::Bold : QFont::Normal); - tableFormat.setFontItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", "table_italic").toBool()); - tableFormat.setFontUnderline(PreferencesDialog::getSettingsValue("syntaxhighlighter", "table_underline").toBool()); + tableFormat = createFormat("table"); + keywordFormat = createFormat("keyword"); + singleLineCommentFormat = createFormat("comment"); + identifierFormat = createFormat("identifier"); + stringFormat = createFormat("string"); - keywordFormat.setForeground(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "keyword_colour").toString())); - keywordFormat.setFontWeight(PreferencesDialog::getSettingsValue("syntaxhighlighter", "keyword_bold").toBool() ? QFont::Bold : QFont::Normal); - keywordFormat.setFontItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", "keyword_italic").toBool()); - keywordFormat.setFontUnderline(PreferencesDialog::getSettingsValue("syntaxhighlighter", "keyword_underline").toBool()); QStringList keywordPatterns; keywordPatterns << "\\bREINDEX\\b" << "\\bINDEXED\\b" << "\\bINDEX\\b" @@ -67,19 +64,11 @@ SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) : } // single line comment - singleLineCommentFormat.setForeground(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "comment_colour").toString())); - singleLineCommentFormat.setFontWeight(PreferencesDialog::getSettingsValue("syntaxhighlighter", "comment_bold").toBool() ? QFont::Bold : QFont::Normal); - singleLineCommentFormat.setFontItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", "comment_italic").toBool()); - singleLineCommentFormat.setFontUnderline(PreferencesDialog::getSettingsValue("syntaxhighlighter", "comment_underline").toBool()); rule.pattern = QRegExp("--[^\n]*"); rule.format = singleLineCommentFormat; highlightingRules.append(rule); // identifiers - identifierFormat.setForeground(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "identifier_colour").toString())); - identifierFormat.setFontWeight(PreferencesDialog::getSettingsValue("syntaxhighlighter", "identifier_bold").toBool() ? QFont::Bold : QFont::Normal); - identifierFormat.setFontItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", "identifier_italic").toBool()); - identifierFormat.setFontUnderline(PreferencesDialog::getSettingsValue("syntaxhighlighter", "identifier_underline").toBool()); rule.pattern = QRegExp("\"[^\"]*\""); // "" rule.format = identifierFormat; highlightingRules.append(rule); @@ -91,10 +80,6 @@ SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) : highlightingRules.append(rule); // string - stringFormat.setForeground(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "string_colour").toString())); - stringFormat.setFontWeight(PreferencesDialog::getSettingsValue("syntaxhighlighter", "string_bold").toBool() ? QFont::Bold : QFont::Normal); - stringFormat.setFontItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", "string_italic").toBool()); - stringFormat.setFontUnderline(PreferencesDialog::getSettingsValue("syntaxhighlighter", "string_underline").toBool()); rule.pattern = QRegExp("'[^']*'"); // '' rule.format = stringFormat; highlightingRules.append(rule); @@ -129,3 +114,13 @@ void SQLiteSyntaxHighlighter::highlightBlock(const QString &text) highlightBlockVector(text, tableNameRules); highlightBlockVector(text, highlightingRules); } + +QTextCharFormat SQLiteSyntaxHighlighter::createFormat(const QString& settings_name) +{ + QTextCharFormat format; + format.setForeground(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", settings_name + "_colour").toString())); + format.setFontWeight(PreferencesDialog::getSettingsValue("syntaxhighlighter", settings_name + "_bold").toBool() ? QFont::Bold : QFont::Normal); + format.setFontItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", settings_name + "_italic").toBool()); + format.setFontUnderline(PreferencesDialog::getSettingsValue("syntaxhighlighter", settings_name + "_underline").toBool()); + return format; +} diff --git a/src/SQLiteSyntaxHighlighter.h b/src/SQLiteSyntaxHighlighter.h index 860cc8d9..71bc85ae 100644 --- a/src/SQLiteSyntaxHighlighter.h +++ b/src/SQLiteSyntaxHighlighter.h @@ -30,6 +30,8 @@ private: QTextCharFormat stringFormat; QTextCharFormat identifierFormat; QTextCharFormat tableFormat; + + QTextCharFormat createFormat(const QString& settings_name); }; #endif // SQLITESYNTAXHIGHLIGHTER_H