1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #3116

Diadlo (4):
      fix(groupinviteform): remove deleted buttons from set
      style(groupinviteform): extracted few variables
      fix(groupinviteform): translation invite message
      refactor(groupinviteform): Deleting made clearer
This commit is contained in:
sudden6 2016-04-15 19:31:58 +02:00
commit 2c07b1b5b2
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 46 additions and 8 deletions

View File

@ -20,6 +20,7 @@
#include "groupinviteform.h" #include "groupinviteform.h"
#include <tox/tox.h> #include <tox/tox.h>
#include <QDebug>
#include <QSignalMapper> #include <QSignalMapper>
#include <QPushButton> #include <QPushButton>
#include <QBoxLayout> #include <QBoxLayout>
@ -95,7 +96,10 @@ void GroupInviteForm::addGroupInvite(int32_t friendId, uint8_t type, QByteArray
QHBoxLayout* groupLayout = new QHBoxLayout(groupWidget); QHBoxLayout* groupLayout = new QHBoxLayout(groupWidget);
CroppingLabel* groupLabel = new CroppingLabel(this); CroppingLabel* groupLabel = new CroppingLabel(this);
groupLabel->setText(tr("Invited by <b>%1</b> on %2.").arg(Nexus::getCore()->getFriendUsername(friendId), QDateTime::currentDateTime().toString())); groupLabels.insert(groupLabel);
QString name = Nexus::getCore()->getFriendUsername(friendId);
QString time = QDateTime::currentDateTime().toString();
groupLabel->setText(tr("Invited by <b>%1</b> on %2.").arg(name, time));
groupLayout->addWidget(groupLabel); groupLayout->addWidget(groupLabel);
QPushButton* acceptButton = new QPushButton(this); QPushButton* acceptButton = new QPushButton(this);
@ -116,6 +120,7 @@ void GroupInviteForm::addGroupInvite(int32_t friendId, uint8_t type, QByteArray
group.friendId = friendId; group.friendId = friendId;
group.type = type; group.type = type;
group.invite = invite; group.invite = invite;
group.time = QDateTime::currentDateTime();
groupInvites.push_front(group); groupInvites.push_front(group);
if (isVisible()) if (isVisible())
@ -136,8 +141,7 @@ void GroupInviteForm::onGroupInviteAccepted()
GroupInvite invite = groupInvites.at(index); GroupInvite invite = groupInvites.at(index);
groupInvites.removeAt(index); groupInvites.removeAt(index);
groupWidget->deleteLater(); deleteInviteButtons(groupWidget);
inviteLayout->removeWidget(groupWidget);
emit groupInviteAccepted(invite.friendId, invite.type, invite.invite); emit groupInviteAccepted(invite.friendId, invite.type, invite.invite);
} }
@ -149,8 +153,22 @@ void GroupInviteForm::onGroupInviteRejected()
int index = inviteLayout->indexOf(groupWidget); int index = inviteLayout->indexOf(groupWidget);
groupInvites.removeAt(index); groupInvites.removeAt(index);
groupWidget->deleteLater(); deleteInviteButtons(groupWidget);
inviteLayout->removeWidget(groupWidget); }
void GroupInviteForm::deleteInviteButtons(QWidget* widget)
{
QList<QPushButton*> buttons = widget->findChildren<QPushButton*>();
QSet<QPushButton*> set = QSet<QPushButton*>::fromList(buttons);
acceptButtons.subtract(set);
rejectButtons.subtract(set);
QList<CroppingLabel*> labels = widget->findChildren<CroppingLabel*>();
groupLabels.remove(labels.at(0));
widget->deleteLater();
inviteLayout->removeWidget(widget);
} }
void GroupInviteForm::retranslateUi() void GroupInviteForm::retranslateUi()
@ -167,14 +185,28 @@ void GroupInviteForm::retranslateUi()
for (QPushButton* rejectButton : rejectButtons) for (QPushButton* rejectButton : rejectButtons)
retranslateRejectButton(rejectButton); retranslateRejectButton(rejectButton);
for (CroppingLabel* label : groupLabels)
retranslateGroupLabel(label);
} }
void GroupInviteForm::retranslateAcceptButton(QPushButton *acceptButton) 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 <b>%1</b> on %2.").arg(name, date));
}
void GroupInviteForm::retranslateAcceptButton(QPushButton* acceptButton)
{ {
acceptButton->setText(tr("Join")); acceptButton->setText(tr("Join"));
} }
void GroupInviteForm::retranslateRejectButton(QPushButton *rejectButton) void GroupInviteForm::retranslateRejectButton(QPushButton* rejectButton)
{ {
rejectButton->setText(tr("Decline")); rejectButton->setText(tr("Decline"));
} }

View File

@ -21,7 +21,9 @@
#define GROUPINVITEFORM_H #define GROUPINVITEFORM_H
#include <QWidget> #include <QWidget>
#include <QDateTime>
#include <QSet> #include <QSet>
#include "src/widget/tool/croppinglabel.h"
#include "src/widget/gui.h" #include "src/widget/gui.h"
class QLabel; class QLabel;
@ -41,7 +43,7 @@ public:
GroupInviteForm(); GroupInviteForm();
~GroupInviteForm(); ~GroupInviteForm();
void show(ContentLayout *contentLayout); void show(ContentLayout* contentLayout);
void addGroupInvite(int32_t friendId, uint8_t type, QByteArray invite); void addGroupInvite(int32_t friendId, uint8_t type, QByteArray invite);
bool isShown() const; bool isShown() const;
@ -61,6 +63,8 @@ private:
void retranslateUi(); void retranslateUi();
void retranslateAcceptButton(QPushButton* acceptButton); void retranslateAcceptButton(QPushButton* acceptButton);
void retranslateRejectButton(QPushButton* rejectButton); void retranslateRejectButton(QPushButton* rejectButton);
void retranslateGroupLabel(CroppingLabel* label);
void deleteInviteButtons(QWidget* widget);
private: private:
struct GroupInvite struct GroupInvite
@ -68,6 +72,7 @@ private:
int32_t friendId; int32_t friendId;
uint8_t type; uint8_t type;
QByteArray invite; QByteArray invite;
QDateTime time;
}; };
QWidget* headWidget; QWidget* headWidget;
@ -77,6 +82,7 @@ private:
QVBoxLayout* inviteLayout; QVBoxLayout* inviteLayout;
QSet<QPushButton*> acceptButtons; QSet<QPushButton*> acceptButtons;
QSet<QPushButton*> rejectButtons; QSet<QPushButton*> rejectButtons;
QSet<CroppingLabel*> groupLabels;
QList<GroupInvite> groupInvites; QList<GroupInvite> groupInvites;
}; };