diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 3e2a87e4..d5cc9982 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1335,8 +1335,6 @@ void MainWindow::reloadSettings() { // Read settings int prefetch_size = PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt(); - int edit_fontsize = PreferencesDialog::getSettingsValue("editor", "fontsize").toInt(); - int edit_tabsize = PreferencesDialog::getSettingsValue("editor", "tabsize").toInt(); int log_fontsize = PreferencesDialog::getSettingsValue("log", "fontsize").toInt(); QFont logfont("Monospace"); @@ -1350,14 +1348,12 @@ void MainWindow::reloadSettings() SqlExecutionArea* sqlArea = qobject_cast(ui->tabSqlAreas->widget(i)); sqlArea->getModel()->setChunkSize(prefetch_size); sqlArea->getResultView()->setFont(logfont); - - QFont font = sqlArea->getEditor()->font(); - font.setPointSize(edit_fontsize); - sqlArea->getEditor()->setFont(font); - sqlArea->getEditor()->setTabWidth(edit_tabsize); + sqlArea->getEditor()->reloadSettings(); } // Set font for SQL logs + ui->editLogApplication->reloadSettings(); + ui->editLogUser->reloadSettings(); ui->editLogApplication->setFont(logfont); ui->editLogUser->setFont(logfont); diff --git a/src/sqltextedit.cpp b/src/sqltextedit.cpp index a4106f65..f0fd4baa 100644 --- a/src/sqltextedit.cpp +++ b/src/sqltextedit.cpp @@ -13,52 +13,13 @@ SqlUiLexer* SqlTextEdit::sqlLexer = 0; SqlTextEdit::SqlTextEdit(QWidget* parent) : QsciScintilla(parent) { - // Initialise lexer if not done yet + // Create lexer object if not done yet if(sqlLexer == 0) - { - // Create lexer object sqlLexer = new SqlUiLexer(this); - // Set syntax highlighting settings - sqlLexer->setDefaultColor(Qt::black); - QFont defaultfont("Monospace"); - defaultfont.setStyleHint(QFont::TypeWriter); - defaultfont.setPointSize(PreferencesDialog::getSettingsValue("editor", "fontsize").toInt()); - sqlLexer->setDefaultFont(defaultfont); - setupSyntaxHighlightingFormat("comment", QsciLexerSQL::Comment); - setupSyntaxHighlightingFormat("comment", QsciLexerSQL::CommentLine); - setupSyntaxHighlightingFormat("comment", QsciLexerSQL::CommentDoc); - setupSyntaxHighlightingFormat("keyword", QsciLexerSQL::Keyword); - setupSyntaxHighlightingFormat("table", QsciLexerSQL::KeywordSet6); - setupSyntaxHighlightingFormat("function", QsciLexerSQL::KeywordSet7); - setupSyntaxHighlightingFormat("string", QsciLexerSQL::DoubleQuotedString); - setupSyntaxHighlightingFormat("string", QsciLexerSQL::SingleQuotedString); - setupSyntaxHighlightingFormat("identifier", QsciLexerSQL::Identifier); - setupSyntaxHighlightingFormat("identifier", QsciLexerSQL::QuotedIdentifier); - } - // Set the lexer setLexer(sqlLexer); - // Set font - QFont font("Monospace"); - font.setStyleHint(QFont::TypeWriter); - font.setPointSize(PreferencesDialog::getSettingsValue("editor", "fontsize").toInt()); - setFont(font); - - // Show line numbers - QFont marginsfont(QFont("Monospace")); - marginsfont.setPointSize(font.pointSize()); - setMarginsFont(marginsfont); - setMarginLineNumbers(0, true); - setMarginsBackgroundColor(Qt::lightGray); - connect(this, SIGNAL(linesChanged()), this, SLOT(updateLineNumberAreaWidth())); - updateLineNumberAreaWidth(); - - // Highlight current line - setCaretLineVisible(true); - setCaretLineBackgroundColor(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_colour").toString())); - // Enable auto completion setAutoCompletionThreshold(3); setAutoCompletionCaseSensitivity(false); @@ -77,15 +38,15 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) : // Enable auto indentation setAutoIndent(true); - // Set tab width - setTabWidth(PreferencesDialog::getSettingsValue("editor", "tabsize").toInt()); - // Enable folding setFolding(QsciScintilla::BoxedTreeFoldStyle); // Create error indicator errorIndicatorNumber = indicatorDefine(QsciScintilla::SquiggleIndicator); setIndicatorForegroundColor(Qt::red, errorIndicatorNumber); + + // Do rest of initialisation + reloadSettings(); } SqlTextEdit::~SqlTextEdit() @@ -136,3 +97,45 @@ void SqlTextEdit::reloadKeywords() // Set lexer again to reload the updated keywords list setLexer(lexer()); } + +void SqlTextEdit::reloadSettings() +{ + // Set syntax highlighting settings + sqlLexer->setDefaultColor(Qt::black); + QFont defaultfont("Monospace"); + defaultfont.setStyleHint(QFont::TypeWriter); + defaultfont.setPointSize(PreferencesDialog::getSettingsValue("editor", "fontsize").toInt()); + sqlLexer->setDefaultFont(defaultfont); + setupSyntaxHighlightingFormat("comment", QsciLexerSQL::Comment); + setupSyntaxHighlightingFormat("comment", QsciLexerSQL::CommentLine); + setupSyntaxHighlightingFormat("comment", QsciLexerSQL::CommentDoc); + setupSyntaxHighlightingFormat("keyword", QsciLexerSQL::Keyword); + setupSyntaxHighlightingFormat("table", QsciLexerSQL::KeywordSet6); + setupSyntaxHighlightingFormat("function", QsciLexerSQL::KeywordSet7); + setupSyntaxHighlightingFormat("string", QsciLexerSQL::DoubleQuotedString); + setupSyntaxHighlightingFormat("string", QsciLexerSQL::SingleQuotedString); + setupSyntaxHighlightingFormat("identifier", QsciLexerSQL::Identifier); + setupSyntaxHighlightingFormat("identifier", QsciLexerSQL::QuotedIdentifier); + + // Set font + QFont font("Monospace"); + font.setStyleHint(QFont::TypeWriter); + font.setPointSize(PreferencesDialog::getSettingsValue("editor", "fontsize").toInt()); + setFont(font); + + // Show line numbers + QFont marginsfont(QFont("Monospace")); + marginsfont.setPointSize(font.pointSize()); + setMarginsFont(marginsfont); + setMarginLineNumbers(0, true); + setMarginsBackgroundColor(Qt::lightGray); + connect(this, SIGNAL(linesChanged()), this, SLOT(updateLineNumberAreaWidth())); + updateLineNumberAreaWidth(); + + // Highlight current line + setCaretLineVisible(true); + setCaretLineBackgroundColor(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", "currentline_colour").toString())); + + // Set tab width + setTabWidth(PreferencesDialog::getSettingsValue("editor", "tabsize").toInt()); +} diff --git a/src/sqltextedit.h b/src/sqltextedit.h index 624a4d0d..4950fc5c 100644 --- a/src/sqltextedit.h +++ b/src/sqltextedit.h @@ -23,6 +23,7 @@ public: public slots: void reloadKeywords(); + void reloadSettings(); protected: void dropEvent(QDropEvent* e);