Skip to content

Commit

Permalink
Merge pull request #687 from vkbo/gui_tweaks
Browse files Browse the repository at this point in the history
Make settings layouts more responsive
  • Loading branch information
vkbo authored Feb 23, 2021
2 parents 0cc1573 + 66282d4 commit 2560b4d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 18 deletions.
3 changes: 1 addition & 2 deletions nw/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def colRange(rgbStart, rgbEnd, nStep):
cA = rgbStart[c]
cB = rgbEnd[c]
dC[c] = (cB-cA)/(nStep-1)
print(dC)

retCol = [rgbStart]
for n in range(nStep):
if n > 0 and n < nStep:
Expand All @@ -177,7 +177,6 @@ def colRange(rgbStart, rgbEnd, nStep):
int(retCol[n-1][2] + dC[2]),
])
retCol[-1] = rgbEnd
print(retCol)

return retCol

Expand Down
14 changes: 14 additions & 0 deletions nw/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def __init__(self):

## Sizes
self.winGeometry = [1200, 650]
self.prefGeometry = [700, 615]
self.treeColWidth = [200, 50, 30]
self.novelColWidth = [200, 50]
self.projColWidth = [200, 60, 140]
Expand Down Expand Up @@ -472,6 +473,9 @@ def loadConfig(self):
self.winGeometry = self._parseLine(
cnfParse, cnfSec, "geometry", self.CNF_I_LST, self.winGeometry
)
self.prefGeometry = self._parseLine(
cnfParse, cnfSec, "preferences", self.CNF_I_LST, self.prefGeometry
)
self.treeColWidth = self._parseLine(
cnfParse, cnfSec, "treecols", self.CNF_I_LST, self.treeColWidth
)
Expand Down Expand Up @@ -701,6 +705,7 @@ def saveConfig(self):
cnfSec = "Sizes"
cnfParse.add_section(cnfSec)
cnfParse.set(cnfSec, "geometry", self._packList(self.winGeometry))
cnfParse.set(cnfSec, "preferences", self._packList(self.prefGeometry))
cnfParse.set(cnfSec, "treecols", self._packList(self.treeColWidth))
cnfParse.set(cnfSec, "novelcols", self._packList(self.novelColWidth))
cnfParse.set(cnfSec, "projcols", self._packList(self.projColWidth))
Expand Down Expand Up @@ -921,6 +926,12 @@ def setWinSize(self, newWidth, newHeight):
self.confChanged = True
return True

def setPreferencesSize(self, newWidth, newHeight):
self.prefGeometry[0] = int(newWidth/self.guiScale)
self.prefGeometry[1] = int(newHeight/self.guiScale)
self.confChanged = True
return True

def setTreeColWidths(self, colWidths):
self.treeColWidth = [int(x/self.guiScale) for x in colWidths]
self.confChanged = True
Expand Down Expand Up @@ -984,6 +995,9 @@ def setViewSynopsis(self, viewState):
def getWinSize(self):
return [int(x*self.guiScale) for x in self.winGeometry]

def getPreferencesSize(self):
return [int(x*self.guiScale) for x in self.prefGeometry]

def getTreeColWidths(self):
return [int(x*self.guiScale) for x in self.treeColWidth]

Expand Down
23 changes: 19 additions & 4 deletions nw/gui/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from PyQt5.QtWidgets import (
QGridLayout, QLabel, QWidget, QVBoxLayout, QHBoxLayout, QSizePolicy,
QAbstractButton, QDialog, QTabWidget, QTabBar, QStyle, QDialogButtonBox,
QStylePainter, QStyleOptionTab, QListWidget, QListWidgetItem, QFrame
QStylePainter, QStyleOptionTab, QListWidget, QListWidgetItem, QFrame,
QLineEdit
)

from nw.constants import trConst, nwUnicode, nwQuotes
Expand All @@ -61,6 +62,7 @@ def __init__(self):
wSp = nw.CONFIG.pxInt(8)
self.setHorizontalSpacing(wSp)
self.setVerticalSpacing(wSp)
self.setColumnStretch(0, 1)

return

Expand Down Expand Up @@ -151,6 +153,7 @@ def addRow(self, theLabel, theWidget, helpText=None, theUnit=None, theButton=Non
labelBox.addWidget(qLabel)
labelBox.addWidget(qHelp)
labelBox.setSpacing(0)
labelBox.addStretch(1)

thisEntry["help"] = qHelp
self.addLayout(labelBox, self._nextRow, 0, 1, 1, Qt.AlignLeft | Qt.AlignTop)
Expand All @@ -163,15 +166,22 @@ def addRow(self, theLabel, theWidget, helpText=None, theUnit=None, theButton=Non
controlBox.addWidget(qWidget, 0, Qt.AlignVCenter)
controlBox.addWidget(QLabel(theUnit), 0, Qt.AlignVCenter)
controlBox.setSpacing(wSp)
self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignVCenter)
self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)

elif theButton is not None:
controlBox = QHBoxLayout()
controlBox.addWidget(qWidget, 0, Qt.AlignVCenter)
controlBox.addWidget(theButton, 0, Qt.AlignVCenter)
controlBox.setSpacing(wSp)
self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignVCenter)
self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)

