Added ability to repeat image recognition with another OCR language from ResultDialog.
This commit is contained in:
parent
5b166cba4c
commit
1f5d6c73bd
@ -25,7 +25,7 @@ Manager::Manager (QObject *parent) :
|
||||
QObject (parent),
|
||||
trayIcon_ (new QSystemTrayIcon (QIcon (":/images/icon.png"), this)),
|
||||
dictionary_ (new LanguageHelper),
|
||||
resultDialog_ (new ResultDialog),
|
||||
resultDialog_ (new ResultDialog (*dictionary_)),
|
||||
captureAction_ (NULL), repeatCaptureAction_ (NULL),
|
||||
repeatAction_ (NULL), clipboardAction_ (NULL),
|
||||
useResultDialog_ (true) {
|
||||
@ -66,7 +66,11 @@ Manager::Manager (QObject *parent) :
|
||||
connect (qApp, SIGNAL (aboutToQuit ()), translatorThread, SLOT (quit ()));
|
||||
|
||||
connect (this, SIGNAL (settingsEdited ()), this, SLOT (applySettings ()));
|
||||
|
||||
resultDialog_->setWindowIcon (trayIcon_->icon ());
|
||||
connect (this, SIGNAL (settingsEdited ()), resultDialog_, SLOT (applySettings ()));
|
||||
connect (resultDialog_, SIGNAL (requestRecognize (ProcessingItem)),
|
||||
this, SIGNAL (requestRecognize (ProcessingItem)));
|
||||
|
||||
|
||||
connect (trayIcon_, SIGNAL (activated (QSystemTrayIcon::ActivationReason)),
|
||||
|
@ -1,28 +1,57 @@
|
||||
#include "ResultDialog.h"
|
||||
#include "ui_ResultDialog.h"
|
||||
#include "StAssert.h"
|
||||
#include "LanguageHelper.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QMenu>
|
||||
|
||||
ResultDialog::ResultDialog (QWidget *parent) :
|
||||
ResultDialog::ResultDialog (const LanguageHelper &dictionary, QWidget *parent) :
|
||||
QDialog (parent),
|
||||
ui (new Ui::ResultDialog),
|
||||
isShowAtCapturePos_ (true) {
|
||||
dictionary_ (dictionary), isShowAtCapturePos_ (true),
|
||||
contextMenu_ (NULL), recognizeSubMenu_ (NULL) {
|
||||
ui->setupUi (this);
|
||||
setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
|
||||
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
|
||||
|
||||
installEventFilter (this);
|
||||
createContextMenu ();
|
||||
applySettings ();
|
||||
}
|
||||
|
||||
ResultDialog::~ResultDialog () {
|
||||
delete contextMenu_;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ResultDialog::applySettings () {
|
||||
dictionary_.updateMenu (recognizeSubMenu_, dictionary_.availableOcrLanguagesUi ());
|
||||
}
|
||||
|
||||
void ResultDialog::createContextMenu () {
|
||||
contextMenu_ = new QMenu ();
|
||||
recognizeSubMenu_ = contextMenu_->addMenu (tr ("Распознать другой язык"));
|
||||
}
|
||||
|
||||
bool ResultDialog::eventFilter (QObject *object, QEvent *event) {
|
||||
Q_UNUSED (object);
|
||||
if (event->type () == QEvent::MouseButtonRelease ||
|
||||
event->type () == QEvent::WindowDeactivate) {
|
||||
if (event->type () == QEvent::MouseButtonPress) {
|
||||
Qt::MouseButton button = static_cast<QMouseEvent *>(event)->button ();
|
||||
if (button == Qt::RightButton) {
|
||||
QAction *action = contextMenu_->exec (QCursor::pos ());
|
||||
QWidget *subMenu = action->parentWidget ();
|
||||
if (recognizeSubMenu_->isAncestorOf (subMenu)) {
|
||||
ProcessingItem item = lastItem_;
|
||||
item.translated = item.recognized = QString ();
|
||||
item.ocrLanguage = dictionary_.ocrUiToCode (action->text ());
|
||||
emit requestRecognize (item);
|
||||
}
|
||||
}
|
||||
hide ();
|
||||
}
|
||||
else if (event->type () == QEvent::WindowDeactivate) {
|
||||
hide ();
|
||||
}
|
||||
return QDialog::eventFilter (object, event);
|
||||
@ -30,6 +59,7 @@ bool ResultDialog::eventFilter (QObject *object, QEvent *event) {
|
||||
|
||||
void ResultDialog::showResult (ProcessingItem item) {
|
||||
ST_ASSERT (item.isValid ());
|
||||
lastItem_ = item;
|
||||
ui->sourceLabel->setPixmap (item.source);
|
||||
ui->recognizeLabel->setText (item.recognized);
|
||||
ui->translateLabel->setText (item.translated);
|
||||
|
@ -2,29 +2,42 @@
|
||||
#define RESULTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMenu>
|
||||
|
||||
#include "ProcessingItem.h"
|
||||
|
||||
namespace Ui {
|
||||
class ResultDialog;
|
||||
}
|
||||
class LanguageHelper;
|
||||
|
||||
class ResultDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ResultDialog (QWidget *parent = 0);
|
||||
explicit ResultDialog (const LanguageHelper &dictionary, QWidget *parent = 0);
|
||||
~ResultDialog ();
|
||||
|
||||
signals:
|
||||
void requestRecognize (ProcessingItem item);
|
||||
|
||||
public:
|
||||
bool eventFilter (QObject *object, QEvent *event);
|
||||
|
||||
public slots:
|
||||
void showResult (ProcessingItem item);
|
||||
void applySettings ();
|
||||
|
||||
private:
|
||||
void createContextMenu ();
|
||||
|
||||
private:
|
||||
Ui::ResultDialog *ui;
|
||||
const LanguageHelper &dictionary_;
|
||||
bool isShowAtCapturePos_;
|
||||
QMenu *contextMenu_;
|
||||
QMenu *recognizeSubMenu_;
|
||||
ProcessingItem lastItem_;
|
||||
};
|
||||
|
||||
#endif // RESULTDIALOG_H
|
||||
|
Loading…
Reference in New Issue
Block a user