From 14c2a30f4c7634918bfcae94c5d7cd54890b2915 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Wed, 2 Aug 2017 23:36:16 +0300 Subject: [PATCH] refactor(groupwidget): Extract setTitle in method --- src/widget/groupwidget.cpp | 19 +++++++++++-------- src/widget/groupwidget.h | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/widget/groupwidget.cpp b/src/widget/groupwidget.cpp index 2a9a0c7f2..0a428df13 100644 --- a/src/widget/groupwidget.cpp +++ b/src/widget/groupwidget.cpp @@ -50,16 +50,9 @@ GroupWidget::GroupWidget(int groupId, const QString& name, bool compact) nameLabel->setText(name); onUserListChanged(); - setAcceptDrops(true); - connect(nameLabel, &CroppingLabel::editFinished, [=](const QString& newName) { - if (!newName.isEmpty()) { - Group* g = GroupList::findGroup(groupId); - emit renameRequested(this, newName); - emit g->getChatForm()->groupTitleChanged(groupId, newName.left(128)); - } - }); + connect(nameLabel, &CroppingLabel::editFinished, this, &GroupWidget::setTitle); Translator::registerHandler(std::bind(&GroupWidget::retranslateUi, this), this); } @@ -68,6 +61,16 @@ GroupWidget::~GroupWidget() 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) { if (!active) diff --git a/src/widget/groupwidget.h b/src/widget/groupwidget.h index 4baf139c3..12ad44e60 100644 --- a/src/widget/groupwidget.h +++ b/src/widget/groupwidget.h @@ -52,8 +52,9 @@ protected: void dragLeaveEvent(QDragLeaveEvent* ev) override; void dropEvent(QDropEvent* ev) override; -private: +private slots: void retranslateUi(); + void setTitle(const QString& newName); public: int groupId;