Move interaction with last result to representer
This commit is contained in:
parent
d55ccd82b9
commit
2da5363448
@ -11,7 +11,6 @@
|
|||||||
#include "updates.h"
|
#include "updates.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
|
|
||||||
@ -127,11 +126,9 @@ void Manager::finishTask(const TaskPtr &task)
|
|||||||
--activeTaskCount_;
|
--activeTaskCount_;
|
||||||
tray_->setActiveTaskCount(activeTaskCount_);
|
tray_->setActiveTaskCount(activeTaskCount_);
|
||||||
|
|
||||||
last_ = task;
|
|
||||||
tray_->setTaskActionsEnabled(last_->isValid());
|
|
||||||
|
|
||||||
if (!task->isValid()) {
|
if (!task->isValid()) {
|
||||||
tray_->showError(task->error);
|
tray_->showError(task->error);
|
||||||
|
tray_->setTaskActionsEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +198,7 @@ void Manager::translated(const TaskPtr &task)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
representer_->represent(task);
|
representer_->represent(task);
|
||||||
|
tray_->setTaskActionsEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::applySettings(const Settings &settings)
|
void Manager::applySettings(const Settings &settings)
|
||||||
@ -232,14 +230,6 @@ void Manager::repeatCapture()
|
|||||||
capturer_->repeatCapture();
|
capturer_->repeatCapture();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::showLast()
|
|
||||||
{
|
|
||||||
if (!last_ || !last_->isValid())
|
|
||||||
return;
|
|
||||||
SOFT_ASSERT(representer_, return );
|
|
||||||
representer_->represent(last_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Manager::settings()
|
void Manager::settings()
|
||||||
{
|
{
|
||||||
SettingsEditor editor(*this, *updater_);
|
SettingsEditor editor(*this, *updater_);
|
||||||
@ -260,16 +250,16 @@ void Manager::settings()
|
|||||||
applySettings(edited);
|
applySettings(edited);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::showLast()
|
||||||
|
{
|
||||||
|
SOFT_ASSERT(representer_, return );
|
||||||
|
representer_->showLast();
|
||||||
|
}
|
||||||
|
|
||||||
void Manager::copyLastToClipboard()
|
void Manager::copyLastToClipboard()
|
||||||
{
|
{
|
||||||
if (!last_ || !last_->isValid())
|
SOFT_ASSERT(representer_, return );
|
||||||
return;
|
representer_->clipboardLast();
|
||||||
|
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
|
||||||
clipboard->setText(last_->recognized + QLatin1String(" - ") +
|
|
||||||
last_->translated);
|
|
||||||
tray_->showInformation(
|
|
||||||
QObject::tr("The last result was copied to the clipboard."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::about()
|
void Manager::about()
|
||||||
|
@ -40,6 +40,5 @@ private:
|
|||||||
std::unique_ptr<Representer> representer_;
|
std::unique_ptr<Representer> representer_;
|
||||||
std::unique_ptr<update::Loader> updater_;
|
std::unique_ptr<update::Loader> updater_;
|
||||||
std::unique_ptr<update::AutoChecker> updateAutoChecker_;
|
std::unique_ptr<update::AutoChecker> updateAutoChecker_;
|
||||||
TaskPtr last_;
|
|
||||||
int activeTaskCount_{0};
|
int activeTaskCount_{0};
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
#include "representer.h"
|
#include "representer.h"
|
||||||
|
#include "debug.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "resultwidget.h"
|
#include "resultwidget.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "trayicon.h"
|
#include "trayicon.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
|
|
||||||
Representer::Representer(Manager &manager, TrayIcon &tray,
|
Representer::Representer(Manager &manager, TrayIcon &tray,
|
||||||
const Settings &settings)
|
const Settings &settings)
|
||||||
: manager_(manager)
|
: 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;
|
Representer::~Representer() = default;
|
||||||
|
|
||||||
void Representer::represent(const TaskPtr &task)
|
void Representer::represent(const TaskPtr &task)
|
||||||
|
@ -11,6 +11,8 @@ public:
|
|||||||
Representer(Manager &manager, TrayIcon &tray, const Settings &settings);
|
Representer(Manager &manager, TrayIcon &tray, const Settings &settings);
|
||||||
~Representer();
|
~Representer();
|
||||||
|
|
||||||
|
void showLast();
|
||||||
|
void clipboardLast();
|
||||||
void represent(const TaskPtr &task);
|
void represent(const TaskPtr &task);
|
||||||
void updateSettings();
|
void updateSettings();
|
||||||
|
|
||||||
|
@ -52,9 +52,16 @@ ResultWidget::ResultWidget(const Settings &settings, QWidget *parent)
|
|||||||
layout->setSpacing(1);
|
layout->setSpacing(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TaskPtr &ResultWidget::task() const
|
||||||
|
{
|
||||||
|
return task_;
|
||||||
|
}
|
||||||
|
|
||||||
void ResultWidget::show(const TaskPtr &task)
|
void ResultWidget::show(const TaskPtr &task)
|
||||||
{
|
{
|
||||||
|
task_ = task;
|
||||||
SOFT_ASSERT(task->isValid(), return );
|
SOFT_ASSERT(task->isValid(), return );
|
||||||
|
|
||||||
image_->setPixmap(task->captured);
|
image_->setPixmap(task->captured);
|
||||||
|
|
||||||
recognized_->setText(task->corrected);
|
recognized_->setText(task->corrected);
|
||||||
|
@ -12,6 +12,7 @@ class ResultWidget : public QFrame
|
|||||||
public:
|
public:
|
||||||
explicit ResultWidget(const Settings& settings, QWidget* parent = nullptr);
|
explicit ResultWidget(const Settings& settings, QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
const TaskPtr& task() const;
|
||||||
void show(const TaskPtr& task);
|
void show(const TaskPtr& task);
|
||||||
using QWidget::show;
|
using QWidget::show;
|
||||||
void updateSettings();
|
void updateSettings();
|
||||||
@ -20,6 +21,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const Settings& settings_;
|
const Settings& settings_;
|
||||||
|
TaskPtr task_;
|
||||||
QLabel* image_;
|
QLabel* image_;
|
||||||
QLabel* recognized_;
|
QLabel* recognized_;
|
||||||
QLabel* translated_;
|
QLabel* translated_;
|
||||||
|
Loading…
Reference in New Issue
Block a user