From f137ba710cc823e920adf2976ee1061f5a61f9aa Mon Sep 17 00:00:00 2001 From: Diadlo Date: Sun, 10 Apr 2016 13:25:27 +0300 Subject: [PATCH 1/4] fix(groupinviteform): remove deleted buttons from set Fix #3087. --- src/widget/form/groupinviteform.cpp | 27 +++++++++++++++++++++++---- src/widget/form/groupinviteform.h | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/widget/form/groupinviteform.cpp b/src/widget/form/groupinviteform.cpp index b409f81e4..904487f56 100644 --- a/src/widget/form/groupinviteform.cpp +++ b/src/widget/form/groupinviteform.cpp @@ -20,6 +20,7 @@ #include "groupinviteform.h" #include +#include #include #include #include @@ -136,8 +137,7 @@ void GroupInviteForm::onGroupInviteAccepted() GroupInvite invite = groupInvites.at(index); groupInvites.removeAt(index); - groupWidget->deleteLater(); - inviteLayout->removeWidget(groupWidget); + deleteInviteButtons(groupWidget); emit groupInviteAccepted(invite.friendId, invite.type, invite.invite); } @@ -149,8 +149,27 @@ void GroupInviteForm::onGroupInviteRejected() int index = inviteLayout->indexOf(groupWidget); groupInvites.removeAt(index); - groupWidget->deleteLater(); - inviteLayout->removeWidget(groupWidget); + + deleteInviteButtons(groupWidget); +} + +void GroupInviteForm::deleteInviteButtons(QWidget *widget) +{ + QList buttons = widget->findChildren(); + + if (acceptButtons.contains(buttons.at(0))) + { + acceptButtons.remove(buttons.at(0)); + rejectButtons.remove(buttons.at(1)); + } + else + { + acceptButtons.remove(buttons.at(1)); + rejectButtons.remove(buttons.at(0)); + } + + widget->deleteLater(); + inviteLayout->removeWidget(widget); } void GroupInviteForm::retranslateUi() diff --git a/src/widget/form/groupinviteform.h b/src/widget/form/groupinviteform.h index 361be65b7..406dcafa1 100644 --- a/src/widget/form/groupinviteform.h +++ b/src/widget/form/groupinviteform.h @@ -78,6 +78,7 @@ private: QSet acceptButtons; QSet rejectButtons; QList groupInvites; + void deleteInviteButtons(QWidget *widget); }; #endif // GROUPINVITEFORM_H From 24b28b1e5192adf073566098687d73801273ff18 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Sun, 10 Apr 2016 13:57:52 +0300 Subject: [PATCH 2/4] style(groupinviteform): extracted few variables --- src/widget/form/groupinviteform.cpp | 10 ++++++---- src/widget/form/groupinviteform.h | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/widget/form/groupinviteform.cpp b/src/widget/form/groupinviteform.cpp index 904487f56..f62435894 100644 --- a/src/widget/form/groupinviteform.cpp +++ b/src/widget/form/groupinviteform.cpp @@ -96,7 +96,9 @@ void GroupInviteForm::addGroupInvite(int32_t friendId, uint8_t type, QByteArray QHBoxLayout* groupLayout = new QHBoxLayout(groupWidget); CroppingLabel* groupLabel = new CroppingLabel(this); - groupLabel->setText(tr("Invited by %1 on %2.").arg(Nexus::getCore()->getFriendUsername(friendId), QDateTime::currentDateTime().toString())); + QString name = Nexus::getCore()->getFriendUsername(friendId); + QString time = QDateTime::currentDateTime().toString(); + groupLabel->setText(tr("Invited by %1 on %2.").arg(name, time)); groupLayout->addWidget(groupLabel); QPushButton* acceptButton = new QPushButton(this); @@ -153,7 +155,7 @@ void GroupInviteForm::onGroupInviteRejected() deleteInviteButtons(groupWidget); } -void GroupInviteForm::deleteInviteButtons(QWidget *widget) +void GroupInviteForm::deleteInviteButtons(QWidget* widget) { QList buttons = widget->findChildren(); @@ -188,12 +190,12 @@ void GroupInviteForm::retranslateUi() retranslateRejectButton(rejectButton); } -void GroupInviteForm::retranslateAcceptButton(QPushButton *acceptButton) +void GroupInviteForm::retranslateAcceptButton(QPushButton* acceptButton) { acceptButton->setText(tr("Join")); } -void GroupInviteForm::retranslateRejectButton(QPushButton *rejectButton) +void GroupInviteForm::retranslateRejectButton(QPushButton* rejectButton) { rejectButton->setText(tr("Decline")); } diff --git a/src/widget/form/groupinviteform.h b/src/widget/form/groupinviteform.h index 406dcafa1..93993ffc7 100644 --- a/src/widget/form/groupinviteform.h +++ b/src/widget/form/groupinviteform.h @@ -20,8 +20,10 @@ #ifndef GROUPINVITEFORM_H #define GROUPINVITEFORM_H +#include #include #include +#include #include "src/widget/gui.h" class QLabel; @@ -61,6 +63,7 @@ private: void retranslateUi(); void retranslateAcceptButton(QPushButton* acceptButton); void retranslateRejectButton(QPushButton* rejectButton); + void deleteInviteButtons(QWidget* widget); private: struct GroupInvite @@ -78,7 +81,6 @@ private: QSet acceptButtons; QSet rejectButtons; QList groupInvites; - void deleteInviteButtons(QWidget *widget); }; #endif // GROUPINVITEFORM_H From 24efaf0594576ba4e761653c6d612f98b440c28a Mon Sep 17 00:00:00 2001 From: Diadlo Date: Sun, 10 Apr 2016 14:01:53 +0300 Subject: [PATCH 3/4] fix(groupinviteform): translation invite message Fix #3083. * Add time in GrupInvite struct * Add translation to invite message * Add set of invite message * Add correct removing invite message --- src/widget/form/groupinviteform.cpp | 20 +++++++++++++++++++- src/widget/form/groupinviteform.h | 9 ++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/widget/form/groupinviteform.cpp b/src/widget/form/groupinviteform.cpp index f62435894..7d483e69e 100644 --- a/src/widget/form/groupinviteform.cpp +++ b/src/widget/form/groupinviteform.cpp @@ -96,6 +96,7 @@ void GroupInviteForm::addGroupInvite(int32_t friendId, uint8_t type, QByteArray QHBoxLayout* groupLayout = new QHBoxLayout(groupWidget); CroppingLabel* groupLabel = new CroppingLabel(this); + groupLabels.insert(groupLabel); QString name = Nexus::getCore()->getFriendUsername(friendId); QString time = QDateTime::currentDateTime().toString(); groupLabel->setText(tr("Invited by %1 on %2.").arg(name, time)); @@ -119,6 +120,7 @@ void GroupInviteForm::addGroupInvite(int32_t friendId, uint8_t type, QByteArray group.friendId = friendId; group.type = type; group.invite = invite; + group.time = QDateTime::currentDateTime(); groupInvites.push_front(group); if (isVisible()) @@ -151,7 +153,6 @@ void GroupInviteForm::onGroupInviteRejected() int index = inviteLayout->indexOf(groupWidget); groupInvites.removeAt(index); - deleteInviteButtons(groupWidget); } @@ -170,6 +171,9 @@ void GroupInviteForm::deleteInviteButtons(QWidget* widget) rejectButtons.remove(buttons.at(0)); } + QList labels = widget->findChildren(); + groupLabels.remove(labels.at(0)); + widget->deleteLater(); inviteLayout->removeWidget(widget); } @@ -188,6 +192,20 @@ void GroupInviteForm::retranslateUi() for (QPushButton* rejectButton : rejectButtons) retranslateRejectButton(rejectButton); + + for (CroppingLabel* label : groupLabels) + retranslateGroupLabel(label); +} + +void GroupInviteForm::retranslateGroupLabel(CroppingLabel* label) +{ + QWidget* groupWidget = label->parentWidget(); + int index = inviteLayout->indexOf(groupWidget); + GroupInvite invite = groupInvites.at(index); + + QString name = Nexus::getCore()->getFriendUsername(invite.friendId); + QString date = invite.time.toString(); + label->setText(tr("Invited by %1 on %2.").arg(name, date)); } void GroupInviteForm::retranslateAcceptButton(QPushButton* acceptButton) diff --git a/src/widget/form/groupinviteform.h b/src/widget/form/groupinviteform.h index 93993ffc7..071a632c1 100644 --- a/src/widget/form/groupinviteform.h +++ b/src/widget/form/groupinviteform.h @@ -20,10 +20,10 @@ #ifndef GROUPINVITEFORM_H #define GROUPINVITEFORM_H -#include #include +#include #include -#include +#include "src/widget/tool/croppinglabel.h" #include "src/widget/gui.h" class QLabel; @@ -43,7 +43,7 @@ public: GroupInviteForm(); ~GroupInviteForm(); - void show(ContentLayout *contentLayout); + void show(ContentLayout* contentLayout); void addGroupInvite(int32_t friendId, uint8_t type, QByteArray invite); bool isShown() const; @@ -63,6 +63,7 @@ private: void retranslateUi(); void retranslateAcceptButton(QPushButton* acceptButton); void retranslateRejectButton(QPushButton* rejectButton); + void retranslateGroupLabel(CroppingLabel* label); void deleteInviteButtons(QWidget* widget); private: @@ -71,6 +72,7 @@ private: int32_t friendId; uint8_t type; QByteArray invite; + QDateTime time; }; QWidget* headWidget; @@ -80,6 +82,7 @@ private: QVBoxLayout* inviteLayout; QSet acceptButtons; QSet rejectButtons; + QSet groupLabels; QList groupInvites; }; From 7b4118a1a37f94af20fdc02234fd155b9c170f88 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Wed, 13 Apr 2016 23:02:26 +0300 Subject: [PATCH 4/4] refactor(groupinviteform): Deleting made clearer --- src/widget/form/groupinviteform.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/widget/form/groupinviteform.cpp b/src/widget/form/groupinviteform.cpp index 7d483e69e..871a10833 100644 --- a/src/widget/form/groupinviteform.cpp +++ b/src/widget/form/groupinviteform.cpp @@ -160,16 +160,9 @@ void GroupInviteForm::deleteInviteButtons(QWidget* widget) { QList buttons = widget->findChildren(); - if (acceptButtons.contains(buttons.at(0))) - { - acceptButtons.remove(buttons.at(0)); - rejectButtons.remove(buttons.at(1)); - } - else - { - acceptButtons.remove(buttons.at(1)); - rejectButtons.remove(buttons.at(0)); - } + QSet set = QSet::fromList(buttons); + acceptButtons.subtract(set); + rejectButtons.subtract(set); QList labels = widget->findChildren(); groupLabels.remove(labels.at(0));