From 042e925f9ff2f558064f8ca314195c89cfcf97a2 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Thu, 21 Feb 2019 13:33:56 +0100 Subject: [PATCH] Make ExtendedScintilla widget run without a lexer When using an ExtendedScintilla widget without setting a lexer, the application would easily crash. This is improved by this commit. --- src/ExtendedScintilla.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ExtendedScintilla.cpp b/src/ExtendedScintilla.cpp index 7d8304c8..06b7c9a4 100644 --- a/src/ExtendedScintilla.cpp +++ b/src/ExtendedScintilla.cpp @@ -90,8 +90,7 @@ void ExtendedScintilla::updateLineNumberAreaWidth() // Calculate the width of this number if it was all zeros (this is because a 1 might require less space than a 0 and this could // cause some flickering depending on the font) and set the new margin width. - QFont font = lexer()->defaultFont(); - setMarginWidth(0, QFontMetrics(font).width(QString("0").repeated(digits)) + 5); + setMarginWidth(0, QFontMetrics(font()).width(QString("0").repeated(digits)) + 5); } void ExtendedScintilla::dropEvent(QDropEvent* e) @@ -147,13 +146,16 @@ void ExtendedScintilla::reloadSettings() void ExtendedScintilla::reloadLexerSettings(QsciLexer *lexer) { // Set syntax highlighting settings - QFont defaultfont(Settings::getValue("editor", "font").toString()); - defaultfont.setStyleHint(QFont::TypeWriter); - defaultfont.setPointSize(Settings::getValue("editor", "fontsize").toInt()); - lexer->setFont(defaultfont); + if(lexer) + { + QFont defaultfont(Settings::getValue("editor", "font").toString()); + defaultfont.setStyleHint(QFont::TypeWriter); + defaultfont.setPointSize(Settings::getValue("editor", "fontsize").toInt()); + lexer->setFont(defaultfont); - lexer->setDefaultColor(QColor(Settings::getValue("syntaxhighlighter", "foreground_colour").toString())); - lexer->setPaper(QColor(Settings::getValue("syntaxhighlighter", "background_colour").toString())); + lexer->setDefaultColor(QColor(Settings::getValue("syntaxhighlighter", "foreground_colour").toString())); + lexer->setPaper(QColor(Settings::getValue("syntaxhighlighter", "background_colour").toString())); + } // Set font QFont font(Settings::getValue("editor", "font").toString()); @@ -162,11 +164,8 @@ void ExtendedScintilla::reloadLexerSettings(QsciLexer *lexer) setFont(font); // Show line numbers - QFont marginsfont(QFont(Settings::getValue("editor", "font").toString())); - marginsfont.setPointSize(font.pointSize()); - setMarginsFont(marginsfont); + setMarginsFont(font); setMarginLineNumbers(0, true); - updateLineNumberAreaWidth(); // Highlight current line @@ -176,7 +175,8 @@ void ExtendedScintilla::reloadLexerSettings(QsciLexer *lexer) // Set tab width setTabWidth(Settings::getValue("editor", "tabsize").toInt()); - lexer->refreshProperties(); + if(lexer) + lexer->refreshProperties(); // Set wrap lines setWrapMode(static_cast(Settings::getValue("editor", "wrap_lines").toInt()));