Move task creation to separate class
This commit is contained in:
parent
6336d3545a
commit
aee380fcd5
@ -30,6 +30,7 @@ INCLUDEPATH += src src/service src/capture src/ocr \
|
|||||||
src/represent src/translate src/correct
|
src/represent src/translate src/correct
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
src/capture/capturearea.h \
|
||||||
src/capture/captureareaselector.h \
|
src/capture/captureareaselector.h \
|
||||||
src/capture/capturer.h \
|
src/capture/capturer.h \
|
||||||
src/correct/corrector.h \
|
src/correct/corrector.h \
|
||||||
@ -58,6 +59,7 @@ HEADERS += \
|
|||||||
src/trayicon.h
|
src/trayicon.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
src/capture/capturearea.cpp \
|
||||||
src/capture/captureareaselector.cpp \
|
src/capture/captureareaselector.cpp \
|
||||||
src/capture/capturer.cpp \
|
src/capture/capturer.cpp \
|
||||||
src/correct/corrector.cpp \
|
src/correct/corrector.cpp \
|
||||||
|
29
src/capture/capturearea.cpp
Normal file
29
src/capture/capturearea.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "capturearea.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
CaptureArea::CaptureArea(const QRect &rect, const Settings &settings)
|
||||||
|
: rect_(rect)
|
||||||
|
, doTranslation_(settings.doTranslation)
|
||||||
|
, sourceLanguage_(settings.sourceLanguage)
|
||||||
|
, targetLanguage_(settings.targetLanguage)
|
||||||
|
, translators_(settings.translators)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskPtr CaptureArea::task(const QPixmap &pixmap) const
|
||||||
|
{
|
||||||
|
if (pixmap.isNull() || rect_.width() < 3 || rect_.height() < 3)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
auto task = std::make_shared<Task>();
|
||||||
|
task->captured = pixmap.copy(rect_);
|
||||||
|
task->capturePoint = rect_.topLeft();
|
||||||
|
task->sourceLanguage = sourceLanguage_;
|
||||||
|
if (doTranslation_ && !translators_.isEmpty()) {
|
||||||
|
task->targetLanguage = targetLanguage_;
|
||||||
|
task->translators = translators_;
|
||||||
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
22
src/capture/capturearea.h
Normal file
22
src/capture/capturearea.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stfwd.h"
|
||||||
|
|
||||||
|
#include <QRect>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class QPixmap;
|
||||||
|
|
||||||
|
class CaptureArea
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CaptureArea(const QRect& rect, const Settings& settings);
|
||||||
|
TaskPtr task(const QPixmap& pixmap) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QRect rect_;
|
||||||
|
bool doTranslation_;
|
||||||
|
LanguageId sourceLanguage_;
|
||||||
|
LanguageId targetLanguage_;
|
||||||
|
QStringList translators_;
|
||||||
|
};
|
@ -149,18 +149,9 @@ void CaptureAreaSelector::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
const auto endPos = event->pos();
|
const auto endPos = event->pos();
|
||||||
const auto selection = QRect(startSelectPos_, endPos).normalized();
|
const auto selection = QRect(startSelectPos_, endPos).normalized();
|
||||||
const auto selectedPixmap = pixmap_.copy(selection);
|
|
||||||
|
|
||||||
startSelectPos_ = currentSelectPos_ = QPoint();
|
startSelectPos_ = currentSelectPos_ = {};
|
||||||
|
|
||||||
if (selectedPixmap.width() < 3 || selectedPixmap.height() < 3) {
|
const auto area = CaptureArea(selection, settings_);
|
||||||
capturer_.canceled();
|
capturer_.selected(area);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto task = std::make_shared<Task>();
|
|
||||||
task->captured = selectedPixmap;
|
|
||||||
task->capturePoint = pos() + selection.topLeft();
|
|
||||||
// TODO add customization menus
|
|
||||||
capturer_.captured(task);
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "capturer.h"
|
#include "capturer.h"
|
||||||
|
#include "capturearea.h"
|
||||||
#include "captureareaselector.h"
|
#include "captureareaselector.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
@ -65,16 +66,17 @@ void Capturer::updateSettings()
|
|||||||
selector_->updateSettings();
|
selector_->updateSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Capturer::captured(const TaskPtr &task)
|
void Capturer::selected(const CaptureArea &area)
|
||||||
{
|
{
|
||||||
SOFT_ASSERT(selector_, return );
|
SOFT_ASSERT(selector_, return manager_.captureCanceled())
|
||||||
selector_->hide();
|
selector_->hide();
|
||||||
|
|
||||||
task->translators = settings_.translators;
|
SOFT_ASSERT(!pixmap_.isNull(), return manager_.captureCanceled())
|
||||||
task->sourceLanguage = settings_.sourceLanguage;
|
auto task = area.task(pixmap_);
|
||||||
if (settings_.doTranslation)
|
if (task)
|
||||||
task->targetLanguage = settings_.targetLanguage;
|
manager_.captured(task);
|
||||||
manager_.captured(task);
|
else
|
||||||
|
manager_.captureCanceled();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Capturer::canceled()
|
void Capturer::canceled()
|
||||||
|
@ -14,7 +14,7 @@ public:
|
|||||||
void repeatCapture();
|
void repeatCapture();
|
||||||
void updateSettings();
|
void updateSettings();
|
||||||
|
|
||||||
void captured(const TaskPtr &task);
|
void selected(const CaptureArea &area);
|
||||||
void canceled();
|
void canceled();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -15,6 +15,7 @@ class Representer;
|
|||||||
class Translator;
|
class Translator;
|
||||||
class Corrector;
|
class Corrector;
|
||||||
class Recognizer;
|
class Recognizer;
|
||||||
|
class CaptureArea;
|
||||||
class CaptureAreaSelector;
|
class CaptureAreaSelector;
|
||||||
|
|
||||||
namespace update
|
namespace update
|
||||||
|
Loading…
Reference in New Issue
Block a user