Pass ProcessingItem through Translator event if it should not be translated (allow user to choose it be key modifiers).
This commit is contained in:
parent
2a1ee13b46
commit
9083a7ca6c
23
Manager.cpp
23
Manager.cpp
@ -29,7 +29,7 @@ Manager::Manager (QObject *parent) :
|
||||
resultDialog_ (new ResultDialog (*dictionary_)),
|
||||
captureAction_ (NULL), repeatCaptureAction_ (NULL),
|
||||
repeatAction_ (NULL), clipboardAction_ (NULL),
|
||||
useResultDialog_ (true) {
|
||||
useResultDialog_ (true), doTranslation_ (true) {
|
||||
GlobalActionHelper::init ();
|
||||
qRegisterMetaType<ProcessingItem>();
|
||||
|
||||
@ -38,7 +38,7 @@ Manager::Manager (QObject *parent) :
|
||||
connect (this, SIGNAL (requestRecognize (ProcessingItem)),
|
||||
recognizer, SLOT (recognize (ProcessingItem)));
|
||||
connect (recognizer, SIGNAL (recognized (ProcessingItem)),
|
||||
SIGNAL (recognized (ProcessingItem)));
|
||||
this, SIGNAL (requestTranslate (ProcessingItem)));
|
||||
connect (recognizer, SIGNAL (error (QString)),
|
||||
SLOT (showError (QString)));
|
||||
connect (this, SIGNAL (settingsEdited ()),
|
||||
@ -157,25 +157,11 @@ void Manager::applySettings () {
|
||||
|
||||
settings.beginGroup (settings_names::translationGroup);
|
||||
defaultTranslationLanguage_ = GET (translationLanguage).toString ();
|
||||
doTranslation_ = GET (doTranslation).toBool ();
|
||||
settings.endGroup ();
|
||||
|
||||
Q_CHECK_PTR (dictionary_);
|
||||
dictionary_->updateAvailableOcrLanguages ();
|
||||
|
||||
settings.beginGroup (settings_names::translationGroup);
|
||||
bool doTranslation = GET (doTranslation).toBool ();
|
||||
if (doTranslation) {
|
||||
disconnect (this, SIGNAL (recognized (ProcessingItem)),
|
||||
this, SLOT (showResult (ProcessingItem)));
|
||||
connect (this, SIGNAL (recognized (ProcessingItem)),
|
||||
this, SIGNAL (requestTranslate (ProcessingItem)), Qt::UniqueConnection);
|
||||
}
|
||||
else {
|
||||
disconnect (this, SIGNAL (recognized (ProcessingItem)),
|
||||
this, SIGNAL (requestTranslate (ProcessingItem)));
|
||||
connect (this, SIGNAL (recognized (ProcessingItem)),
|
||||
this, SLOT (showResult (ProcessingItem)), Qt::UniqueConnection);
|
||||
}
|
||||
#undef GET
|
||||
}
|
||||
|
||||
@ -210,7 +196,8 @@ void Manager::capture () {
|
||||
}
|
||||
|
||||
void Manager::handleSelection (ProcessingItem item) {
|
||||
if (item.translateLanguage.isEmpty ()) {
|
||||
bool altMod = item.modifiers & Qt::AltModifier;
|
||||
if ((doTranslation_ && !altMod) || (!doTranslation_ && altMod)) {
|
||||
item.translateLanguage = defaultTranslationLanguage_;
|
||||
}
|
||||
emit requestRecognize (item);
|
||||
|
@ -23,7 +23,6 @@ class Manager : public QObject {
|
||||
|
||||
signals:
|
||||
void requestRecognize (ProcessingItem item);
|
||||
void recognized (ProcessingItem item);
|
||||
void requestTranslate (ProcessingItem item);
|
||||
void closeSelections ();
|
||||
void settingsEdited ();
|
||||
@ -64,6 +63,7 @@ class Manager : public QObject {
|
||||
//! Used threads. For proper termination.
|
||||
QList<QThread *> threads_;
|
||||
QString defaultTranslationLanguage_;
|
||||
bool doTranslation_;
|
||||
};
|
||||
|
||||
#endif // MANAGER_H
|
||||
|
@ -46,6 +46,10 @@ void WebTranslator::addProxyToView () {
|
||||
}
|
||||
|
||||
void WebTranslator::translate (ProcessingItem item) {
|
||||
if (item.translateLanguage.isEmpty ()) {
|
||||
emit translated (item);
|
||||
return;
|
||||
}
|
||||
queue_.push_back (item);
|
||||
translateQueued ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user