forked from Public-Mirror/Textractor
Merge pull request #160 from Niakr1s/master
Feature: show/hide original text
This commit is contained in:
commit
68534619aa
@ -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>
|
||||||
@ -17,6 +18,8 @@
|
|||||||
|
|
||||||
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_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;
|
||||||
@ -100,6 +103,11 @@ public:
|
|||||||
setSizeGripEnabled(!lock);
|
setSizeGripEnabled(!lock);
|
||||||
settings->setValue(SIZE_LOCK, lock);
|
settings->setValue(SIZE_LOCK, lock);
|
||||||
};
|
};
|
||||||
|
auto setShowOriginal = [=](bool showOriginal)
|
||||||
|
{
|
||||||
|
if (!showOriginal) QMessageBox::information(this, SHOW_ORIGINAL, SHOW_ORIGINAL_INFO);
|
||||||
|
settings->setValue(SHOW_ORIGINAL, showOriginal);
|
||||||
|
};
|
||||||
setGeometry(settings->value(WINDOW, geometry()).toRect());
|
setGeometry(settings->value(WINDOW, geometry()).toRect());
|
||||||
setLock(settings->value(SIZE_LOCK, false).toBool());
|
setLock(settings->value(SIZE_LOCK, false).toBool());
|
||||||
setTopmost(settings->value(TOPMOST, false).toBool());
|
setTopmost(settings->value(TOPMOST, false).toBool());
|
||||||
@ -117,6 +125,9 @@ public:
|
|||||||
auto lock = menu->addAction(SIZE_LOCK, setLock);
|
auto lock = menu->addAction(SIZE_LOCK, setLock);
|
||||||
lock->setCheckable(true);
|
lock->setCheckable(true);
|
||||||
lock->setChecked(settings->value(SIZE_LOCK, false).toBool());
|
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(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(TEXT_COLOR, [=] { setTextColor(QColorDialog::getColor(display->palette().windowText().color(), this, TEXT_COLOR, QColorDialog::ShowAlphaChannel)); });
|
||||||
menu->addAction(FONT, requestFont);
|
menu->addAction(FONT, requestFont);
|
||||||
@ -186,7 +197,11 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved
|
|||||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||||
{
|
{
|
||||||
std::lock_guard l(m);
|
std::lock_guard l(m);
|
||||||
if (!window || !sentenceInfo["current select"]) return false;
|
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()) qSentence = qSentence.section('\n', qSentence.count('\n') / 2 + 1);
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(window, [=] { window->display->setText(qSentence); });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
6
text.cpp
6
text.cpp
@ -110,6 +110,9 @@ const wchar_t* TRANSLATION_ERROR = L"Error while translating";
|
|||||||
const char* EXTRA_WINDOW_INFO = u8R"(Right click to change settings
|
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_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";
|
||||||
@ -381,6 +384,9 @@ I'm currently looking for a new job: email me if you know anyone hiring US softw
|
|||||||
EXTRA_WINDOW_INFO = u8R"(Правый клик для изменения настроек
|
EXTRA_WINDOW_INFO = u8R"(Правый клик для изменения настроек
|
||||||
Нажмите и перетащите за края - для перемещения, или за правый-нижний угол - для изменения размера)";
|
Нажмите и перетащите за края - для перемещения, или за правый-нижний угол - для изменения размера)";
|
||||||
TOPMOST = u8"Поверх всех окон";
|
TOPMOST = u8"Поверх всех окон";
|
||||||
|
SHOW_ORIGINAL = u8"Исходный текст";
|
||||||
|
SHOW_ORIGINAL_INFO = u8R"(Исходный текст будет скрыт
|
||||||
|
Работает только если это расширение используется после расширения перевода)";
|
||||||
SIZE_LOCK = u8"Фиксированный размер";
|
SIZE_LOCK = u8"Фиксированный размер";
|
||||||
BG_COLOR = u8"Цвет заднего фона";
|
BG_COLOR = u8"Цвет заднего фона";
|
||||||
TEXT_COLOR = u8"Цвет текста";
|
TEXT_COLOR = u8"Цвет текста";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user