Move interaction with last result to representer

This commit is contained in:
Gres 2020-03-28 12:16:54 +03:00
parent d55ccd82b9
commit 2da5363448
6 changed files with 43 additions and 21 deletions

View File

@ -11,7 +11,6 @@
#include "updates.h"
#include <QApplication>
#include <QClipboard>
#include <QMessageBox>
#include <QNetworkProxy>
@ -127,11 +126,9 @@ void Manager::finishTask(const TaskPtr &task)
--activeTaskCount_;
tray_->setActiveTaskCount(activeTaskCount_);
last_ = task;
tray_->setTaskActionsEnabled(last_->isValid());
if (!task->isValid()) {
tray_->showError(task->error);
tray_->setTaskActionsEnabled(false);
return;
}
@ -201,6 +198,7 @@ void Manager::translated(const TaskPtr &task)
return;
representer_->represent(task);
tray_->setTaskActionsEnabled(true);
}
void Manager::applySettings(const Settings &settings)
@ -232,14 +230,6 @@ void Manager::repeatCapture()
capturer_->repeatCapture();
}
void Manager::showLast()
{
if (!last_ || !last_->isValid())
return;
SOFT_ASSERT(representer_, return );
representer_->represent(last_);
}
void Manager::settings()
{
SettingsEditor editor(*this, *updater_);
@ -260,16 +250,16 @@ void Manager::settings()
applySettings(edited);
}
void Manager::showLast()
{
SOFT_ASSERT(representer_, return );
representer_->showLast();
}
void Manager::copyLastToClipboard()
{
if (!last_ || !last_->isValid())
return;
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(last_->recognized + QLatin1String(" - ") +
last_->translated);
tray_->showInformation(
QObject::tr("The last result was copied to the clipboard."));
SOFT_ASSERT(representer_, return );
representer_->clipboardLast();
}
void Manager::about()

View File

@ -40,6 +40,5 @@ private:
std::unique_ptr<Representer> representer_;
std::unique_ptr<update::Loader> updater_;
std::unique_ptr<update::AutoChecker> updateAutoChecker_;
TaskPtr last_;
int activeTaskCount_{0};
};

View File

@ -1,10 +1,14 @@
#include "representer.h"
#include "debug.h"
#include "manager.h"
#include "resultwidget.h"
#include "settings.h"
#include "task.h"
#include "trayicon.h"
#include <QApplication>
#include <QClipboard>
Representer::Representer(Manager &manager, TrayIcon &tray,
const Settings &settings)
: manager_(manager)
@ -13,6 +17,24 @@ Representer::Representer(Manager &manager, TrayIcon &tray,
{
}
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();
clipboard->setText(task->recognized + QLatin1String(" - ") +
task->translated);
tray_.showInformation(
QObject::tr("The last result was copied to the clipboard."));
}
Representer::~Representer() = default;
void Representer::represent(const TaskPtr &task)

View File

@ -11,6 +11,8 @@ public:
Representer(Manager &manager, TrayIcon &tray, const Settings &settings);
~Representer();
void showLast();
void clipboardLast();
void represent(const TaskPtr &task);
void updateSettings();

View File

@ -52,9 +52,16 @@ ResultWidget::ResultWidget(const Settings &settings, QWidget *parent)
layout->setSpacing(1);
}
const TaskPtr &ResultWidget::task() const
{
return task_;
}
void ResultWidget::show(const TaskPtr &task)
{
task_ = task;
SOFT_ASSERT(task->isValid(), return );
image_->setPixmap(task->captured);
recognized_->setText(task->corrected);

View File

@ -12,6 +12,7 @@ class ResultWidget : public QFrame
public:
explicit ResultWidget(const Settings& settings, QWidget* parent = nullptr);
const TaskPtr& task() const;
void show(const TaskPtr& task);
using QWidget::show;
void updateSettings();
@ -20,6 +21,7 @@ public:
private:
const Settings& settings_;
TaskPtr task_;
QLabel* image_;
QLabel* recognized_;
QLabel* translated_;