From 6c2913fe4733ae41c28631d8a6656b2cefcb4661 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: Sat, 14 Sep 2024 10:39:56 +0800 Subject: [PATCH] fix --- .../LunaTranslator/rendertext/textbrowser.py | 27 ++++++++++++++----- .../rendertext/textbrowser_imp/base.py | 5 ---- .../files/defaultconfig/config.json | 2 +- plugins/CMakeLists.txt | 2 +- plugins/winsharedutils/clipboard.cpp | 3 +-- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/LunaTranslator/LunaTranslator/rendertext/textbrowser.py b/LunaTranslator/LunaTranslator/rendertext/textbrowser.py index bccb2bca..6d8c4482 100644 --- a/LunaTranslator/LunaTranslator/rendertext/textbrowser.py +++ b/LunaTranslator/LunaTranslator/rendertext/textbrowser.py @@ -275,8 +275,10 @@ class TextBrowser(QWidget, dataget): textlines, linetags = self._splitlinestags(font, tag, text) text = "\n".join(textlines) tag = self._join_tags(linetags, True) - tag = tag if isshowhira else [] - self._textbrowser_append(origin, atcenter, text, tag, color) + tagshow = tag if isshowhira else [] + else: + tagshow = [] + self._textbrowser_append(origin, atcenter, text, tagshow, color) if len(tag) and (isshow_fenci or isfenciclick): self.addsearchwordmask(isshow_fenci, isfenciclick, tag) @@ -466,7 +468,7 @@ class TextBrowser(QWidget, dataget): for label in self.iteryinyinglabelsave[iter_context_class]: label.hide() - + maxh = self.maxvisheight subtext = [] subpos = [] lastpos = None @@ -475,6 +477,8 @@ class TextBrowser(QWidget, dataget): self.textcursor.setPosition(posx) posx += 1 tl1 = self.textbrowser.cursorRect(self.textcursor).topLeft() + if tl1.y() > maxh: + break if lastpos is None or tl1.y() != lastpos.y(): lastpos = tl1 subpos.append(lastpos) @@ -534,15 +538,21 @@ class TextBrowser(QWidget, dataget): self.textcursor.setPosition(blockstart + s) self.textbrowser.setTextCursor(self.textcursor) tl1 = self.textbrowser.cursorRect(self.textcursor).topLeft() + if tl1.y() > maxh: + return collects[collecti].move(tl1.x(), tl1.y() + self.labeloffset_y) collecti += 1 + @property + def maxvisheight(self): + return QApplication.primaryScreen().virtualGeometry().height() * 2 + def _showyinyingtext(self, b1, b2, color, font): linei = self.yinyingposline doc = self.textbrowser.document() block = doc.findBlockByNumber(0) - + maxh = self.maxvisheight for blocki in range(b1, b2): block = doc.findBlockByNumber(blocki) layout = block.layout() @@ -558,18 +568,20 @@ class TextBrowser(QWidget, dataget): self.textcursor.setPosition(blockstart + s) self.textbrowser.setTextCursor(self.textcursor) tl1 = self.textbrowser.cursorRect(self.textcursor).topLeft() - + if tl1.y() > maxh: + self.yinyingposline = linei + return if self.yinyinglabels_idx >= len(self.yinyinglabels): self.yinyinglabels.append(self.currentclass(self.toplabel2)) _ = self.yinyinglabels[self.yinyinglabels_idx] self.yinyinglabels_idx += 1 - _.setColor(color) _.setText(block.text()[s : s + l]) _.setFont(font) _.adjustSize() _.move(tl1.x(), tl1.y() + self.labeloffset_y) _.show() + linei += 1 self.yinyingposline = linei @@ -663,6 +675,7 @@ class TextBrowser(QWidget, dataget): self.settextposcursor(pos) savetaglabels_idx = 0 lines = [[]] + maxh = self.maxvisheight for word in x: l = len(word["orig_X"]) tl1 = self.textbrowser.cursorRect(self.textcursor).topLeft() @@ -672,6 +685,8 @@ class TextBrowser(QWidget, dataget): if not self._checkwordhastag(word): continue tl2 = self.textbrowser.cursorRect(self.textcursor).topLeft() + if tl2.y() > maxh: + break _ = self.solvejiaminglabel( savetaglabels_idx, word, fonthira, fontori_m, tl1, fha ) diff --git a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/base.py b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/base.py index 0b2df1d9..f48ef6ff 100644 --- a/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/base.py +++ b/LunaTranslator/LunaTranslator/rendertext/textbrowser_imp/base.py @@ -15,9 +15,6 @@ class base(QWidget): def extraWH(self): return 2 * self.config.get("width", 0), 2 * self.config.get("width", 0) - def init(self): - pass - @property def config(self): return globalconfig["rendertext"]["textbrowser"][self.typename].get("args", {}) @@ -41,8 +38,6 @@ class base(QWidget): self._pix = None self._m_text = "" - self.init() - def adjustSize(self): self._pix = None font = self.font() diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 142c281f..46fbe3fe 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -2009,7 +2009,7 @@ "ZoomFactor": 1, "realtime_edit_target": "realtime_edit", "magpiepath": "", - "movefollow": true, + "movefollow": false, "focusnotop": false, "autostarthook": true, "minlength": 0, diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index aac7079d..ecaa2fae 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 35) -set(VERSION_PATCH 4) +set(VERSION_PATCH 5) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h) diff --git a/plugins/winsharedutils/clipboard.cpp b/plugins/winsharedutils/clipboard.cpp index e2324d12..74580383 100644 --- a/plugins/winsharedutils/clipboard.cpp +++ b/plugins/winsharedutils/clipboard.cpp @@ -31,8 +31,7 @@ std::optional clipboard_get_internal() LPWSTR pszText = static_cast(GlobalLock(hData)); if (pszText == 0) break; - int sz = GlobalSize(hData); - data = std::move(std::wstring(pszText, sz)); + data = std::move(std::wstring(pszText)); GlobalUnlock(hData); } while (false); CloseClipboard();