mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
Copy font setting logic from QgsPythonConsoleBase to QgsCodeEditor
This commit is contained in:
parent
28245ef32b
commit
e2ff63da48
@ -77,15 +77,7 @@ class QgsPythonConsoleBase(QgsCodeEditorPython):
|
||||
self.lexer.setFoldComments(True)
|
||||
self.lexer.setFoldQuotes(True)
|
||||
|
||||
font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
|
||||
|
||||
# output and console
|
||||
loadFont = self.settings.value("pythonConsole/fontfamilytext")
|
||||
if loadFont:
|
||||
font.setFamily(loadFont)
|
||||
fontSize = self.settings.value("pythonConsole/fontsize", type=int)
|
||||
if fontSize:
|
||||
font.setPointSize(fontSize)
|
||||
font = self.getMonospaceFont()
|
||||
|
||||
self.lexer.setDefaultFont(font)
|
||||
self.lexer.setDefaultColor(self.color(QgsCodeEditor.ColorRole.Default))
|
||||
|
@ -430,13 +430,29 @@ 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;
|
||||
int fontSize = settings.value( QStringLiteral( "qgis/stylesheet/fontPointSize" ), 10 ).toInt();
|
||||
font.setPointSize( fontSize );
|
||||
if ( !settings.value( QStringLiteral( "codeEditor/fontfamily" ), QString(), QgsSettings::Gui ).toString().isEmpty() )
|
||||
font.setFamily( settings.value( QStringLiteral( "codeEditor/fontfamily" ), QString(), QgsSettings::Gui ).toString() );
|
||||
|
||||
const int fontSize = settings.value( QStringLiteral( "codeEditor/fontsize" ), 0, QgsSettings::Gui ).toInt();
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
if ( fontSize > 0 )
|
||||
font.setPointSize( fontSize );
|
||||
else
|
||||
{
|
||||
// The font size gotten from getMonospaceFont() is too small on Mac
|
||||
font.setPointSize( QLabel().font().pointSize() );
|
||||
}
|
||||
#else
|
||||
if ( fontSize > 0 )
|
||||
font.setPointSize( fontSize );
|
||||
else
|
||||
{
|
||||
int fontSize = settings.value( QStringLiteral( "qgis/stylesheet/fontPointSize" ), 10 ).toInt();
|
||||
font.setPointSize( fontSize );
|
||||
}
|
||||
#endif
|
||||
font.setBold( false );
|
||||
|
||||
|
@ -12,12 +12,15 @@ __copyright__ = 'Copyright 2020, The QGIS Project'
|
||||
|
||||
import qgis # NOQA
|
||||
|
||||
import sys
|
||||
|
||||
from qgis.core import QgsSettings, QgsApplication
|
||||
from qgis.gui import QgsCodeEditor
|
||||
|
||||
from qgis.PyQt.QtCore import QCoreApplication
|
||||
from qgis.PyQt.QtGui import QColor
|
||||
from qgis.PyQt.QtGui import QColor, QFont
|
||||
from qgis.testing import start_app, unittest
|
||||
from utilities import getTestFont
|
||||
|
||||
start_app()
|
||||
|
||||
@ -61,6 +64,23 @@ class TestQgsCodeEditor(unittest.TestCase):
|
||||
QgsCodeEditor.setColor(QgsCodeEditor.ColorRole.Keyword, QColor('#cc11bb'))
|
||||
self.assertEqual(QgsCodeEditor.color(QgsCodeEditor.ColorRole.Keyword).name(), '#cc11bb')
|
||||
|
||||
def testFontFamily(self):
|
||||
f = QgsCodeEditor().getMonospaceFont()
|
||||
self.assertTrue(f.styleHint() & QFont.Monospace)
|
||||
|
||||
QgsSettings().setValue('codeEditor/fontfamily', getTestFont().family(), QgsSettings.Gui)
|
||||
f = QgsCodeEditor().getMonospaceFont()
|
||||
self.assertEqual(f.family(), 'QGIS Vera Sans')
|
||||
|
||||
@unittest.skipIf(sys.platform == 'darwin', 'MacOS has different font logic')
|
||||
def testFontSize(self):
|
||||
f = QgsCodeEditor().getMonospaceFont()
|
||||
self.assertEqual(f.pointSize(), 10)
|
||||
|
||||
QgsSettings().setValue('codeEditor/fontsize', 14, QgsSettings.Gui)
|
||||
f = QgsCodeEditor().getMonospaceFont()
|
||||
self.assertEqual(f.pointSize(), 14)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user