2020-02-21 00:45:53 +07:00
|
|
|
#include "representer.h"
|
2020-03-28 16:16:54 +07:00
|
|
|
#include "debug.h"
|
2020-03-29 15:09:55 +07:00
|
|
|
#include "geometryutils.h"
|
2020-02-21 00:45:53 +07:00
|
|
|
#include "manager.h"
|
2020-03-29 15:09:55 +07:00
|
|
|
#include "resulteditor.h"
|
2020-02-21 00:45:53 +07:00
|
|
|
#include "resultwidget.h"
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "task.h"
|
|
|
|
|
#include "trayicon.h"
|
|
|
|
|
|
2020-03-28 16:16:54 +07:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QClipboard>
|
2020-03-29 15:09:55 +07:00
|
|
|
#include <QScreen>
|
2020-03-28 16:16:54 +07:00
|
|
|
|
2020-03-21 17:03:58 +07:00
|
|
|
Representer::Representer(Manager &manager, TrayIcon &tray,
|
2020-03-29 15:09:55 +07:00
|
|
|
const Settings &settings, const CommonModels &models)
|
2020-02-21 00:45:53 +07:00
|
|
|
: manager_(manager)
|
|
|
|
|
, tray_(tray)
|
2020-03-21 17:03:58 +07:00
|
|
|
, settings_(settings)
|
2020-03-29 15:09:55 +07:00
|
|
|
, models_(models)
|
2020-02-21 00:45:53 +07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 15:09:55 +07:00
|
|
|
Representer::~Representer() = default;
|
|
|
|
|
|
2020-03-28 16:16:54 +07:00
|
|
|
void Representer::showLast()
|
|
|
|
|
{
|
|
|
|
|
SOFT_ASSERT(widget_, return );
|
|
|
|
|
widget_->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Representer::clipboardLast()
|
|
|
|
|
{
|
|
|
|
|
SOFT_ASSERT(widget_, return );
|
|
|
|
|
SOFT_ASSERT(widget_->task(), return );
|
2020-03-29 15:09:55 +07:00
|
|
|
clipboardText(widget_->task());
|
2020-03-28 16:16:54 +07:00
|
|
|
tray_.showInformation(
|
|
|
|
|
QObject::tr("The last result was copied to the clipboard."));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 00:45:53 +07:00
|
|
|
void Representer::represent(const TaskPtr &task)
|
|
|
|
|
{
|
2020-03-21 17:03:58 +07:00
|
|
|
if (settings_.resultShowType == ResultMode::Tooltip)
|
2020-02-21 00:45:53 +07:00
|
|
|
showTooltip(task);
|
|
|
|
|
else
|
|
|
|
|
showWidget(task);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 17:03:58 +07:00
|
|
|
void Representer::updateSettings()
|
2020-02-21 00:45:53 +07:00
|
|
|
{
|
2020-03-20 01:47:46 +07:00
|
|
|
if (widget_)
|
2020-03-21 17:03:58 +07:00
|
|
|
widget_->updateSettings();
|
2020-02-21 00:45:53 +07:00
|
|
|
}
|
|
|
|
|
|
2020-03-29 15:09:55 +07:00
|
|
|
void Representer::clipboardText(const TaskPtr &task)
|
|
|
|
|
{
|
|
|
|
|
if (!task)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
|
auto text = task->recognized;
|
|
|
|
|
if (!task->translated.isEmpty())
|
|
|
|
|
text += QLatin1String(" - ") + task->translated;
|
|
|
|
|
clipboard->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Representer::clipboardImage(const TaskPtr &task)
|
|
|
|
|
{
|
|
|
|
|
if (!task)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
|
clipboard->setPixmap(task->captured);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Representer::edit(const TaskPtr &task)
|
|
|
|
|
{
|
|
|
|
|
if (!editor_)
|
|
|
|
|
editor_ = std::make_unique<ResultEditor>(manager_, models_, settings_);
|
|
|
|
|
|
|
|
|
|
editor_->show(task);
|
|
|
|
|
|
|
|
|
|
const auto cursor = QCursor::pos();
|
|
|
|
|
const auto screen = QApplication::screenAt(cursor);
|
|
|
|
|
SOFT_ASSERT(screen, return );
|
|
|
|
|
editor_->move(service::geometry::cornerAtPoint(cursor, editor_->size(),
|
|
|
|
|
screen->geometry()));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 00:45:53 +07:00
|
|
|
void Representer::showTooltip(const TaskPtr &task)
|
|
|
|
|
{
|
|
|
|
|
auto message = task->recognized + " - " + task->translated;
|
|
|
|
|
tray_.showInformation(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Representer::showWidget(const TaskPtr &task)
|
|
|
|
|
{
|
2020-03-21 17:03:58 +07:00
|
|
|
if (!widget_)
|
2020-03-29 15:09:55 +07:00
|
|
|
widget_ = std::make_unique<ResultWidget>(*this, settings_);
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
|
widget_->show(task);
|
|
|
|
|
}
|