1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-11-14 03:29:02 +00:00

Initial work on #653

- Update both qt/directories_dialog.py and qt/result_window.py to have
the same resizing on out of bounds.
- Update moveToScreenCenter to do most of the checks needed
- Add additional preference to help track maximized position of
results window
This commit is contained in:
Andrew Senetar 2020-05-13 23:07:14 -05:00
parent debf309a9a
commit fa87f76298
Signed by: arsenetar
GPG Key ID: C63300DCE48AB2F1
4 changed files with 39 additions and 23 deletions

View File

@ -206,8 +206,6 @@ class DirectoriesDialog(QMainWindow):
if self.app.prefs.directoriesWindowRect is not None:
self.setGeometry(self.app.prefs.directoriesWindowRect)
else:
moveToScreenCenter(self)
def _setupColumns(self):
header = self.treeView.header()
@ -326,3 +324,9 @@ class DirectoriesDialog(QMainWindow):
def selectionChanged(self, selected, deselected):
self._updateRemoveButton()
def showEvent(self, event):
if self.isMaximized() is False:
# have to do this here as the frameGeometry is not correct until shown
moveToScreenCenter(self)
super().showEvent(event)

View File

@ -30,7 +30,7 @@ class Preferences(PreferencesBase):
self.language = trans.installed_lang
self.tableFontSize = get("TableFontSize", self.tableFontSize)
self.reference_bold_font = get('ReferenceBoldFont', self.reference_bold_font)
self.reference_bold_font = get("ReferenceBoldFont", self.reference_bold_font)
self.resultWindowIsMaximized = get(
"ResultWindowIsMaximized", self.resultWindowIsMaximized
)
@ -68,6 +68,7 @@ class Preferences(PreferencesBase):
self.tableFontSize = QApplication.font().pointSize()
self.reference_bold_font = True
self.resultWindowIsMaximized = False
self.resultWindowMaximizeLocation = None
self.resultWindowRect = None
self.directoriesWindowRect = None
self.recentResults = []
@ -99,7 +100,7 @@ class Preferences(PreferencesBase):
set_("Language", self.language)
set_("TableFontSize", self.tableFontSize)
set_('ReferenceBoldFont', self.reference_bold_font)
set_("ReferenceBoldFont", self.reference_bold_font)
set_("ResultWindowIsMaximized", self.resultWindowIsMaximized)
self.set_rect("ResultWindowRect", self.resultWindowRect)
self.set_rect("DirectoriesWindowRect", self.directoriesWindowRect)

View File

@ -20,7 +20,6 @@ from PyQt5.QtWidgets import (
QDialog,
QPushButton,
QCheckBox,
QDesktopWidget,
)
from hscommon.trans import trget
@ -344,21 +343,12 @@ class ResultWindow(QMainWindow):
self.statusLabel = QLabel(self)
self.statusbar.addPermanentWidget(self.statusLabel, 1)
if self.app.prefs.resultWindowRect is not None:
self.setGeometry(self.app.prefs.resultWindowRect)
if self.app.prefs.resultWindowIsMaximized:
if self.app.prefs.resultWindowMaximizeLocation is not None:
self.move(self.app.prefs.resultWindowMaximizeLocation)
self.setWindowState(self.windowState() | Qt.WindowMaximized)
else:
if self.app.prefs.resultWindowRect is not None:
self.setGeometry(self.app.prefs.resultWindowRect)
# if not on any screen move to center of default screen
# moves to center of closest screen if partially off screen
frame = self.frameGeometry()
if QDesktopWidget().screenNumber(self) == -1:
moveToScreenCenter(self)
elif QDesktopWidget().availableGeometry(self).contains(frame) is False:
frame.moveCenter(QDesktopWidget().availableGeometry(self).center())
self.move(frame.topLeft())
else:
moveToScreenCenter(self)
# --- Private
def _update_column_actions_status(self):
@ -452,7 +442,10 @@ class ResultWindow(QMainWindow):
def appWillSavePrefs(self):
prefs = self.app.prefs
prefs.resultWindowIsMaximized = self.isMaximized()
prefs.resultWindowRect = self.geometry()
if self.isMaximized():
prefs.resultWindowMaximizeLocation = self.geometry().topLeft()
else:
prefs.resultWindowRect = self.geometry()
def columnToggled(self, action):
index = action.item_index
@ -478,3 +471,9 @@ class ResultWindow(QMainWindow):
def closeEvent(self, event):
# this saves the location of the results window when it is closed
self.appWillSavePrefs()
def showEvent(self, event):
if self.isMaximized() is False:
# have to do this here as the frameGeometry is not correct until shown
moveToScreenCenter(self)
super().showEvent(event)

View File

@ -15,9 +15,8 @@ import logging
from hscommon.util import first
from PyQt5.QtCore import QStandardPaths
from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtGui import QPixmap, QIcon, QGuiApplication
from PyQt5.QtWidgets import (
QDesktopWidget,
QSpacerItem,
QSizePolicy,
QAction,
@ -27,8 +26,21 @@ from PyQt5.QtWidgets import (
def moveToScreenCenter(widget):
frame = widget.frameGeometry()
frame.moveCenter(QDesktopWidget().availableGeometry().center())
widget.move(frame.topLeft())
if QGuiApplication.screenAt(frame.center()) is None:
# if center not on any screen use default screen
screen = QGuiApplication.screens[0].availableGeometry()
else:
screen = QGuiApplication.screenAt(frame.center()).availableGeometry()
# moves to center of screen if partially off screen
if screen.contains(frame) is False:
# make sure the frame is not larger than screen
# resize does not seem to take frame size into account (move does)
widget.resize(
frame.size().boundedTo(screen.size() - (frame.size() - widget.size()))
)
frame = widget.frameGeometry()
frame.moveCenter(screen.center())
widget.move(frame.topLeft())
def verticalSpacer(size=None):