diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 0095aa17..510b1bd2 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -18,10 +18,15 @@ from gui.setting_about import doupdate from gui.dialog_memory import dialog_memory from gui.textbrowser import Textbrowser from gui.rangeselect import rangeselct_function -from gui.usefulwidget import resizableframeless, getQMessageBox, LIconLabel +from gui.usefulwidget import ( + resizableframeless, + getQMessageBox, + LIconLabel, + findnearestscreen, +) from gui.edittext import edittrans from gui.dialog_savedgame import dialog_savedgame_integrated -from gui.dialog_savedgame_setting import browserdialog +from gui.dialog_savedgame_setting import browserdialog, calculate_centered_rect from gui.dynalang import LDialog @@ -699,6 +704,7 @@ class TranslatorWindow(resizableframeless): self.hide() def show_(self): + if globalconfig["showintab"]: windows.ShowWindow(self.winid, windows.SW_SHOWNOACTIVATE) else: @@ -706,6 +712,12 @@ class TranslatorWindow(resizableframeless): windows.SetForegroundWindow(self.winid) gobject.baseobject.commonstylebase.hide() + # 若窗口飞了,则将窗口拉回来 + usescreen, mindis = findnearestscreen(self.geometry()) + if mindis < 0: + return + self.setGeometry(calculate_centered_rect(usescreen.geometry(), self.size())) + def aftershowdosomething(self): windows.SetForegroundWindow(self.winid) diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 530ba7ec..c0d034fb 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -308,6 +308,36 @@ def makerect(_): return [x, x + w, y, y + h] +def findnearestscreen(rect: QRect): + # QScreen ,distance + # -1时,是有交集 + # -2时,是被包围 + # >=0时,是不在任何屏幕内 + mindis = 9999999999 + usescreen = QApplication.primaryScreen() + for screen in QApplication.screens(): + rect1, rect2 = screen.geometry(), rect + if rect1.contains(rect2): + return screen, -2 + if rect1.intersects(rect2): + r = rect1.intersected(rect2) + area = r.width() * r.width() + dis = -area + else: + distances = [] + distances.append(abs(rect1.right() - rect2.left())) + distances.append(abs(rect1.left() - rect2.right())) + distances.append(abs(rect1.bottom() - rect2.top())) + distances.append(abs(rect1.top() - rect2.bottom())) + dis = min(distances) + if dis < mindis: + mindis = dis + usescreen = screen + if mindis < 0: + mindis = -1 + return usescreen, mindis + + class saveposwindow(LMainWindow): def __init__(self, parent, poslist=None, flags=None) -> None: if flags: @@ -317,17 +347,10 @@ class saveposwindow(LMainWindow): self.poslist = poslist if self.poslist: - contains = False - usescreen = QApplication.primaryScreen() - for screen in QApplication.screens(): - if not screen.geometry().contains(QPoint(poslist[0], poslist[1])): - continue - contains = True - usescreen = screen - break + usescreen, mindis = findnearestscreen(QRect(poslist[0], poslist[1], 1, 1)) poslist[2] = max(0, min(poslist[2], usescreen.size().width())) poslist[3] = max(0, min(poslist[3], usescreen.size().height())) - if not contains: + if mindis != -2: poslist[0] = min( max(poslist[0], 0), usescreen.size().width() - poslist[2] ) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index c4bddf51..c4483544 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 36) -set(VERSION_PATCH 4) +set(VERSION_PATCH 5) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)