This commit is contained in:
恍兮惚兮 2024-12-20 15:09:55 +08:00
parent a9cfd873aa
commit e6839de4e3
6 changed files with 261 additions and 215 deletions

View File

@ -23,6 +23,7 @@ from gui.usefulwidget import (
getboxlayout, getboxlayout,
MySwitch, MySwitch,
Prompt_dialog, Prompt_dialog,
IconButton,
getsimplecombobox, getsimplecombobox,
) )
from gui.dialog_savedgame_common import ( from gui.dialog_savedgame_common import (
@ -48,6 +49,7 @@ from gui.dialog_savedgame_common import (
class dialog_savedgame_integrated(saveposwindow): class dialog_savedgame_integrated(saveposwindow):
def selectlayout(self, type): def selectlayout(self, type):
self.syssettingbtn.setVisible(type != 2)
try: try:
globalconfig["gamemanager_integrated_internal_layout"] = type globalconfig["gamemanager_integrated_internal_layout"] = type
klass = [ klass = [
@ -83,6 +85,7 @@ class dialog_savedgame_integrated(saveposwindow):
[self.layout1btn, self.layout2btn, self.layout3btn][ [self.layout1btn, self.layout2btn, self.layout3btn][
(type + 2) % 3 (type + 2) % 3
].setEnabled(True) ].setEnabled(True)
self.__internal = _
except: except:
print_exc() print_exc()
@ -99,7 +102,7 @@ class dialog_savedgame_integrated(saveposwindow):
w, self.internallayout = getboxlayout( w, self.internallayout = getboxlayout(
[], margin0=True, makewidget=True, both=True [], margin0=True, makewidget=True, both=True
) )
self.__internal = None
self.internallayout.addWidget(QWidget()) self.internallayout.addWidget(QWidget())
self.setCentralWidget(w) self.setCentralWidget(w)
self.layout1btn = MySwitch(self, icon="fa.th") self.layout1btn = MySwitch(self, icon="fa.th")
@ -108,22 +111,41 @@ class dialog_savedgame_integrated(saveposwindow):
self.layout1btn.clicked.connect(functools.partial(self.selectlayout, 0)) self.layout1btn.clicked.connect(functools.partial(self.selectlayout, 0))
self.layout2btn.clicked.connect(functools.partial(self.selectlayout, 1)) self.layout2btn.clicked.connect(functools.partial(self.selectlayout, 1))
self.layout3btn.clicked.connect(functools.partial(self.selectlayout, 2)) self.layout3btn.clicked.connect(functools.partial(self.selectlayout, 2))
self.layout1btn.setFixedSize(QSize(20, 20)) self.layout1btn.setFixedSize(QSize(20, 25))
self.layout2btn.setFixedSize(QSize(20, 20)) self.layout2btn.setFixedSize(QSize(20, 25))
self.layout3btn.setFixedSize(QSize(20, 20)) self.layout3btn.setFixedSize(QSize(20, 25))
self.syssettingbtn = IconButton(icon="fa.gear", parent=self)
self.syssettingbtn.setFixedSize(QSize(25, 25))
self.syssettingbtn.clicked.connect(self.syssetting)
self.show() self.show()
self.selectlayout(globalconfig["gamemanager_integrated_internal_layout"]) self.selectlayout(globalconfig["gamemanager_integrated_internal_layout"])
def syssetting(self):
dialog_syssetting(
self.__internal,
type_={0: 1, 1: 2}[globalconfig["gamemanager_integrated_internal_layout"]],
)
def resizeEvent(self, e: QResizeEvent): def resizeEvent(self, e: QResizeEvent):
self.layout1btn.move(e.size().width() - self.layout1btn.width(), 0) self.layout1btn.move(e.size().width() - self.layout1btn.width() - 5, 0)
self.layout2btn.move( self.layout2btn.move(
e.size().width() - self.layout2btn.width() - self.layout1btn.width(), 0 e.size().width() - self.layout2btn.width() - self.layout1btn.width() - 5, 0
) )
self.layout3btn.move( self.layout3btn.move(
e.size().width() e.size().width()
- self.layout3btn.width() - self.layout3btn.width()
- self.layout2btn.width() - self.layout2btn.width()
- self.layout1btn.width(), - self.layout1btn.width()
- 5,
0,
)
self.syssettingbtn.move(
e.size().width()
- self.syssettingbtn.width()
- self.layout3btn.width()
- self.layout2btn.width()
- self.layout1btn.width()
- 5,
0, 0,
) )
@ -188,7 +210,13 @@ class dialog_savedgame_new(QWidget):
self.flow.deleteLater() self.flow.deleteLater()
self.flow = lazyscrollflow() self.flow = lazyscrollflow()
self.flow.bgclicked.connect(ItemWidget.clearfocus) self.flow.bgclicked.connect(ItemWidget.clearfocus)
self.formLayout.insertWidget(self.formLayout.count() - 1, self.flow) self.flow.setsize(
QSize(
globalconfig["dialog_savegame_layout"]["itemw"],
globalconfig["dialog_savegame_layout"]["itemh"],
)
)
self.formLayout.insertWidget(self.formLayout.count(), self.flow)
idx = 0 idx = 0
for k in self.reflist: for k in self.reflist:
if newtags != self.currtags: if newtags != self.currtags:
@ -242,13 +270,11 @@ class dialog_savedgame_new(QWidget):
gamesetting = LAction(("游戏设置")) gamesetting = LAction(("游戏设置"))
addgame = LAction(("添加游戏")) addgame = LAction(("添加游戏"))
batchadd = LAction(("批量添加")) batchadd = LAction(("批量添加"))
othersetting = LAction(("其他设置"))
if self.currentfocusuid: if self.currentfocusuid:
exists = os.path.exists(get_launchpath(self.currentfocusuid)) exists = os.path.exists(get_launchpath(self.currentfocusuid))
if exists: if exists:
menu.addAction(startgame) menu.addAction(startgame)
if exists:
menu.addAction(opendir) menu.addAction(opendir)
menu.addAction(gamesetting) menu.addAction(gamesetting)
menu.addAction(delgame) menu.addAction(delgame)
@ -264,7 +290,6 @@ class dialog_savedgame_new(QWidget):
menu.addAction(addgame) menu.addAction(addgame)
menu.addAction(batchadd) menu.addAction(batchadd)
menu.addSeparator() menu.addSeparator()
menu.addAction(othersetting)
action = menu.exec(self.mapToGlobal(p)) action = menu.exec(self.mapToGlobal(p))
if action == startgame: if action == startgame:
startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid) startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid)
@ -280,8 +305,6 @@ class dialog_savedgame_new(QWidget):
self.clicked3() self.clicked3()
elif action == batchadd: elif action == batchadd:
self.clicked3_batch() self.clicked3_batch()
elif action == othersetting:
dialog_syssetting(self)
elif action == editname or action == addlist: elif action == editname or action == addlist:
_dia = Prompt_dialog( _dia = Prompt_dialog(
@ -351,6 +374,19 @@ class dialog_savedgame_new(QWidget):
), ),
) )
def callchange(self):
self.flow.setsize(
QSize(
globalconfig["dialog_savegame_layout"]["itemw"],
globalconfig["dialog_savegame_layout"]["itemh"],
)
)
self.flow.resizeandshow()
for _ in self.flow.widgets:
if not isinstance(_, ItemWidget):
continue
_.others()
def setstyle(self): def setstyle(self):
key = "savegame_textfont1" key = "savegame_textfont1"
fontstring = globalconfig.get(key, "") fontstring = globalconfig.get(key, "")
@ -416,7 +452,7 @@ class dialog_savedgame_new(QWidget):
self.currtags = tuple() self.currtags = tuple()
self.tagswidget.tagschanged.connect(self.tagschanged) self.tagswidget.tagschanged.connect(self.tagschanged)
_ = QLabel() _ = QLabel()
_.setFixedWidth(60) _.setFixedWidth(80)
layout.addWidget(self.tagswidget) layout.addWidget(self.tagswidget)
layout.addWidget(_) layout.addWidget(_)
formLayout.addLayout(layout) formLayout.addLayout(layout)
@ -425,29 +461,8 @@ class dialog_savedgame_new(QWidget):
self.customContextMenuRequested.connect(self.showmenu) self.customContextMenuRequested.connect(self.showmenu)
formLayout.addWidget(self.flow) formLayout.addWidget(self.flow)
self.formLayout = formLayout self.formLayout = formLayout
buttonlayout = QHBoxLayout()
self.buttonlayout = buttonlayout
self.savebutton = [] self.savebutton = []
self.simplebutton(
"开始游戏",
True,
lambda: startgamecheck(
self, getreflist(self.reftagid), self.currentfocusuid
),
True,
)
self.simplebutton("游戏设置", True, self.showsettingdialog, False)
self.simplebutton("删除游戏", True, self.clicked2, False)
self.simplebutton("打开目录", True, self.clicked4, True)
self.simplebutton("添加到列表", True, self.addtolist, False)
# if globalconfig["startgamenototop"]:
self.simplebutton("左移", True, functools.partial(self.moverank, -1), False)
self.simplebutton("右移", True, functools.partial(self.moverank, 1), False)
self.simplebutton("添加游戏", False, self.clicked3, 1)
self.simplebutton("批量添加", False, self.clicked3_batch, 1)
self.simplebutton("其他设置", False, lambda: dialog_syssetting(self), False)
formLayout.addLayout(buttonlayout)
self.idxsave = [] self.idxsave = []
self.setLayout(formLayout) self.setLayout(formLayout)
self.activategamenum = 1 self.activategamenum = 1
@ -484,6 +499,17 @@ class dialog_savedgame_new(QWidget):
idx = getreflist(uid).index(gameuid) idx = getreflist(uid).index(gameuid)
getreflist(uid).insert(0, getreflist(uid).pop(idx)) getreflist(uid).insert(0, getreflist(uid).pop(idx))
def keyPressEvent(self, e: QKeyEvent):
if e.key() == Qt.Key.Key_Return:
startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid)
elif e.key() == Qt.Key.Key_Delete:
self.clicked2()
elif e.key() == Qt.Key.Key_Left:
self.moverank(-1)
elif e.key() == Qt.Key.Key_Right:
self.moverank(1)
super().keyPressEvent(e)
def moverank(self, dx): def moverank(self, dx):
game = self.currentfocusuid game = self.currentfocusuid
@ -503,16 +529,6 @@ class dialog_savedgame_new(QWidget):
except: except:
print_exc() print_exc()
def simplebutton(self, text, save, callback, exists):
button5 = LPushButton(text)
button5.setMinimumWidth(10)
if save:
self.savebutton.append((button5, exists))
button5.clicked.connect(callback)
button5.setFocusPolicy(Qt.FocusPolicy.NoFocus)
self.buttonlayout.addWidget(button5)
return button5
def itemfocuschanged(self, b, k): def itemfocuschanged(self, b, k):
if b: if b:
@ -542,16 +558,9 @@ class dialog_savedgame_new(QWidget):
def newline(self, k, first=False): def newline(self, k, first=False):
itemw = globalconfig["dialog_savegame_layout"]["itemw"]
itemh = globalconfig["dialog_savegame_layout"]["itemh"]
if first: if first:
self.idxsave.insert(0, k) self.idxsave.insert(0, k)
self.flow.insertwidget( self.flow.insertwidget(0, functools.partial(self.getagameitem, k, True))
0, (functools.partial(self.getagameitem, k, True), QSize(itemw, itemh))
)
else: else:
self.idxsave.append(k) self.idxsave.append(k)
self.flow.addwidget( self.flow.addwidget(functools.partial(self.getagameitem, k, False))
(functools.partial(self.getagameitem, k, False), QSize(itemw, itemh))
)

