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"
|
2013-11-26 13:44:00 +07:00
|
|
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
ResultDialog::ResultDialog (QWidget *parent) :
|
|
|
|
QDialog (parent),
|
|
|
|
ui (new Ui::ResultDialog),
|
|
|
|
isShowAtCapturePos_ (true) {
|
|
|
|
ui->setupUi (this);
|
2013-11-26 13:44:00 +07:00
|
|
|
setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
|
|
|
|
Qt::WindowStaysOnTopHint);
|
|
|
|
|
|
|
|
installEventFilter (this);
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
ResultDialog::~ResultDialog () {
|
2013-11-26 13:44:00 +07:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
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-09-23 01:41:08 +07:00
|
|
|
if (event->type () == QEvent::MouseButtonRelease) {
|
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 ());
|
2013-11-26 13:44:00 +07:00
|
|
|
ui->sourceLabel->setPixmap (item.source);
|
|
|
|
ui->recognizeLabel->setText (item.recognized);
|
|
|
|
ui->translateLabel->setText (item.translated);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|