Add native font dialog option and fix tests
This commit is contained in:
@@ -273,12 +273,12 @@ class ToOdt(Tokenizer):
|
||||
fontWeight = str(intWeight)
|
||||
fontBold = str(min(intWeight + 300, 900))
|
||||
|
||||
self._fontFamily = self._textFont.family()
|
||||
self._fontSize = self._textFont.pointSize()
|
||||
self._fontWeight = FONT_WEIGHT_MAP.get(fontWeight, fontWeight)
|
||||
self._fontStyle = FONT_STYLE.get(self._textFont.style(), "normal")
|
||||
self._fontPitch = "fixed" if self._textFont.fixedPitch() else "variable"
|
||||
self._fontBold = FONT_WEIGHT_MAP.get(fontBold, fontBold)
|
||||
self._fontFamily = self._textFont.family()
|
||||
self._fontSize = self._textFont.pointSize()
|
||||
self._fontWeight = FONT_WEIGHT_MAP.get(fontWeight, fontWeight)
|
||||
self._fontStyle = FONT_STYLE.get(self._textFont.style(), "normal")
|
||||
self._fontPitch = "fixed" if self._textFont.fixedPitch() else "variable"
|
||||
self._fontBold = FONT_WEIGHT_MAP.get(fontBold, fontBold)
|
||||
|
||||
self._fSizeTitle = f"{round(2.50 * self._fontSize):d}pt"
|
||||
self._fSizeHead1 = f"{round(2.00 * self._fontSize):d}pt"
|
||||
|
||||
@@ -206,6 +206,14 @@ class GuiPreferences(QDialog):
|
||||
self.tr("Scrolling available with mouse wheel and keys only.")
|
||||
)
|
||||
|
||||
# Native Font Dialog
|
||||
self.nativeFont = NSwitch(self)
|
||||
self.nativeFont.setChecked(CONFIG.nativeFont)
|
||||
self.mainForm.addRow(
|
||||
self.tr("Use the system's font selection dialog"), self.nativeFont,
|
||||
self.tr("Turn off to use the Qt font dialog, which may have more options.")
|
||||
)
|
||||
|
||||
# Document Style
|
||||
# ==============
|
||||
|
||||
@@ -803,7 +811,7 @@ class GuiPreferences(QDialog):
|
||||
@pyqtSlot()
|
||||
def _selectGuiFont(self) -> None:
|
||||
"""Open the QFontDialog and set a font for the font style."""
|
||||
font, status = SHARED.getFont(self._guiFont, CONFIG.nativeFont)
|
||||
font, status = SHARED.getFont(self._guiFont, self.nativeFont.isChecked())
|
||||
if status:
|
||||
self.guiFont.setText(describeFont(font))
|
||||
self.guiFont.setCursorPosition(0)
|
||||
@@ -813,7 +821,7 @@ class GuiPreferences(QDialog):
|
||||
@pyqtSlot()
|
||||
def _selectTextFont(self) -> None:
|
||||
"""Open the QFontDialog and set a font for the font style."""
|
||||
font, status = SHARED.getFont(self._textFont, CONFIG.nativeFont)
|
||||
font, status = SHARED.getFont(self._textFont, self.nativeFont.isChecked())
|
||||
if status:
|
||||
self.textFont.setText(describeFont(font))
|
||||
self.textFont.setCursorPosition(0)
|
||||
@@ -882,6 +890,7 @@ class GuiPreferences(QDialog):
|
||||
CONFIG.guiTheme = guiTheme
|
||||
CONFIG.hideVScroll = self.hideVScroll.isChecked()
|
||||
CONFIG.hideHScroll = self.hideHScroll.isChecked()
|
||||
CONFIG.nativeFont = self.nativeFont.isChecked()
|
||||
CONFIG.setGuiFont(self._guiFont)
|
||||
|
||||
# Document Style
|
||||
|
||||
@@ -50,6 +50,7 @@ class GuiQuoteSelect(QDialog):
|
||||
|
||||
logger.debug("Create: GuiQuoteSelect")
|
||||
self.setObjectName("GuiQuoteSelect")
|
||||
self.setWindowTitle(self.tr("Select Quote Style"))
|
||||
|
||||
self.outerBox = QVBoxLayout()
|
||||
self.innerBox = QHBoxLayout()
|
||||
|
||||
+9
-11
@@ -256,8 +256,11 @@ class SharedData(QObject):
|
||||
QThreadPool.globalInstance().start(runnable, priority=priority)
|
||||
return
|
||||
|
||||
def getProjectPath(self, parent: QWidget, path: str | Path | None = None,
|
||||
allowZip: bool = False) -> Path | None:
|
||||
def getProjectPath(
|
||||
self, parent: QWidget,
|
||||
path: str | Path | None = None,
|
||||
allowZip: bool = False
|
||||
) -> Path | None:
|
||||
"""Open the file dialog and select a novelWriter project file."""
|
||||
label = (self.tr("novelWriter Project File or Zip File")
|
||||
if allowZip else self.tr("novelWriter Project File"))
|
||||
@@ -270,15 +273,10 @@ class SharedData(QObject):
|
||||
|
||||
def getFont(self, current: QFont, native: bool) -> tuple[QFont, bool]:
|
||||
"""Open the font dialog and select a font."""
|
||||
if native:
|
||||
font, status = QFontDialog.getFont(current, self.mainGui)
|
||||
else:
|
||||
options = QFontDialog.FontDialogOption.DontUseNativeDialog
|
||||
font, status = QFontDialog.getFont(current, self.mainGui, options=options)
|
||||
font.setOverline(False)
|
||||
font.setStrikeOut(False)
|
||||
font.setUnderline(False)
|
||||
return font, status
|
||||
kwargs = {}
|
||||
if not native:
|
||||
kwargs["options"] = QFontDialog.FontDialogOption.DontUseNativeDialog
|
||||
return QFontDialog.getFont(current, self.mainGui, self.tr("Select Font"), **kwargs)
|
||||
|
||||
def findTopLevelWidget(self, kind: type[NWWidget]) -> NWWidget | None:
|
||||
"""Find a top level widget."""
|
||||
|
||||
@@ -160,20 +160,12 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
||||
prefs = GuiPreferences(nwGUI)
|
||||
prefs.show()
|
||||
|
||||
# Mock Font
|
||||
class MockFont:
|
||||
|
||||
def family(self):
|
||||
return "TestFont"
|
||||
|
||||
def pointSize(self):
|
||||
return 42
|
||||
|
||||
# Appearance
|
||||
prefs.guiLocale.setCurrentIndex(prefs.guiLocale.findData("en_US"))
|
||||
prefs.guiTheme.setCurrentIndex(prefs.guiTheme.findData("default_dark"))
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QFontDialog, "getFont", lambda *a, **k: (QFont(), True))
|
||||
prefs.nativeFont.setChecked(True) # Use OS font dialog
|
||||
prefs.guiFontButton.click()
|
||||
prefs.hideVScroll.setChecked(True)
|
||||
prefs.hideHScroll.setChecked(True)
|
||||
@@ -188,6 +180,7 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
||||
prefs.guiSyntax.setCurrentIndex(prefs.guiSyntax.findData("default_dark"))
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QFontDialog, "getFont", lambda *a, **k: (QFont(), True))
|
||||
prefs.nativeFont.setChecked(False) # Use Qt font dialog
|
||||
prefs.textFontButton.click()
|
||||
prefs.emphLabels.setChecked(False)
|
||||
prefs.showFullPath.setChecked(False)
|
||||
|
||||
@@ -26,7 +26,7 @@ from PyQt5.QtCore import pyqtSlot
|
||||
from PyQt5.QtGui import QFont
|
||||
from PyQt5.QtWidgets import QFontDialog
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter import SHARED
|
||||
from novelwriter.common import describeFont
|
||||
from novelwriter.constants import nwHeadFmt
|
||||
from novelwriter.core.buildsettings import BuildSettings, FilterMode
|
||||
@@ -575,7 +575,6 @@ def testBuildSettings_Format(monkeypatch, qtbot, nwGUI):
|
||||
assert bSettings.toolStack.currentWidget() is fmtTab
|
||||
|
||||
# Check initial values
|
||||
assert fmtTab._textFont == CONFIG.textFont
|
||||
assert fmtTab.lineHeight.value() == 1.2
|
||||
|
||||
assert fmtTab.justifyText.isChecked() is False
|
||||
|
||||
Reference in New Issue
Block a user