Paged dialog with vertical tabs now working

This commit is contained in:
Veronica K. B. Olsen
2020-05-17 16:08:58 +02:00
parent bd9b40a1ca
commit 80872feceb
3 changed files with 79 additions and 36 deletions
+67 -12
View File
@@ -28,9 +28,11 @@
import logging import logging
import nw import nw
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt, QRect, QPoint
from PyQt5.QtGui import QPalette
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QHBoxLayout, QVBoxLayout, QTabWidget QWidget, QDialog, QHBoxLayout, QVBoxLayout, QTabWidget, QTabBar,
QStylePainter, QStyleOptionTab, QStyle, QLabel
) )
from nw.constants import nwUnicode from nw.constants import nwUnicode
@@ -40,26 +42,79 @@ logger = logging.getLogger(__name__)
class PagedDialog(QDialog): class PagedDialog(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent=parent) QDialog.__init__(self, parent=parent)
self._outerBox = QVBoxLayout() self._outerBox = QVBoxLayout()
self._innerBox = QHBoxLayout() self._buttonBox = QHBoxLayout()
self._navBox = QVBoxLayout() self._tabBox = QTabWidget()
self._tabBox = QTabWidget()
self._outerBox.addLayout(self._innerBox) self._tabBar = VerticalTabBar(self)
self._innerBox.addLayout(self._navBox) self._tabBox.setTabBar(self._tabBar)
self._innerBox.addWidget(self._tabBox) self._tabBox.setTabPosition(QTabWidget.West)
self._tabBar.setExpanding(False)
self._outerBox.addWidget(self._tabBox)
self._outerBox.addLayout(self._buttonBox)
self.setLayout(self._outerBox) self.setLayout(self._outerBox)
# Default Margins
qM = self._outerBox.contentsMargins()
mL = qM.left()
mR = qM.right()
mT = qM.top()
mB = qM.bottom()
self.setContentsMargins(0, 0, 0, 0)
self._outerBox.setContentsMargins(0, 0, 0, mB)
self._buttonBox.setContentsMargins(mL, 0, mR, 0)
self._outerBox.setSpacing(mT)
return return
def addPage(self, tabWidget, tabLabel): def addTab(self, tabWidget, tabLabel):
self._tabBox.addTab(tabWidget, tabLabel) self._tabBox.addTab(tabWidget, tabLabel)
return return
def addControls(self, buttonBar): def addControls(self, buttonBar):
self._outerBox.addWidget(buttonBar) self._buttonBox.addWidget(buttonBar)
return return
# END Class PagedDialog # END Class PagedDialog
class VerticalTabBar(QTabBar):
def __init__(self, parent=None):
QTabBar.__init__(self, parent=parent)
return
def tabSizeHint(self, theIndex):
tSize = QTabBar.tabSizeHint(self, theIndex)
tSize.transpose()
return tSize
def paintEvent(self, theEvent):
pObj = QStylePainter(self)
oObj = QStyleOptionTab()
for i in range(self.count()):
self.initStyleOption(oObj, i)
pObj.drawControl(QStyle.CE_TabBarTabShape, oObj)
pObj.save()
oSize = oObj.rect.size()
oSize.transpose()
oRect = QRect(QPoint(), oSize)
oRect.moveCenter(oObj.rect.center())
oObj.rect = oRect
oCenter = self.tabRect(i).center()
pObj.translate(oCenter)
pObj.rotate(90)
pObj.translate(-oCenter)
pObj.drawControl(QStyle.CE_TabBarTabLabel, oObj)
pObj.restore()
return
# END Class VerticalTabBar
+8 -20
View File
@@ -38,51 +38,39 @@ from PyQt5.QtWidgets import (
QFileDialog QFileDialog
) )
from nw.gui.additions import QSwitch, QConfigLayout from nw.gui.additions import QSwitch, QConfigLayout, PagedDialog
from nw.core import NWSpellCheck, NWSpellSimple, NWSpellEnchant from nw.core import NWSpellCheck, NWSpellSimple, NWSpellEnchant
from nw.constants import nwAlert, nwQuotes from nw.constants import nwAlert, nwQuotes
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class GuiConfigEditor(QDialog): class GuiConfigEditor(PagedDialog):
def __init__(self, theParent, theProject): def __init__(self, theParent, theProject):
QDialog.__init__(self, theParent) PagedDialog.__init__(self, theParent)
logger.debug("Initialising ConfigEditor ...") logger.debug("Initialising ConfigEditor ...")
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
self.theProject = theProject self.theProject = theProject
self.outerBox = QHBoxLayout()
self.innerBox = QVBoxLayout()
self.setWindowTitle("Preferences") self.setWindowTitle("Preferences")
self.guiDeco = self.theParent.theTheme.loadDecoration("settings", (64,64))
self.outerBox.setSpacing(16)
self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop)
self.outerBox.addLayout(self.innerBox)
self.setLayout(self.outerBox)
self.tabGeneral = GuiConfigEditGeneralTab(self.theParent) self.tabGeneral = GuiConfigEditGeneralTab(self.theParent)
self.tabLayout = GuiConfigEditLayoutTab(self.theParent) self.tabLayout = GuiConfigEditLayoutTab(self.theParent)
self.tabEditing = GuiConfigEditEditingTab(self.theParent) self.tabEditing = GuiConfigEditEditingTab(self.theParent)
self.tabAutoRep = GuiConfigEditAutoReplaceTab(self.theParent) self.tabAutoRep = GuiConfigEditAutoReplaceTab(self.theParent)
self.tabWidget = QTabWidget() self.addTab(self.tabGeneral, "General")
self.tabWidget.setMinimumWidth(600) self.addTab(self.tabLayout, "Layout")
self.tabWidget.addTab(self.tabGeneral, "General") self.addTab(self.tabEditing, "Editing")
self.tabWidget.addTab(self.tabLayout, "Layout") self.addTab(self.tabAutoRep, "Auto-Replace")
self.tabWidget.addTab(self.tabEditing, "Editing")
self.tabWidget.addTab(self.tabAutoRep, "Auto-Replace")
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox.accepted.connect(self._doSave) self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self._doClose) self.buttonBox.rejected.connect(self._doClose)
self.addControls(self.buttonBox)
self.innerBox.addWidget(self.tabWidget)
self.innerBox.addWidget(self.buttonBox)
self.show() self.show()
+4 -4
View File
@@ -61,10 +61,10 @@ class GuiProjectEditor(PagedDialog):
self.tabImport = GuiProjectEditStatus(self.theParent, self.theProject.importItems) self.tabImport = GuiProjectEditStatus(self.theParent, self.theProject.importItems)
self.tabReplace = GuiProjectEditReplace(self.theParent, self.theProject) self.tabReplace = GuiProjectEditReplace(self.theParent, self.theProject)
self.addPage(self.tabMain, "Settings") self.addTab(self.tabMain, "Settings")
self.addPage(self.tabStatus, "Status") self.addTab(self.tabStatus, "Status")
self.addPage(self.tabImport, "Importance") self.addTab(self.tabImport, "Importance")
self.addPage(self.tabReplace,"Auto-Replace") self.addTab(self.tabReplace,"Auto-Replace")
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox.accepted.connect(self._doSave) self.buttonBox.accepted.connect(self._doSave)