From 8a61d57ce472cc67a0cfd680fef53efee284704a Mon Sep 17 00:00:00 2001
From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com>
Date: Tue, 19 Dec 2023 17:29:33 +0100
Subject: [PATCH] Update title on welcome dialog
---
.../assets/images/novelwriter-text-dark.svg | 4 ++
.../assets/images/novelwriter-text-light.svg | 4 ++
novelwriter/config.py | 13 +++++
novelwriter/core/options.py | 2 +-
novelwriter/gui/theme.py | 19 ++++---
novelwriter/tools/welcome.py | 56 +++++++++++++++----
6 files changed, 78 insertions(+), 20 deletions(-)
create mode 100644 novelwriter/assets/images/novelwriter-text-dark.svg
create mode 100644 novelwriter/assets/images/novelwriter-text-light.svg
diff --git a/novelwriter/assets/images/novelwriter-text-dark.svg b/novelwriter/assets/images/novelwriter-text-dark.svg
new file mode 100644
index 00000000..c80b2b8d
--- /dev/null
+++ b/novelwriter/assets/images/novelwriter-text-dark.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/novelwriter/assets/images/novelwriter-text-light.svg b/novelwriter/assets/images/novelwriter-text-light.svg
new file mode 100644
index 00000000..8af7fa12
--- /dev/null
+++ b/novelwriter/assets/images/novelwriter-text-light.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/novelwriter/config.py b/novelwriter/config.py
index debe960b..501c7f22 100644
--- a/novelwriter/config.py
+++ b/novelwriter/config.py
@@ -110,6 +110,7 @@ class Config:
# Size Settings
self._mainWinSize = [1200, 650] # Last size of the main GUI window
+ self._welcomeSize = [800, 500] # Last size of the welcome window
self._prefsWinSize = [700, 615] # Last size of the Preferences dialog
self._projLoadCols = [280, 60, 160] # Last columns widths of the Project Load dialog
self._mainPanePos = [300, 800] # Last position of the main window splitter
@@ -249,6 +250,10 @@ class Config:
def mainWinSize(self) -> list[int]:
return [int(x*self.guiScale) for x in self._mainWinSize]
+ @property
+ def welcomeWinSize(self) -> list[int]:
+ return [int(x*self.guiScale) for x in self._welcomeSize]
+
@property
def preferencesWinSize(self) -> list[int]:
return [int(x*self.guiScale) for x in self._prefsWinSize]
@@ -306,6 +311,12 @@ class Config:
self._mainWinSize[1] = height
return
+ def setWelcomeWinSize(self, width: int, height: int) -> None:
+ """Set the size of the Preferences dialog window."""
+ self._welcomeSize[0] = int(width/self.guiScale)
+ self._welcomeSize[1] = int(height/self.guiScale)
+ return
+
def setPreferencesWinSize(self, width: int, height: int) -> None:
"""Set the size of the Preferences dialog window."""
self._prefsWinSize[0] = int(width/self.guiScale)
@@ -545,6 +556,7 @@ class Config:
# Sizes
sec = "Sizes"
self._mainWinSize = conf.rdIntList(sec, "mainwindow", self._mainWinSize)
+ self._welcomeSize = conf.rdIntList(sec, "welcome", self._welcomeSize)
self._prefsWinSize = conf.rdIntList(sec, "preferences", self._prefsWinSize)
self._projLoadCols = conf.rdIntList(sec, "projloadcols", self._projLoadCols)
self._mainPanePos = conf.rdIntList(sec, "mainpane", self._mainPanePos)
@@ -652,6 +664,7 @@ class Config:
conf["Sizes"] = {
"mainwindow": self._packList(self._mainWinSize),
+ "welcome": self._packList(self._welcomeSize),
"preferences": self._packList(self._prefsWinSize),
"projloadcols": self._packList(self._projLoadCols),
"mainpane": self._packList(self._mainPanePos),
diff --git a/novelwriter/core/options.py b/novelwriter/core/options.py
index a219cfc1..90364dfe 100644
--- a/novelwriter/core/options.py
+++ b/novelwriter/core/options.py
@@ -42,7 +42,7 @@ logger = logging.getLogger(__name__)
NWEnum = TypeVar("NWEnum", bound=Enum)
-VALID_MAP = {
+VALID_MAP: dict[str, set[str]] = {
"GuiWritingStats": {
"winWidth", "winHeight", "widthCol0", "widthCol1", "widthCol2",
"widthCol3", "sortCol", "sortOrder", "incNovel", "incNotes",
diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py
index a5d731bf..1c8572d3 100644
--- a/novelwriter/gui/theme.py
+++ b/novelwriter/gui/theme.py
@@ -67,6 +67,7 @@ class GuiTheme:
self.themeLicense = ""
self.themeLicenseUrl = ""
self.themeIcons = ""
+ self.isLightTheme = True
# GUI
self.statNone = [120, 120, 120]
@@ -112,7 +113,7 @@ class GuiTheme:
self._setGuiFont()
# Load Themes
- self._guiPalette = QPalette()
+ self._guiPalette = QPalette()
self._themeList: list[tuple[str, str]] = []
self._syntaxList: list[tuple[str, str]] = []
self._availThemes: dict[str, Path] = {}
@@ -256,7 +257,8 @@ class GuiTheme:
textLNess = textCol.lightnessF()
if self.helpText == [0, 0, 0]:
- if backLNess > textLNess:
+ self.isLightTheme = backLNess > textLNess
+ if self.isLightTheme:
helpLCol = textLNess + 0.35*(backLNess - textLNess)
else:
helpLCol = backLNess + 0.65*(textLNess - backLNess)
@@ -443,7 +445,7 @@ class GuiIcons:
missing, a blank icon is returned and a warning issued.
"""
- ICON_KEYS = {
+ ICON_KEYS: set[str] = {
# Project and GUI Icons
"novelwriter", "alert_error", "alert_info", "alert_question", "alert_warn",
"build_excluded", "build_filtered", "build_included", "proj_chapter", "proj_details",
@@ -478,13 +480,15 @@ class GuiIcons:
"deco_doc_nt_n",
}
- TOGGLE_ICON_KEYS = {
+ TOGGLE_ICON_KEYS: dict[str, tuple[str, str]] = {
"sticky": ("sticky-on", "sticky-off"),
"bullet": ("bullet-on", "bullet-off"),
}
- IMAGE_MAP = {
- "wiz-back": "wizard-back.jpg",
+ IMAGE_MAP: dict[str, tuple[str, str]] = {
+ "wiz-back": ("wizard-back.jpg", "wizard-back.jpg"),
+ "welcome": ("welcome.jpg", "welcome.jpg"),
+ "nw-text": ("novelwriter-text-light.svg", "novelwriter-text-dark.svg"),
}
def __init__(self, mainTheme: GuiTheme) -> None:
@@ -598,7 +602,8 @@ class GuiIcons:
if name in self._themeMap:
imgPath = self._themeMap[name]
elif name in self.IMAGE_MAP:
- imgPath = CONFIG.assetPath("images") / self.IMAGE_MAP[name]
+ idx = 0 if self.mainTheme.isLightTheme else 1
+ imgPath = CONFIG.assetPath("images") / self.IMAGE_MAP[name][idx]
else:
logger.error("Decoration with name '%s' does not exist", name)
return QPixmap()
diff --git a/novelwriter/tools/welcome.py b/novelwriter/tools/welcome.py
index 3e2328c2..1800706e 100644
--- a/novelwriter/tools/welcome.py
+++ b/novelwriter/tools/welcome.py
@@ -28,7 +28,7 @@ import logging
from typing import TYPE_CHECKING
from datetime import datetime
-from PyQt5.QtGui import QPaintEvent, QPainter, QPixmap
+from PyQt5.QtGui import QCloseEvent, QPaintEvent, QPainter
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (
QDialog, QDialogButtonBox, QHBoxLayout, QLabel, QStackedWidget,
@@ -36,6 +36,7 @@ from PyQt5.QtWidgets import (
)
from novelwriter import CONFIG, SHARED, __version__, __date__
+from novelwriter.constants import nwUnicode
if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain
@@ -50,19 +51,30 @@ class GuiWelcome(QDialog):
logger.debug("Create: GuiWelcome")
- self.bgImage = QPixmap(str(CONFIG.assetPath("images") / "welcome.jpg"))
+ self.setWindowTitle(self.tr("Welcome"))
+ self.setMinimumWidth(CONFIG.pxInt(700))
+ self.setMinimumHeight(CONFIG.pxInt(400))
+
+ hA = CONFIG.pxInt(8)
+ hB = CONFIG.pxInt(16)
+ hC = CONFIG.pxInt(24)
+ hD = CONFIG.pxInt(36)
+ hE = CONFIG.pxInt(48)
+ hF = CONFIG.pxInt(96)
+
+ self.resize(*CONFIG.welcomeWinSize)
+
+ self.bgImage = SHARED.theme.loadDecoration("welcome")
+ self.nwImage = SHARED.theme.loadDecoration("nw-text", h=hD)
self.nwLogo = QLabel()
- self.nwLogo.setPixmap(SHARED.theme.getPixmap("novelwriter", (96, 96)))
-
- font = self.font()
- font.setPointSize(48)
+ self.nwLogo.setPixmap(SHARED.theme.getPixmap("novelwriter", (hF, hF)))
self.nwLabel = QLabel("novelWriter")
- self.nwLabel.setFont(font)
+ self.nwLabel.setPixmap(self.nwImage)
- self.nwInfo = QLabel(self.tr("Version {0}, Released on {1}").format(
- __version__, datetime.strptime(__date__, "%Y-%m-%d").strftime("%x")
+ self.nwInfo = QLabel(self.tr("Version {0} {1} Released on {2}").format(
+ __version__, nwUnicode.U_ENDASH, datetime.strptime(__date__, "%Y-%m-%d").strftime("%x")
))
self.mainStack = QStackedWidget()
@@ -71,6 +83,8 @@ class GuiWelcome(QDialog):
# Buttons
# =======
self.btnBox = QDialogButtonBox(QDialogButtonBox.Open | QDialogButtonBox.Cancel, self)
+ self.btnBox.accepted.connect(self.accept)
+ self.btnBox.rejected.connect(self.close)
self.newButton = self.btnBox.addButton(self.tr("New Project"), QDialogButtonBox.ActionRole)
self.newButton.setIcon(SHARED.theme.getIcon("add"))
@@ -81,9 +95,12 @@ class GuiWelcome(QDialog):
# Assemble
# ========
self.innerBox = QVBoxLayout()
+ self.innerBox.addSpacing(hB)
self.innerBox.addWidget(self.nwLabel)
self.innerBox.addWidget(self.nwInfo)
+ self.innerBox.addSpacing(hA)
self.innerBox.addWidget(self.mainStack)
+ self.innerBox.addSpacing(hA)
self.innerBox.addWidget(self.btnBox)
topRight = Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignRight
@@ -91,12 +108,10 @@ class GuiWelcome(QDialog):
self.outerBox = QHBoxLayout()
self.outerBox.addWidget(self.nwLogo, 3, topRight)
self.outerBox.addLayout(self.innerBox, 7)
- self.outerBox.setContentsMargins(24, 24, 24, 96)
+ self.outerBox.setContentsMargins(hF, hE, hC, hE)
self.setLayout(self.outerBox)
- self.setMinimumSize(900, 500)
-
logger.debug("Ready: GuiWelcome")
return
@@ -119,6 +134,23 @@ class GuiWelcome(QDialog):
super().paintEvent(event)
return
+ def closeEvent(self, event: QCloseEvent) -> None:
+ """Capture the user closing the window and save settings."""
+ self._saveSettings()
+ event.accept()
+ self.deleteLater()
+ return
+
+ ##
+ # Internal Functions
+ ##
+
+ def _saveSettings(self) -> None:
+ """Save the user GUI settings."""
+ logger.debug("Saving State: GuiWelcome")
+ CONFIG.setWelcomeWinSize(self.width(), self.height())
+ return
+
# END Class GuiWelcome