else:
self.addWidget(qWidget, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignVCenter)
if isinstance(theWidget, QLineEdit):
qLayout = QHBoxLayout()
qLayout.addWidget(theWidget)
self.addLayout(qLayout, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
else:
self.addWidget(qWidget, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)

qLabel.setBuddy(qWidget)

Expand Down Expand Up @@ -207,6 +217,9 @@ def __init__(self, theText, textCol, fontSize=0.9):
lblFont.setPointSizeF(fontSize*lblFont.pointSizeF())
self.setFont(lblFont)

self.setWordWrap(True)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

return

# END Class QHelpLabel
Expand Down Expand Up @@ -409,13 +422,15 @@ class VerticalTabBar(QTabBar):

def __init__(self, theParent=None):
QTabBar.__init__(self, parent=theParent)
self._mW = nw.CONFIG.pxInt(150)
return

def tabSizeHint(self, theIndex):
"""Returns a transposed size hint for the rotated bar.
"""
tSize = QTabBar.tabSizeHint(self, theIndex)
tSize.transpose()
tSize.setWidth(min(tSize.width(), self._mW))
return tSize

def paintEvent(self, theEvent):
Expand Down
18 changes: 17 additions & 1 deletion nw/gui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ def __init__(self, theParent, theProject):
self.buttonBox.rejected.connect(self._doClose)
self.addControls(self.buttonBox)

self.resize(*self.mainConf.getPreferencesSize())

logger.debug("GuiPreferences initialisation complete")

return

##
# Buttons
# Slots
##

def _doSave(self):
Expand All @@ -102,16 +104,30 @@ def _doSave(self):
nwAlert.INFO
)

self._saveWindowSize()
self.accept()

return

def _doClose(self):
"""Close the preferences without saving the changes.
"""
self._saveWindowSize()
self.reject()
return

##
# Internal Functions
##

def _saveWindowSize(self):
"""Save the dialog window size.
"""
winWidth = self.mainConf.rpxInt(self.width())
winHeight = self.mainConf.rpxInt(self.height())
self.mainConf.setPreferencesSize(winWidth, winHeight)
return

# END Class GuiPreferences

class GuiPreferencesGeneral(QWidget):
Expand Down
17 changes: 7 additions & 10 deletions nw/gui/projsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ def __init__(self, theParent, theProject):
self.mainForm.addGroupLabel(self.tr("Project Settings"))

xW = self.mainConf.pxInt(250)
xH = self.mainConf.pxInt(100)
xH = self.mainConf.pxInt(80)

self.editName = QLineEdit()
self.editName.setMaxLength(200)
self.editName.setFixedWidth(xW)
self.editName.setMaximumWidth(xW)
self.editName.setText(self.theProject.projName)
self.mainForm.addRow(
self.tr("Working title"),
Expand All @@ -183,7 +183,7 @@ def __init__(self, theParent, theProject):

self.editTitle = QLineEdit()
self.editTitle.setMaxLength(200)
self.editTitle.setFixedWidth(xW)
self.editTitle.setMaximumWidth(xW)
self.editTitle.setText(self.theProject.bookTitle)
self.mainForm.addRow(
self.tr("Novel title"),
Expand All @@ -192,20 +192,17 @@ def __init__(self, theParent, theProject):
)

self.editAuthors = QPlainTextEdit()
bookAuthors = ""
for bookAuthor in self.theProject.bookAuthors:
bookAuthors += bookAuthor+"\n"
self.editAuthors.setPlainText(bookAuthors)
self.editAuthors.setFixedHeight(xH)
self.editAuthors.setFixedWidth(xW)
self.editAuthors.setMinimumHeight(xH)
self.editAuthors.setMaximumWidth(xW)
self.editAuthors.setPlainText("\n".join(self.theProject.bookAuthors))
self.mainForm.addRow(
self.tr("Author(s)"),
self.editAuthors,
self.tr("One name per line.")
)

self.spellLang = QComboBox(self)
self.spellLang.setFixedWidth(xW)
self.spellLang.setMaximumWidth(xW)
theDict = self.theParent.docEditor.theDict
self.spellLang.addItem(self.tr("Default"), "None")
if theDict is not None:
Expand Down
1 change: 1 addition & 0 deletions tests/reference/baseConfig_novelwriter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ guilang = en-GB

[Sizes]
geometry = 1200, 650
preferences = 700, 615
treecols = 200, 50, 30
novelcols = 200, 50
projcols = 200, 60, 140
Expand Down
1 change: 1 addition & 0 deletions tests/reference/guiPreferences_novelwriter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ guilang = en-GB

[Sizes]
geometry = 1200, 650
preferences = 700, 615
treecols = 200, 50, 30
novelcols = 200, 50
projcols = 200, 60, 140
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gui/test_gui_projsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def testGuiProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi

assert projEdit.tabMain.editName.text() == "New Project"
assert projEdit.tabMain.editTitle.text() == ""
assert projEdit.tabMain.editAuthors.toPlainText() == "Jane Smith\nJohn Smith\n"
assert projEdit.tabMain.editAuthors.toPlainText() == "Jane Smith\nJohn Smith"
assert projEdit.tabMain.spellLang.currentData() == "en"
assert projEdit.tabMain.doBackup.isChecked() is False

Expand Down

0 comments on commit 2560b4d

Please sign in to comment.