Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 Jun 19, 2020
1 parent 88766f6 commit f52652b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
19 changes: 13 additions & 6 deletions src/gui/qgscodeeditor.cpp
Expand Up @@ -19,8 +19,10 @@
#include "qgssettings.h"
#include "qgssymbollayerutils.h"

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

Expand Down Expand Up @@ -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 ) ) );
Expand Down Expand Up @@ -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;
}
5 changes: 0 additions & 5 deletions src/gui/qgscodeeditorexpression.cpp
Expand Up @@ -19,7 +19,6 @@

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

QgsCodeEditorExpression::QgsCodeEditorExpression( QWidget *parent )
: QgsCodeEditor( parent )
Expand Down Expand Up @@ -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 );
Expand Down
5 changes: 0 additions & 5 deletions src/gui/qgscodeeditorhtml.cpp
Expand Up @@ -20,7 +20,6 @@
#include <QWidget>
#include <QString>
#include <QFont>
#include <QLabel>
#include <Qsci/qscilexerhtml.h>


Expand Down Expand Up @@ -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 );
Expand Down
5 changes: 0 additions & 5 deletions src/gui/qgscodeeditorsql.cpp
Expand Up @@ -20,7 +20,6 @@
#include <QWidget>
#include <QString>
#include <QFont>
#include <QLabel>


QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent )
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit f52652b

Please sign in to comment.