View File

@ -76,26 +76,26 @@ class ItemWidget(QWidget):
def resizeEvent(self, a0: QResizeEvent) -> None: def resizeEvent(self, a0: QResizeEvent) -> None:
self.bottommask.resize(a0.size()) self.bottommask.resize(a0.size())
self.maskshowfileexists.resize(a0.size()) self.maskshowfileexists.resize(a0.size())
self.resizex()
def resizex(self):
margin = globalconfig["dialog_savegame_layout"]["margin"]
textH = (
globalconfig["dialog_savegame_layout"]["textH"]
if globalconfig["showgametitle"]
else 0
)
self._w.setFixedHeight(self.height() - textH)
self.wrap.setContentsMargins(margin, margin, margin, margin)
def others(self):
self._lb.setText(self.file if globalconfig["showgametitle"] else "")
self.resizex()
self._img.switch()
def __init__(self, gameuid, pixmap, file) -> None: def __init__(self, gameuid, pixmap, file) -> None:
super().__init__() super().__init__()
self.itemw = globalconfig["dialog_savegame_layout"]["itemw"] self.file = file
self.itemh = globalconfig["dialog_savegame_layout"]["itemh"]
# self.imgw = globalconfig["dialog_savegame_layout"]["imgw"]
# self.imgh = globalconfig["dialog_savegame_layout"]["imgh"]
# margin = (
# self.itemw - self.imgw
# ) // 2 # globalconfig['dialog_savegame_layout']['margin']
margin = globalconfig["dialog_savegame_layout"]["margin"]
if globalconfig["showgametitle"]:
textH = globalconfig["dialog_savegame_layout"]["textH"]
else:
textH = 0
self.imgw = self.itemw - 2 * margin
self.imgh = self.itemh - textH - 2 * margin
#
self.setFixedSize(QSize(self.itemw, self.itemh))
# self.setFocusPolicy(Qt.StrongFocus)
self.maskshowfileexists = QLabel(self) self.maskshowfileexists = QLabel(self)
exists = os.path.exists(get_launchpath(gameuid)) exists = os.path.exists(get_launchpath(gameuid))
self.maskshowfileexists.setObjectName("savegame_exists" + str(exists)) self.maskshowfileexists.setObjectName("savegame_exists" + str(exists))
@ -104,19 +104,18 @@ class ItemWidget(QWidget):
self.bottommask.setObjectName("savegame_onselectcolor1") self.bottommask.setObjectName("savegame_onselectcolor1")
layout = QVBoxLayout() layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0) layout.setContentsMargins(0, 0, 0, 0)
self._img = IMGWidget(self.imgw, self.imgh, pixmap) self._img = IMGWidget(pixmap)
_w = QWidget() _w = QWidget()
_w.setStyleSheet("background-color: rgba(255,255,255, 0);") _w.setStyleSheet("background-color: rgba(255,255,255, 0);")
wrap = QVBoxLayout() wrap = QVBoxLayout()
_w.setLayout(wrap) _w.setLayout(wrap)
_w.setFixedHeight(self.imgh + 2 * margin) self._w = _w
wrap.setContentsMargins(margin, margin, margin, margin)
wrap.addWidget(self._img) wrap.addWidget(self._img)
self.wrap = wrap
layout.addWidget(_w) layout.addWidget(_w)
layout.setSpacing(0) layout.setSpacing(0)
self._lb = QLabel() self._lb = QLabel()
if globalconfig["showgametitle"]: self._lb.setText(file if globalconfig["showgametitle"] else "")
self._lb.setText(file)
self._lb.setWordWrap(True) self._lb.setWordWrap(True)
self._lb.setObjectName("savegame_textfont1") self._lb.setObjectName("savegame_textfont1")
self._lb.setAlignment(Qt.AlignmentFlag.AlignHCenter) self._lb.setAlignment(Qt.AlignmentFlag.AlignHCenter)
@ -156,10 +155,12 @@ class IMGWidget(QLabel):
elif globalconfig["imagewrapmode"] == 3: elif globalconfig["imagewrapmode"] == 3:
return size return size
def setimg(self, pixmap): def setimg(self, pixmap: QPixmap):
if type(pixmap) != QPixmap: if not (self.height() and self.width()):
pixmap = pixmap() return
if self.__last == (self.size(), globalconfig["imagewrapmode"]):
return
self.__last = (self.size(), globalconfig["imagewrapmode"])
rate = self.devicePixelRatioF() rate = self.devicePixelRatioF()
newpixmap = QPixmap(self.size() * rate) newpixmap = QPixmap(self.size() * rate)
newpixmap.setDevicePixelRatio(rate) newpixmap.setDevicePixelRatio(rate)
@ -169,7 +170,6 @@ class IMGWidget(QLabel):
painter.setRenderHint(QPainter.RenderHint.Antialiasing) painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.drawPixmap(self.getrect(pixmap.size()), pixmap) painter.drawPixmap(self.getrect(pixmap.size()), pixmap)
painter.end() painter.end()
self.setPixmap(newpixmap) self.setPixmap(newpixmap)
def getrect(self, size): def getrect(self, size):
@ -180,11 +180,20 @@ class IMGWidget(QLabel):
rect.setSize(size) rect.setSize(size)
return rect return rect
def __init__(self, w, h, pixmap) -> None: def resizeEvent(self, a0):
self.setimg(self._pixmap)
return super().resizeEvent(a0)
def __init__(self, pixmap) -> None:
super().__init__() super().__init__()
self.setFixedSize(QSize(w, h))
self.setScaledContents(True) self.setScaledContents(True)
self.setimg(pixmap) if type(pixmap) != QPixmap:
pixmap = pixmap()
self._pixmap = pixmap
self.__last = None
def switch(self):
self.setimg(self._pixmap)
class ClickableLabel(QLabel): class ClickableLabel(QLabel):
@ -592,6 +601,9 @@ class dialog_syssetting(LDialog):
self.parent().setstyle() self.parent().setstyle()
def closeEvent(self, e):
self.parent().callchange()
def __init__(self, parent, type_=1) -> None: def __init__(self, parent, type_=1) -> None:
super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) super().__init__(parent, Qt.WindowType.WindowCloseButtonHint)
self.setWindowTitle("其他设置") self.setWindowTitle("其他设置")
@ -607,26 +619,11 @@ class dialog_syssetting(LDialog):
getsimpleswitch(globalconfig, "startgamenototop"), getsimpleswitch(globalconfig, "startgamenototop"),
) )
if type_ == 1:
formLayout.addRow(
"显示标题",
getsimpleswitch(globalconfig, "showgametitle"),
)
formLayout.addRow(
"缩放",
getsimplecombobox(
["填充", "适应", "拉伸", "居中"],
globalconfig,
"imagewrapmode",
),
)
formLayout.addRow(SplitLine()) formLayout.addRow(SplitLine())
if type_ == 1: if type_ == 1:
for key, name in [ for key, name in [
("itemw", "宽度"), ("itemw", "宽度"),
("itemh", "高度"), ("itemh", "高度"),
# ("imgw", "图片宽度"),
# ("imgh", "图片高度"),
("margin", "边距"), ("margin", "边距"),
("textH", "文字区高度"), ("textH", "文字区高度"),
]: ]:
@ -643,10 +640,21 @@ class dialog_syssetting(LDialog):
isfontselector=True, isfontselector=True,
), ),
) )
formLayout.addRow(
"显示标题",
getsimpleswitch(globalconfig, "showgametitle"),
)
formLayout.addRow(
"缩放",
getsimplecombobox(
["填充", "适应", "拉伸", "居中"],
globalconfig,
"imagewrapmode",
),
)
elif type_ == 2: elif type_ == 2:
for key, name in [ for key, name in [
("listitemwidth", "宽度"),
("listitemheight", "高度"), ("listitemheight", "高度"),
]: ]:
formLayout.addRow( formLayout.addRow(

View File

@ -1,7 +1,7 @@
from qtsymbols import * from qtsymbols import *
import os, functools, uuid, threading, shutil, time import os, functools, uuid, threading, shutil, time
from traceback import print_exc from traceback import print_exc
import gobject import gobject, base64
from myutils.config import ( from myutils.config import (
savehook_new_list, savehook_new_list,
savehook_new_data, savehook_new_data,
@ -34,7 +34,6 @@ from gui.dialog_savedgame_common import (
opendirforgameuid, opendirforgameuid,
getcachedimage, getcachedimage,
getpixfunction, getpixfunction,
dialog_syssetting,
addgamesingle, addgamesingle,
addgamebatch, addgamebatch,
addgamebatch_x, addgamebatch_x,
@ -84,6 +83,11 @@ class clickitem(QWidget):
self.bottommask.resize(a0.size()) self.bottommask.resize(a0.size())
self.maskshowfileexists.resize(a0.size()) self.maskshowfileexists.resize(a0.size())
self.bottomline.resize(a0.size()) self.bottomline.resize(a0.size())
size = globalconfig["dialog_savegame_layout"]["listitemheight"]
margin = min(3, int(size / 15))
self.lay1.setContentsMargins(margin, margin, margin, margin)
self._.setFixedSize(QSize(size - 2 * margin, size - 2 * margin))
self._2.setFixedHeight(size)
def __init__(self, uid): def __init__(self, uid):
super().__init__() super().__init__()
@ -91,10 +95,8 @@ class clickitem(QWidget):
self.uid = uid self.uid = uid
self.lay = QHBoxLayout() self.lay = QHBoxLayout()
self.lay.setSpacing(0) self.lay.setSpacing(0)
size = globalconfig["dialog_savegame_layout"]["listitemheight"]
margin = min(3, int(size / 15))
lay1 = QHBoxLayout() lay1 = QHBoxLayout()
lay1.setContentsMargins(margin, margin, margin, margin) self.lay1 = lay1
self.lay.setContentsMargins(0, 0, 0, 0) self.lay.setContentsMargins(0, 0, 0, 0)
self.maskshowfileexists = QLabel(self) self.maskshowfileexists = QLabel(self)
exists = os.path.exists(get_launchpath(uid)) exists = os.path.exists(get_launchpath(uid))
@ -105,9 +107,8 @@ class clickitem(QWidget):
_ = QLabel(self) _ = QLabel(self)
_.setStyleSheet("""background-color: rgba(255,255,255, 0);""") _.setStyleSheet("""background-color: rgba(255,255,255, 0);""")
self.bottomline = _ self.bottomline = _
_ = QLabel() _ = QLabel()
_.setFixedSize(QSize(size - 2 * margin, size - 2 * margin)) self._ = _
_.setScaledContents(True) _.setScaledContents(True)
_.setStyleSheet("background-color: rgba(255,255,255, 0);") _.setStyleSheet("background-color: rgba(255,255,255, 0);")
icon = getpixfunction(uid, small=True, iconfirst=True) icon = getpixfunction(uid, small=True, iconfirst=True)
@ -117,7 +118,7 @@ class clickitem(QWidget):
self.lay.addLayout(lay1) self.lay.addLayout(lay1)
_ = QLabel(savehook_new_data[uid]["title"]) _ = QLabel(savehook_new_data[uid]["title"])
_.setWordWrap(True) _.setWordWrap(True)
_.setFixedHeight(size) self._2 = _
_.setObjectName("savegame_textfont2") _.setObjectName("savegame_textfont2")
self.lay.addWidget(_) self.lay.addWidget(_)
self.setLayout(self.lay) self.setLayout(self.lay)
@ -190,6 +191,7 @@ class ImageDelegate(QStyledItemDelegate):
class MyQListWidget(QListWidget): class MyQListWidget(QListWidget):
iscleared = pyqtSignal(bool)
def sethor(self, hor): def sethor(self, hor):
if hor: if hor:
@ -211,7 +213,11 @@ class MyQListWidget(QListWidget):
self.loadTimer = QTimer(interval=25, timeout=self.loadImage) self.loadTimer = QTimer(interval=25, timeout=self.loadImage)
self.loadTimer.start() self.loadTimer.start()
def islg1(self):
self.iscleared.emit(self.model().rowCount() > 1)
def loadImage(self): def loadImage(self):
self.islg1()
try: try:
start = self.indexAt(self.viewport().rect().topLeft()).row() start = self.indexAt(self.viewport().rect().topLeft()).row()
end = self.indexAt(self.viewport().rect().bottomRight()).row() end = self.indexAt(self.viewport().rect().bottomRight()).row()
@ -313,7 +319,8 @@ class hoverbtn(LLabel):
clicked = pyqtSignal() clicked = pyqtSignal()
def mousePressEvent(self, a0: QMouseEvent) -> None: def mousePressEvent(self, a0: QMouseEvent) -> None:
self.clicked.emit() if a0.button() == Qt.MouseButton.LeftButton:
self.clicked.emit()
return super().mousePressEvent(a0) return super().mousePressEvent(a0)
def __init__(self, *argc): def __init__(self, *argc):
@ -345,6 +352,10 @@ class viewpixmap_x(QWidget):
def sizeHint(self): def sizeHint(self):
return QSize(400, 400) return QSize(400, 400)
def setnextable(self, b):
self.leftclick.setVisible(b)
self.rightclick.setVisible(b)
def __init__(self, parent=None) -> None: def __init__(self, parent=None) -> None:
super().__init__(parent) super().__init__(parent)
self.pixmapviewer = pixmapviewer(self) self.pixmapviewer = pixmapviewer(self)
@ -552,6 +563,7 @@ class pixwrapper(QWidget):
self.vlayout.setContentsMargins(0, 0, 0, 0) self.vlayout.setContentsMargins(0, 0, 0, 0)
self.pixview = viewpixmap_x(self) self.pixview = viewpixmap_x(self)
self.pixview.startgame.connect(self.startgame) self.pixview.startgame.connect(self.startgame)
self.previewimages.list.iscleared.connect(self.pixview.setnextable)
self.spliter = QSplitter(self) self.spliter = QSplitter(self)
self.vlayout.addWidget(self.spliter) self.vlayout.addWidget(self.spliter)
self.setrank(rank) self.setrank(rank)
@ -643,6 +655,7 @@ class pixwrapper(QWidget):
self.k = k self.k = k
pixmaps = savehook_new_data[k]["imagepath_all"].copy() pixmaps = savehook_new_data[k]["imagepath_all"].copy()
self.previewimages.setpixmaps(pixmaps, savehook_new_data[k]["currentvisimage"]) self.previewimages.setpixmaps(pixmaps, savehook_new_data[k]["currentvisimage"])
self.pixview.bottombtn.setVisible(os.path.exists(get_launchpath(k)))
class dialog_savedgame_v3(QWidget): class dialog_savedgame_v3(QWidget):
@ -655,7 +668,7 @@ class dialog_savedgame_v3(QWidget):
self.righttop.removeTab(1) self.righttop.removeTab(1)
tabadd_lazy( tabadd_lazy(
self.righttop, self.righttop,
savehook_new_data[k]["title"], "设置",
lambda v: v.addWidget(dialog_setting_game_internal(self, k)), lambda v: v.addWidget(dialog_setting_game_internal(self, k)),
) )
self.righttop.setCurrentIndex(currvis) self.righttop.setCurrentIndex(currvis)
@ -670,13 +683,6 @@ class dialog_savedgame_v3(QWidget):
else: else:
self.currentfocusuid = None self.currentfocusuid = None
for _btn, exists in self.savebutton:
_able1 = b and (
(not exists)
or (self.currentfocusuid)
and (os.path.exists(get_launchpath(self.currentfocusuid)))
)
_btn.setEnabled(_able1)
if self.currentfocusuid: if self.currentfocusuid:
self.viewitem(k) self.viewitem(k)
@ -700,7 +706,6 @@ class dialog_savedgame_v3(QWidget):
self.reftagid, self.reftagid,
getreflist(self.reftagid), getreflist(self.reftagid),
), ),
1 + globalconfig["dialog_savegame_layout"]["listitemheight"],
) )
self.stack.directshow() self.stack.directshow()
@ -794,6 +799,12 @@ class dialog_savedgame_v3(QWidget):
def directshow(self): def directshow(self):
self.stack.directshow() self.stack.directshow()
def callchange(self):
self.stack.setheight(
globalconfig["dialog_savegame_layout"]["listitemheight"] + 1
)
self.stack.directshow_1()
def setstyle(self): def setstyle(self):
key = "savegame_textfont2" key = "savegame_textfont2"
fontstring = globalconfig.get(key, "") fontstring = globalconfig.get(key, "")
@ -832,17 +843,20 @@ class dialog_savedgame_v3(QWidget):
self.reftagid = None self.reftagid = None
self.reallist = {} self.reallist = {}
self.stack = stackedlist() self.stack = stackedlist()
self.stack.setheight(
globalconfig["dialog_savegame_layout"]["listitemheight"] + 1
)
self.stack.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.stack.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.stack.customContextMenuRequested.connect(self.stack_showmenu) self.stack.customContextMenuRequested.connect(self.stack_showmenu)
self.stack.setFixedWidth(
globalconfig["dialog_savegame_layout"]["listitemwidth"]
)
self.stack.bgclicked.connect(clickitem.clearfocus) self.stack.bgclicked.connect(clickitem.clearfocus)
self.setstyle() self.setstyle()
lay = QHBoxLayout() spl = QSplitter()
self.setLayout(lay) _l = QHBoxLayout()
lay.addWidget(self.stack) _l.addWidget(spl)
lay.setSpacing(0) self.setLayout(_l)
spl.addWidget(self.stack)
self.righttop = makesubtab_lazy() self.righttop = makesubtab_lazy()
self.pixview = pixwrapper() self.pixview = pixwrapper()
self.pixview.startgame.connect( self.pixview.startgame.connect(
@ -855,31 +869,15 @@ class dialog_savedgame_v3(QWidget):
rightlay.setContentsMargins(0, 0, 0, 0) rightlay.setContentsMargins(0, 0, 0, 0)
_w.setLayout(rightlay) _w.setLayout(rightlay)
self.righttop.addTab(_w, "画廊") self.righttop.addTab(_w, "画廊")
lay.addWidget(self.righttop) spl.addWidget(self.righttop)
rightlay.addWidget(self.pixview)
self.buttonlayout = QHBoxLayout() def __(_):
self.savebutton = [] globalconfig["dialog_savegame_layout"]["listitemwidth_2"] = spl.sizes()
rightlay.addLayout(self.buttonlayout)
spl.setSizes(globalconfig["dialog_savegame_layout"]["listitemwidth_2"])
spl.splitterMoved.connect(__)
rightlay.addWidget(self.pixview)
self.simplebutton(
"开始游戏",
True,
lambda: startgamecheck(
self, getreflist(self.reftagid), self.currentfocusuid
),
True,
)
self.simplebutton("删除游戏", True, self.shanchuyouxi, False)
self.simplebutton("打开目录", True, self.clicked4, True)
self.simplebutton("添加到列表", True, self.addtolist, False)
# if globalconfig["startgamenototop"]:
self.simplebutton("上移", True, functools.partial(self.moverank, -1), False)
self.simplebutton("下移", True, functools.partial(self.moverank, 1), False)
self.simplebutton("添加游戏", False, self.clicked3, 1)
self.simplebutton("批量添加", False, self.clicked3_batch, 1)
self.simplebutton(
"其他设置", False, lambda: dialog_syssetting(self, type_=2), False
)
isfirst = True isfirst = True
for i, tag in enumerate(savegametaged): for i, tag in enumerate(savegametaged):
# None # None
@ -913,7 +911,6 @@ class dialog_savedgame_v3(QWidget):
group0.insertw( group0.insertw(
rowreal, rowreal,
functools.partial(self.delayitemcreater, k, vis, tagid, lst), functools.partial(self.delayitemcreater, k, vis, tagid, lst),
1 + globalconfig["dialog_savegame_layout"]["listitemheight"],
) )
rowreal += 1 rowreal += 1
@ -1083,16 +1080,6 @@ class dialog_savedgame_v3(QWidget):
def clicked(self): def clicked(self):
startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid) startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid)
def simplebutton(self, text, save, callback, exists):
button5 = LPushButton(text)
button5.setMinimumWidth(10)
if save:
self.savebutton.append((button5, exists))
button5.clicked.connect(callback)
button5.setFocusPolicy(Qt.FocusPolicy.NoFocus)
self.buttonlayout.addWidget(button5)
return button5
def dragEnterEvent(self, event: QDragEnterEvent): def dragEnterEvent(self, event: QDragEnterEvent):
if event.mimeData().hasUrls(): if event.mimeData().hasUrls():
event.accept() event.accept()

View File

@ -120,14 +120,21 @@ class Setting(closeashidewindow):
) )
self.setCentralWidget(self.tab_widget) self.setCentralWidget(self.tab_widget)
do() do()
width = 0
fn = QFont() if globalconfig.get("setting_split"):
fn.setPointSizeF(globalconfig["settingfontsize"] + 4) self.tab_widget.splitter.setSizes(globalconfig["setting_split"])
fn.setFamily(globalconfig["settingfonttype"]) else:
fm = QFontMetrics(fn) width = 0
for title in _TRL(self.tab_widget.titles): fn = QFont()
width = max(fm.size(0, title).width(), width) fn.setPointSizeF(globalconfig["settingfontsize"] + 4)
width += 50 fn.setFamily(globalconfig["settingfonttype"])
self.tab_widget.splitter.setStretchFactor(0, 0) fm = QFontMetrics(fn)
self.tab_widget.splitter.setStretchFactor(1, 1) for title in _TRL(self.tab_widget.titles):
self.tab_widget.splitter.setSizes([width, self.tab_widget.width() - width]) width = max(fm.size(0, title).width(), width)
width += 50
self.tab_widget.splitter.setSizes([width, self.tab_widget.width() - width])
def __(_):
globalconfig["setting_split"] = self.tab_widget.splitter.sizes()
self.tab_widget.splitter.splitterMoved.connect(__)

