Skip to content

Commit

Permalink
Merge pull request #269 from vkbo/gui_font_size
Browse files Browse the repository at this point in the history
GUI Font Size Settings
  • Loading branch information
vkbo committed May 30, 2020
2 parents 1696fa5 + 521ab95 commit c95fa4c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
27 changes: 15 additions & 12 deletions nw/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

from PyQt5.Qt import PYQT_VERSION_STR
from PyQt5.QtCore import QT_VERSION_STR, QStandardPaths, QSysInfo
from PyQt5.QtWidgets import QErrorMessage

from nw.constants import nwFiles, nwUnicode
from nw.common import splitVersionNumber, formatTimeStamp
Expand Down Expand Up @@ -82,11 +81,12 @@ def __init__(self):
self.confChanged = False

## General
self.guiTheme = "default"
self.guiSyntax = "default_light"
self.guiIcons = "typicons_grey_light"
self.guiDark = False
self.guiLang = "en" # Hardcoded for now
self.guiTheme = "default"
self.guiSyntax = "default_light"
self.guiIcons = "typicons_grey_light"
self.guiDark = False
self.guiLang = "en" # Hardcoded for now
self.guiFontSize = 12

## Sizes
self.winGeometry = [1100, 650]
Expand Down Expand Up @@ -202,7 +202,6 @@ def initConfig(self, confPath=None, dataPath=None):
"""Initialise the config class. The manual setting of confPath
and dataPath is mainly intended for the test suite.
"""

if confPath is None:
confRoot = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
self.confPath = path.join(path.abspath(confRoot), self.appHandle)
Expand Down Expand Up @@ -318,6 +317,9 @@ def loadConfig(self):
self.guiDark = self._parseLine(
cnfParse, cnfSec, "guidark", self.CNF_BOOL, self.guiDark
)
self.guiFontSize = self._parseLine(
cnfParse, cnfSec, "guifontsize", self.CNF_INT, self.guiFontSize
)

## Sizes
cnfSec = "Sizes"
Expand Down Expand Up @@ -464,11 +466,12 @@ def saveConfig(self):
## Main
cnfSec = "Main"
cnfParse.add_section(cnfSec)
cnfParse.set(cnfSec,"timestamp", formatTimeStamp(time()))
cnfParse.set(cnfSec,"theme", str(self.guiTheme))
cnfParse.set(cnfSec,"syntax", str(self.guiSyntax))
cnfParse.set(cnfSec,"icons", str(self.guiIcons))
cnfParse.set(cnfSec,"guidark", str(self.guiDark))
cnfParse.set(cnfSec,"timestamp", formatTimeStamp(time()))
cnfParse.set(cnfSec,"theme", str(self.guiTheme))
cnfParse.set(cnfSec,"syntax", str(self.guiSyntax))
cnfParse.set(cnfSec,"icons", str(self.guiIcons))
cnfParse.set(cnfSec,"guidark", str(self.guiDark))
cnfParse.set(cnfSec,"guifontsize", str(self.guiFontSize))

## Sizes
cnfSec = "Sizes"
Expand Down
20 changes: 18 additions & 2 deletions nw/gui/dialogs/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ def __init__(self, theParent):
"This may improve the look of icons on dark themes."
)

## Font Size
self.guiFontSize = QSpinBox(self)
self.guiFontSize.setMinimum(8)
self.guiFontSize.setMaximum(60)
self.guiFontSize.setSingleStep(1)
self.guiFontSize.setValue(self.mainConf.guiFontSize)
self.mainForm.addRow(
"Font size",
self.guiFontSize,
"Changing this requires restarting %s." % nw.__package__,
theUnit="pt"
)

# GUI Settings
# ============
self.mainForm.addGroupLabel("GUI Settings")
Expand Down Expand Up @@ -266,6 +279,7 @@ def saveValues(self):
guiTheme = self.selectTheme.currentData()
guiIcons = self.selectIcons.currentData()
guiDark = self.preferDarkIcons.isChecked()
guiFontSize = self.guiFontSize.value()
showFullPath = self.showFullPath.isChecked()
autoSaveDoc = self.autoSaveDoc.value()
autoSaveProj = self.autoSaveProj.value()
Expand All @@ -276,10 +290,12 @@ def saveValues(self):
# Check if restart is needed
needsRestart |= self.mainConf.guiTheme != guiTheme
needsRestart |= self.mainConf.guiIcons != guiIcons
needsRestart |= self.mainConf.guiFontSize != guiFontSize

self.mainConf.guiTheme = guiTheme
self.mainConf.guiIcons = guiIcons
self.mainConf.guiDark = guiDark
self.mainConf.guiFontSize = guiFontSize
self.mainConf.showFullPath = showFullPath
self.mainConf.autoSaveDoc = autoSaveDoc
self.mainConf.autoSaveProj = autoSaveProj
Expand Down Expand Up @@ -353,8 +369,8 @@ def __init__(self, theParent):

## Font Size
self.textStyleSize = QSpinBox(self)
self.textStyleSize.setMinimum(5)
self.textStyleSize.setMaximum(120)
self.textStyleSize.setMinimum(8)
self.textStyleSize.setMaximum(60)
self.textStyleSize.setSingleStep(1)
self.textStyleSize.setValue(self.mainConf.textSize)
self.mainForm.addRow(
Expand Down
8 changes: 6 additions & 2 deletions nw/gui/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def __init__(self, theParent):
self.confFile = None
self.cssFile = None

# Set Font Size and Theme
self.guiFont = qApp.font()
self.guiFont.setPointSizeF(self.mainConf.guiFontSize)
qApp.setFont(self.guiFont)

self.updateTheme()
self.theIcons.updateTheme()

Expand All @@ -119,8 +124,7 @@ def __init__(self, theParent):
self.loadDecoration = self.theIcons.loadDecoration

# Extract Other Info
self.guiDPI = qApp.primaryScreen().physicalDotsPerInch()
self.guiFont = qApp.font()
self.guiDPI = qApp.primaryScreen().physicalDotsPerInch()

qMetric = QFontMetrics(self.guiFont)
self.fontPointSize = self.guiFont.pointSizeF()
Expand Down
1 change: 1 addition & 0 deletions tests/reference/novelwriter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ theme = default
syntax = default_light
icons = typicons_grey_light
guidark = False
guifontsize = 12

[Sizes]
geometry = 1100, 650
Expand Down

0 comments on commit c95fa4c

Please sign in to comment.