Add a base button size, and make it default for switches and tool buttons

This commit is contained in:
Veronica Berglyd Olsen
2024-04-01 15:39:54 +02:00
parent cfde84f851
commit c000307f14
5 changed files with 18 additions and 15 deletions
+4 -4
View File
@@ -27,20 +27,20 @@ from PyQt5.QtGui import QMouseEvent, QPainter, QPaintEvent, QResizeEvent
from PyQt5.QtCore import QEvent, QPropertyAnimation, Qt, pyqtProperty from PyQt5.QtCore import QEvent, QPropertyAnimation, Qt, pyqtProperty
from PyQt5.QtWidgets import QAbstractButton, QSizePolicy, QWidget from PyQt5.QtWidgets import QAbstractButton, QSizePolicy, QWidget
from novelwriter import CONFIG from novelwriter import CONFIG, SHARED
class NSwitch(QAbstractButton): class NSwitch(QAbstractButton):
__slots__ = ("_xW", "_xH", "_xR", "_rB", "_rH", "_rR", "_offset") __slots__ = ("_xW", "_xH", "_xR", "_rB", "_rH", "_rR", "_offset")
def __init__(self, parent: QWidget | None = None, height: int = 0) -> None: def __init__(self, parent: QWidget, height: int = 0) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
self._xH = height or CONFIG.pxInt(20) self._xH = height or SHARED.theme.baseButtonHeight
self._xW = 2*self._xH self._xW = 2*self._xH
self._xR = int(self._xH*0.5) self._xR = int(self._xH*0.5)
self._rB = int(CONFIG.guiScale*2) self._rB = CONFIG.pxInt(2)
self._rH = self._xH - 2*self._rB self._rH = self._xH - 2*self._rB
self._rR = self._xR - self._rB self._rR = self._xR - self._rB
+1 -1
View File
@@ -54,7 +54,7 @@ class GuiSideBar(QWidget):
self.mainGui = mainGui self.mainGui = mainGui
iPx = CONFIG.pxInt(24) iPx = int(1.2*SHARED.theme.baseButtonHeight)
self.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0)
self.installEventFilter(StatusTipFilter(mainGui)) self.installEventFilter(StatusTipFilter(mainGui))
+2
View File
@@ -159,6 +159,7 @@ class GuiTheme:
self.fontPointSize = self.guiFont.pointSizeF() self.fontPointSize = self.guiFont.pointSizeF()
self.fontPixelSize = int(round(qMetric.height())) self.fontPixelSize = int(round(qMetric.height()))
self.baseIconSize = int(round(qMetric.ascent())) self.baseIconSize = int(round(qMetric.ascent()))
self.baseButtonHeight = int(round(1.35*qMetric.ascent()))
self.textNHeight = qMetric.boundingRect("N").height() self.textNHeight = qMetric.boundingRect("N").height()
self.textNWidth = qMetric.boundingRect("N").width() self.textNWidth = qMetric.boundingRect("N").width()
@@ -171,6 +172,7 @@ class GuiTheme:
logger.debug("GUI Font Point Size: %.2f", self.fontPointSize) logger.debug("GUI Font Point Size: %.2f", self.fontPointSize)
logger.debug("GUI Font Pixel Size: %d", self.fontPixelSize) logger.debug("GUI Font Pixel Size: %d", self.fontPixelSize)
logger.debug("GUI Base Icon Size: %d", self.baseIconSize) logger.debug("GUI Base Icon Size: %d", self.baseIconSize)
logger.debug("GUI Base Button Height: %d", self.baseButtonHeight)
logger.debug("Text 'N' Height: %d", self.textNHeight) logger.debug("Text 'N' Height: %d", self.textNHeight)
logger.debug("Text 'N' Width: %d", self.textNWidth) logger.debug("Text 'N' Width: %d", self.textNWidth)
+4 -3
View File
@@ -53,12 +53,13 @@ class GuiLipsum(QDialog):
self.setWindowTitle(self.tr("Insert Placeholder Text")) self.setWindowTitle(self.tr("Insert Placeholder Text"))
vSp = CONFIG.pxInt(4)
nPx = CONFIG.pxInt(64)
self.innerBox = QHBoxLayout() self.innerBox = QHBoxLayout()
self.innerBox.setSpacing(CONFIG.pxInt(16)) self.innerBox.setSpacing(CONFIG.pxInt(16))
# Icon # Icon
nPx = CONFIG.pxInt(64)
vSp = CONFIG.pxInt(4)
self.docIcon = QLabel() self.docIcon = QLabel()
self.docIcon.setPixmap(SHARED.theme.getPixmap("proj_document", (nPx, nPx))) self.docIcon.setPixmap(SHARED.theme.getPixmap("proj_document", (nPx, nPx)))
@@ -78,7 +79,7 @@ class GuiLipsum(QDialog):
self.paraCount.setValue(5) self.paraCount.setValue(5)
self.randLabel = QLabel(self.tr("Randomise order")) self.randLabel = QLabel(self.tr("Randomise order"))
self.randSwitch = NSwitch() self.randSwitch = NSwitch(self)
self.formBox = QGridLayout() self.formBox = QGridLayout()
self.formBox.addWidget(self.headLabel, 0, 0, 1, 2, Qt.AlignLeft) self.formBox.addWidget(self.headLabel, 0, 0, 1, 2, Qt.AlignLeft)
+7 -7
View File
@@ -187,43 +187,43 @@ class GuiWritingStats(QDialog):
self.infoForm.setRowStretch(6, 1) self.infoForm.setRowStretch(6, 1)
# Filter Options # Filter Options
sPx = SHARED.theme.baseIconSize iPx = SHARED.theme.baseIconSize
self.filterBox = QGroupBox(self.tr("Filters"), self) self.filterBox = QGroupBox(self.tr("Filters"), self)
self.filterForm = QGridLayout(self) self.filterForm = QGridLayout(self)
self.filterBox.setLayout(self.filterForm) self.filterBox.setLayout(self.filterForm)
self.incNovel = NSwitch(self, height=sPx) self.incNovel = NSwitch(self, height=iPx)
self.incNovel.setChecked( self.incNovel.setChecked(
pOptions.getBool("GuiWritingStats", "incNovel", True) pOptions.getBool("GuiWritingStats", "incNovel", True)
) )
self.incNovel.clicked.connect(self._updateListBox) self.incNovel.clicked.connect(self._updateListBox)
self.incNotes = NSwitch(self, height=sPx) self.incNotes = NSwitch(self, height=iPx)
self.incNotes.setChecked( self.incNotes.setChecked(
pOptions.getBool("GuiWritingStats", "incNotes", True) pOptions.getBool("GuiWritingStats", "incNotes", True)
) )
self.incNotes.clicked.connect(self._updateListBox) self.incNotes.clicked.connect(self._updateListBox)
self.hideZeros = NSwitch(self, height=sPx) self.hideZeros = NSwitch(self, height=iPx)
self.hideZeros.setChecked( self.hideZeros.setChecked(
pOptions.getBool("GuiWritingStats", "hideZeros", True) pOptions.getBool("GuiWritingStats", "hideZeros", True)
) )
self.hideZeros.clicked.connect(self._updateListBox) self.hideZeros.clicked.connect(self._updateListBox)
self.hideNegative = NSwitch(self, height=sPx) self.hideNegative = NSwitch(self, height=iPx)
self.hideNegative.setChecked( self.hideNegative.setChecked(
pOptions.getBool("GuiWritingStats", "hideNegative", False) pOptions.getBool("GuiWritingStats", "hideNegative", False)
) )
self.hideNegative.clicked.connect(self._updateListBox) self.hideNegative.clicked.connect(self._updateListBox)
self.groupByDay = NSwitch(self, height=sPx) self.groupByDay = NSwitch(self, height=iPx)
self.groupByDay.setChecked( self.groupByDay.setChecked(
pOptions.getBool("GuiWritingStats", "groupByDay", False) pOptions.getBool("GuiWritingStats", "groupByDay", False)
) )
self.groupByDay.clicked.connect(self._updateListBox) self.groupByDay.clicked.connect(self._updateListBox)
self.showIdleTime = NSwitch(self, height=sPx) self.showIdleTime = NSwitch(self, height=iPx)
self.showIdleTime.setChecked( self.showIdleTime.setChecked(
pOptions.getBool("GuiWritingStats", "showIdleTime", False) pOptions.getBool("GuiWritingStats", "showIdleTime", False)
) )