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 "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,6 +185,20 @@ void GroupInviteForm::retranslateUi()
|
||||||
|
|
||||||
for (QPushButton* rejectButton : rejectButtons)
|
for (QPushButton* rejectButton : rejectButtons)
|
||||||
retranslateRejectButton(rejectButton);
|
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 <b>%1</b> on %2.").arg(name, date));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupInviteForm::retranslateAcceptButton(QPushButton* acceptButton)
|
void GroupInviteForm::retranslateAcceptButton(QPushButton* acceptButton)
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user