2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2026-06-08 20:37:23 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 Synergy App Ltd
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ScreenSettingsDialog.h"
|
2024-10-18 22:47:32 +00:00
|
|
|
#include "ui_ScreenSettingsDialog.h"
|
2024-08-08 17:41:59 +00:00
|
|
|
|
|
|
|
|
#include "gui/config/Screen.h"
|
2025-03-21 00:09:40 +00:00
|
|
|
#include "validators/AliasValidator.h"
|
|
|
|
|
#include "validators/ScreenNameValidator.h"
|
|
|
|
|
#include "validators/ValidationError.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <QMessageBox>
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
using enum ScreenConfig::Modifier;
|
|
|
|
|
using enum ScreenConfig::SwitchCorner;
|
|
|
|
|
using enum ScreenConfig::Fix;
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-10-18 22:47:32 +00:00
|
|
|
ScreenSettingsDialog::~ScreenSettingsDialog() = default;
|
|
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
ScreenSettingsDialog::ScreenSettingsDialog(QWidget *parent, Screen *screen, const ScreenList *screens)
|
2024-07-02 19:07:06 +00:00
|
|
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
2025-05-23 03:31:07 +00:00
|
|
|
ui{std::make_unique<Ui::ScreenSettingsDialog>()},
|
2025-09-01 22:59:14 +00:00
|
|
|
m_screen(screen)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-08-01 00:13:01 +00:00
|
|
|
|
2025-05-23 03:31:07 +00:00
|
|
|
ui->setupUi(this);
|
2025-09-01 22:59:14 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Cancel)->setFocus();
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
ui->lineNameEdit->setText(m_screen->name());
|
2025-07-03 13:03:14 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
const auto valNameError = new validators::ValidationError(this, ui->lblNameError);
|
|
|
|
|
const auto valName = new validators::ScreenNameValidator(ui->lineNameEdit, valNameError, screens);
|
|
|
|
|
ui->lineNameEdit->setValidator(valName);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
const auto valAliasError = new validators::ValidationError(this, ui->lblAliasError);
|
|
|
|
|
const auto valAlias = new validators::AliasValidator(ui->lineAddAlias, valAliasError);
|
|
|
|
|
ui->lineAddAlias->setValidator(valAlias);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
for (int i = 0; i < m_screen->aliases().count(); i++)
|
|
|
|
|
new QListWidgetItem(m_screen->aliases()[i], ui->listAliases);
|
2025-05-23 03:31:07 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
ui->comboShift->setCurrentIndex(m_screen->modifier(static_cast<int>(Shift)));
|
|
|
|
|
ui->comboCtrl->setCurrentIndex(m_screen->modifier(static_cast<int>(Ctrl)));
|
|
|
|
|
ui->comboAlt->setCurrentIndex(m_screen->modifier(static_cast<int>(Alt)));
|
|
|
|
|
ui->comboMeta->setCurrentIndex(m_screen->modifier(static_cast<int>(Meta)));
|
|
|
|
|
ui->comboSuper->setCurrentIndex(m_screen->modifier(static_cast<int>(Super)));
|
2026-05-14 13:58:06 +00:00
|
|
|
ui->comboAltGr->setCurrentIndex(m_screen->modifier(static_cast<int>(AltGr)));
|
2025-05-23 03:31:07 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
ui->chkDeadTopLeft->setChecked(m_screen->switchCorner(static_cast<int>(TopLeft)));
|
|
|
|
|
ui->chkDeadTopRight->setChecked(m_screen->switchCorner(static_cast<int>(TopRight)));
|
|
|
|
|
ui->chkDeadBottomLeft->setChecked(m_screen->switchCorner(static_cast<int>(BottomLeft)));
|
|
|
|
|
ui->chkDeadBottomRight->setChecked(m_screen->switchCorner(static_cast<int>(BottomRight)));
|
|
|
|
|
ui->sbSwitchCornerSize->setValue(m_screen->switchCornerSize());
|
2025-05-23 03:31:07 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
ui->chkFixCapsLock->setChecked(m_screen->fix(CapsLock));
|
|
|
|
|
ui->chkFixNumLock->setChecked(m_screen->fix(NumLock));
|
|
|
|
|
ui->chkFixScrollLock->setChecked(m_screen->fix(ScrollLock));
|
|
|
|
|
ui->chkFixXTest->setChecked(m_screen->fix(XTest));
|
2025-09-02 00:14:56 +00:00
|
|
|
|
|
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ScreenSettingsDialog::accept);
|
|
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ScreenSettingsDialog::reject);
|
|
|
|
|
connect(ui->btnAddAlias, &QPushButton::clicked, this, &ScreenSettingsDialog::addAlias);
|
|
|
|
|
connect(ui->btnRemoveAlias, &QPushButton::clicked, this, &ScreenSettingsDialog::removeAlias);
|
|
|
|
|
connect(ui->lineAddAlias, &QLineEdit::textChanged, this, &ScreenSettingsDialog::checkNewAliasName);
|
|
|
|
|
connect(ui->listAliases, &QListWidget::itemSelectionChanged, this, &ScreenSettingsDialog::aliasSelected);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ScreenSettingsDialog::accept()
|
|
|
|
|
{
|
2025-09-01 22:59:14 +00:00
|
|
|
if (ui->lineNameEdit->text().isEmpty()) {
|
2024-07-02 19:07:06 +00:00
|
|
|
QMessageBox::warning(
|
|
|
|
|
this, tr("Screen name is empty"),
|
|
|
|
|
tr("The screen name cannot be empty. "
|
2024-10-17 18:04:35 +00:00
|
|
|
"Please either fill in a name or cancel the dialog.")
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
return;
|
2025-05-08 10:29:27 +00:00
|
|
|
}
|
2025-09-01 22:59:14 +00:00
|
|
|
if (!ui->lblNameError->text().isEmpty()) {
|
2024-07-02 19:07:06 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
m_screen->setName(ui->lineNameEdit->text());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
for (int i = 0; i < ui->listAliases->count(); i++) {
|
|
|
|
|
QString alias(ui->listAliases->item(i)->text());
|
|
|
|
|
if (alias == ui->lineNameEdit->text()) {
|
2024-07-02 19:07:06 +00:00
|
|
|
QMessageBox::warning(
|
|
|
|
|
this, tr("Screen name matches alias"),
|
|
|
|
|
tr("The screen name cannot be the same as an alias. "
|
2024-10-17 18:04:35 +00:00
|
|
|
"Please either remove the alias or change the screen name.")
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
return;
|
2021-03-23 07:49:52 +00:00
|
|
|
}
|
2025-09-01 22:59:14 +00:00
|
|
|
m_screen->addAlias(alias);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
m_screen->setModifier(Shift, ui->comboShift->currentIndex());
|
|
|
|
|
m_screen->setModifier(Ctrl, ui->comboCtrl->currentIndex());
|
|
|
|
|
m_screen->setModifier(Alt, ui->comboAlt->currentIndex());
|
|
|
|
|
m_screen->setModifier(Meta, ui->comboMeta->currentIndex());
|
|
|
|
|
m_screen->setModifier(Super, ui->comboSuper->currentIndex());
|
2026-05-14 13:58:06 +00:00
|
|
|
m_screen->setModifier(AltGr, ui->comboAltGr->currentIndex());
|
2024-10-17 18:04:35 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
m_screen->setSwitchCorner(TopLeft, ui->chkDeadTopLeft->isChecked());
|
|
|
|
|
m_screen->setSwitchCorner(TopRight, ui->chkDeadTopRight->isChecked());
|
|
|
|
|
m_screen->setSwitchCorner(BottomLeft, ui->chkDeadBottomLeft->isChecked());
|
|
|
|
|
m_screen->setSwitchCorner(BottomRight, ui->chkDeadBottomRight->isChecked());
|
|
|
|
|
m_screen->setSwitchCornerSize(ui->sbSwitchCornerSize->value());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-09-01 22:59:14 +00:00
|
|
|
m_screen->setFix(CapsLock, ui->chkFixCapsLock->isChecked());
|
|
|
|
|
m_screen->setFix(NumLock, ui->chkFixNumLock->isChecked());
|
|
|
|
|
m_screen->setFix(ScrollLock, ui->chkFixScrollLock->isChecked());
|
|
|
|
|
m_screen->setFix(XTest, ui->chkFixXTest->isChecked());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
QDialog::accept();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-02 00:14:56 +00:00
|
|
|
void ScreenSettingsDialog::addAlias()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-09-01 22:59:14 +00:00
|
|
|
if (!ui->lineAddAlias->text().isEmpty() &&
|
|
|
|
|
ui->listAliases->findItems(ui->lineAddAlias->text(), Qt::MatchFixedString).isEmpty()) {
|
|
|
|
|
new QListWidgetItem(ui->lineAddAlias->text(), ui->listAliases);
|
|
|
|
|
ui->lineAddAlias->clear();
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-05 01:42:04 +00:00
|
|
|
void ScreenSettingsDialog::removeAlias() const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-09-02 00:14:56 +00:00
|
|
|
QList<QListWidgetItem *> items = ui->listAliases->selectedItems();
|
|
|
|
|
qDeleteAll(items);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-02 00:14:56 +00:00
|
|
|
void ScreenSettingsDialog::checkNewAliasName(const QString &text)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-09-02 00:14:56 +00:00
|
|
|
ui->btnAddAlias->setEnabled(!text.isEmpty() && ui->lblAliasError->text().isEmpty());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-02 00:14:56 +00:00
|
|
|
void ScreenSettingsDialog::aliasSelected()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-09-01 22:59:14 +00:00
|
|
|
ui->btnRemoveAlias->setEnabled(!ui->listAliases->selectedItems().isEmpty());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|