ScreenTranslator/src/capture/captureareaeditor.cpp

75 lines
2.3 KiB
C++
Raw Normal View History

2020-03-25 02:05:45 +07:00
#include "captureareaeditor.h"
#include "capturearea.h"
#include "captureareaselector.h"
2020-03-28 18:26:05 +07:00
#include "commonmodels.h"
2020-03-25 02:05:45 +07:00
#include "languagecodes.h"
#include <QCheckBox>
#include <QComboBox>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
2020-03-25 02:05:45 +07:00
2020-03-28 18:26:05 +07:00
CaptureAreaEditor::CaptureAreaEditor(const CommonModels &models,
2020-03-28 18:35:56 +07:00
QWidget *parent)
: QWidget(parent)
2020-03-28 01:24:50 +07:00
, doTranslation_(new QCheckBox(tr("Translate:"), this))
2020-03-25 02:05:45 +07:00
, sourceLanguage_(new QComboBox(this))
, targetLanguage_(new QComboBox(this))
{
setCursor(Qt::CursorShape::ArrowCursor);
auto layout = new QGridLayout(this);
auto row = 0;
2020-03-28 01:24:50 +07:00
layout->addWidget(new QLabel(tr("Recognize:")), row, 0);
layout->addWidget(sourceLanguage_, row, 1);
auto swapLanguages = new QPushButton(tr(""));
layout->addWidget(swapLanguages, row, 2, 2, 1);
++row;
2020-03-28 01:24:50 +07:00
layout->addWidget(doTranslation_, row, 0);
layout->addWidget(targetLanguage_, row, 1);
2020-03-25 02:05:45 +07:00
2020-03-28 18:26:05 +07:00
sourceLanguage_->setModel(models.sourceLanguageModel());
targetLanguage_->setModel(models.targetLanguageModel());
2020-03-25 02:05:45 +07:00
targetLanguage_->setEnabled(doTranslation_->isChecked());
swapLanguages->setFlat(true);
{
auto font = swapLanguages->font();
font.setPointSize(std::max(font.pointSize() * 2, 16));
swapLanguages->setFont(font);
}
swapLanguages->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
2020-03-25 02:05:45 +07:00
connect(doTranslation_, &QCheckBox::toggled, //
targetLanguage_, &QComboBox::setEnabled);
connect(swapLanguages, &QPushButton::clicked, //
this, &CaptureAreaEditor::swapLanguages);
2020-03-25 02:05:45 +07:00
}
CaptureAreaEditor::~CaptureAreaEditor() = default;
void CaptureAreaEditor::swapLanguages()
{
const auto target = targetLanguage_->currentText();
targetLanguage_->setCurrentText(sourceLanguage_->currentText());
sourceLanguage_->setCurrentText(target);
}
2020-03-25 02:05:45 +07:00
void CaptureAreaEditor::set(const CaptureArea &area)
{
doTranslation_->setChecked(area.doTranslation_);
sourceLanguage_->setCurrentText(LanguageCodes::name(area.sourceLanguage_));
targetLanguage_->setCurrentText(LanguageCodes::name(area.targetLanguage_));
}
void CaptureAreaEditor::apply(CaptureArea &area) const
{
area.doTranslation_ = doTranslation_->isChecked();
area.sourceLanguage_ =
LanguageCodes::idForName(sourceLanguage_->currentText());
area.targetLanguage_ =
LanguageCodes::idForName(targetLanguage_->currentText());
}