From 99be5fd40f0a0773aaa3f66477ef9c2aac077666 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 4 Mar 2020 23:30:59 -0700 Subject: [PATCH] configurable max size --- extensions/extrawindow.cpp | 10 ++++++++-- text.cpp | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index b105307..8e1543d 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -17,6 +17,7 @@ extern const char* EXTRA_WINDOW_INFO; extern const char* SENTENCE_TOO_BIG; +extern const char* MAX_SENTENCE_SIZE; extern const char* TOPMOST; extern const char* OPACITY; extern const char* SHOW_ORIGINAL; @@ -159,6 +160,7 @@ public: { ui.display->setTextFormat(Qt::PlainText); if (settings.contains(WINDOW) && QGuiApplication::screenAt(settings.value(WINDOW).toRect().bottomRight())) setGeometry(settings.value(WINDOW).toRect()); + maxSentenceSize = settings.value(MAX_SENTENCE_SIZE, maxSentenceSize).toInt(); for (auto [name, default, slot] : Array{ { TOPMOST, false, &ExtraWindow::setTopmost }, @@ -173,6 +175,10 @@ public: action->setCheckable(true); action->setChecked(default); } + menu.addAction(MAX_SENTENCE_SIZE, this, [this] + { + settings.setValue(MAX_SENTENCE_SIZE, maxSentenceSize = QInputDialog::getInt(this, MAX_SENTENCE_SIZE, "", maxSentenceSize, 0, INT_MAX, 1, nullptr, Qt::WindowCloseButtonHint)); + }); ui.display->installEventFilter(this); ui.display->setMouseTracking(true); @@ -296,7 +302,7 @@ private: } bool locked, showOriginal, useDictionary; - int maxSentenceSize = 1500; + int maxSentenceSize = 500; QPoint oldPos; class @@ -389,7 +395,7 @@ private: definitions.clear(); definitionIndex = 0; std::unordered_set foundDefinitions; - for (term = term.left(500); !term.isEmpty(); term.chop(1)) + for (term = term.left(100); !term.isEmpty(); term.chop(1)) for (const auto& [rootTerm, definition, inflections] : LookupDefinitions(term, foundDefinitions)) definitions.push_back( QStringLiteral("

%1 (%5/%6)

%2%3

%4

").arg( diff --git a/text.cpp b/text.cpp index ccca508..9f1f0ee 100644 --- a/text.cpp +++ b/text.cpp @@ -122,7 +122,8 @@ const wchar_t* TOO_MANY_TRANS_REQUESTS = L"Too many translation requests: refuse const wchar_t* TRANSLATION_ERROR = L"Error while translating"; const char* EXTRA_WINDOW_INFO = u8R"(Right click to change settings Click and drag on window edges to move, or the bottom right corner to resize)"; -const char* SENTENCE_TOO_BIG = u8"Sentence much too large to display"; +const char* SENTENCE_TOO_BIG = u8"Sentence too large to display"; +const char* MAX_SENTENCE_SIZE = u8"Max sentence size"; const char* TOPMOST = u8"Always on top"; const char* DICTIONARY = u8"Dictionary"; const char* DICTIONARY_INSTRUCTIONS = u8R"(This file is used only for the "Dictionary" feature of the Extra Window extension.