Add a custom box layout for the wrapped widget
This commit is contained in:
@@ -7,6 +7,7 @@ Created: 2020-05-03 [0.4.5] NColourLabel
|
||||
Created: 2024-01-08 [2.3b1] NScrollableForm
|
||||
Created: 2024-01-26 [2.3b1] NScrollablePage
|
||||
Created: 2024-01-26 [2.3b1] NFixedPage
|
||||
Created: 2024-03-12 [2.4b1] NWrappedWidgetBox
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2024, Veronica Berglyd Olsen
|
||||
@@ -269,3 +270,24 @@ class NColourLabel(QLabel):
|
||||
return
|
||||
|
||||
# END Class NColourLabel
|
||||
|
||||
|
||||
class NWrappedWidgetBox(QHBoxLayout):
|
||||
"""Extension: A Text-Wrapped Widget Box
|
||||
|
||||
A custom layout box where a widget is wrapped within the box. The
|
||||
widget is inserted at the {0} position so that it can be used for
|
||||
translation strings.
|
||||
"""
|
||||
|
||||
def __init__(self, text: str, widget: QWidget) -> None:
|
||||
super().__init__()
|
||||
before, _, after = text.partition(r"{0}")
|
||||
if before:
|
||||
self.addWidget(QLabel(before.rstrip()))
|
||||
self.addWidget(widget)
|
||||
if after:
|
||||
self.addWidget(QLabel(after.lstrip()))
|
||||
return
|
||||
|
||||
# END Class NWrappedWidgetBox
|
||||
|
||||
@@ -45,6 +45,7 @@ from novelwriter.enum import nwItemClass
|
||||
from novelwriter.common import formatInt, makeFileNameSafe
|
||||
from novelwriter.constants import nwFiles
|
||||
from novelwriter.core.coretools import ProjectBuilder
|
||||
from novelwriter.extensions.configlayout import NWrappedWidgetBox
|
||||
from novelwriter.extensions.switch import NSwitch
|
||||
from novelwriter.extensions.modified import NSpinBox
|
||||
from novelwriter.extensions.versioninfo import VersionInfoWidget
|
||||
@@ -630,27 +631,18 @@ class _NewProjectForm(QWidget):
|
||||
self.numChapters.setValue(5)
|
||||
self.numChapters.setToolTip(self.tr("Set to 0 to only add scenes"))
|
||||
|
||||
lblChA, _, lblChB = self.tr("Add {0} chapter documents").partition(r"{0}")
|
||||
lblScA, _, lblScB = self.tr("Add {0} scene documents (to each chapter)").partition(r"{0}")
|
||||
|
||||
self.chapterBox = QHBoxLayout()
|
||||
if lblChA:
|
||||
self.chapterBox.addWidget(QLabel(lblChA))
|
||||
self.chapterBox.addWidget(self.numChapters)
|
||||
if lblChB:
|
||||
self.chapterBox.addWidget(QLabel(lblChB))
|
||||
self.chapterBox = NWrappedWidgetBox(
|
||||
self.tr("Add {0} chapter documents"), self.numChapters
|
||||
)
|
||||
self.chapterBox.addStretch(1)
|
||||
|
||||
self.numScenes = NSpinBox(self)
|
||||
self.numScenes.setRange(0, 200)
|
||||
self.numScenes.setValue(5)
|
||||
|
||||
self.sceneBox = QHBoxLayout()
|
||||
if lblScA:
|
||||
self.sceneBox.addWidget(QLabel(lblScA))
|
||||
self.sceneBox.addWidget(self.numScenes)
|
||||
if lblScB:
|
||||
self.sceneBox.addWidget(QLabel(lblScB))
|
||||
self.sceneBox = NWrappedWidgetBox(
|
||||
self.tr("Add {0} scene documents (to each chapter)"), self.numScenes
|
||||
)
|
||||
self.sceneBox.addStretch(1)
|
||||
|
||||
self.novelForm = QVBoxLayout()
|
||||
|
||||
Reference in New Issue
Block a user