deskflow/src/lib/gui/dialogs/ScreenSettingsDialog.cpp

144 lines
5.6 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
* 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"
#include "ui_ScreenSettingsDialog.h"
#include "gui/config/Screen.h"
#include "validators/AliasValidator.h"
#include "validators/ScreenNameValidator.h"
#include "validators/ValidationError.h"
2012-06-10 16:50:54 +00:00
#include <QMessageBox>
2012-06-10 16:50:54 +00:00
using enum ScreenConfig::Modifier;
using enum ScreenConfig::SwitchCorner;
using enum ScreenConfig::Fix;
Refactored core process management and IPC client (#7425) * Also ignore `command_pre` for Fedora itself * Improve warning message * Fixed layout issues on main window * Restore fusion theme for Windows dark mode * Further correct main window layout * Set CWD for launch on Windows to same dir as .env * Use signals for tray icon instead of callback * Reduce complexity for setting tray icon * Further reduce tray icon complexity * Reduce tray retry time * Fixed tray not showing on macOS * Refactor function names * Move tray icon to lib * Decouple server connection class * Move server connection to lib * Move client config to lib * Remove redundant forward declarations * Fixed some namespaces in the new lib * Move core process code to new class * Improve member names on new process class * Remove copy/pasta code * Move OSX helpers to lib * Add .mm to lib config * Fixed copyright * Improve reliability of log line handling * Fixed TLS certificate generate bugs * Remove client list * Refactor core process handling to fix various problems * Fixed process/connection status bugs * Fixed function signature issue on macOS * Fixed override warnings * Fixed string format warning * Save `wasStarted` state and use that instead * Use only filename in dialog * Use lambda for simple slot * Scroll to bottom if at bottome * Set value based on position before text added and set horizontal scroll too * Add 1px tollerance for Linux * Simplify start/stop mutex * Always stop service on restart * Increase scroll bottom threshold to 2 * Log warning instead of critical * Fixed long-standing dir CD-up hack * Remove include * Remove include * Fixed rogue dumbisense includes * Account for optional distro_like * Add QAction include to solve incomplete type * Remove rogue #pragma * Static cast log value * Solve event queue delete warning * Fixed integ test on Windows 10 * Reduce enum verbosity * Use static instance instead of global * Make function const * Use unique_ptr instead of new and delete, and made some functions const * Fixed smart pointer use * Fixed variable shadowing * Fixed wrong use of using * Fixed missing namespace using * Simplify TLS error handling * Improve UX around certificate errors and success * Decouple app config from core process through interface * First iteration of core process test * Mark dtor as override * Rename attach launch entry * Add TODO * Create proxy for process * Move IPC client to deps * Fixed warnings * Reorganize new GUI lib dir structure * Update includes to reflect new paths * Reorg GUI tests * Abstract IPC client * Refactor about screen * Fixed .ui warnings * Remove redundant include * Fixed typo * Fixed typos and add spelling * Fixed misleading function name * Improve comment * Improve code coverage for core process * Remove noisy log line * Make global const * Use default dtor * Use vector instead of new * Make ctor explicit * Make ctor explicit (2) * Use enum class * Fixed bad enum * Stub out core tool * Stub out dir operation * Extract byte functions * Add missing return path * Simplify byte/int functions * Fix truncation * Use ctor member assignment * Fixed segfault in process proxy * Fixed print warning * Make function const * Cleanup header * Fixed missing name * Update ChangeLog * Make more functions const
2024-08-07 14:05:18 +00:00
ScreenSettingsDialog::~ScreenSettingsDialog() = default;
ScreenSettingsDialog::ScreenSettingsDialog(QWidget *parent, Screen *screen, const ScreenList *screens)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
ui{std::make_unique<Ui::ScreenSettingsDialog>()},
m_screen(screen)
{
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Cancel)->setFocus();
ui->lineNameEdit->setText(m_screen->name());
const auto valNameError = new validators::ValidationError(this, ui->lblNameError);
const auto valName = new validators::ScreenNameValidator(ui->lineNameEdit, valNameError, screens);
ui->lineNameEdit->setValidator(valName);
const auto valAliasError = new validators::ValidationError(this, ui->lblAliasError);
const auto valAlias = new validators::AliasValidator(ui->lineAddAlias, valAliasError);
ui->lineAddAlias->setValidator(valAlias);
for (int i = 0; i < m_screen->aliases().count(); i++)
new QListWidgetItem(m_screen->aliases()[i], ui->listAliases);
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)));
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());
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));
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
}
void ScreenSettingsDialog::accept()
{
if (ui->lineNameEdit->text().isEmpty()) {
QMessageBox::warning(
this, tr("Screen name is empty"),
tr("The screen name cannot be empty. "
"Please either fill in a name or cancel the dialog.")
);
return;
2025-05-08 10:29:27 +00:00
}
if (!ui->lblNameError->text().isEmpty()) {
return;
}
m_screen->setName(ui->lineNameEdit->text());
for (int i = 0; i < ui->listAliases->count(); i++) {
QString alias(ui->listAliases->item(i)->text());
if (alias == ui->lineNameEdit->text()) {
QMessageBox::warning(
this, tr("Screen name matches alias"),
tr("The screen name cannot be the same as an alias. "
"Please either remove the alias or change the screen name.")
);
return;
}
m_screen->addAlias(alias);
}
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());
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());
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());
QDialog::accept();
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::addAlias()
{
if (!ui->lineAddAlias->text().isEmpty() &&
ui->listAliases->findItems(ui->lineAddAlias->text(), Qt::MatchFixedString).isEmpty()) {
new QListWidgetItem(ui->lineAddAlias->text(), ui->listAliases);
ui->lineAddAlias->clear();
}
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::removeAlias() const
{
QList<QListWidgetItem *> items = ui->listAliases->selectedItems();
qDeleteAll(items);
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::checkNewAliasName(const QString &text)
{
ui->btnAddAlias->setEnabled(!text.isEmpty() && ui->lblAliasError->text().isEmpty());
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::aliasSelected()
{
ui->btnRemoveAlias->setEnabled(!ui->listAliases->selectedItems().isEmpty());
2012-06-10 16:50:54 +00:00
}