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."""
|
||||
|
||||
Reference in New Issue
Block a user