2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
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
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
ActionDialog::ActionDialog(QWidget *parent, 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>()},
|
2024-07-16 13:36:44 +00:00
|
|
|
m_ServerConfig(config),
|
|
|
|
|
m_Hotkey(hotkey),
|
|
|
|
|
m_Action(action),
|
2024-10-17 18:04:35 +00:00
|
|
|
m_pButtonGroupType(new QButtonGroup(this))
|
|
|
|
|
{
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->setupUi(this);
|
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++)
|
2024-07-02 19:07:06 +00:00
|
|
|
m_pButtonGroupType->addButton(typeButtons[i], i);
|
|
|
|
|
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pKeySequenceWidgetHotkey->setText(m_Action.keySequence().toString());
|
|
|
|
|
ui->m_pKeySequenceWidgetHotkey->setKeySequence(m_Action.keySequence());
|
2024-07-02 19:07:06 +00:00
|
|
|
m_pButtonGroupType->button(m_Action.type())->setChecked(true);
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pComboSwitchInDirection->setCurrentIndex(m_Action.switchDirection());
|
|
|
|
|
ui->m_pComboLockCursorToScreen->setCurrentIndex(m_Action.lockCursorMode());
|
2024-07-02 19:07:06 +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
|
|
|
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pGroupBoxScreens->setChecked(m_Action.haveScreens());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
int idx = 0;
|
2024-10-21 02:58:12 +00:00
|
|
|
for (const Screen &screen : serverConfig().screens()) {
|
2024-07-02 19:07:06 +00:00
|
|
|
if (!screen.isNull()) {
|
|
|
|
|
QListWidgetItem *pListItem = new QListWidgetItem(screen.name());
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pListScreens->addItem(pListItem);
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_Action.typeScreenNames().indexOf(screen.name()) != -1)
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pListScreens->setCurrentItem(pListItem);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pComboSwitchToScreen->addItem(screen.name());
|
2024-07-02 19:07:06 +00:00
|
|
|
if (screen.name() == m_Action.switchScreenName())
|
2024-10-18 22:14:46 +00:00
|
|
|
ui->m_pComboSwitchToScreen->setCurrentIndex(idx);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
|
}
|
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()
|
|
|
|
|
{
|
|
|
|
|
if (!sequenceWidget()->valid() && m_pButtonGroupType->checkedId() >= 0 && m_pButtonGroupType->checkedId() < 3)
|
2024-07-02 19:07:06 +00:00
|
|
|
return;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
m_Action.setKeySequence(sequenceWidget()->keySequence());
|
|
|
|
|
m_Action.setType(m_pButtonGroupType->checkedId());
|
2024-10-18 22:14:46 +00:00
|
|
|
m_Action.setHaveScreens(ui->m_pGroupBoxScreens->isChecked());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +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)
|
2024-07-02 19:07:06 +00:00
|
|
|
m_Action.typeScreenNames().append(pItem->text());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-18 22:14:46 +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
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (sequenceWidget()->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
|
|
|
|
|
|
|
|
const KeySequenceWidget *ActionDialog::sequenceWidget() const
|
|
|
|
|
{
|
|
|
|
|
return ui->m_pKeySequenceWidgetHotkey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActionDialog::~ActionDialog() = default;
|