View File

@ -147,6 +147,11 @@ class ScrollArea(QScrollArea):
visible_rect = QRect(x, y, width, height) visible_rect = QRect(x, y, width, height)
self.scrolled.emit(visible_rect) self.scrolled.emit(visible_rect)
def keyPressEvent(self, e: QKeyEvent):
if e.key() == Qt.Key.Key_Left or e.key() == Qt.Key.Key_Right:
return e.ignore()
super().keyPressEvent(e)
class ScrollFlow(QWidget): class ScrollFlow(QWidget):
bgclicked = pyqtSignal() bgclicked = pyqtSignal()
@ -345,10 +350,10 @@ class lazyscrollflow(ScrollArea):
if not region.intersects(geo): if not region.intersects(geo):
continue continue
widfunc, _ = self.widgets[i] widfunc = self.widgets[i]
if not widfunc: if not widfunc:
continue continue
self.widgets[i] = (None, _) self.widgets[i] = None
needdos.append((i, widfunc)) needdos.append((i, widfunc))
for i, widfunc in needdos: for i, widfunc in needdos:
try: try:
@ -425,48 +430,58 @@ class lazyscrollflow(ScrollArea):
else: else:
return None return None
def setsize(self, size: QSize):
self._size = size
def spacing(self): def spacing(self):
return self._spacing return self._spacing
def anylyze(self, effective_rect: QRect, space_x, N):
x = effective_rect.x()
for _ in range(N):
next_x = x + self._size.width() + space_x
if next_x > effective_rect.right():
return x
x = next_x
return x
def fakeresize(self): def fakeresize(self):
if self.verticalScrollBar().isVisible():
scrollw = self.verticalScrollBar().width()
else:
scrollw = 0
with self.lock: with self.lock:
# m = self.contentsMargins() scrollw = (
rect = QRect() self.verticalScrollBar().width()
rect.setSize(self.size()) if self.verticalScrollBar().isVisible()
effective_rect = rect.adjusted( else 0
self._margin, self._margin, -self._margin, -self._margin )
) # (+m.left(), +m.top(), -m.right(), -m.bottom()) effective_rect = QRect(
self._margin,
self._margin,
self.width() - 2 * self._margin - scrollw,
self.height() - 2 * self._margin,
)
x = effective_rect.x() x = effective_rect.x()
y = effective_rect.y() y = effective_rect.y()
line_height = 0 space_x = self.spacing()
space_y = self.spacing()
dx = (
effective_rect.right()
- self.anylyze(effective_rect, space_x, len(self.widgets))
) // 2
for i, wid in enumerate(self.widgets): for i, wid in enumerate(self.widgets):
space_x = self.spacing()
space_y = self.spacing()
if isinstance(wid, QWidget): if isinstance(wid, QWidget):
sz = wid.size()
resize = True resize = True
else: else:
_, sz = wid
resize = False resize = False
next_x = x + sz.width() + space_x next_x = x + self._size.width() + space_x
if next_x > effective_rect.right() - scrollw and line_height > 0: if next_x > effective_rect.right() and i:
x = effective_rect.x() x = effective_rect.x()
y = y + line_height + space_y y = y + self._size.height() + space_y
next_x = x + sz.width() + space_x next_x = x + self._size.width() + space_x
line_height = 0
if resize: if resize:
wid.setGeometry(QRect(QPoint(x, y), sz)) wid.setGeometry(QRect(QPoint(x + dx, y), self._size))
self.fakegeos[i] = QRect(QPoint(x, y), sz) self.fakegeos[i] = QRect(QPoint(x + dx, y), self._size)
x = next_x x = next_x
line_height = max(line_height, sz.height())
new_height = y + line_height - rect.y() + self._margin new_height = y + self._size.height() + self._margin
self.internalwid.setFixedHeight(new_height) self.internalwid.setFixedHeight(new_height)
@ -481,9 +496,17 @@ def has_intersection(interval1, interval2):
class delayloadvbox(QWidget): class delayloadvbox(QWidget):
def __init__(self):
def setheight(self, h):
self._h = h
self.setFixedHeight(len(self.internal_widgets) * self._h)
for _ in self.internal_widgets:
if isinstance(_, QWidget):
_.resize(_.width(), h)
def __init__(self, h=1):
super().__init__() super().__init__()
self.internal_itemH = [] self._h = h
self.internal_widgets = [] self.internal_widgets = []
self.lock = threading.Lock() self.lock = threading.Lock()
self.nowvisregion = QRect() self.nowvisregion = QRect()
@ -505,9 +528,9 @@ class delayloadvbox(QWidget):
ydiff = self.y() ydiff = self.y()
needdos = [] needdos = []
with self.lock: with self.lock:
for i, h in enumerate(self.internal_itemH): for i in range(len(self.internal_widgets)):
ystart = ylastend ystart = ylastend
yend = ystart + h yend = ystart + self._h
ylastend = yend ylastend = yend
if isinstance(self.internal_widgets[i], QWidget): if isinstance(self.internal_widgets[i], QWidget):
self.internal_widgets[i].move(0, ystart - ydiff) self.internal_widgets[i].move(0, ystart - ydiff)
@ -519,7 +542,7 @@ class delayloadvbox(QWidget):
if not widfunc: if not widfunc:
continue continue
self.internal_widgets[i] = None self.internal_widgets[i] = None
needdos.append((i, widfunc, ystart - ydiff, h)) needdos.append((i, widfunc, ystart - ydiff, self._h))
for i, widfunc, ystart, h in needdos: for i, widfunc, ystart, h in needdos:
try: try:
@ -541,7 +564,6 @@ class delayloadvbox(QWidget):
def switchidx(self, idx1, idx2): def switchidx(self, idx1, idx2):
with self.lock: with self.lock:
self.internal_widgets.insert(idx2, self.internal_widgets.pop(idx1)) self.internal_widgets.insert(idx2, self.internal_widgets.pop(idx1))
self.internal_itemH.insert(idx2, self.internal_itemH.pop(idx1))
self._dovisinternal(False, self.nowvisregion) self._dovisinternal(False, self.nowvisregion)
def popw(self, i): def popw(self, i):
@ -552,8 +574,7 @@ class delayloadvbox(QWidget):
w.setParent(None) w.setParent(None)
w.deleteLater() w.deleteLater()
self.internal_widgets.pop(i) self.internal_widgets.pop(i)
self.internal_itemH.pop(i) self.setFixedHeight(len(self.internal_widgets) * self._h)
self.setFixedHeight(sum(self.internal_itemH))
# setFixedHeight会导致上面的闪烁 # setFixedHeight会导致上面的闪烁
self._dovisinternal(False, self.nowvisregion) self._dovisinternal(False, self.nowvisregion)
@ -562,18 +583,16 @@ class delayloadvbox(QWidget):
return return
with self.lock: with self.lock:
self.internal_widgets.insert(0, self.internal_widgets.pop(i)) self.internal_widgets.insert(0, self.internal_widgets.pop(i))
self.internal_itemH.insert(0, self.internal_itemH.pop(i))
self._dovisinternal(False, self.nowvisregion) self._dovisinternal(False, self.nowvisregion)
def insertw(self, i, wf, height): def insertw(self, i, wf):
refresh = True refresh = True
with self.lock: with self.lock:
if i == -1: if i == -1:
refresh = False refresh = False
i = self.len() i = self.len()
self.internal_itemH.insert(i, height)
self.internal_widgets.insert(i, wf) self.internal_widgets.insert(i, wf)
self.setFixedHeight(sum(self.internal_itemH)) self.setFixedHeight(len(self.internal_widgets) * self._h)
if refresh: if refresh:
self._dovisinternal(False, self.nowvisregion) self._dovisinternal(False, self.nowvisregion)
@ -639,6 +658,7 @@ class shrinkableitem(QWidget):
self.items.setVisible(opened) self.items.setVisible(opened)
shrinker.setChecked(opened) shrinker.setChecked(opened)
self._ref_p_stackedlist = p self._ref_p_stackedlist = p
self._h = 1
def visheight(self): def visheight(self):
hh = self.btn.height() hh = self.btn.height()
@ -666,8 +686,8 @@ class shrinkableitem(QWidget):
def switchidx(self, idx1, idx2): def switchidx(self, idx1, idx2):
self.items.switchidx(idx1, idx2) self.items.switchidx(idx1, idx2)
def insertw(self, i, wf, height): def insertw(self, i, wf):
self.items.insertw(i, wf, height) self.items.insertw(i, wf)
def torank1(self, i): def torank1(self, i):
self.items.torank1(i) self.items.torank1(i)
@ -684,13 +704,24 @@ class shrinkableitem(QWidget):
def button(self): def button(self):
return self.btn return self.btn
def setheight(self, h):
self.items.setheight(h)
class stackedlist(ScrollArea): class stackedlist(ScrollArea):
bgclicked = pyqtSignal() bgclicked = pyqtSignal()
def setheight(self, h):
for i in range(self.len()):
self.w(i).setheight(h)
self._h = h
def mousePressEvent(self, _2) -> None: def mousePressEvent(self, _2) -> None:
self.bgclicked.emit() self.bgclicked.emit()
def directshow_1(self):
self.doshowlazywidget(True, self.internal.visibleRegion().boundingRect())
def directshow(self): def directshow(self):
QApplication.processEvents() QApplication.processEvents()
self.doshowlazywidget(True, self.internal.visibleRegion().boundingRect()) self.doshowlazywidget(True, self.internal.visibleRegion().boundingRect())
@ -704,6 +735,7 @@ class stackedlist(ScrollArea):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._h = 1
self.setStyleSheet( self.setStyleSheet(
"""QWidget#shit{background-color:transparent;}QScrollArea{background-color:transparent;border:0px}""" """QWidget#shit{background-color:transparent;}QScrollArea{background-color:transparent;border:0px}"""
) )
@ -739,6 +771,7 @@ class stackedlist(ScrollArea):
region.setHeight(region.height() - self.w(i).visheight()) region.setHeight(region.height() - self.w(i).visheight())
def insertw(self, i, w: shrinkableitem): def insertw(self, i, w: shrinkableitem):
w.setheight(self._h)
self.lay.insertWidget(i, w) self.lay.insertWidget(i, w)
def popw(self, i) -> shrinkableitem: def popw(self, i) -> shrinkableitem:

View File

@ -532,8 +532,10 @@
"transparent": 25, "transparent": 25,
"transparentselect": 25, "transparentselect": 25,
"transparentnotexits": 25, "transparentnotexits": 25,
"listitemheight": 40, "listitemwidth_2": [
"listitemwidth": 300 300,
500
]
}, },
"gamemanageruseversion": 0, "gamemanageruseversion": 0,
"gamemanager_integrated_internal_layout": 0, "gamemanager_integrated_internal_layout": 0,