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:
commit
2c07b1b5b2
|
@ -20,6 +20,7 @@
|
|||
#include "groupinviteform.h"
|
||||
|
||||
#include <tox/tox.h>
|
||||
#include <QDebug>
|
||||
#include <QSignalMapper>
|
||||
#include <QPushButton>
|
||||
#include <QBoxLayout>
|
||||
|
@ -95,7 +96,10 @@ 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 <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);
|
||||
|
||||
QPushButton* acceptButton = new QPushButton(this);
|
||||
|
@ -116,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())
|
||||
|
@ -136,8 +141,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 +153,22 @@ void GroupInviteForm::onGroupInviteRejected()
|
|||
int index = inviteLayout->indexOf(groupWidget);
|
||||
groupInvites.removeAt(index);
|
||||
|
||||
groupWidget->deleteLater();
|
||||
inviteLayout->removeWidget(groupWidget);
|
||||
deleteInviteButtons(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()
|
||||
|
@ -167,14 +185,28 @@ void GroupInviteForm::retranslateUi()
|
|||
|
||||
for (QPushButton* rejectButton : rejectButtons)
|
||||
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"));
|
||||
}
|
||||
|
||||
void GroupInviteForm::retranslateRejectButton(QPushButton *rejectButton)
|
||||
void GroupInviteForm::retranslateRejectButton(QPushButton* rejectButton)
|
||||
{
|
||||
rejectButton->setText(tr("Decline"));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
#define GROUPINVITEFORM_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QDateTime>
|
||||
#include <QSet>
|
||||
#include "src/widget/tool/croppinglabel.h"
|
||||
#include "src/widget/gui.h"
|
||||
|
||||
class QLabel;
|
||||
|
@ -41,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;
|
||||
|
||||
|
@ -61,6 +63,8 @@ private:
|
|||
void retranslateUi();
|
||||
void retranslateAcceptButton(QPushButton* acceptButton);
|
||||
void retranslateRejectButton(QPushButton* rejectButton);
|
||||
void retranslateGroupLabel(CroppingLabel* label);
|
||||
void deleteInviteButtons(QWidget* widget);
|
||||
|
||||
private:
|
||||
struct GroupInvite
|
||||
|
@ -68,6 +72,7 @@ private:
|
|||
int32_t friendId;
|
||||
uint8_t type;
|
||||
QByteArray invite;
|
||||
QDateTime time;
|
||||
};
|
||||
|
||||
QWidget* headWidget;
|
||||
|
@ -77,6 +82,7 @@ private:
|
|||
QVBoxLayout* inviteLayout;
|
||||
QSet<QPushButton*> acceptButtons;
|
||||
QSet<QPushButton*> rejectButtons;
|
||||
QSet<CroppingLabel*> groupLabels;
|
||||
QList<GroupInvite> groupInvites;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user