Add ability to swap languages in customization menu
This commit is contained in:
parent
897db5b6c4
commit
7ed6742f51
@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QFormLayout>
|
#include <QGridLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
|
|
||||||
CaptureAreaEditor::CaptureAreaEditor(CaptureAreaSelector &selector)
|
CaptureAreaEditor::CaptureAreaEditor(CaptureAreaSelector &selector)
|
||||||
@ -23,17 +25,36 @@ CaptureAreaEditor::CaptureAreaEditor(CaptureAreaSelector &selector)
|
|||||||
{
|
{
|
||||||
setCursor(Qt::CursorShape::ArrowCursor);
|
setCursor(Qt::CursorShape::ArrowCursor);
|
||||||
|
|
||||||
auto layout = new QFormLayout(this);
|
auto layout = new QGridLayout(this);
|
||||||
layout->addRow(doTranslation_);
|
auto row = 0;
|
||||||
layout->addRow(tr("Recognition language"), sourceLanguage_);
|
layout->addWidget(doTranslation_, row, 0, 1, 2);
|
||||||
layout->addRow(tr("Translation language"), targetLanguage_);
|
|
||||||
|
++row;
|
||||||
|
layout->addWidget(new QLabel(tr("Recognition language:")), row, 0);
|
||||||
|
layout->addWidget(sourceLanguage_, row, 1);
|
||||||
|
auto swapLanguages = new QPushButton(tr("⇵"));
|
||||||
|
layout->addWidget(swapLanguages, row, 2, 2, 1);
|
||||||
|
|
||||||
|
++row;
|
||||||
|
layout->addWidget(new QLabel(tr("Translation language:")), row, 0);
|
||||||
|
layout->addWidget(targetLanguage_, row, 1);
|
||||||
|
|
||||||
sourceLanguage_->setModel(sourceLanguageModel_.get());
|
sourceLanguage_->setModel(sourceLanguageModel_.get());
|
||||||
targetLanguage_->setModel(targetLanguageModel_.get());
|
targetLanguage_->setModel(targetLanguageModel_.get());
|
||||||
targetLanguage_->setEnabled(doTranslation_->isChecked());
|
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);
|
||||||
|
|
||||||
connect(doTranslation_, &QCheckBox::toggled, //
|
connect(doTranslation_, &QCheckBox::toggled, //
|
||||||
targetLanguage_, &QComboBox::setEnabled);
|
targetLanguage_, &QComboBox::setEnabled);
|
||||||
|
connect(swapLanguages, &QPushButton::clicked, //
|
||||||
|
this, &CaptureAreaEditor::swapLanguages);
|
||||||
}
|
}
|
||||||
|
|
||||||
CaptureAreaEditor::~CaptureAreaEditor() = default;
|
CaptureAreaEditor::~CaptureAreaEditor() = default;
|
||||||
@ -45,6 +66,13 @@ void CaptureAreaEditor::updateSettings(const Settings &settings)
|
|||||||
targetLanguageModel_->setStringList(Translator::availableLanguageNames());
|
targetLanguageModel_->setStringList(Translator::availableLanguageNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CaptureAreaEditor::swapLanguages()
|
||||||
|
{
|
||||||
|
const auto target = targetLanguage_->currentText();
|
||||||
|
targetLanguage_->setCurrentText(sourceLanguage_->currentText());
|
||||||
|
sourceLanguage_->setCurrentText(target);
|
||||||
|
}
|
||||||
|
|
||||||
void CaptureAreaEditor::set(const CaptureArea &area)
|
void CaptureAreaEditor::set(const CaptureArea &area)
|
||||||
{
|
{
|
||||||
doTranslation_->setChecked(area.doTranslation_);
|
doTranslation_->setChecked(area.doTranslation_);
|
||||||
|
@ -20,6 +20,8 @@ public:
|
|||||||
void updateSettings(const Settings& settings);
|
void updateSettings(const Settings& settings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void swapLanguages();
|
||||||
|
|
||||||
CaptureAreaSelector& selector_;
|
CaptureAreaSelector& selector_;
|
||||||
QCheckBox* doTranslation_;
|
QCheckBox* doTranslation_;
|
||||||
QComboBox* sourceLanguage_;
|
QComboBox* sourceLanguage_;
|
||||||
|
Loading…
Reference in New Issue
Block a user