Fix some minor GUI issues

This commit is contained in:
Veronica Berglyd Olsen
2025-01-11 21:42:37 +01:00
parent 86f210cfbf
commit 1307fccc59
3 changed files with 11 additions and 28 deletions
+4 -6
View File
@@ -23,15 +23,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from PyQt6.QtCore import QByteArray, QPropertyAnimation, Qt
from PyQt6.QtCore import QPropertyAnimation, Qt, pyqtProperty
from PyQt6.QtGui import QEnterEvent, QMouseEvent, QPainter, QPaintEvent, QResizeEvent
from PyQt6.QtWidgets import QAbstractButton, QWidget
from novelwriter import CONFIG, SHARED
from novelwriter.types import QtMouseLeft, QtNoPen, QtPaintAntiAlias, QtSizeFixed
OFFSET = QByteArray(b"offset") # type: ignore
class NSwitch(QAbstractButton):
@@ -59,11 +57,11 @@ class NSwitch(QAbstractButton):
# Properties
##
@property
@pyqtProperty(int)
def offset(self) -> int: # type: ignore
return self._offset
@offset.setter # type: ignore
@offset.setter
def offset(self, offset: int) -> None:
self._offset = offset
self.update()
@@ -123,7 +121,7 @@ class NSwitch(QAbstractButton):
"""Animate the switch on mouse release."""
super().mouseReleaseEvent(event)
if event.button() == QtMouseLeft:
anim = QPropertyAnimation(self, OFFSET, self)
anim = QPropertyAnimation(self, b"offset", self)
anim.setDuration(120)
anim.setStartValue(self._offset)
anim.setEndValue((self._xW - self._xR) if self.isChecked() else self._xR)
+3 -14
View File
@@ -29,8 +29,8 @@ from datetime import datetime
from pathlib import Path
from PyQt6.QtCore import (
QAbstractListModel, QEvent, QModelIndex, QObject, QPoint, QSize, Qt,
pyqtSignal, pyqtSlot
QAbstractListModel, QModelIndex, QObject, QPoint, QSize, Qt, pyqtSignal,
pyqtSlot
)
from PyQt6.QtGui import QAction, QCloseEvent, QColor, QFont, QPainter, QPaintEvent, QPen, QShortcut
from PyQt6.QtWidgets import (
@@ -590,7 +590,7 @@ class _NewProjectForm(QWidget):
self.browseFill = NIconToolButton(self, iSz, "document_add", "blue")
self.fillMenu = _PopLeftDirectionMenu(self.browseFill)
self.fillMenu = QMenu(self.browseFill)
self.fillBlank = self.fillMenu.addAction(self.tr("Create a fresh project"))
self.fillBlank.setIcon(SHARED.theme.getIcon("document"))
@@ -802,14 +802,3 @@ class _NewProjectForm(QWidget):
self.extraWidget.setVisible(self._fillMode == self.FILL_BLANK)
return
class _PopLeftDirectionMenu(QMenu):
def event(self, event: QEvent) -> bool:
"""Overload the show event and move the menu popup location."""
if event.type() == QEvent.Type.Show:
if isinstance(parent := self.parent(), QWidget):
offset = QPoint(parent.width() - self.width(), parent.height())
self.move(parent.mapToGlobal(offset))
return super(_PopLeftDirectionMenu, self).event(event)