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