2020-02-21 00:45:53 +07:00
|
|
|
#include "representer.h"
|
2020-03-28 16:16:54 +07:00
|
|
|
#include "debug.h"
|
2020-02-21 00:45:53 +07:00
|
|
|
#include "manager.h"
|
|
|
|
|
#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-21 17:03:58 +07:00
|
|
|
Representer::Representer(Manager &manager, TrayIcon &tray,
|
|
|
|
|
const Settings &settings)
|
2020-02-21 00:45:53 +07:00
|
|
|
: manager_(manager)
|
|
|
|
|
, tray_(tray)
|
2020-03-21 17:03:58 +07:00
|
|
|
, settings_(settings)
|
2020-02-21 00:45:53 +07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
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 );
|
|
|
|
|
const auto task = widget_->task();
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
2020-03-28 18:31:11 +07:00
|
|
|
auto text = task->recognized;
|
|
|
|
|
if (!task->translated.isEmpty())
|
|
|
|
|
text += QLatin1String(" - ") + task->translated;
|
|
|
|
|
clipboard->setText(text);
|
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
|
|
|
Representer::~Representer() = default;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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_)
|
|
|
|
|
widget_ = std::make_unique<ResultWidget>(settings_);
|
2020-02-21 00:45:53 +07:00
|
|
|
|
|
|
|
|
widget_->show(task);
|
|
|
|
|
}
|