From 845216fa2fbc4f4c7447b6e6ebf816dd72685a18 Mon Sep 17 00:00:00 2001 From: dubslow Date: Mon, 17 Nov 2014 20:15:44 -0600 Subject: [PATCH] set aliases from chat form (half of #780) --- src/widget/form/chatform.cpp | 2 ++ src/widget/form/chatform.h | 1 + src/widget/form/genericchatform.cpp | 1 + src/widget/form/groupchatform.cpp | 1 - src/widget/friendwidget.cpp | 22 +++++++++++++--------- src/widget/friendwidget.h | 1 + src/widget/widget.cpp | 1 + 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index d4cde243b..44017003a 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -76,6 +76,8 @@ ChatForm::ChatForm(Friend* chatFriend) connect(chatWidget, &ChatAreaWidget::onFileTranfertInterract, this, &ChatForm::onFileTansBtnClicked); connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed); connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts())); + connect(nameLabel, &CroppingLabel::textChanged, this, [=](QString text, QString orig) + {if (text != orig) emit aliasChanged(text);} ); setAcceptDrops(true); } diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index b8920b86f..6f6505a8b 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -49,6 +49,7 @@ signals: void cancelCall(int callId, int friendId); void micMuteToggle(int callId); void volMuteToggle(int callId); + void aliasChanged(const QString& alias); public slots: void deliverOfflineMsgs(); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 15f089a30..9fbdb9d4a 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -47,6 +47,7 @@ GenericChatForm::GenericChatForm(QWidget *parent) : nameLabel = new CroppingLabel(); nameLabel->setObjectName("nameLabel"); nameLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize()); + nameLabel->setEditable(true); avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png"); QHBoxLayout *headLayout = new QHBoxLayout(), *mainFootLayout = new QHBoxLayout(); diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index de6fd951a..fb1566a66 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -52,7 +52,6 @@ GroupChatForm::GroupChatForm(Group* chatGroup) } nameLabel->setText(group->widget->getName()); - nameLabel->setEditable(true); nusersLabel->setFont(Style::getFont(Style::Medium)); nusersLabel->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size())); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 1904f02b2..a5cf11043 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -218,6 +218,18 @@ void FriendWidget::mouseMoveEvent(QMouseEvent *ev) } } +void FriendWidget::setAlias(const QString& _alias) +{ + QString alias = _alias.trimmed(); + alias.remove(QRegExp("[\\t\\n\\v\\f\\r\\x0000]")); // we should really treat regular names this way as well (*ahem* zetok) + alias = alias.left(128); // same as TOX_MAX_NAME_LENGTH + Friend* f = FriendList::findFriend(friendId); + f->setAlias(alias); + Settings::getInstance().setFriendAlias(f->getToxID(), alias); + hide(); + show(); +} + void FriendWidget::setFriendAlias() { bool ok; @@ -227,13 +239,5 @@ void FriendWidget::setFriendAlias() f->getDisplayedName(), &ok); if (ok) - { - alias = alias.trimmed(); - alias.remove(QRegExp("[\t\n\v\f\r]")); - alias = alias.left(128); // same as TOX_MAX_NAME_LENGTH - f->setAlias(alias); - Settings::getInstance().setFriendAlias(f->getToxID(), alias); - hide(); - show(); - } + setAlias(alias); } diff --git a/src/widget/friendwidget.h b/src/widget/friendwidget.h index 1aa2840a5..0223149b2 100644 --- a/src/widget/friendwidget.h +++ b/src/widget/friendwidget.h @@ -44,6 +44,7 @@ signals: public slots: void onAvatarChange(int FriendId, const QPixmap& pic); void onAvatarRemoved(int FriendId); + void setAlias(const QString& alias); protected: void mousePressEvent(QMouseEvent* ev); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 78741038e..3e9aa8d38 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -646,6 +646,7 @@ void Widget::addFriend(int friendId, const QString &userId) connect(newfriend->getChatForm(), SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int))); connect(newfriend->getChatForm(), SIGNAL(micMuteToggle(int)), core, SLOT(micMuteToggle(int))); connect(newfriend->getChatForm(), SIGNAL(volMuteToggle(int)), core, SLOT(volMuteToggle(int))); + connect(newfriend->getChatForm(), &ChatForm::aliasChanged, newfriend->getFriendWidget(), &FriendWidget::setAlias); connect(core, &Core::fileReceiveRequested, newfriend->getChatForm(), &ChatForm::onFileRecvRequest); connect(core, &Core::avInvite, newfriend->getChatForm(), &ChatForm::onAvInvite); connect(core, &Core::avStart, newfriend->getChatForm(), &ChatForm::onAvStart);