Update closing project procedure, and editor scrolling (#1247)

This commit is contained in:
Veronica Berglyd Olsen
2022-11-16 11:28:47 +01:00
committed by GitHub
5 changed files with 40 additions and 36 deletions
-9
View File
@@ -130,15 +130,6 @@ class nwAlert(Enum):
# END Enum nwAlert # END Enum nwAlert
class nwState(Enum):
NONE = 0
BAD = 1
GOOD = 2
# END Enum nwState
class nwView(Enum): class nwView(Enum):
EDITOR = 0 EDITOR = 0
+11 -6
View File
@@ -666,12 +666,17 @@ class GuiDocEditor(QTextEdit):
theCursor.setPosition(minmax(position, 0, nChars-1)) theCursor.setPosition(minmax(position, 0, nChars-1))
self.setTextCursor(theCursor) self.setTextCursor(theCursor)
# The editor scrolls so the cursor is on the last line, so we must correct # By default, the editor scrolls so the cursor is on the
vPos = self.verticalScrollBar().value() # Current scrollbar position # last line, so we must correct it. The user setting for
cPos = self.cursorRect().topLeft().y() # Cursor position to scroll to # auto-scroll is used to determine the scroll distance. This
dMrg = int(self.document().documentMargin()) # Document margin to subtract # makes it compatible with the typewriter scrolling feature
mPos = int(self.viewport().height()*0.1) # Distance from top to adjust for (10%) # when it is enabled. By default, it's 30% of viewport.
self.verticalScrollBar().setValue(max(0, vPos + cPos - dMrg - mPos)) vPos = self.verticalScrollBar().value()
cPos = self.cursorRect().topLeft().y()
mPos = int(self.mainConf.autoScrollPos*0.01 * self.viewport().height())
if cPos > mPos:
# Only scroll if the cursor is past the auto-scroll limit
self.verticalScrollBar().setValue(max(0, vPos + cPos - mPos))
self.docFooter.updateLineCount() self.docFooter.updateLineCount()
+14 -11
View File
@@ -34,7 +34,6 @@ from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton
from novelwriter.common import formatTime from novelwriter.common import formatTime
from novelwriter.enum import nwState
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -53,8 +52,8 @@ class GuiMainStatus(QStatusBar):
self.userIdle = False self.userIdle = False
colNone = QColor(*self.mainTheme.statNone) colNone = QColor(*self.mainTheme.statNone)
colTrue = QColor(*self.mainTheme.statUnsaved) colSaved = QColor(*self.mainTheme.statSaved)
colFalse = QColor(*self.mainTheme.statSaved) colUnsaved = QColor(*self.mainTheme.statUnsaved)
iPx = self.mainTheme.baseIconSize iPx = self.mainTheme.baseIconSize
@@ -72,7 +71,7 @@ class GuiMainStatus(QStatusBar):
self.addPermanentWidget(self.langText) self.addPermanentWidget(self.langText)
# The Editor Status # The Editor Status
self.docIcon = StatusLED(colNone, colTrue, colFalse, iPx, iPx, self) self.docIcon = StatusLED(colNone, colSaved, colUnsaved, iPx, iPx, self)
self.docText = QLabel(self.tr("Editor")) self.docText = QLabel(self.tr("Editor"))
self.docIcon.setContentsMargins(0, 0, 0, 0) self.docIcon.setContentsMargins(0, 0, 0, 0)
self.docText.setContentsMargins(0, 0, xM, 0) self.docText.setContentsMargins(0, 0, xM, 0)
@@ -80,7 +79,7 @@ class GuiMainStatus(QStatusBar):
self.addPermanentWidget(self.docText) self.addPermanentWidget(self.docText)
# The Project Status # The Project Status
self.projIcon = StatusLED(colNone, colTrue, colFalse, iPx, iPx, self) self.projIcon = StatusLED(colNone, colSaved, colUnsaved, iPx, iPx, self)
self.projText = QLabel(self.tr("Project")) self.projText = QLabel(self.tr("Project"))
self.projIcon.setContentsMargins(0, 0, 0, 0) self.projIcon.setContentsMargins(0, 0, 0, 0)
self.projText.setContentsMargins(0, 0, xM, 0) self.projText.setContentsMargins(0, 0, xM, 0)
@@ -122,8 +121,8 @@ class GuiMainStatus(QStatusBar):
self.setRefTime(None) self.setRefTime(None)
self.setLanguage(None, "") self.setLanguage(None, "")
self.setProjectStats(0, 0) self.setProjectStats(0, 0)
self.setProjectStatus(nwState.NONE) self.setProjectStatus(StatusLED.S_NONE)
self.setDocumentStatus(nwState.NONE) self.setDocumentStatus(StatusLED.S_NONE)
self.updateTime() self.updateTime()
return True return True
@@ -236,14 +235,14 @@ class GuiMainStatus(QStatusBar):
def doUpdateProjectStatus(self, isChanged): def doUpdateProjectStatus(self, isChanged):
"""Slot for updating the project status. """Slot for updating the project status.
""" """
self.setProjectStatus(nwState.GOOD if isChanged else nwState.BAD) self.setProjectStatus(StatusLED.S_BAD if isChanged else StatusLED.S_GOOD)
return return
@pyqtSlot(bool) @pyqtSlot(bool)
def doUpdateDocumentStatus(self, isChanged): def doUpdateDocumentStatus(self, isChanged):
"""Slot for updating the document status. """Slot for updating the document status.
""" """
self.setDocumentStatus(nwState.GOOD if isChanged else nwState.BAD) self.setDocumentStatus(StatusLED.S_BAD if isChanged else StatusLED.S_GOOD)
return return
# END Class GuiMainStatus # END Class GuiMainStatus
@@ -251,6 +250,10 @@ class GuiMainStatus(QStatusBar):
class StatusLED(QAbstractButton): class StatusLED(QAbstractButton):
S_NONE = 0
S_BAD = 1
S_GOOD = 2
def __init__(self, colNone, colGood, colBad, sW, sH, parent=None): def __init__(self, colNone, colGood, colBad, sW, sH, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
@@ -271,9 +274,9 @@ class StatusLED(QAbstractButton):
def setState(self, theState): def setState(self, theState):
"""Set the colour state. """Set the colour state.
""" """
if theState == nwState.GOOD: if theState == self.S_GOOD:
self._theCol = self._colGood self._theCol = self._colGood
elif theState == nwState.BAD: elif theState == self.S_BAD:
self._theCol = self._colBad self._theCol = self._colBad
else: else:
self._theCol = self._colNone self._theCol = self._colNone
+8 -3
View File
@@ -312,7 +312,7 @@ class GuiMain(QMainWindow):
# Work Area # Work Area
self.docEditor.clearEditor() self.docEditor.clearEditor()
self.docEditor.setDictionaries() self.docEditor.setDictionaries()
self.closeDocViewer() self.closeDocViewer(byUser=False)
self.outlineView.clearProject() self.outlineView.clearProject()
# General # General
@@ -1220,14 +1220,19 @@ class GuiMain(QMainWindow):
self.theProject.data.setLastHandle(None, "editor") self.theProject.data.setLastHandle(None, "editor")
return return
def closeDocViewer(self): def closeDocViewer(self, byUser=True):
"""Close the document view panel. """Close the document view panel.
""" """
self.docViewer.clearViewer() self.docViewer.clearViewer()
self.theProject.data.setLastHandle(None, "viewer") if byUser:
# Only reset the last handle if the user called this
self.theProject.data.setLastHandle(None, "viewer")
# Hide the panel
bPos = self.splitMain.sizes() bPos = self.splitMain.sizes()
self.splitView.setVisible(False) self.splitView.setVisible(False)
self.splitDocs.setSizes([bPos[1], 0]) self.splitDocs.setSizes([bPos[1], 0])
return not self.splitView.isVisible() return not self.splitView.isVisible()
def toggleFocusMode(self): def toggleFocusMode(self):
+7 -7
View File
@@ -24,7 +24,7 @@ import pytest
from tools import C, buildTestProject from tools import C, buildTestProject
from novelwriter.enum import nwState from novelwriter.gui.statusbar import StatusLED
@pytest.mark.gui @pytest.mark.gui
@@ -44,19 +44,19 @@ def testGuiStatusBar_Main(qtbot, nwGUI, projPath, mockRnd):
assert nwGUI.mainStatus.refTime == refTime assert nwGUI.mainStatus.refTime == refTime
# Project Status # Project Status
nwGUI.mainStatus.setProjectStatus(nwState.NONE) nwGUI.mainStatus.setProjectStatus(StatusLED.S_NONE)
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colNone assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colNone
nwGUI.mainStatus.setProjectStatus(nwState.BAD) nwGUI.mainStatus.setProjectStatus(StatusLED.S_BAD)
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colBad assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colBad
nwGUI.mainStatus.setProjectStatus(nwState.GOOD) nwGUI.mainStatus.setProjectStatus(StatusLED.S_GOOD)
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colGood assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colGood
# Document Status # Document Status
nwGUI.mainStatus.setDocumentStatus(nwState.NONE) nwGUI.mainStatus.setDocumentStatus(StatusLED.S_NONE)
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colNone assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colNone
nwGUI.mainStatus.setDocumentStatus(nwState.BAD) nwGUI.mainStatus.setDocumentStatus(StatusLED.S_BAD)
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colBad assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colBad
nwGUI.mainStatus.setDocumentStatus(nwState.GOOD) nwGUI.mainStatus.setDocumentStatus(StatusLED.S_GOOD)
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colGood assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colGood
# Idle Status # Idle Status