deskflow/src/gui/src/ScreenSettingsDialog.cpp

166 lines
6.1 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* Copyright (C) 2012 Symless Ltd.
2012-06-10 16:50:54 +00:00
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
2012-06-10 16:50:54 +00:00
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
2012-06-10 16:50:54 +00:00
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScreenSettingsDialog.h"
#include "gui/config/Screen.h"
#include "gui/styles.h"
#include "gui/validators/AliasValidator.h"
#include "gui/validators/ScreenNameValidator.h"
#include "gui/validators/ValidationError.h"
2012-06-10 16:50:54 +00:00
#include <QMessageBox>
2012-06-10 16:50:54 +00:00
#include <QtCore>
#include <QtGui>
using namespace deskflow::gui;
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(
QWidget *parent, Screen *pScreen, const ScreenList *pScreens)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::ScreenSettingsDialogBase(),
m_pScreen(pScreen) {
setupUi(this);
m_pLabelAliasError->setStyleSheet(kStyleErrorActiveLabel);
m_pLabelNameError->setStyleSheet(kStyleErrorActiveLabel);
m_pLineEditName->setText(m_pScreen->name());
m_pLineEditName->setValidator(new validators::ScreenNameValidator(
m_pLineEditName, new validators::ValidationError(this, m_pLabelNameError),
pScreens));
m_pLineEditName->selectAll();
m_pLineEditAlias->setValidator(new validators::AliasValidator(
m_pLineEditAlias,
new validators::ValidationError(this, m_pLabelAliasError)));
for (int i = 0; i < m_pScreen->aliases().count(); i++)
new QListWidgetItem(m_pScreen->aliases()[i], m_pListAliases);
m_pComboBoxShift->setCurrentIndex(
m_pScreen->modifier(static_cast<int>(Shift)));
m_pComboBoxCtrl->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Ctrl)));
m_pComboBoxAlt->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Alt)));
m_pComboBoxMeta->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Meta)));
m_pComboBoxSuper->setCurrentIndex(
m_pScreen->modifier(static_cast<int>(Super)));
m_pCheckBoxCornerTopLeft->setChecked(
m_pScreen->switchCorner(static_cast<int>(TopLeft)));
m_pCheckBoxCornerTopRight->setChecked(
m_pScreen->switchCorner(static_cast<int>(TopRight)));
m_pCheckBoxCornerBottomLeft->setChecked(
m_pScreen->switchCorner(static_cast<int>(BottomLeft)));
m_pCheckBoxCornerBottomRight->setChecked(
m_pScreen->switchCorner(static_cast<int>(BottomRight)));
m_pSpinBoxSwitchCornerSize->setValue(m_pScreen->switchCornerSize());
m_pCheckBoxCapsLock->setChecked(m_pScreen->fix(CapsLock));
m_pCheckBoxNumLock->setChecked(m_pScreen->fix(NumLock));
m_pCheckBoxScrollLock->setChecked(m_pScreen->fix(ScrollLock));
m_pCheckBoxXTest->setChecked(m_pScreen->fix(XTest));
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::accept() {
if (m_pLineEditName->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;
} else if (!m_pLabelNameError->text().isEmpty()) {
return;
}
m_pScreen->init();
m_pScreen->setName(m_pLineEditName->text());
for (int i = 0; i < m_pListAliases->count(); i++) {
QString alias(m_pListAliases->item(i)->text());
if (alias == m_pLineEditName->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_pScreen->addAlias(alias);
}
m_pScreen->setModifier(
static_cast<int>(Shift), m_pComboBoxShift->currentIndex());
m_pScreen->setModifier(
static_cast<int>(Ctrl), m_pComboBoxCtrl->currentIndex());
m_pScreen->setModifier(static_cast<int>(Alt), m_pComboBoxAlt->currentIndex());
m_pScreen->setModifier(
static_cast<int>(Meta), m_pComboBoxMeta->currentIndex());
m_pScreen->setModifier(
static_cast<int>(Super), m_pComboBoxSuper->currentIndex());
m_pScreen->setSwitchCorner(
static_cast<int>(TopLeft), m_pCheckBoxCornerTopLeft->isChecked());
m_pScreen->setSwitchCorner(
static_cast<int>(TopRight), m_pCheckBoxCornerTopRight->isChecked());
m_pScreen->setSwitchCorner(
static_cast<int>(BottomLeft), m_pCheckBoxCornerBottomLeft->isChecked());
m_pScreen->setSwitchCorner(
static_cast<int>(BottomRight), m_pCheckBoxCornerBottomRight->isChecked());
m_pScreen->setSwitchCornerSize(m_pSpinBoxSwitchCornerSize->value());
m_pScreen->setFix(
static_cast<int>(CapsLock), m_pCheckBoxCapsLock->isChecked());
m_pScreen->setFix(static_cast<int>(NumLock), m_pCheckBoxNumLock->isChecked());
m_pScreen->setFix(
static_cast<int>(ScrollLock), m_pCheckBoxScrollLock->isChecked());
m_pScreen->setFix(static_cast<int>(XTest), m_pCheckBoxXTest->isChecked());
QDialog::accept();
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::on_m_pButtonAddAlias_clicked() {
if (!m_pLineEditAlias->text().isEmpty() &&
m_pListAliases->findItems(m_pLineEditAlias->text(), Qt::MatchFixedString)
.isEmpty()) {
new QListWidgetItem(m_pLineEditAlias->text(), m_pListAliases);
m_pLineEditAlias->clear();
}
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::on_m_pLineEditAlias_textChanged(
const QString &text) {
m_pButtonAddAlias->setEnabled(
!text.isEmpty() && m_pLabelAliasError->text().isEmpty());
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::on_m_pButtonRemoveAlias_clicked() {
QList<QListWidgetItem *> items = m_pListAliases->selectedItems();
2012-06-10 16:50:54 +00:00
for (int i = 0; i < items.count(); i++)
delete items[i];
2012-06-10 16:50:54 +00:00
}
void ScreenSettingsDialog::on_m_pListAliases_itemSelectionChanged() {
m_pButtonRemoveAlias->setEnabled(!m_pListAliases->selectedItems().isEmpty());
2012-06-10 16:50:54 +00:00
}