2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-05 00:09:20 +00:00
|
|
|
* Copyright (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-06-10 16:50:54 +00:00
|
|
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
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
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
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 "ActionDialog.h"
|
2024-10-18 22:14:46 +00:00
|
|
|
#include "ui_ActionDialog.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
#include "Action.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "Hotkey.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
#include "KeySequence.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "ServerConfig.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <QButtonGroup>
|
2018-06-24 16:22:21 +00:00
|
|
|
|
2025-01-05 00:09:20 +00:00
|
|
|
ActionDialog::ActionDialog(QWidget *parent, const ServerConfig &config, Hotkey &hotkey, Action &action)
|
2024-07-02 19:07:06 +00:00
|
|
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
2024-10-18 22:14:46 +00:00
|
|
|
ui{std::make_unique<Ui::ActionDialog>()},
|
2025-01-05 00:36:35 +00:00
|
|
|
m_hotkey(hotkey),
|
|
|
|
|
m_action(action),
|
|
|
|
|
m_buttonGroupType(new QButtonGroup(this))
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->setupUi(this);
|
2025-01-05 00:50:43 +00:00
|
|
|
connect(ui->keySequenceWidget, &KeySequenceWidget::keySequenceChanged, this, &ActionDialog::keySequenceChanged);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
// work around Qt Designer's lack of a QButtonGroup; we need it to get
|
|
|
|
|
// at the button id of the checked radio button
|
2024-07-16 13:36:44 +00:00
|
|
|
QRadioButton *const typeButtons[] = {
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pRadioPress,
|
|
|
|
|
ui->m_pRadioRelease,
|
|
|
|
|
ui->m_pRadioPressAndRelease,
|
|
|
|
|
ui->m_pRadioSwitchToScreen,
|
|
|
|
|
ui->m_pRadioSwitchInDirection,
|
|
|
|
|
ui->m_pRadioLockCursorToScreen,
|
|
|
|
|
ui->m_pRadioRestartAllConnections
|
2024-10-17 18:04:35 +00:00
|
|
|
};
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++)
|
2025-01-05 00:36:35 +00:00
|
|
|
m_buttonGroupType->addButton(typeButtons[i], i);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-01-05 00:50:43 +00:00
|
|
|
ui->keySequenceWidget->setText(m_action.keySequence().toString());
|
|
|
|
|
ui->keySequenceWidget->setKeySequence(m_action.keySequence());
|
2025-01-05 00:36:35 +00:00
|
|
|
m_buttonGroupType->button(m_action.type())->setChecked(true);
|
|
|
|
|
ui->m_pComboSwitchInDirection->setCurrentIndex(m_action.switchDirection());
|
|
|
|
|
ui->m_pComboLockCursorToScreen->setCurrentIndex(m_action.lockCursorMode());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-01-05 00:36:35 +00:00
|
|
|
if (m_action.activeOnRelease())
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pRadioHotkeyReleased->setChecked(true);
|
2024-07-02 19:07:06 +00:00
|
|
|
else
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pRadioHotkeyPressed->setChecked(true);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-01-05 00:36:35 +00:00
|
|
|
ui->m_pGroupBoxScreens->setChecked(m_action.haveScreens());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-01-05 00:09:20 +00:00
|
|
|
for (const Screen &screen : config.screens()) {
|
2025-01-05 00:17:36 +00:00
|
|
|
if (screen.isNull())
|
|
|
|
|
continue;
|
|
|
|
|
QListWidgetItem *pListItem = new QListWidgetItem(screen.name());
|
|
|
|
|
ui->m_pListScreens->addItem(pListItem);
|
2025-01-05 00:36:35 +00:00
|
|
|
if (m_action.typeScreenNames().indexOf(screen.name()) != -1)
|
2025-01-05 00:17:36 +00:00
|
|
|
ui->m_pListScreens->setCurrentItem(pListItem);
|
|
|
|
|
|
|
|
|
|
ui->m_pComboSwitchToScreen->addItem(screen.name());
|
2025-01-05 00:36:35 +00:00
|
|
|
if (screen.name() == m_action.switchScreenName())
|
2025-01-05 00:23:42 +00:00
|
|
|
ui->m_pComboSwitchToScreen->setCurrentIndex(ui->m_pComboSwitchToScreen->count() - 1);
|
2024-10-21 02:58:12 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ActionDialog::accept()
|
|
|
|
|
{
|
2025-01-05 00:50:43 +00:00
|
|
|
if (!ui->keySequenceWidget->valid() && m_buttonGroupType->checkedId() >= 0 && m_buttonGroupType->checkedId() < 3)
|
2024-07-02 19:07:06 +00:00
|
|
|
return;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-01-05 00:50:43 +00:00
|
|
|
m_action.setKeySequence(ui->keySequenceWidget->keySequence());
|
2025-01-05 00:36:35 +00:00
|
|
|
m_action.setType(m_buttonGroupType->checkedId());
|
|
|
|
|
m_action.setHaveScreens(ui->m_pGroupBoxScreens->isChecked());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-01-05 00:36:35 +00:00
|
|
|
m_action.typeScreenNames().clear();
|
2024-10-21 02:58:12 +00:00
|
|
|
|
2024-10-21 03:07:31 +00:00
|
|
|
const auto &selection = ui->m_pListScreens->selectedItems();
|
|
|
|
|
for (const QListWidgetItem *pItem : selection)
|
2025-01-05 00:36:35 +00:00
|
|
|
m_action.typeScreenNames().append(pItem->text());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-01-05 00:36:35 +00:00
|
|
|
m_action.setSwitchScreenName(ui->m_pComboSwitchToScreen->currentText());
|
|
|
|
|
m_action.setSwitchDirection(ui->m_pComboSwitchInDirection->currentIndex());
|
|
|
|
|
m_action.setLockCursorMode(ui->m_pComboLockCursorToScreen->currentIndex());
|
|
|
|
|
m_action.setActiveOnRelease(ui->m_pRadioHotkeyReleased->isChecked());
|
|
|
|
|
m_action.setRestartServer(ui->m_pRadioRestartAllConnections->isChecked());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
QDialog::accept();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-05 00:50:43 +00:00
|
|
|
void ActionDialog::keySequenceChanged()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-01-05 00:50:43 +00:00
|
|
|
if (ui->keySequenceWidget->keySequence().isMouseButton()) {
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pGroupBoxScreens->setEnabled(false);
|
|
|
|
|
ui->m_pListScreens->setEnabled(false);
|
2024-07-02 19:07:06 +00:00
|
|
|
} else {
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pGroupBoxScreens->setEnabled(true);
|
|
|
|
|
ui->m_pListScreens->setEnabled(true);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
2024-10-18 22:14:46 +00:00
|
|
|
|
|
|
|
|
ActionDialog::~ActionDialog() = default;
|