Generalise the custom help label widget

This commit is contained in:
Veronica Berglyd Olsen
2024-01-22 23:55:37 +01:00
parent f35722ab35
commit 9f2c5379b7
4 changed files with 36 additions and 30 deletions
+5 -4
View File
@@ -35,7 +35,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED
from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.configlayout import NHelpLabel
from novelwriter.extensions.configlayout import NColourLabel
logger = logging.getLogger(__name__)
@@ -54,9 +54,10 @@ class GuiDocMerge(QDialog):
self._data = {}
self.headLabel = QLabel("<b>{0}</b>".format(self.tr("Documents to Merge")))
self.helpLabel = NHelpLabel(self.tr(
"Drag and drop items to change the order, or uncheck to exclude."
), SHARED.theme.helpText)
self.helpLabel = NColourLabel(
self.tr("Drag and drop items to change the order, or uncheck to exclude."),
SHARED.theme.helpText, parent=self, wrap=True
)
iPx = SHARED.theme.baseIconSize
hSp = CONFIG.pxInt(12)
+3 -3
View File
@@ -35,7 +35,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED
from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.configlayout import NHelpLabel
from novelwriter.extensions.configlayout import NColourLabel
logger = logging.getLogger(__name__)
@@ -58,9 +58,9 @@ class GuiDocSplit(QDialog):
self.setWindowTitle(self.tr("Split Document"))
self.headLabel = QLabel("<b>{0}</b>".format(self.tr("Document Headers")))
self.helpLabel = NHelpLabel(
self.helpLabel = NColourLabel(
self.tr("Select the maximum level to split into files."),
SHARED.theme.helpText
SHARED.theme.helpText, parent=self, wrap=True
)
# Values
+6 -12
View File
@@ -26,11 +26,11 @@ from __future__ import annotations
import logging
from PyQt5.QtGui import QCloseEvent, QFont, QKeyEvent, QKeySequence, QPalette
from PyQt5.QtGui import QCloseEvent, QFont, QKeyEvent, QKeySequence
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import (
QAbstractButton, QComboBox, QCompleter, QDialog, QDialogButtonBox,
QDoubleSpinBox, QFileDialog, QFontDialog, QHBoxLayout, QLabel, QLineEdit,
QDoubleSpinBox, QFileDialog, QFontDialog, QHBoxLayout, QLineEdit,
QPushButton, QSpinBox, QToolButton, QVBoxLayout, QWidget, qApp
)
@@ -38,7 +38,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.constants import nwConst, nwUnicode
from novelwriter.dialogs.quotes import GuiQuoteSelect
from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.configlayout import NScrollableForm
from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm
from novelwriter.extensions.pagedsidebar import NPagedSideBar
logger = logging.getLogger(__name__)
@@ -58,15 +58,9 @@ class GuiPreferences(QDialog):
self.resize(*CONFIG.preferencesWinSize)
# Title
font = self.font()
font.setPointSizeF(1.25*SHARED.theme.fontPointSize)
palette = self.palette()
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.helpText)
self.titleLabel = QLabel(self.tr("Preferences"), self)
self.titleLabel.setFont(font)
self.titleLabel.setPalette(palette)
self.titleLabel = NColourLabel(
self.tr("Preferences"), SHARED.theme.helpText, parent=self, scale=1.25
)
self.titleLabel.setIndent(CONFIG.pxInt(4))
# SideBar
+22 -11
View File
@@ -3,7 +3,7 @@ novelWriter Custom Widget: Config Layout
==========================================
File History:
Created: 2020-05-03 [0.4.5] NConfigLayout, NHelpLabel
Created: 2020-05-03 [0.4.5] NConfigLayout, NColourLabel
Created: 2023-05-23 [2.1b1] NSimpleLayout
Created: 2024-01-08 [2.3b1] NScrollableForm
@@ -40,6 +40,10 @@ LEFT_TOP = Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
class NScrollableForm(QScrollArea):
"""Extension: Scrollable Form Widget
A custom widget that creates a form within a scrollable area.
"""
def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent)
@@ -48,7 +52,7 @@ class NScrollableForm(QScrollArea):
self._first = True
self._sections: dict[int, QLabel] = {}
self._editable: dict[str, NHelpLabel] = {}
self._editable: dict[str, NColourLabel] = {}
self._index: dict[str, QWidget] = {}
self._layout = QVBoxLayout()
@@ -130,7 +134,7 @@ class NScrollableForm(QScrollArea):
qLabel.setBuddy(widget)
if helpText:
qHelp = NHelpLabel(str(helpText), self._helpCol, self._fontScale)
qHelp = NColourLabel(str(helpText), self._helpCol, scale=self._fontScale, wrap=True)
qHelp.setIndent(mPx)
labelBox = QVBoxLayout()
labelBox.addWidget(qLabel)
@@ -197,7 +201,7 @@ class NConfigLayout(QGridLayout):
"""Set the text for the help label."""
if row in self._itemMap:
qHelp = self._itemMap[row][1]
if isinstance(qHelp, NHelpLabel):
if isinstance(qHelp, NColourLabel):
qHelp.setText(text)
return
@@ -226,7 +230,7 @@ class NConfigLayout(QGridLayout):
qHelp = None
if helpText is not None:
qHelp = NHelpLabel(str(helpText), self._helpCol, self._fontScale)
qHelp = NColourLabel(str(helpText), self._helpCol, scale=self._fontScale, wrap=True)
qHelp.setIndent(wSp)
labelBox = QVBoxLayout()
labelBox.addWidget(qLabel)
@@ -326,10 +330,16 @@ class NSimpleLayout(QGridLayout):
# END Class NSimpleLayout
class NHelpLabel(QLabel):
class NColourLabel(QLabel):
"""Extension: A Coloured Label
def __init__(self, text: str, color: QColor, scale: float = FONT_SCALE) -> None:
super().__init__(text)
A custom widget that draws a label in a specific colour, and
optionally at a specific size, and word wrapped.
"""
def __init__(self, text: str, color: QColor, parent: QWidget | None = None,
scale: float = FONT_SCALE, wrap: bool = False) -> None:
super().__init__(text, parent=parent)
lblCol = self.palette()
lblCol.setColor(QPalette.WindowText, color)
@@ -339,9 +349,10 @@ class NHelpLabel(QLabel):
lblFont.setPointSizeF(scale*lblFont.pointSizeF())
self.setFont(lblFont)
self.setWordWrap(True)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
if wrap:
self.setWordWrap(True)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
return
# END Class NHelpLabel
# END Class NColourLabel