Skip to content

Commit

Permalink
Initial work on #653
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
arsenetar committed May 14, 2020
1 parent debf309 commit fa87f76
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
8 changes: 6 additions & 2 deletions qt/directories_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ def _setupUi(self):

if self.app.prefs.directoriesWindowRect is not None:
self.setGeometry(self.app.prefs.directoriesWindowRect)
else:
moveToScreenCenter(self)

def _setupColumns(self):
header = self.treeView.header()
Expand Down Expand Up @@ -326,3 +324,9 @@ def scanTypeChanged(self, index):

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)
5 changes: 3 additions & 2 deletions qt/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _load_values(self, settings):
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
)
Expand Down Expand Up @@ -68,6 +68,7 @@ def reset(self):
self.tableFontSize = QApplication.font().pointSize()
self.reference_bold_font = True
self.resultWindowIsMaximized = False
self.resultWindowMaximizeLocation = None
self.resultWindowRect = None
self.directoriesWindowRect = None
self.recentResults = []
Expand Down Expand Up @@ -99,7 +100,7 @@ def _save_values(self, settings):
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)
Expand Down
29 changes: 14 additions & 15 deletions qt/result_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
QDialog,
QPushButton,
QCheckBox,
QDesktopWidget,
)

from hscommon.trans import trget
Expand Down Expand Up @@ -344,21 +343,12 @@ def _setupUi(self):
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):
Expand Down Expand Up @@ -452,7 +442,10 @@ def saveResultsTriggered(self):
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
Expand All @@ -478,3 +471,9 @@ def searchChanged(self):
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)
20 changes: 16 additions & 4 deletions qtlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
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,
Expand All @@ -27,8 +26,21 @@

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):
Expand Down

0 comments on commit fa87f76

Please sign in to comment.