mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Fix request translations and make group button stay down
This commit is contained in:
parent
2043908e15
commit
d21a6d29de
@ -43,8 +43,6 @@ AddFriendForm::AddFriendForm()
|
||||
bold.setBold(true);
|
||||
headLabel.setFont(bold);
|
||||
|
||||
retranslateUi();
|
||||
|
||||
tabWidget->addTab(main, QString());
|
||||
QScrollArea* scrollArea = new QScrollArea(tabWidget);
|
||||
QWidget* requestWidget = new QWidget(tabWidget);
|
||||
@ -69,12 +67,9 @@ AddFriendForm::AddFriendForm()
|
||||
connect(&sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
|
||||
connect(Nexus::getCore(), &Core::usernameSet, this, &AddFriendForm::onUsernameSet);
|
||||
|
||||
retranslateUi();
|
||||
Translator::registerHandler(std::bind(&AddFriendForm::retranslateUi, this), this);
|
||||
|
||||
acceptMapper = new QSignalMapper(requestWidget);
|
||||
rejectMapper = new QSignalMapper(requestWidget);
|
||||
connect(acceptMapper, SIGNAL(mapped(QWidget*)), this, SLOT(onFriendRequestAccepted(QWidget*)));
|
||||
connect(rejectMapper, SIGNAL(mapped(QWidget*)), this, SLOT(onFriendRequestRejected(QWidget*)));
|
||||
int size = Settings::getInstance().getFriendRequestSize();
|
||||
|
||||
for (int i = 0; i < size; ++i)
|
||||
@ -178,8 +173,9 @@ void AddFriendForm::setIdFromClipboard()
|
||||
}
|
||||
}
|
||||
|
||||
void AddFriendForm::onFriendRequestAccepted(QWidget* friendWidget)
|
||||
void AddFriendForm::onFriendRequestAccepted()
|
||||
{
|
||||
QWidget* friendWidget = static_cast<QWidget*>(sender());
|
||||
int index = requestsLayout->indexOf(friendWidget);
|
||||
friendWidget->deleteLater();
|
||||
requestsLayout->removeWidget(friendWidget);
|
||||
@ -188,8 +184,9 @@ void AddFriendForm::onFriendRequestAccepted(QWidget* friendWidget)
|
||||
Settings::getInstance().savePersonal();
|
||||
}
|
||||
|
||||
void AddFriendForm::onFriendRequestRejected(QWidget* friendWidget)
|
||||
void AddFriendForm::onFriendRequestRejected()
|
||||
{
|
||||
QWidget* friendWidget = static_cast<QWidget*>(sender());
|
||||
int index = requestsLayout->indexOf(friendWidget);
|
||||
friendWidget->deleteLater();
|
||||
requestsLayout->removeWidget(friendWidget);
|
||||
@ -219,6 +216,12 @@ void AddFriendForm::retranslateUi()
|
||||
|
||||
tabWidget->setTabText(0, tr("Add a friend"));
|
||||
tabWidget->setTabText(1, tr("Friend requests"));
|
||||
|
||||
for (QPushButton* acceptButton : acceptButtons)
|
||||
retranslateAcceptButton(acceptButton);
|
||||
|
||||
for (QPushButton* rejectButton : rejectButtons)
|
||||
retranslateRejectButton(rejectButton);
|
||||
}
|
||||
|
||||
void AddFriendForm::addFriendRequestWidget(const QString &friendAddress, const QString &message)
|
||||
@ -228,19 +231,36 @@ void AddFriendForm::addFriendRequestWidget(const QString &friendAddress, const Q
|
||||
QVBoxLayout* horLayout = new QVBoxLayout();
|
||||
horLayout->setMargin(0);
|
||||
friendLayout->addLayout(horLayout);
|
||||
|
||||
CroppingLabel* friendLabel = new CroppingLabel(friendWidget);
|
||||
friendLabel->setText("<b>" + friendAddress + "</b>");
|
||||
horLayout->addWidget(friendLabel);
|
||||
|
||||
QLabel* messageLabel = new QLabel(message);
|
||||
messageLabel->setWordWrap(true);
|
||||
horLayout->addWidget(messageLabel, 1);
|
||||
QPushButton* acceptButton = new QPushButton(tr("Accept"));
|
||||
connect(acceptButton, SIGNAL(pressed()), acceptMapper,SLOT(map()));
|
||||
acceptMapper->setMapping(acceptButton, friendWidget);
|
||||
|
||||
QPushButton* acceptButton = new QPushButton(friendWidget);
|
||||
acceptButtons.insert(acceptButton);
|
||||
connect(acceptButton, &QPushButton::released, this, &AddFriendForm::onFriendRequestAccepted);
|
||||
friendLayout->addWidget(acceptButton);
|
||||
QPushButton* rejectButton = new QPushButton(tr("Reject"));
|
||||
connect(rejectButton, SIGNAL(pressed()), rejectMapper,SLOT(map()));
|
||||
rejectMapper->setMapping(rejectButton, friendWidget);
|
||||
retranslateAcceptButton(acceptButton);
|
||||
|
||||
QPushButton* rejectButton = new QPushButton(friendWidget);
|
||||
acceptButtons.insert(acceptButton);
|
||||
connect(acceptButton, &QPushButton::released, this, &AddFriendForm::onFriendRequestAccepted);
|
||||
friendLayout->addWidget(rejectButton);
|
||||
retranslateRejectButton(rejectButton);
|
||||
|
||||
requestsLayout->insertWidget(0, friendWidget);
|
||||
}
|
||||
|
||||
void AddFriendForm::retranslateAcceptButton(QPushButton *acceptButton)
|
||||
{
|
||||
acceptButton->setText(tr("Accept"));
|
||||
}
|
||||
|
||||
void AddFriendForm::retranslateRejectButton(QPushButton *rejectButton)
|
||||
{
|
||||
rejectButton->setText(tr("Reject"));
|
||||
}
|
||||
|
@ -25,9 +25,9 @@
|
||||
#include <QLineEdit>
|
||||
#include <QTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSet>
|
||||
|
||||
class QTabWidget;
|
||||
class QSignalMapper;
|
||||
|
||||
namespace Ui {class MainWindow;}
|
||||
|
||||
@ -63,13 +63,15 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void onSendTriggered();
|
||||
void onFriendRequestAccepted(QWidget *friendWidget);
|
||||
void onFriendRequestRejected(QWidget *friendWidget);
|
||||
void onFriendRequestAccepted();
|
||||
void onFriendRequestRejected();
|
||||
void onCurrentChanged(int index);
|
||||
|
||||
private:
|
||||
void retranslateUi();
|
||||
void addFriendRequestWidget(const QString& friendAddress, const QString& message);
|
||||
void retranslateAcceptButton(QPushButton* acceptButton);
|
||||
void retranslateRejectButton(QPushButton* rejectButton);
|
||||
|
||||
private:
|
||||
void setIdFromClipboard();
|
||||
@ -82,8 +84,8 @@ private:
|
||||
QString lastUsername; // Cached username so we can retranslate the invite message
|
||||
QTabWidget* tabWidget;
|
||||
QVBoxLayout* requestsLayout;
|
||||
QSignalMapper* acceptMapper;
|
||||
QSignalMapper* rejectMapper;
|
||||
QSet<QPushButton*> acceptButtons;
|
||||
QSet<QPushButton*> rejectButtons;
|
||||
};
|
||||
|
||||
#endif // ADDFRIENDFORM_H
|
||||
|
@ -17,12 +17,8 @@
|
||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "groupinviteform.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "src/widget/tool/croppinglabel.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/core/core.h"
|
||||
|
||||
#include <tox/tox.h>
|
||||
#include <QSignalMapper>
|
||||
#include <QPushButton>
|
||||
@ -30,6 +26,11 @@
|
||||
#include <QGroupBox>
|
||||
#include <QDateTime>
|
||||
#include <QLabel>
|
||||
#include "ui_mainwindow.h"
|
||||
#include "src/widget/tool/croppinglabel.h"
|
||||
#include "src/widget/translator.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/core/core.h"
|
||||
|
||||
GroupInviteForm::GroupInviteForm()
|
||||
{
|
||||
@ -56,12 +57,8 @@ GroupInviteForm::GroupInviteForm()
|
||||
QHBoxLayout* headLayout = new QHBoxLayout(headWidget);
|
||||
headLayout->addWidget(headLabel);
|
||||
|
||||
acceptMapper = new QSignalMapper(this);
|
||||
rejectMapper = new QSignalMapper(this);
|
||||
connect(acceptMapper, SIGNAL(mapped(QWidget*)), this, SLOT(onGroupInviteAccepted(QWidget*)));
|
||||
connect(rejectMapper, SIGNAL(mapped(QWidget*)), this, SLOT(onGroupInviteRejected(QWidget*)));
|
||||
|
||||
retranslateUi();
|
||||
Translator::registerHandler(std::bind(&GroupInviteForm::retranslateUi, this), this);
|
||||
}
|
||||
|
||||
void GroupInviteForm::show(Ui::MainWindow &ui)
|
||||
@ -81,15 +78,17 @@ void GroupInviteForm::addGroupInvite(int32_t friendId, uint8_t type, QByteArray
|
||||
groupLabel->setText(tr("Invited by <b>%1</b> on %2.").arg(Nexus::getCore()->getFriendUsername(friendId), QDateTime::currentDateTime().toString()));
|
||||
groupLayout->addWidget(groupLabel);
|
||||
|
||||
QPushButton* acceptButton = new QPushButton(tr("Join"));
|
||||
connect(acceptButton, SIGNAL(pressed()), acceptMapper,SLOT(map()));
|
||||
acceptMapper->setMapping(acceptButton, groupWidget);
|
||||
QPushButton* acceptButton = new QPushButton(this);
|
||||
acceptButtons.insert(acceptButton);
|
||||
connect(acceptButton, &QPushButton::released, this, &GroupInviteForm::onGroupInviteAccepted);
|
||||
groupLayout->addWidget(acceptButton);
|
||||
retranslateAcceptButton(acceptButton);
|
||||
|
||||
QPushButton* rejectButton = new QPushButton(tr("Decline"));
|
||||
connect(rejectButton, SIGNAL(pressed()), rejectMapper,SLOT(map()));
|
||||
rejectMapper->setMapping(rejectButton, groupWidget);
|
||||
QPushButton* rejectButton = new QPushButton(this);
|
||||
rejectButtons.insert(rejectButton);
|
||||
connect(rejectButton, &QPushButton::released, this, &GroupInviteForm::onGroupInviteRejected);
|
||||
groupLayout->addWidget(rejectButton);
|
||||
retranslateRejectButton(rejectButton);
|
||||
|
||||
inviteLayout->insertWidget(0, groupWidget);
|
||||
|
||||
@ -109,8 +108,9 @@ void GroupInviteForm::showEvent(QShowEvent* event)
|
||||
emit groupInvitesSeen();
|
||||
}
|
||||
|
||||
void GroupInviteForm::onGroupInviteAccepted(QWidget* groupWidget)
|
||||
void GroupInviteForm::onGroupInviteAccepted()
|
||||
{
|
||||
QWidget* groupWidget = static_cast<QWidget*>(sender());
|
||||
int index = inviteLayout->indexOf(groupWidget);
|
||||
GroupInvite invite = groupInvites.at(index);
|
||||
groupInvites.removeAt(index);
|
||||
@ -121,8 +121,9 @@ void GroupInviteForm::onGroupInviteAccepted(QWidget* groupWidget)
|
||||
emit groupInviteAccepted(invite.friendId, invite.type, invite.invite);
|
||||
}
|
||||
|
||||
void GroupInviteForm::onGroupInviteRejected(QWidget* groupWidget)
|
||||
void GroupInviteForm::onGroupInviteRejected()
|
||||
{
|
||||
QWidget* groupWidget = static_cast<QWidget*>(sender());
|
||||
int index = inviteLayout->indexOf(groupWidget);
|
||||
groupInvites.removeAt(index);
|
||||
|
||||
@ -135,4 +136,20 @@ void GroupInviteForm::retranslateUi()
|
||||
headLabel->setText(tr("Groups"));
|
||||
createButton->setText(tr("Create new group"));
|
||||
inviteBox->setTitle(tr("Group invites"));
|
||||
|
||||
for (QPushButton* acceptButton : acceptButtons)
|
||||
retranslateAcceptButton(acceptButton);
|
||||
|
||||
for (QPushButton* rejectButton : rejectButtons)
|
||||
retranslateRejectButton(rejectButton);
|
||||
}
|
||||
|
||||
void GroupInviteForm::retranslateAcceptButton(QPushButton *acceptButton)
|
||||
{
|
||||
acceptButton->setText(tr("Join"));
|
||||
}
|
||||
|
||||
void GroupInviteForm::retranslateRejectButton(QPushButton *rejectButton)
|
||||
{
|
||||
rejectButton->setText(tr("Decline"));
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define GROUPINVITEFORM_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSet>
|
||||
|
||||
class QLabel;
|
||||
class QVBoxLayout;
|
||||
@ -48,11 +49,13 @@ protected:
|
||||
void showEvent(QShowEvent* event) final override;
|
||||
|
||||
private slots:
|
||||
void onGroupInviteAccepted(QWidget* groupWidget);
|
||||
void onGroupInviteRejected(QWidget* groupWidget);
|
||||
void onGroupInviteAccepted();
|
||||
void onGroupInviteRejected();
|
||||
|
||||
private:
|
||||
void retranslateUi();
|
||||
void retranslateAcceptButton(QPushButton* acceptButton);
|
||||
void retranslateRejectButton(QPushButton* rejectButton);
|
||||
|
||||
private:
|
||||
struct GroupInvite
|
||||
@ -67,8 +70,8 @@ private:
|
||||
QPushButton* createButton;
|
||||
QGroupBox* inviteBox;
|
||||
QVBoxLayout* inviteLayout;
|
||||
QSignalMapper* acceptMapper;
|
||||
QSignalMapper* rejectMapper;
|
||||
QSet<QPushButton*> acceptButtons;
|
||||
QSet<QPushButton*> rejectButtons;
|
||||
QList<GroupInvite> groupInvites;
|
||||
};
|
||||
|
||||
|
@ -336,6 +336,7 @@ void Widget::init()
|
||||
addFriendForm->show(*ui);
|
||||
setWindowTitle(tr("Add friend"));
|
||||
ui->addButton->setCheckable(true);
|
||||
ui->groupButton->setCheckable(true);
|
||||
ui->transferButton->setCheckable(true);
|
||||
ui->settingsButton->setCheckable(true);
|
||||
setActiveToolMenuButton(Widget::AddButton);
|
||||
|
Loading…
x
Reference in New Issue
Block a user