ScreenTranslator/ResultDialog.cpp

70 lines
1.6 KiB
C++
Raw Normal View History

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>
ResultDialog::ResultDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ResultDialog),
isShowAtCapturePos_ (true)
{
ui->setupUi(this);
setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
Qt::WindowStaysOnTopHint);
installEventFilter (this);
}
ResultDialog::~ResultDialog()
{
delete ui;
}
bool ResultDialog::eventFilter(QObject* object, QEvent* event)
{
Q_UNUSED (object);
if (event->type () == QEvent::MouseButtonRelease)
{
hide ();
}
return QDialog::eventFilter (object, event);
}
void ResultDialog::showResult(ProcessingItem item)
{
2015-06-30 00:26:33 +07:00
ST_ASSERT (!item.source.isNull ());
ST_ASSERT (!item.recognized.isEmpty ());
ST_ASSERT (!item.translated.isEmpty ());
ST_ASSERT (!item.screenPos.isNull ());
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 ();
QDesktopWidget* desktop = QApplication::desktop ();
Q_CHECK_PTR (desktop);
2013-11-26 13:44:00 +07:00
if (isShowAtCapturePos_)
{
QPoint correction = QPoint (ui->frame->lineWidth (), ui->frame->lineWidth ());
move (item.screenPos - correction);
QRect screenRect = desktop->screenGeometry (this);
int minY = screenRect.bottom () - height ();
if (y () > minY)
{
move (x (), minY);
}
2013-11-26 13:44:00 +07:00
}
else
{
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);
}
}