Simplify text width settings (#943)

* Remove the fixed text width switch, resolves #924
* Update tests
* Clean up code to set text width and add to viewer
This commit is contained in:
Veronica Berglyd Olsen
2021-12-31 17:17:27 +01:00
committed by GitHub
parent 6ac9e1aec4
commit 7024254960
8 changed files with 37 additions and 56 deletions
+7 -10
View File
@@ -117,7 +117,6 @@ class Config:
# Text Editor # Text Editor
self.textFont = None # Editor font self.textFont = None # Editor font
self.textSize = 12 # Editor font size self.textSize = 12 # Editor font size
self.textFixedW = True # Keep editor text fixed width
self.textWidth = 600 # Editor text width self.textWidth = 600 # Editor text width
self.textMargin = 40 # Editor/viewer text margin self.textMargin = 40 # Editor/viewer text margin
self.tabWidth = 40 # Editor tabulator width self.tabWidth = 40 # Editor tabulator width
@@ -468,7 +467,6 @@ class Config:
cnfSec = "Editor" cnfSec = "Editor"
self.textFont = theConf.rdStr(cnfSec, "textfont", self.textFont) self.textFont = theConf.rdStr(cnfSec, "textfont", self.textFont)
self.textSize = theConf.rdInt(cnfSec, "textsize", self.textSize) self.textSize = theConf.rdInt(cnfSec, "textsize", self.textSize)
self.textFixedW = theConf.rdBool(cnfSec, "fixedwidth", self.textFixedW)
self.textWidth = theConf.rdInt(cnfSec, "width", self.textWidth) self.textWidth = theConf.rdInt(cnfSec, "width", self.textWidth)
self.textMargin = theConf.rdInt(cnfSec, "margin", self.textMargin) self.textMargin = theConf.rdInt(cnfSec, "margin", self.textMargin)
self.tabWidth = theConf.rdInt(cnfSec, "tabwidth", self.tabWidth) self.tabWidth = theConf.rdInt(cnfSec, "tabwidth", self.tabWidth)
@@ -590,7 +588,6 @@ class Config:
theConf["Editor"] = { theConf["Editor"] = {
"textfont": str(self.textFont), "textfont": str(self.textFont),
"textsize": str(self.textSize), "textsize": str(self.textSize),
"fixedwidth": str(self.textFixedW),
"width": str(self.textWidth), "width": str(self.textWidth),
"margin": str(self.textMargin), "margin": str(self.textMargin),
"tabwidth": str(self.tabWidth), "tabwidth": str(self.tabWidth),
@@ -922,17 +919,17 @@ class Config:
def getOutlinePanePos(self): def getOutlinePanePos(self):
return [int(x*self.guiScale) for x in self.outlnPanePos] return [int(x*self.guiScale) for x in self.outlnPanePos]
def getTextWidth(self): def getTextWidth(self, focusMode=False):
return self.pxInt(self.textWidth) if focusMode:
return self.pxInt(max(self.focusWidth, 200))
else:
return self.pxInt(max(self.textWidth, 200))
def getTextMargin(self): def getTextMargin(self):
return self.pxInt(self.textMargin) return self.pxInt(max(self.textMargin, 0))
def getTabWidth(self): def getTabWidth(self):
return self.pxInt(self.tabWidth) return self.pxInt(max(self.tabWidth, 0))
def getFocusWidth(self):
return self.pxInt(self.focusWidth)
def getErrData(self): def getErrData(self):
"""Compile and return error messages from the initialisation of """Compile and return error messages from the initialisation of
+5 -15
View File
@@ -537,39 +537,30 @@ class GuiPreferencesDocuments(QWidget):
# Max Text Width in Normal Mode # Max Text Width in Normal Mode
self.textWidth = QSpinBox(self) self.textWidth = QSpinBox(self)
self.textWidth.setMinimum(300) self.textWidth.setMinimum(0)
self.textWidth.setMaximum(10000) self.textWidth.setMaximum(10000)
self.textWidth.setSingleStep(10) self.textWidth.setSingleStep(10)
self.textWidth.setValue(self.mainConf.textWidth) self.textWidth.setValue(self.mainConf.textWidth)
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Maximum text width in \"Normal Mode\""), self.tr("Maximum text width in \"Normal Mode\""),
self.textWidth, self.textWidth,
self.tr("Horizontal margins are scaled automatically."), self.tr("Set to 0 to disable this feature."),
theUnit=self.tr("px") theUnit=self.tr("px")
) )
# Max Text Width in Focus Mode # Max Text Width in Focus Mode
self.focusWidth = QSpinBox(self) self.focusWidth = QSpinBox(self)
self.focusWidth.setMinimum(300) self.focusWidth.setMinimum(200)
self.focusWidth.setMaximum(10000) self.focusWidth.setMaximum(10000)
self.focusWidth.setSingleStep(10) self.focusWidth.setSingleStep(10)
self.focusWidth.setValue(self.mainConf.focusWidth) self.focusWidth.setValue(self.mainConf.focusWidth)
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Maximum text width in \"Focus Mode\""), self.tr("Maximum text width in \"Focus Mode\""),
self.focusWidth, self.focusWidth,
self.tr("Horizontal margins are scaled automatically."), self.tr("The maximum width cannot be disabled."),
theUnit=self.tr("px") theUnit=self.tr("px")
) )
# Document Fixed Width
self.textFixedW = QSwitch()
self.textFixedW.setChecked(not self.mainConf.textFixedW)
self.mainForm.addRow(
self.tr("Disable maximum text width in \"Normal Mode\""),
self.textFixedW,
self.tr("Text width is defined by the margins only.")
)
# Focus Mode Footer # Focus Mode Footer
self.hideFocusFooter = QSwitch() self.hideFocusFooter = QSwitch()
self.hideFocusFooter.setChecked(self.mainConf.hideFocusFooter) self.hideFocusFooter.setChecked(self.mainConf.hideFocusFooter)
@@ -597,7 +588,7 @@ class GuiPreferencesDocuments(QWidget):
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Text margin"), self.tr("Text margin"),
self.textMargin, self.textMargin,
self.tr("If maximum width is set, this becomes the minimum margin."), self.tr("The minimum margin around the text in the editor and viewer."),
theUnit=self.tr("px") theUnit=self.tr("px")
) )
@@ -626,7 +617,6 @@ class GuiPreferencesDocuments(QWidget):
# Text Flow # Text Flow
self.mainConf.textWidth = self.textWidth.value() self.mainConf.textWidth = self.textWidth.value()
self.mainConf.focusWidth = self.focusWidth.value() self.mainConf.focusWidth = self.focusWidth.value()
self.mainConf.textFixedW = not self.textFixedW.isChecked()
self.mainConf.hideFocusFooter = self.hideFocusFooter.isChecked() self.mainConf.hideFocusFooter = self.hideFocusFooter.isChecked()
self.mainConf.doJustify = self.doJustify.isChecked() self.mainConf.doJustify = self.doJustify.isChecked()
self.mainConf.textMargin = self.textMargin.value() self.mainConf.textMargin = self.textMargin.value()
+7 -14
View File
@@ -509,8 +509,8 @@ class GuiDocEditor(QTextEdit):
def updateDocMargins(self): def updateDocMargins(self):
"""Automatically adjust the margins so the text is centred if """Automatically adjust the margins so the text is centred if
Config.textFixedW is enabled or we're in Focus Mode. Otherwise, we have a text width set or we're in Focus Mode. Otherwise, just
just ensure the margins are set correctly. ensure the margins are set correctly.
""" """
wW = self.width() wW = self.width()
wH = self.height() wH = self.height()
@@ -522,16 +522,10 @@ class GuiDocEditor(QTextEdit):
hBar = self.horizontalScrollBar() hBar = self.horizontalScrollBar()
sH = hBar.height() if hBar.isVisible() else 0 sH = hBar.height() if hBar.isVisible() else 0
if self.mainConf.textFixedW or self.theParent.isFocusMode: tM = cM
if self.theParent.isFocusMode: if self.mainConf.textWidth > 0 or self.theParent.isFocusMode:
tW = self.mainConf.getFocusWidth() tW = self.mainConf.getTextWidth(self.theParent.isFocusMode)
else: tM = max((wW - sW - tW)//2, cM)
tW = self.mainConf.getTextWidth()
tM = (wW - sW - tW)//2
if tM < cM:
tM = cM
else:
tM = cM
tB = self.frameWidth() tB = self.frameWidth()
tW = wW - 2*tB - sW tW = wW - 2*tB - sW
@@ -541,13 +535,12 @@ class GuiDocEditor(QTextEdit):
self.docHeader.setGeometry(tB, tB, tW, tH) self.docHeader.setGeometry(tB, tB, tW, tH)
self.docFooter.setGeometry(tB, fY, tW, fH) self.docFooter.setGeometry(tB, fY, tW, fH)
rH = 0
if self.docSearch.isVisible(): if self.docSearch.isVisible():
rH = self.docSearch.height() rH = self.docSearch.height()
rW = self.docSearch.width() rW = self.docSearch.width()
rL = wW - sW - rW - 2*tB rL = wW - sW - rW - 2*tB
self.docSearch.move(rL, 2*tB) self.docSearch.move(rL, 2*tB)
else:
rH = 0
uM = max(cM, tH, rH) uM = max(cM, tH, rH)
lM = max(cM, fH) lM = max(cM, fH)
+12 -4
View File
@@ -313,22 +313,30 @@ class GuiDocViewer(QTextBrowser):
def updateDocMargins(self): def updateDocMargins(self):
"""Automatically adjust the margins so the text is centred. """Automatically adjust the margins so the text is centred.
""" """
wW = self.width()
wH = self.height()
cM = self.mainConf.getTextMargin()
vBar = self.verticalScrollBar() vBar = self.verticalScrollBar()
sW = vBar.width() if vBar.isVisible() else 0 sW = vBar.width() if vBar.isVisible() else 0
hBar = self.horizontalScrollBar() hBar = self.horizontalScrollBar()
sH = hBar.height() if hBar.isVisible() else 0 sH = hBar.height() if hBar.isVisible() else 0
cM = self.mainConf.getTextMargin() tM = cM
if self.mainConf.textWidth > 0:
tW = self.mainConf.getTextWidth()
tM = max((wW - sW - tW)//2, cM)
tB = self.frameWidth() tB = self.frameWidth()
tW = self.width() - 2*tB - sW tW = wW - 2*tB - sW
tH = self.docHeader.height() tH = self.docHeader.height()
fH = self.docFooter.height() fH = self.docFooter.height()
fY = self.height() - fH - tB - sH fY = wH - fH - tB - sH
self.docHeader.setGeometry(tB, tB, tW, tH) self.docHeader.setGeometry(tB, tB, tW, tH)
self.docFooter.setGeometry(tB, fY, tW, fH) self.docFooter.setGeometry(tB, fY, tW, fH)
self.setViewportMargins(cM, max(cM, tH), cM, max(cM, fH)) self.setViewportMargins(tM, max(cM, tH), tM, max(cM, fH))
return return
+1 -2
View File
@@ -1,5 +1,5 @@
[Main] [Main]
timestamp = 2021-09-15 14:39:52 timestamp = 2021-12-31 16:45:32
theme = default theme = default
syntax = default_light syntax = default_light
icons = typicons_light icons = typicons_light
@@ -30,7 +30,6 @@ emphlabels = True
[Editor] [Editor]
textfont = None textfont = None
textsize = 12 textsize = 12
fixedwidth = True
width = 600 width = 600
margin = 40 margin = 40
tabwidth = 40 tabwidth = 40
@@ -1,5 +1,5 @@
[Main] [Main]
timestamp = 2021-09-15 14:29:30 timestamp = 2021-12-31 16:45:34
theme = default theme = default
syntax = default_light syntax = default_light
icons = typicons_light icons = typicons_light
@@ -30,7 +30,6 @@ emphlabels = True
[Editor] [Editor]
textfont = None textfont = None
textsize = 13 textsize = 13
fixedwidth = False
width = 700 width = 700
margin = 45 margin = 45
tabwidth = 45 tabwidth = 45
+4 -4
View File
@@ -505,16 +505,16 @@ def testBaseConfig_SettersGetters(tmpConf, tmpDir, outDir, refDir):
# ============ # ============
tmpConf.guiScale = 1.0 tmpConf.guiScale = 1.0
assert tmpConf.getTextWidth() == 600 assert tmpConf.getTextWidth(False) == 600
assert tmpConf.getTextWidth(True) == 800
assert tmpConf.getTextMargin() == 40 assert tmpConf.getTextMargin() == 40
assert tmpConf.getTabWidth() == 40 assert tmpConf.getTabWidth() == 40
assert tmpConf.getFocusWidth() == 800
tmpConf.guiScale = 2.0 tmpConf.guiScale = 2.0
assert tmpConf.getTextWidth() == 1200 assert tmpConf.getTextWidth(False) == 1200
assert tmpConf.getTextWidth(True) == 1600
assert tmpConf.getTextMargin() == 80 assert tmpConf.getTextMargin() == 80
assert tmpConf.getTabWidth() == 80 assert tmpConf.getTabWidth() == 80
assert tmpConf.getFocusWidth() == 1600
# Flag Setters # Flag Setters
# ============ # ============
@@ -144,11 +144,6 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
tabDocs.textMargin.setValue(45) tabDocs.textMargin.setValue(45)
tabDocs.tabWidth.setValue(45) tabDocs.tabWidth.setValue(45)
qtbot.wait(keyDelay)
assert not tabDocs.textFixedW.isChecked()
qtbot.mouseClick(tabDocs.textFixedW, Qt.LeftButton)
assert tabDocs.textFixedW.isChecked()
qtbot.wait(keyDelay) qtbot.wait(keyDelay)
assert not tabDocs.hideFocusFooter.isChecked() assert not tabDocs.hideFocusFooter.isChecked()
qtbot.mouseClick(tabDocs.hideFocusFooter, Qt.LeftButton) qtbot.mouseClick(tabDocs.hideFocusFooter, Qt.LeftButton)