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
|
|
|
|
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),
|
2025-01-05 03:20:24 +00:00
|
|
|
m_action(action)
|
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);
|
2025-01-05 03:20:24 +00:00
|
|
|
connect(
|
|
|
|
|
ui->comboActionType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ActionDialog::actionTypeChanged
|
|
|
|
|
);
|
2025-01-05 00:58:58 +00:00
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ActionDialog::accept);
|
|
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ActionDialog::reject);
|
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 03:20:24 +00:00
|
|
|
|
2025-01-05 00:36:35 +00:00
|
|
|
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 03:20:24 +00:00
|
|
|
ui->comboActionType->setCurrentIndex(m_action.type());
|
|
|
|
|
ui->comboTriggerOn->setCurrentIndex(m_action.activeOnRelease());
|
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;
|
2025-01-05 03:34:53 +00:00
|
|
|
auto *newListItem = new QListWidgetItem(screen.name());
|
|
|
|
|
newListItem->setCheckState(Qt::Checked);
|
|
|
|
|
if ((m_action.typeScreenNames().indexOf(screen.name()) == -1) &&
|
|
|
|
|
(m_action.haveScreens() && !m_action.typeScreenNames().isEmpty()))
|
|
|
|
|
newListItem->setCheckState(Qt::Unchecked);
|
|
|
|
|
|
|
|
|
|
ui->listScreens->addItem(newListItem);
|
2025-01-05 00:17:36 +00:00
|
|
|
|
|
|
|
|
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 03:20:24 +00:00
|
|
|
if (!ui->keySequenceWidget->valid() && ui->comboActionType->currentIndex() >= 0 &&
|
|
|
|
|
ui->comboActionType->currentIndex() < 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 03:20:24 +00:00
|
|
|
m_action.setType(ui->comboActionType->currentIndex());
|
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
|
|
|
|
2025-01-05 03:34:53 +00:00
|
|
|
int screenCount = ui->listScreens->count();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ui->listScreens->count(); i++) {
|
|
|
|
|
const auto &item = ui->listScreens->item(i);
|
|
|
|
|
m_action.typeScreenNames().append(item->text());
|
|
|
|
|
if (item->checkState() == Qt::Unchecked) {
|
|
|
|
|
screenCount--;
|
|
|
|
|
m_action.typeScreenNames().removeLast();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (screenCount == ui->listScreens->count())
|
|
|
|
|
m_action.typeScreenNames().clear();
|
|
|
|
|
|
|
|
|
|
m_action.setHaveScreens(screenCount);
|
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());
|
2025-01-05 02:40:05 +00:00
|
|
|
m_action.setActiveOnRelease(ui->comboTriggerOn->currentIndex());
|
2025-01-05 03:20:24 +00:00
|
|
|
m_action.setRestartServer(ui->comboActionType->currentIndex() == ActionTypes::RestartServer);
|
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 03:34:53 +00:00
|
|
|
ui->listScreens->setEnabled(ui->keySequenceWidget->valid() && !ui->keySequenceWidget->keySequence().isMouseButton());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
2024-10-18 22:14:46 +00:00
|
|
|
|
2025-01-05 03:20:24 +00:00
|
|
|
void ActionDialog::actionTypeChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
ui->keySequenceWidget->setEnabled(isKeyAction(index));
|
2025-01-05 03:34:53 +00:00
|
|
|
ui->listScreens->setEnabled(isKeyAction(index));
|
2025-01-05 03:20:24 +00:00
|
|
|
ui->m_pComboSwitchToScreen->setEnabled(index == ActionTypes::SwitchTo);
|
|
|
|
|
ui->m_pComboSwitchInDirection->setEnabled(index == ActionTypes::SwitchInDirection);
|
|
|
|
|
ui->m_pComboLockCursorToScreen->setEnabled(index == ActionTypes::ModifyCursorLock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ActionDialog::isKeyAction(int index)
|
|
|
|
|
{
|
|
|
|
|
return ((index == ActionTypes::PressKey) || (index == ActionTypes::ReleaseKey) || (index == ActionTypes::ToggleKey));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 22:14:46 +00:00
|
|
|
ActionDialog::~ActionDialog() = default;
|