2013-11-26 13:44:00 +07:00
|
|
|
#include "ResultDialog.h"
|
|
|
|
#include "ui_ResultDialog.h"
|
2015-06-30 00:26:33 +07:00
|
|
|
#include "StAssert.h"
|
2015-10-01 00:38:55 +07:00
|
|
|
#include "LanguageHelper.h"
|
2013-11-26 13:44:00 +07:00
|
|
|
|
|
|
|
#include <QDesktopWidget>
|
2015-10-01 00:38:55 +07:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QMenu>
|
2013-11-26 13:44:00 +07:00
|
|
|
|
2015-10-01 00:38:55 +07:00
|
|
|
ResultDialog::ResultDialog (const LanguageHelper &dictionary, QWidget *parent) :
|
2015-09-23 01:41:08 +07:00
|
|
|
QDialog (parent),
|
|
|
|
ui (new Ui::ResultDialog),
|
2015-10-01 00:38:55 +07:00
|
|
|
dictionary_ (dictionary), isShowAtCapturePos_ (true),
|
|
|
|
contextMenu_ (NULL), recognizeSubMenu_ (NULL) {
|
2015-09-23 01:41:08 +07:00
|
|
|
ui->setupUi (this);
|
2013-11-26 13:44:00 +07:00
|
|
|
setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
|
2015-09-30 23:49:10 +07:00
|
|
|
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
|
2013-11-26 13:44:00 +07:00
|
|
|
|
|
|
|
installEventFilter (this);
|
2015-10-01 00:38:55 +07:00
|
|
|
createContextMenu ();
|
|
|
|
applySettings ();
|
2013-11-26 13:44:00 +07:00
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
ResultDialog::~ResultDialog () {
|
2015-10-01 00:38:55 +07:00
|
|
|
delete contextMenu_;
|
2013-11-26 13:44:00 +07:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:38:55 +07:00
|
|
|
void ResultDialog::applySettings () {
|
|
|
|
dictionary_.updateMenu (recognizeSubMenu_, dictionary_.availableOcrLanguagesUi ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultDialog::createContextMenu () {
|
|
|
|
contextMenu_ = new QMenu ();
|
|
|
|
recognizeSubMenu_ = contextMenu_->addMenu (tr ("Распознать другой язык"));
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
bool ResultDialog::eventFilter (QObject *object, QEvent *event) {
|
2013-11-26 13:44:00 +07:00
|
|
|
Q_UNUSED (object);
|
2015-10-01 00:38:55 +07:00
|
|
|
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) {
|
2013-11-26 13:44:00 +07:00
|
|
|
hide ();
|
|
|
|
}
|
|
|
|
return QDialog::eventFilter (object, event);
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
void ResultDialog::showResult (ProcessingItem item) {
|
2015-09-29 03:24:08 +07:00
|
|
|
ST_ASSERT (item.isValid ());
|
2015-10-01 00:38:55 +07:00
|
|
|
lastItem_ = item;
|
2013-11-26 13:44:00 +07:00
|
|
|
ui->sourceLabel->setPixmap (item.source);
|
|
|
|
ui->recognizeLabel->setText (item.recognized);
|
|
|
|
ui->translateLabel->setText (item.translated);
|
2015-09-29 19:37:47 +07:00
|
|
|
bool gotTranslation = !item.translated.isEmpty ();
|
|
|
|
ui->translateLabel->setVisible (gotTranslation);
|
|
|
|
ui->translateLine->setVisible (gotTranslation);
|
2013-11-26 13:44:00 +07:00
|
|
|
|
2013-11-28 02:15:21 +07:00
|
|
|
show ();
|
2013-11-26 13:44:00 +07:00
|
|
|
adjustSize ();
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
QDesktopWidget *desktop = QApplication::desktop ();
|
2013-11-26 23:59:47 +07:00
|
|
|
Q_CHECK_PTR (desktop);
|
2015-09-23 01:41:08 +07:00
|
|
|
if (isShowAtCapturePos_) {
|
2013-11-26 13:44:00 +07:00
|
|
|
QPoint correction = QPoint (ui->frame->lineWidth (), ui->frame->lineWidth ());
|
|
|
|
move (item.screenPos - correction);
|
2013-11-26 23:59:47 +07:00
|
|
|
QRect screenRect = desktop->screenGeometry (this);
|
|
|
|
int minY = screenRect.bottom () - height ();
|
2015-09-23 01:41:08 +07:00
|
|
|
if (y () > minY) {
|
2013-11-26 23:59:47 +07:00
|
|
|
move (x (), minY);
|
|
|
|
}
|
2013-11-26 13:44:00 +07:00
|
|
|
}
|
2015-09-23 01:41:08 +07:00
|
|
|
else {
|
2013-11-26 23:59:47 +07:00
|
|
|
|
2013-11-26 13:44:00 +07:00
|
|
|
QRect screenRect = desktop->availableGeometry (this);
|
2015-06-30 00:26:33 +07:00
|
|
|
ST_ASSERT (screenRect.isValid ());
|
2013-11-26 13:44:00 +07:00
|
|
|
QPoint newPos (screenRect.width () - width (), screenRect.height () - height ());
|
|
|
|
move (newPos);
|
|
|
|
}
|
2015-09-29 22:11:00 +07:00
|
|
|
activateWindow ();
|
2013-11-26 13:44:00 +07:00
|
|
|
}
|