Added ability to retranslate item from ResultDialog.
This commit is contained in:
		
							parent
							
								
									f33c0431b9
								
							
						
					
					
						commit
						3e499b86c5
					
				@ -87,6 +87,8 @@ void GoogleWebTranslator::load (const ProcessingItem &item) {
 | 
				
			|||||||
    emit error (tr ("Неверные парметры для перевода."));
 | 
					    emit error (tr ("Неверные парметры для перевода."));
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  QUrl url (QString ("https://translate.google.com/#auto/%1/%2").arg (translationLanguage_, item.recognized));
 | 
					  QString translateLanguage = (item.translateLanguage.isEmpty ())
 | 
				
			||||||
 | 
					                              ? translationLanguage_ : item.translateLanguage;
 | 
				
			||||||
 | 
					  QUrl url (QString ("https://translate.google.com/#auto/%1/%2").arg (translateLanguage, item.recognized));
 | 
				
			||||||
  view_->setUrl (url);
 | 
					  view_->setUrl (url);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -71,6 +71,8 @@ Manager::Manager (QObject *parent) :
 | 
				
			|||||||
  connect (this, SIGNAL (settingsEdited ()), resultDialog_, SLOT (applySettings ()));
 | 
					  connect (this, SIGNAL (settingsEdited ()), resultDialog_, SLOT (applySettings ()));
 | 
				
			||||||
  connect (resultDialog_, SIGNAL (requestRecognize (ProcessingItem)),
 | 
					  connect (resultDialog_, SIGNAL (requestRecognize (ProcessingItem)),
 | 
				
			||||||
           this, SIGNAL (requestRecognize (ProcessingItem)));
 | 
					           this, SIGNAL (requestRecognize (ProcessingItem)));
 | 
				
			||||||
 | 
					  connect (resultDialog_, SIGNAL (requestTranslate (ProcessingItem)),
 | 
				
			||||||
 | 
					           this, SIGNAL (requestTranslate (ProcessingItem)));
 | 
				
			||||||
  connect (resultDialog_, SIGNAL (requestClipboard ()), SLOT (copyLastToClipboard ()));
 | 
					  connect (resultDialog_, SIGNAL (requestClipboard ()), SLOT (copyLastToClipboard ()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -11,6 +11,7 @@ struct ProcessingItem {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  QString ocrLanguage;
 | 
					  QString ocrLanguage;
 | 
				
			||||||
  QString sourceLanguage;
 | 
					  QString sourceLanguage;
 | 
				
			||||||
 | 
					  QString translateLanguage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Qt::KeyboardModifiers modifiers;
 | 
					  Qt::KeyboardModifiers modifiers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,8 @@ ResultDialog::ResultDialog (const LanguageHelper &dictionary, QWidget *parent) :
 | 
				
			|||||||
  QDialog (parent),
 | 
					  QDialog (parent),
 | 
				
			||||||
  ui (new Ui::ResultDialog),
 | 
					  ui (new Ui::ResultDialog),
 | 
				
			||||||
  dictionary_ (dictionary), isShowAtCapturePos_ (true),
 | 
					  dictionary_ (dictionary), isShowAtCapturePos_ (true),
 | 
				
			||||||
  contextMenu_ (NULL), recognizeSubMenu_ (NULL), clipboardAction_ (NULL) {
 | 
					  contextMenu_ (NULL), recognizeSubMenu_ (NULL),  translateSubMenu_ (NULL),
 | 
				
			||||||
 | 
					  clipboardAction_ (NULL) {
 | 
				
			||||||
  ui->setupUi (this);
 | 
					  ui->setupUi (this);
 | 
				
			||||||
  setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
 | 
					  setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
 | 
				
			||||||
                  Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
 | 
					                  Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
 | 
				
			||||||
@ -32,11 +33,13 @@ const ProcessingItem &ResultDialog::item () const {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void ResultDialog::applySettings () {
 | 
					void ResultDialog::applySettings () {
 | 
				
			||||||
  dictionary_.updateMenu (recognizeSubMenu_, dictionary_.availableOcrLanguagesUi ());
 | 
					  dictionary_.updateMenu (recognizeSubMenu_, dictionary_.availableOcrLanguagesUi ());
 | 
				
			||||||
 | 
					  dictionary_.updateMenu (translateSubMenu_, dictionary_.translateLanguagesUi ());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ResultDialog::createContextMenu () {
 | 
					void ResultDialog::createContextMenu () {
 | 
				
			||||||
  contextMenu_ = new QMenu ();
 | 
					  contextMenu_ = new QMenu ();
 | 
				
			||||||
  recognizeSubMenu_ = contextMenu_->addMenu (tr ("Распознать другой язык"));
 | 
					  recognizeSubMenu_ = contextMenu_->addMenu (tr ("Распознать другой язык"));
 | 
				
			||||||
 | 
					  translateSubMenu_ = contextMenu_->addMenu (tr ("Перевести на другой язык"));
 | 
				
			||||||
  clipboardAction_ = contextMenu_->addAction (tr ("Скопировать в буфер"));
 | 
					  clipboardAction_ = contextMenu_->addAction (tr ("Скопировать в буфер"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -52,6 +55,12 @@ bool ResultDialog::eventFilter (QObject *object, QEvent *event) {
 | 
				
			|||||||
        item.ocrLanguage = dictionary_.ocrUiToCode (action->text ());
 | 
					        item.ocrLanguage = dictionary_.ocrUiToCode (action->text ());
 | 
				
			||||||
        emit requestRecognize (item);
 | 
					        emit requestRecognize (item);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      else if (translateSubMenu_->findChildren<QAction *> ().contains (action)) {
 | 
				
			||||||
 | 
					        ProcessingItem item = item_;
 | 
				
			||||||
 | 
					        item.translated.clear ();
 | 
				
			||||||
 | 
					        item.translateLanguage = dictionary_.translateUiToCode (action->text ());
 | 
				
			||||||
 | 
					        emit requestTranslate (item);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      else if (action == clipboardAction_) {
 | 
					      else if (action == clipboardAction_) {
 | 
				
			||||||
        emit requestClipboard ();
 | 
					        emit requestClipboard ();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,7 @@ class ResultDialog : public QDialog {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  signals:
 | 
					  signals:
 | 
				
			||||||
    void requestRecognize (ProcessingItem item);
 | 
					    void requestRecognize (ProcessingItem item);
 | 
				
			||||||
 | 
					    void requestTranslate (ProcessingItem item);
 | 
				
			||||||
    void requestClipboard (); // Assume that slot will be called immediately.
 | 
					    void requestClipboard (); // Assume that slot will be called immediately.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
@ -39,6 +40,7 @@ class ResultDialog : public QDialog {
 | 
				
			|||||||
    bool isShowAtCapturePos_;
 | 
					    bool isShowAtCapturePos_;
 | 
				
			||||||
    QMenu *contextMenu_;
 | 
					    QMenu *contextMenu_;
 | 
				
			||||||
    QMenu *recognizeSubMenu_;
 | 
					    QMenu *recognizeSubMenu_;
 | 
				
			||||||
 | 
					    QMenu *translateSubMenu_;
 | 
				
			||||||
    QAction *clipboardAction_;
 | 
					    QAction *clipboardAction_;
 | 
				
			||||||
    ProcessingItem item_;
 | 
					    ProcessingItem item_;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -55,7 +55,9 @@ void Translator::translate (ProcessingItem item) {
 | 
				
			|||||||
    emit error (tr ("Неверные парметры для перевода."));
 | 
					    emit error (tr ("Неверные парметры для перевода."));
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  QUrl url (translateBaseUrl.arg (item.recognized, sourceLanguage, translationLanguage_));
 | 
					  QString translateLanguage = (item.translateLanguage.isEmpty ())
 | 
				
			||||||
 | 
					                              ? translationLanguage_ : item.translateLanguage;
 | 
				
			||||||
 | 
					  QUrl url (translateBaseUrl.arg (item.recognized, sourceLanguage, translateLanguage));
 | 
				
			||||||
  QNetworkReply *reply = network_.get (QNetworkRequest (url));
 | 
					  QNetworkReply *reply = network_.get (QNetworkRequest (url));
 | 
				
			||||||
  items_.insert (reply, item);
 | 
					  items_.insert (reply, item);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user