This commit is contained in:
恍兮惚兮 2024-09-16 21:09:07 +08:00
parent a02cdb5cce
commit 65e1dc652e
3 changed files with 47 additions and 12 deletions

View File

@ -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)

View File

@ -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]
)

View File

@ -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)