refactor: ServerConfigDialog hotkeyTab, no auto connections use naming std

This commit is contained in:
sithlord48 2025-02-01 09:54:01 -05:00 committed by Nick Bolton
parent 76fd40a3ec
commit 169422a0eb
3 changed files with 125 additions and 133 deletions

View file

@ -44,6 +44,24 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, Ap
ui->lblNewScreen->setEnabled(!model().isFull()); ui->lblNewScreen->setEnabled(!model().isFull());
ui->lblNewScreen->setPixmap(QIcon::fromTheme("video-display").pixmap(QSize(64, 64))); ui->lblNewScreen->setPixmap(QIcon::fromTheme("video-display").pixmap(QSize(64, 64)));
connect(ui->btnNewHotkey, &QPushButton::clicked, this, &ServerConfigDialog::addHotkey);
connect(ui->btnEditHotkey, &QPushButton::clicked, this, &ServerConfigDialog::editHotkey);
connect(ui->btnRemoveHotkey, &QPushButton::clicked, this, &ServerConfigDialog::removeHotkey);
connect(ui->listHotkeys, &QListView::doubleClicked, this, &ServerConfigDialog::editHotkey);
connect(
ui->listHotkeys->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ServerConfigDialog::listHotkeysSelectionChanged
);
connect(ui->btnNewAction, &QPushButton::clicked, this, &ServerConfigDialog::addAction);
connect(ui->btnEditAction, &QPushButton::clicked, this, &ServerConfigDialog::editAction);
connect(ui->btnRemoveAction, &QPushButton::clicked, this, &ServerConfigDialog::removeAction);
connect(ui->listActions, &QListView::doubleClicked, this, &ServerConfigDialog::editAction);
connect(
ui->listActions->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ServerConfigDialog::listActionsSelectionChanged
);
ui->m_pButtonBrowseConfigFile->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen)); ui->m_pButtonBrowseConfigFile->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen));
// force the first tab, since qt creator sets the active tab as the last one // force the first tab, since qt creator sets the active tab as the last one
// the developer was looking at, and it's easy to accidentally save that. // the developer was looking at, and it's easy to accidentally save that.
@ -78,7 +96,7 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, Ap
ui->m_pSpinBoxClipboardSizeLimit->setEnabled(serverConfig().clipboardSharing()); ui->m_pSpinBoxClipboardSizeLimit->setEnabled(serverConfig().clipboardSharing());
for (const Hotkey &hotkey : std::as_const(serverConfig().hotkeys())) for (const Hotkey &hotkey : std::as_const(serverConfig().hotkeys()))
ui->m_pListHotkeys->addItem(hotkey.text()); ui->listHotkeys->addItem(hotkey.text());
ui->screenSetupView->setModel(&m_ScreenSetupModel); ui->screenSetupView->setModel(&m_ScreenSetupModel);
@ -293,111 +311,120 @@ void ServerConfigDialog::reject()
QDialog::reject(); QDialog::reject();
} }
void ServerConfigDialog::on_m_pButtonNewHotkey_clicked() void ServerConfigDialog::addHotkey()
{ {
Hotkey hotkey; Hotkey hotkey;
HotkeyDialog dlg(this, hotkey); HotkeyDialog dlg(this, hotkey);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
serverConfig().hotkeys().append(hotkey); serverConfig().hotkeys().append(hotkey);
ui->m_pListHotkeys->addItem(hotkey.text()); ui->listHotkeys->addItem(hotkey.text());
onChange(); onChange();
} }
} }
void ServerConfigDialog::on_m_pButtonEditHotkey_clicked() void ServerConfigDialog::editHotkey()
{ {
int idx = ui->m_pListHotkeys->currentRow(); int row = ui->listHotkeys->currentRow();
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); if (row < 0 || row >= serverConfig().hotkeys().size()) {
Hotkey &hotkey = serverConfig().hotkeys()[idx]; qDebug() << "Atempt to editing out of bounds hotkey row: " << row;
return;
}
Hotkey &hotkey = serverConfig().hotkeys()[row];
HotkeyDialog dlg(this, hotkey); HotkeyDialog dlg(this, hotkey);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
ui->m_pListHotkeys->currentItem()->setText(hotkey.text()); ui->listHotkeys->currentItem()->setText(hotkey.text());
onChange(); onChange();
} }
} }
void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked() void ServerConfigDialog::removeHotkey()
{ {
int idx = ui->m_pListHotkeys->currentRow(); int row = ui->listHotkeys->currentRow();
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); if (row < 0 || row >= serverConfig().hotkeys().size()) {
serverConfig().hotkeys().removeAt(idx); qDebug() << "Atempt to remove out of bounds hotkey row: " << row;
ui->m_pListActions->clear(); return;
delete ui->m_pListHotkeys->item(idx); }
serverConfig().hotkeys().removeAt(row);
ui->listActions->clear();
delete ui->listHotkeys->item(row);
onChange(); onChange();
} }
void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged() void ServerConfigDialog::listHotkeysSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{ {
bool itemsSelected = !ui->m_pListHotkeys->selectedItems().isEmpty(); bool itemsSelected = !selected.isEmpty();
ui->m_pButtonEditHotkey->setEnabled(itemsSelected); ui->btnEditHotkey->setEnabled(itemsSelected);
ui->m_pButtonRemoveHotkey->setEnabled(itemsSelected); ui->btnRemoveHotkey->setEnabled(itemsSelected);
ui->m_pButtonNewAction->setEnabled(itemsSelected); ui->btnNewAction->setEnabled(itemsSelected);
if (itemsSelected && serverConfig().hotkeys().size() > 0) { if (itemsSelected && !serverConfig().hotkeys().isEmpty()) {
ui->m_pListActions->clear(); ui->listActions->clear();
const Hotkey &hotkey = serverConfig().hotkeys().at(selected.indexes().first().row());
int idx = ui->m_pListHotkeys->row(ui->m_pListHotkeys->selectedItems()[0]);
// There's a bug somewhere around here: We get idx == 1 right after we
// deleted the next to last item, so idx can only possibly be 0. GDB shows
// we got called indirectly from the delete line in
// on_m_pButtonRemoveHotkey_clicked() above, but the delete is of course
// necessary and seems correct. The while() is a generalized workaround for
// all that and shouldn't be required.
while (idx >= 0 && idx >= serverConfig().hotkeys().size())
idx--;
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
const Hotkey &hotkey = serverConfig().hotkeys()[idx];
for (const Action &action : hotkey.actions()) for (const Action &action : hotkey.actions())
ui->m_pListActions->addItem(action.text()); ui->listActions->addItem(action.text());
} }
} }
void ServerConfigDialog::on_m_pButtonNewAction_clicked() void ServerConfigDialog::addAction()
{ {
int idx = ui->m_pListHotkeys->currentRow(); int row = ui->listHotkeys->currentRow();
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); if (row < 0 || row >= serverConfig().hotkeys().size()) {
Hotkey &hotkey = serverConfig().hotkeys()[idx]; qDebug() << "Atempt to add action to out of bounds hotkey row: " << row;
return;
}
Hotkey &hotkey = serverConfig().hotkeys()[row];
Action action; Action action;
ActionDialog dlg(this, serverConfig(), hotkey, action); ActionDialog dlg(this, serverConfig(), hotkey, action);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
hotkey.actions().append(action); hotkey.actions().append(action);
ui->m_pListActions->addItem(action.text()); ui->listActions->addItem(action.text());
onChange(); onChange();
} }
} }
void ServerConfigDialog::on_m_pButtonEditAction_clicked() void ServerConfigDialog::editAction()
{ {
int idxHotkey = ui->m_pListHotkeys->currentRow(); int hotkeyRow = ui->listHotkeys->currentRow();
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size()); if (hotkeyRow < 0 || hotkeyRow >= serverConfig().hotkeys().size()) {
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey]; qDebug() << "Atempt to edit action from out of bounds hotkey row: " << hotkeyRow;
return;
}
Hotkey &hotkey = serverConfig().hotkeys()[hotkeyRow];
int idxAction = ui->m_pListActions->currentRow(); int actionRow = ui->listActions->currentRow();
Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size()); if (actionRow < 0 || actionRow >= hotkey.actions().size()) {
Action &action = hotkey.actions()[idxAction]; qDebug() << "Atempt to remove out of bounds action row: " << actionRow;
return;
}
Action &action = hotkey.actions()[actionRow];
ActionDialog dlg(this, serverConfig(), hotkey, action); ActionDialog dlg(this, serverConfig(), hotkey, action);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
ui->m_pListActions->currentItem()->setText(action.text()); ui->listActions->currentItem()->setText(action.text());
onChange(); onChange();
} }
} }
void ServerConfigDialog::on_m_pButtonRemoveAction_clicked() void ServerConfigDialog::removeAction()
{ {
int idxHotkey = ui->m_pListHotkeys->currentRow(); int hotkeyRow = ui->listHotkeys->currentRow();
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size()); if (hotkeyRow < 0 || hotkeyRow >= serverConfig().hotkeys().size()) {
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey]; qDebug() << "Atempt to remove action from out of bounds hotkey row: " << hotkeyRow;
return;
}
Hotkey &hotkey = serverConfig().hotkeys()[hotkeyRow];
int idxAction = ui->m_pListActions->currentRow(); int actionRow = ui->listActions->currentRow();
Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size()); if (actionRow < 0 || actionRow >= hotkey.actions().size()) {
qDebug() << "Atempt to remove out of bounds action row: " << actionRow;
return;
}
hotkey.actions().removeAt(idxAction); hotkey.actions().removeAt(actionRow);
delete ui->m_pListActions->currentItem(); delete ui->listActions->currentItem();
onChange(); onChange();
} }
@ -410,10 +437,11 @@ void ServerConfigDialog::on_m_pCheckBoxEnableClipboard_stateChanged(int const st
} }
} }
void ServerConfigDialog::on_m_pListActions_itemSelectionChanged() void ServerConfigDialog::listActionsSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{ {
ui->m_pButtonEditAction->setEnabled(!ui->m_pListActions->selectedItems().isEmpty()); bool enabled = !selected.isEmpty();
ui->m_pButtonRemoveAction->setEnabled(!ui->m_pListActions->selectedItems().isEmpty()); ui->btnEditAction->setEnabled(enabled);
ui->btnRemoveAction->setEnabled(enabled);
} }
void ServerConfigDialog::addClient() void ServerConfigDialog::addClient()

