Skip to content
Permalink
Browse files

[code editor] Improve creation of monospace font by:

- Stop relying on the python console settings;
- Using modern way to retreive monospace font family;
- Using QGIS' font size;
- Increasing likelihood of getting a monospace font on all platforms.

(cherry picked from commit 4ddce03)
  • Loading branch information
nirvn authored and nyalldawson committed May 25, 2020
1 parent 88766f6 commit f52652bc05329048beff77dfb94c9842c7e82835
Showing with 13 additions and 21 deletions.
  1. +13 −6 src/gui/qgscodeeditor.cpp
  2. +0 −5 src/gui/qgscodeeditorexpression.cpp
  3. +0 −5 src/gui/qgscodeeditorhtml.cpp
  4. +0 −5 src/gui/qgscodeeditorsql.cpp
@@ -19,8 +19,10 @@
#include "qgssettings.h"
#include "qgssymbollayerutils.h"

#include <QLabel>
#include <QWidget>
#include <QFont>
#include <QFontDatabase>
#include <QDebug>
#include <QFocusEvent>

@@ -103,6 +105,9 @@ void QgsCodeEditor::setSciWidget()
}
QPalette pal = qApp->palette();

QFont font = getMonospaceFont();
setFont( font );

setUtf8( true );
setCaretLineVisible( true );
setCaretLineBackgroundColor( colors.value( QStringLiteral( "caretLineColor" ), QColor( 252, 243, 237 ) ) );
@@ -193,14 +198,16 @@ bool QgsCodeEditor::isFixedPitch( const QFont &font )

QFont QgsCodeEditor::getMonospaceFont()
{
QFont font = QFontDatabase::systemFont( QFontDatabase::FixedFont );
#ifdef Q_OS_MAC
// The font size gotten from getMonospaceFont() is too small on Mac
font.setPointSize( QLabel().font().pointSize() );
#else
QgsSettings settings;
QString loadFont = settings.value( QStringLiteral( "pythonConsole/fontfamilytextEditor" ), "Monospace" ).toString();
int fontSize = settings.value( QStringLiteral( "pythonConsole/fontsizeEditor" ), 10 ).toInt();

QFont font( loadFont );
font.setFixedPitch( true );
int fontSize = settings.value( QStringLiteral( "qgis/stylesheet/fontPointSize" ), 10 ).toInt();
font.setPointSize( fontSize );
font.setStyleHint( QFont::TypeWriter );
#endif
font.setBold( false );

return font;
}
@@ -19,7 +19,6 @@

#include <QString>
#include <QFont>
#include <QLabel>

QgsCodeEditorExpression::QgsCodeEditorExpression( QWidget *parent )
: QgsCodeEditor( parent )
@@ -113,10 +112,6 @@ void QgsCodeEditorExpression::initializeLexer()
}

QFont font = getMonospaceFont();
#ifdef Q_OS_MAC
// The font size gotten from getMonospaceFont() is too small on Mac
font.setPointSize( QLabel().font().pointSize() );
#endif
QColor defaultColor = colors.value( QStringLiteral( "sql/defaultFontColor" ), Qt::black );

mSqlLexer = new QgsLexerExpression( this );
@@ -20,7 +20,6 @@
#include <QWidget>
#include <QString>
#include <QFont>
#include <QLabel>
#include <Qsci/qscilexerhtml.h>


@@ -49,10 +48,6 @@ void QgsCodeEditorHTML::setSciLexerHTML()
}

QFont font = getMonospaceFont();
#ifdef Q_OS_MAC
// The font size gotten from getMonospaceFont() is too small on Mac
font.setPointSize( QLabel().font().pointSize() );
#endif
QColor defaultColor = colors.value( QStringLiteral( "html/defaultFontColor" ), Qt::black );

QsciLexerHTML *lexer = new QsciLexerHTML( this );
@@ -20,7 +20,6 @@
#include <QWidget>
#include <QString>
#include <QFont>
#include <QLabel>


QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent )
@@ -50,10 +49,6 @@ void QgsCodeEditorSQL::setSciLexerSQL()
}

QFont font = getMonospaceFont();
#ifdef Q_OS_MAC
// The font size gotten from getMonospaceFont() is too small on Mac
font.setPointSize( QLabel().font().pointSize() );
#endif
QColor defaultColor = colors.value( QStringLiteral( "sql/defaultFontColor" ), Qt::black );

QsciLexerSQL *sqlLexer = new QgsCaseInsensitiveLexerSQL( this );

0 comments on commit f52652b

Please sign in to comment.
You can’t perform that action at this time.