From 9028f7fbaab19cee59ea9881dbc4d0bcc1bddb65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 1 Aug 2024 17:19:53 +0800 Subject: [PATCH] move --- LunaTranslator/LunaTranslator/gui/dynalang.py | 7 ++++ LunaTranslator/LunaTranslator/gui/showword.py | 2 +- .../LunaTranslator/gui/translatorUI.py | 22 ++---------- .../LunaTranslator/gui/usefulwidget.py | 36 +++++++++++++++++++ LunaTranslator/LunaTranslator/qtawesome.py | 10 +++--- 5 files changed, 52 insertions(+), 25 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/dynalang.py b/LunaTranslator/LunaTranslator/gui/dynalang.py index 25f18951..218ec7c1 100644 --- a/LunaTranslator/LunaTranslator/gui/dynalang.py +++ b/LunaTranslator/LunaTranslator/gui/dynalang.py @@ -5,6 +5,7 @@ from qtsymbols import * class LLabel(QLabel): def __init__(self, *argc): self.__s = None + self._ToolTip = None if len(argc) == 1: if isinstance(argc[0], str): self.__s = argc[0] @@ -21,6 +22,12 @@ class LLabel(QLabel): def updatelangtext(self): if self.__s: super().setText(_TR(self.__s)) + if self._ToolTip: + super().setToolTip(_TR(self._ToolTip)) + + def setToolTip(self, t): + self._ToolTip = t + super().setToolTip(_TR(t)) class LMessageBox(QMessageBox): diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index d690dca7..a55cf3b6 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -635,7 +635,7 @@ class CustomTabBar(LTabBar): class QLineEdit1(QLineEdit): - def mousePressEvent(self, a0: qtawesome.QMouseEvent) -> None: + def mousePressEvent(self, a0: QMouseEvent) -> None: # 点击浏览器后,无法重新获取焦点。 windows.SetFocus(int(self.winId())) return super().mousePressEvent(a0) diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 7089b99b..e6c58325 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -18,7 +18,7 @@ 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, isinrect, getQMessageBox +from gui.usefulwidget import resizableframeless, isinrect, getQMessageBox, LIconLabel from gui.edittext import edittrans from gui.dialog_savedgame import browserdialog, dialog_savedgame_integrated from gui.dynalang import LPushButton, LDialog @@ -1035,26 +1035,8 @@ class QUnFrameWindow(resizableframeless): button.clicked.connect(functools.partial(self.callwrap, clickfunc)) else: - class __(LPushButton): - def __init__(self, p): - super().__init__(p) - self._lb = QLabel(p) - self._lb.setStyleSheet("background-color: transparent;") - self._lb.raise_() - def hideEvent(self, _): - self._lb.hide() - - def showEvent(self, _): - self._lb.show() - - def moveEvent(self, event): - self._lb.move(event.pos()) - - def resizeEvent(self, event): - self._lb.resize(event.size()) - - button = __(self._TitleLabel) + button = LIconLabel(self._TitleLabel) if tips: button.setToolTip(tips) diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 7e284f5a..1d13dfa6 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -1928,3 +1928,39 @@ class statusbutton(QPushButton): def setEnabled(self, _): super().setEnabled(_) self.seticon() + + +class LIconLabel(LLabel): + def __init__(self, *argc): + super().__init__(*argc) + self._icon = QIcon() + self._size = QSize() + + def setIcon(self, icon: QIcon): + self._icon = icon + self.update() + + def setIconSize(self, size: QSize): + self._size = size + self.update() + + def paintEvent(self, a0: QPaintEvent) -> None: + + painter = QPainter(self) + if self._size.isEmpty(): + size = self.size() + else: + size = self._size + rect = QRect( + (self.width() - size.width()) // 2, + (self.height() - size.height()) // 2, + size.width(), + size.height(), + ) + self._icon.paint( + painter, + rect, + Qt.AlignmentFlag.AlignCenter, + QIcon.Mode.Normal, + QIcon.State.On, + ) diff --git a/LunaTranslator/LunaTranslator/qtawesome.py b/LunaTranslator/LunaTranslator/qtawesome.py index 857316ff..f789eca1 100644 --- a/LunaTranslator/LunaTranslator/qtawesome.py +++ b/LunaTranslator/LunaTranslator/qtawesome.py @@ -5,7 +5,7 @@ from qtsymbols import * class CharIconPainter: - def paint(self, iconic, painter, rect, char, color): + def paint(self, iconic, painter, rect, mode, state, char, color): painter.save() qcolor = QColor(color) painter.setPen(qcolor) @@ -28,13 +28,15 @@ class CharIconEngine(QIconEngine): self.char = char self.color = color - def paint(self, painter, rect): - self.painter.paint(self.iconic, painter, rect, self.char, self.color) + def paint(self, painter, rect, mode, state): + self.painter.paint( + self.iconic, painter, rect, mode, state, self.char, self.color + ) def pixmap(self, size, mode, state): pm = QPixmap(size) pm.fill(Qt.GlobalColor.transparent) - self.paint(QPainter(pm), QRect(QPoint(0, 0), size)) + self.paint(QPainter(pm), QRect(QPoint(0, 0), size), mode, state) return pm