Added ability to swap translation/ocr languages.
This commit is contained in:
parent
a57e0b1af8
commit
027c7b46a0
16
Manager.cpp
16
Manager.cpp
@ -216,12 +216,26 @@ void Manager::capture () {
|
||||
|
||||
void Manager::handleSelection (ProcessingItem item) {
|
||||
bool altMod = item.modifiers & Qt::AltModifier;
|
||||
if ((doTranslation_ && !altMod) || (!doTranslation_ && altMod)) {
|
||||
bool doTranslation = (doTranslation_ && !altMod) || (!doTranslation_ && altMod);
|
||||
if (doTranslation) {
|
||||
item.translateLanguage = defaultTranslationLanguage_;
|
||||
}
|
||||
if (item.ocrLanguage.isEmpty ()) {
|
||||
item.ocrLanguage = defaultOrcLanguage_;
|
||||
}
|
||||
if (item.swapLanguages_) {
|
||||
QString translate = (item.translateLanguage.isEmpty ())
|
||||
? defaultTranslationLanguage_ : item.translateLanguage;
|
||||
if (doTranslation) {
|
||||
item.translateLanguage = dictionary_->ocrToTranslateCodes (item.ocrLanguage);
|
||||
}
|
||||
item.sourceLanguage.clear ();
|
||||
item.ocrLanguage = dictionary_->translateToOcrCodes (translate);
|
||||
if (item.ocrLanguage.isEmpty ()) {
|
||||
showError (tr ("Не найден подходящий язык распознавания."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (item.sourceLanguage.isEmpty ()) {
|
||||
item.sourceLanguage = dictionary_->ocrToTranslateCodes (item.ocrLanguage);
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
#include "ProcessingItem.h"
|
||||
|
||||
ProcessingItem::ProcessingItem ()
|
||||
: swapLanguages_ (false) {
|
||||
|
||||
}
|
||||
|
||||
bool ProcessingItem::isValid (bool checkOnlyInput) const {
|
||||
bool valid = true;
|
||||
valid &= (!screenPos.isNull ());
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QPixmap>
|
||||
|
||||
struct ProcessingItem {
|
||||
ProcessingItem ();
|
||||
QPoint screenPos;
|
||||
QPixmap source;
|
||||
QString recognized;
|
||||
@ -14,6 +15,7 @@ struct ProcessingItem {
|
||||
QString translateLanguage;
|
||||
|
||||
Qt::KeyboardModifiers modifiers;
|
||||
bool swapLanguages_;
|
||||
|
||||
bool isValid (bool checkOnlyInput = false) const;
|
||||
};
|
||||
|
@ -11,7 +11,7 @@
|
||||
SelectionDialog::SelectionDialog (const LanguageHelper &dictionary, QWidget *parent) :
|
||||
QDialog (parent),
|
||||
ui (new Ui::SelectionDialog), dictionary_ (dictionary),
|
||||
languageMenu_ (new QMenu) {
|
||||
languageMenu_ (new QMenu), swapLanguagesAction_ (NULL) {
|
||||
ui->setupUi (this);
|
||||
setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
|
||||
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
|
||||
@ -28,6 +28,9 @@ SelectionDialog::~SelectionDialog () {
|
||||
|
||||
void SelectionDialog::applySettings () {
|
||||
dictionary_.updateMenu (languageMenu_, dictionary_.availableOcrLanguagesUi ());
|
||||
if (!languageMenu_->isEmpty ()) {
|
||||
swapLanguagesAction_ = languageMenu_->addAction (tr ("Поменять язык текста и перевода"));
|
||||
}
|
||||
}
|
||||
|
||||
bool SelectionDialog::eventFilter (QObject *object, QEvent *event) {
|
||||
@ -88,10 +91,15 @@ bool SelectionDialog::eventFilter (QObject *object, QEvent *event) {
|
||||
reject ();
|
||||
return QDialog::eventFilter (object, event);
|
||||
}
|
||||
item.ocrLanguage = dictionary_.ocrUiToCode (action->text ());
|
||||
ST_ASSERT (!item.ocrLanguage.isEmpty ());
|
||||
item.sourceLanguage = dictionary_.ocrToTranslateCodes (item.ocrLanguage);
|
||||
ST_ASSERT (!item.sourceLanguage.isEmpty ());
|
||||
if (action == swapLanguagesAction_) {
|
||||
item.swapLanguages_ = true;
|
||||
}
|
||||
else {
|
||||
item.ocrLanguage = dictionary_.ocrUiToCode (action->text ());
|
||||
ST_ASSERT (!item.ocrLanguage.isEmpty ());
|
||||
item.sourceLanguage = dictionary_.ocrToTranslateCodes (item.ocrLanguage);
|
||||
ST_ASSERT (!item.sourceLanguage.isEmpty ());
|
||||
}
|
||||
}
|
||||
emit selected (item);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class SelectionDialog : public QDialog {
|
||||
QPoint currentSelectPos_;
|
||||
QPixmap currentPixmap_;
|
||||
QMenu *languageMenu_;
|
||||
QAction *swapLanguagesAction_;
|
||||
};
|
||||
|
||||
#endif // SELECTIONDIALOG_H
|
||||
|
Loading…
Reference in New Issue
Block a user