From 40d3c3693d56dc7e7a3f1146079a07f776feb0d3 Mon Sep 17 00:00:00 2001 From: Gleb Petrovicev Date: Sun, 13 Oct 2024 15:28:06 +0200 Subject: [PATCH 1/2] Fixed invitee removal on del / middle mouse click --- client/roomdialogs.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/roomdialogs.cpp b/client/roomdialogs.cpp index aab8f252..d154fb92 100644 --- a/client/roomdialogs.cpp +++ b/client/roomdialogs.cpp @@ -336,11 +336,15 @@ class InviteeList : public QListWidget { if (event->key() == Qt::Key_Delete) delete takeItem(currentRow()); + else + QListWidget::keyPressEvent(event); } void mousePressEvent(QMouseEvent* event) override { if (event->button() == Qt::MiddleButton) delete takeItem(currentRow()); + else + QListWidget::mousePressEvent(event); } }; @@ -353,7 +357,7 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts, , nextInvitee(new NextInvitee) , inviteButton( new QPushButton(tr("Add", "Add a user to the list of invitees"))) - , invitees(new QListWidget) + , invitees(new InviteeList) { Q_ASSERT(!accounts->empty()); From 9b7fd98d1f37f6ccd65c90e4f68dca6a031ef57b Mon Sep 17 00:00:00 2001 From: Gleb Petrovicev Date: Sun, 13 Oct 2024 15:40:33 +0200 Subject: [PATCH 2/2] Added Remove button --- client/roomdialogs.cpp | 34 +++++++++++++++++++++------- client/roomdialogs.h | 3 ++- client/translations/quaternion_en.ts | 16 +++++++++---- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/client/roomdialogs.cpp b/client/roomdialogs.cpp index d154fb92..62c814b7 100644 --- a/client/roomdialogs.cpp +++ b/client/roomdialogs.cpp @@ -355,8 +355,10 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts, , accountChooser(new AccountSelector(accounts)) , version(nullptr) // Will be initialized below , nextInvitee(new NextInvitee) - , inviteButton( + , addToInviteesButton( new QPushButton(tr("Add", "Add a user to the list of invitees"))) + , removeFromInviteesButton( + new QPushButton(tr("Remove", "Remove a user from the list of invitees"))) , invitees(new InviteeList) { Q_ASSERT(!accounts->empty()); @@ -381,9 +383,11 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts, this, &CreateRoomDialog::updatePushButtons); // connect(nextInvitee, &NextInvitee::editTextChanged, // this, &CreateRoomDialog::updateUserList); - inviteButton->setFocusPolicy(Qt::NoFocus); - inviteButton->setDisabled(true); - connect(inviteButton, &QPushButton::clicked, [this] { + + // Add button initialization + addToInviteesButton->setFocusPolicy(Qt::NoFocus); + addToInviteesButton->setDisabled(true); + connect(addToInviteesButton, &QPushButton::clicked, [this] { auto userName = nextInvitee->currentText(); if (userName.indexOf('@') == -1) { @@ -397,6 +401,18 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts, invitees->addItem(item); nextInvitee->clear(); }); + + // Remove button initialization + removeFromInviteesButton->setFocusPolicy(Qt::NoFocus); + removeFromInviteesButton->setDisabled(true); + connect(removeFromInviteesButton, &QPushButton::clicked, [this] { + if (invitees->currentItem() == nullptr) + return; + delete invitees->takeItem(invitees->currentRow()); + }); + connect(invitees, &InviteeList::currentItemChanged, this, + &CreateRoomDialog::updatePushButtons); + invitees->setSizeAdjustPolicy( QAbstractScrollArea::AdjustToContentsOnFirstShow); invitees->setUniformItemSizes(true); @@ -406,7 +422,8 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts, auto* inviteLayout = new QHBoxLayout; inviteLayout->addWidget(nextInvitee); - inviteLayout->addWidget(inviteButton); + inviteLayout->addWidget(addToInviteesButton); + inviteLayout->addWidget(removeFromInviteesButton); mainFormLayout->addRow(tr("Invite user(s)"), inviteLayout); mainFormLayout->addRow("", invitees); @@ -421,9 +438,10 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts, void CreateRoomDialog::updatePushButtons() { - inviteButton->setEnabled(!nextInvitee->currentText().isEmpty()); - if (inviteButton->isEnabled() && nextInvitee->hasFocus()) - inviteButton->setDefault(true); + addToInviteesButton->setEnabled(!nextInvitee->currentText().isEmpty()); + removeFromInviteesButton->setEnabled(invitees->currentItem() != nullptr); + if (addToInviteesButton->isEnabled() && nextInvitee->hasFocus()) + addToInviteesButton->setDefault(true); else buttonBox()->button(QDialogButtonBox::Ok)->setDefault(true); } diff --git a/client/roomdialogs.h b/client/roomdialogs.h index bbd20723..c9aec1c7 100644 --- a/client/roomdialogs.h +++ b/client/roomdialogs.h @@ -96,7 +96,8 @@ class CreateRoomDialog : public RoomDialogBase AccountSelector* accountChooser; QComboBox* version; QComboBox* nextInvitee; - QPushButton* inviteButton; + QPushButton* addToInviteesButton; + QPushButton* removeFromInviteesButton; QListWidget* invitees; QHash userLists; diff --git a/client/translations/quaternion_en.ts b/client/translations/quaternion_en.ts index 9394cc3e..b0dc149e 100644 --- a/client/translations/quaternion_en.ts +++ b/client/translations/quaternion_en.ts @@ -250,28 +250,34 @@ CreateRoomDialog - + Create room Create room - + Add Add a user to the list of invitees Add - + + Remove + Remove a user from the list of invitees + + + + Please fill the fields as desired. None are mandatory Please fill the fields as desired. None are mandatory - + Invite user(s) Invite user(s) - + Creating the room, please wait Creating the room, please wait