View file

@ -14,6 +14,8 @@
#include <QDialog> #include <QDialog>
class QItemSelection;
namespace Ui { namespace Ui {
class ServerConfigDialog; class ServerConfigDialog;
} }
@ -36,15 +38,6 @@ public slots:
} }
protected slots: protected slots:
void on_m_pButtonNewHotkey_clicked();
void on_m_pListHotkeys_itemSelectionChanged();
void on_m_pButtonEditHotkey_clicked();
void on_m_pButtonRemoveHotkey_clicked();
void on_m_pButtonNewAction_clicked();
void on_m_pListActions_itemSelectionChanged();
void on_m_pButtonEditAction_clicked();
void on_m_pButtonRemoveAction_clicked();
void on_m_pCheckBoxEnableClipboard_stateChanged(int state); void on_m_pCheckBoxEnableClipboard_stateChanged(int state);
void onScreenRemoved(); void onScreenRemoved();
void on_m_pCheckBoxUseExternalConfig_toggled(bool checked = false); void on_m_pCheckBoxUseExternalConfig_toggled(bool checked = false);
@ -53,6 +46,17 @@ protected slots:
protected: protected:
void addClient(); void addClient();
bool addComputer(const QString &clientName, bool doSilent); bool addComputer(const QString &clientName, bool doSilent);
void addHotkey();
void editHotkey();
void removeHotkey();
void listHotkeysSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void addAction();
void editAction();
void removeAction();
void listActionsSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
ServerConfig &serverConfig() ServerConfig &serverConfig()
{ {
return m_ServerConfig; return m_ServerConfig;

View file

@ -22,9 +22,6 @@
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabComputers"> <widget class="QWidget" name="tabComputers">
<attribute name="title"> <attribute name="title">
<string>Computers</string> <string>Computers</string>
@ -166,27 +163,22 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="m_pTabHotkeys"> <widget class="QWidget" name="tabHotkeys">
<attribute name="title"> <attribute name="title">
<string>Hotkeys</string> <string>Hotkeys</string>
</attribute> </attribute>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout" name="_2">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupHotkeys">
<property name="font">
<font>
<kerning>false</kerning>
</font>
</property>
<property name="title"> <property name="title">
<string>&amp;Hotkeys</string> <string>&amp;Hotkeys</string>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout" name="_3">
<item row="0" column="0" rowspan="4"> <item row="0" column="0" rowspan="4">
<widget class="QListWidget" name="m_pListHotkeys"/> <widget class="QListWidget" name="listHotkeys"/>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QPushButton" name="m_pButtonNewHotkey"> <widget class="QPushButton" name="btnNewHotkey">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -196,7 +188,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QPushButton" name="m_pButtonEditHotkey"> <widget class="QPushButton" name="btnEditHotkey">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -206,7 +198,7 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QPushButton" name="m_pButtonRemoveHotkey"> <widget class="QPushButton" name="btnRemoveHotkey">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -216,7 +208,7 @@
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<spacer> <spacer name="hotkeySpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Vertical</enum> <enum>Qt::Orientation::Vertical</enum>
</property> </property>
@ -232,7 +224,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupActions">
<property name="font"> <property name="font">
<font> <font>
<kerning>true</kerning> <kerning>true</kerning>
@ -243,10 +235,10 @@
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<item row="0" column="0" rowspan="4"> <item row="0" column="0" rowspan="4">
<widget class="QListWidget" name="m_pListActions"/> <widget class="QListWidget" name="listActions"/>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QPushButton" name="m_pButtonNewAction"> <widget class="QPushButton" name="btnNewAction">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -256,7 +248,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QPushButton" name="m_pButtonEditAction"> <widget class="QPushButton" name="btnEditAction">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -266,7 +258,7 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QPushButton" name="m_pButtonRemoveAction"> <widget class="QPushButton" name="btnRemoveAction">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -276,7 +268,7 @@
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<spacer> <spacer name="actionSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Vertical</enum> <enum>Qt::Orientation::Vertical</enum>
</property> </property>
@ -1134,14 +1126,14 @@ Enabling this setting will disable the server config GUI.</string>
<tabstops> <tabstops>
<tabstop>m_pButtonBrowseConfigFile</tabstop> <tabstop>m_pButtonBrowseConfigFile</tabstop>
<tabstop>screenSetupView</tabstop> <tabstop>screenSetupView</tabstop>
<tabstop>m_pListHotkeys</tabstop> <tabstop>listHotkeys</tabstop>
<tabstop>m_pButtonNewHotkey</tabstop> <tabstop>btnNewHotkey</tabstop>
<tabstop>m_pButtonEditHotkey</tabstop> <tabstop>btnEditHotkey</tabstop>
<tabstop>m_pButtonRemoveHotkey</tabstop> <tabstop>btnRemoveHotkey</tabstop>
<tabstop>m_pListActions</tabstop> <tabstop>listActions</tabstop>
<tabstop>m_pButtonNewAction</tabstop> <tabstop>btnNewAction</tabstop>
<tabstop>m_pButtonEditAction</tabstop> <tabstop>btnEditAction</tabstop>
<tabstop>m_pButtonRemoveAction</tabstop> <tabstop>btnRemoveAction</tabstop>
<tabstop>m_pCheckBoxSwitchDelay</tabstop> <tabstop>m_pCheckBoxSwitchDelay</tabstop>
<tabstop>m_pSpinBoxSwitchDelay</tabstop> <tabstop>m_pSpinBoxSwitchDelay</tabstop>
<tabstop>m_pCheckBoxSwitchDoubleTap</tabstop> <tabstop>m_pCheckBoxSwitchDoubleTap</tabstop>
@ -1206,37 +1198,5 @@ Enabling this setting will disable the server config GUI.</string>
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>m_pListHotkeys</sender>
<signal>itemDoubleClicked(QListWidgetItem*)</signal>
<receiver>m_pButtonEditHotkey</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>35</x>
<y>84</y>
</hint>
<hint type="destinationlabel">
<x>45</x>
<y>80</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_pListActions</sender>
<signal>itemDoubleClicked(QListWidgetItem*)</signal>
<receiver>m_pButtonEditAction</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>79</x>
<y>84</y>
</hint>
<hint type="destinationlabel">
<x>89</x>
<y>80</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>