note showing original works iff used after translation extension

This commit is contained in:
Akash Mozumdar 2019-06-16 15:50:17 -04:00
parent f86a776536
commit a9a9c0cea5
2 changed files with 8 additions and 6 deletions

View File

@ -3,6 +3,7 @@
#include <QDialog> #include <QDialog>
#include <QInputDialog> #include <QInputDialog>
#include <QColorDialog> #include <QColorDialog>
#include <QMessageBox>
#include <QMenu> #include <QMenu>
#include <QLayout> #include <QLayout>
#include <QLabel> #include <QLabel>
@ -14,6 +15,7 @@
extern const char* EXTRA_WINDOW_INFO; extern const char* EXTRA_WINDOW_INFO;
extern const char* TOPMOST; extern const char* TOPMOST;
extern const char* SHOW_ORIGINAL; extern const char* SHOW_ORIGINAL;
extern const char* SHOW_ORIGINAL_INFO;
extern const char* SIZE_LOCK; extern const char* SIZE_LOCK;
extern const char* BG_COLOR; extern const char* BG_COLOR;
extern const char* TEXT_COLOR; extern const char* TEXT_COLOR;
@ -73,7 +75,9 @@ public:
setSizeGripEnabled(!lock); setSizeGripEnabled(!lock);
settings->setValue(SIZE_LOCK, lock); settings->setValue(SIZE_LOCK, lock);
}; };
auto setShowOriginal = [=](bool showOriginal) { auto setShowOriginal = [=](bool showOriginal)
{
if (!showOriginal) QMessageBox::information(this, SHOW_ORIGINAL, SHOW_ORIGINAL_INFO);
settings->setValue(SHOW_ORIGINAL, showOriginal); settings->setValue(SHOW_ORIGINAL, showOriginal);
}; };
setGeometry(settings->value(WINDOW, geometry()).toRect()); setGeometry(settings->value(WINDOW, geometry()).toRect());
@ -165,11 +169,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
if (window == nullptr || !sentenceInfo["current select"]) return false; if (window == nullptr || !sentenceInfo["current select"]) return false;
QString qSentence = QString::fromStdWString(sentence); QString qSentence = QString::fromStdWString(sentence);
if (!window->settings->value(SHOW_ORIGINAL).toBool()) if (!window->settings->value(SHOW_ORIGINAL).toBool()) qSentence = qSentence.section('\n', qSentence.count('\n') / 2 + 1);
{
int middle = qSentence.count('\n') / 2;
qSentence = qSentence.section('\n', middle + 1);
};
QMetaObject::invokeMethod(window, [=] { window->display->setText(qSentence); }); QMetaObject::invokeMethod(window, [=] { window->display->setText(qSentence); });
return false; return false;

View File

@ -110,6 +110,8 @@ 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)"; Click and drag on window edges to move, or the bottom right corner to resize)";
const char* TOPMOST = u8"Always on Top"; const char* TOPMOST = u8"Always on Top";
const char* SHOW_ORIGINAL = u8"Original Text"; const char* SHOW_ORIGINAL = u8"Original Text";
const char* SHOW_ORIGINAL_INFO = u8R"(Original text will not be shown
Only works if this extension is used directly after a translation extension)";
const char* SIZE_LOCK = u8"Size Locked"; const char* SIZE_LOCK = u8"Size Locked";
const char* BG_COLOR = u8"Background Color"; const char* BG_COLOR = u8"Background Color";
const char* TEXT_COLOR = u8"Text Color"; const char* TEXT_COLOR = u8"Text Color";