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

refactor(groupwidget): Extract setTitle in method

This commit is contained in:
Diadlo 2017-08-02 23:36:16 +03:00
parent 99ebb73562
commit 14c2a30f4c
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
2 changed files with 13 additions and 9 deletions

View File

@ -50,16 +50,9 @@ GroupWidget::GroupWidget(int groupId, const QString& name, bool compact)
nameLabel->setText(name); nameLabel->setText(name);
onUserListChanged(); onUserListChanged();
setAcceptDrops(true); setAcceptDrops(true);
connect(nameLabel, &CroppingLabel::editFinished, [=](const QString& newName) { connect(nameLabel, &CroppingLabel::editFinished, this, &GroupWidget::setTitle);
if (!newName.isEmpty()) {
Group* g = GroupList::findGroup(groupId);
emit renameRequested(this, newName);
emit g->getChatForm()->groupTitleChanged(groupId, newName.left(128));
}
});
Translator::registerHandler(std::bind(&GroupWidget::retranslateUi, this), this); Translator::registerHandler(std::bind(&GroupWidget::retranslateUi, this), this);
} }
@ -68,6 +61,16 @@ GroupWidget::~GroupWidget()
Translator::unregister(this); Translator::unregister(this);
} }
void GroupWidget::setTitle(const QString& newName)
{
if (!newName.isEmpty()) {
Group* g = GroupList::findGroup(groupId);
g->setName(newName);
emit renameRequested(this, newName);
emit g->getChatForm()->groupTitleChanged(groupId, newName.left(128));
}
}
void GroupWidget::contextMenuEvent(QContextMenuEvent* event) void GroupWidget::contextMenuEvent(QContextMenuEvent* event)
{ {
if (!active) if (!active)

View File

@ -52,8 +52,9 @@ protected:
void dragLeaveEvent(QDragLeaveEvent* ev) override; void dragLeaveEvent(QDragLeaveEvent* ev) override;
void dropEvent(QDropEvent* ev) override; void dropEvent(QDropEvent* ev) override;
private: private slots:
void retranslateUi(); void retranslateUi();
void setTitle(const QString& newName);
public: public:
int groupId; int groupId;