From f86a77653699ebb30aa1b86e76a5dbf54587ab24 Mon Sep 17 00:00:00 2001 From: Niakr1s Date: Sun, 16 Jun 2019 00:30:41 +0300 Subject: [PATCH] Feature: Show original text --- extensions/extrawindow.cpp | 17 ++++++++++++++++- text.cpp | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index d0f9508..d01c58c 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -13,6 +13,7 @@ extern const char* EXTRA_WINDOW_INFO; extern const char* TOPMOST; +extern const char* SHOW_ORIGINAL; extern const char* SIZE_LOCK; extern const char* BG_COLOR; extern const char* TEXT_COLOR; @@ -72,6 +73,9 @@ public: setSizeGripEnabled(!lock); settings->setValue(SIZE_LOCK, lock); }; + auto setShowOriginal = [=](bool showOriginal) { + settings->setValue(SHOW_ORIGINAL, showOriginal); + }; setGeometry(settings->value(WINDOW, geometry()).toRect()); setLock(settings->value(SIZE_LOCK, false).toBool()); setTopmost(settings->value(TOPMOST, false).toBool()); @@ -86,6 +90,9 @@ public: auto lock = menu->addAction(SIZE_LOCK, setLock); lock->setCheckable(true); lock->setChecked(settings->value(SIZE_LOCK, false).toBool()); + auto showOriginal = menu->addAction(SHOW_ORIGINAL, setShowOriginal); + showOriginal->setCheckable(true); + showOriginal->setChecked(settings->value(SHOW_ORIGINAL, true).toBool()); menu->addAction(BG_COLOR, [=] { setBackgroundColor(QColorDialog::getColor(bgColor, this, BG_COLOR, QColorDialog::ShowAlphaChannel)); }); menu->addAction(TEXT_COLOR, [=] { setTextColor(QColorDialog::getColor(display->palette().windowText().color(), this, TEXT_COLOR, QColorDialog::ShowAlphaChannel)); }); menu->addAction(FONT_SIZE, [=] { setFontSize(QInputDialog::getInt(this, FONT_SIZE, "", display->font().pointSize(), 0, INT_MAX, 1, nullptr, Qt::WindowCloseButtonHint)); }); @@ -156,6 +163,14 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) { std::lock_guard l(m); if (window == nullptr || !sentenceInfo["current select"]) return false; - QMetaObject::invokeMethod(window, [=] { window->display->setText(QString::fromStdWString(sentence)); }); + + QString qSentence = QString::fromStdWString(sentence); + if (!window->settings->value(SHOW_ORIGINAL).toBool()) + { + int middle = qSentence.count('\n') / 2; + qSentence = qSentence.section('\n', middle + 1); + }; + + QMetaObject::invokeMethod(window, [=] { window->display->setText(qSentence); }); return false; } diff --git a/text.cpp b/text.cpp index 696c138..fdad540 100644 --- a/text.cpp +++ b/text.cpp @@ -109,6 +109,7 @@ 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* TOPMOST = u8"Always on Top"; +const char* SHOW_ORIGINAL = u8"Original Text"; const char* SIZE_LOCK = u8"Size Locked"; const char* BG_COLOR = u8"Background Color"; const char* TEXT_COLOR = u8"Text Color"; @@ -377,6 +378,7 @@ I'm currently looking for a new job: email me if you know anyone hiring US softw EXTRA_WINDOW_INFO = u8R"(Правый клик для изменения настроек Нажмите и перетащите за края - для перемещения, или за правый-нижний угол - для изменения размера)"; TOPMOST = u8"Поверх всех окон"; + SHOW_ORIGINAL = u8"Исходный текст"; SIZE_LOCK = u8"Фиксированный размер"; BG_COLOR = u8"Цвет заднего фона"; TEXT_COLOR = u8"Цвет текста";