mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Update renamed friends and groups during search
This commit is contained in:
parent
167a8971ec
commit
8e796a1d8b
@ -83,13 +83,12 @@ CircleWidget::CircleWidget(FriendListWidget *parent, int id_)
|
||||
setName(Settings::getInstance().getCircleName(id));
|
||||
}
|
||||
|
||||
connect(nameLabel, &CroppingLabel::textChanged, [this](const QString &newName, const QString &oldName)
|
||||
connect(nameLabel, &CroppingLabel::editFinished, [this](const QString &newName)
|
||||
{
|
||||
if (isCompact())
|
||||
maxCropLabel(nameLabel);
|
||||
nameLabel->setText(oldName);
|
||||
emit renameRequested(newName);
|
||||
Settings::getInstance().setCircleName(id, newName);
|
||||
if (!newName.isEmpty())
|
||||
{
|
||||
emit renameRequested(newName);
|
||||
}
|
||||
});
|
||||
|
||||
bool isNew = false;
|
||||
@ -148,6 +147,9 @@ void CircleWidget::search(const QString &searchString, bool updateAll, bool hide
|
||||
void CircleWidget::setName(const QString &name)
|
||||
{
|
||||
nameLabel->setText(name);
|
||||
Settings::getInstance().setCircleName(id, name);
|
||||
if (isCompact())
|
||||
maxCropLabel(nameLabel);
|
||||
}
|
||||
|
||||
void CircleWidget::renameCircle()
|
||||
|
@ -103,8 +103,10 @@ ChatForm::ChatForm(Friend* chatFriend)
|
||||
Core::getInstance()->sendTyping(f->getFriendID(), false);
|
||||
isTyping = false;
|
||||
} );
|
||||
connect(nameLabel, &CroppingLabel::textChanged, this, [=](QString text, QString orig) {
|
||||
if (text != orig) emit aliasChanged(text);
|
||||
connect(nameLabel, &CroppingLabel::editFinished, this, [=](const QString& newName)
|
||||
{
|
||||
nameLabel->setText(newName);
|
||||
emit aliasChanged(newName);
|
||||
} );
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
@ -96,8 +96,14 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||
connect(callButton, &QPushButton::clicked, this, &GroupChatForm::onCallClicked);
|
||||
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
|
||||
connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle()));
|
||||
connect(nameLabel, &CroppingLabel::textChanged, this, [=](QString text, QString orig)
|
||||
{if (text != orig) emit groupTitleChanged(group->getGroupId(), text.left(128));} );
|
||||
connect(nameLabel, &CroppingLabel::editFinished, this, [=](const QString& newName)
|
||||
{
|
||||
if (!newName.isEmpty())
|
||||
{
|
||||
nameLabel->setText(newName);
|
||||
emit groupTitleChanged(group->getGroupId(), newName.left(128));
|
||||
}
|
||||
});
|
||||
|
||||
setAcceptDrops(true);
|
||||
Translator::registerHandler(std::bind(&GroupChatForm::retranslateUi, this), this);
|
||||
|
@ -113,13 +113,8 @@ void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnl
|
||||
}
|
||||
}
|
||||
|
||||
void FriendListWidget::renameGroupWidget(const QString &newName)
|
||||
void FriendListWidget::renameGroupWidget(GroupWidget* groupWidget, const QString &newName)
|
||||
{
|
||||
assert(sender() != nullptr);
|
||||
|
||||
GroupWidget* groupWidget = dynamic_cast<GroupWidget*>(sender());
|
||||
assert(groupWidget != nullptr);
|
||||
|
||||
groupLayout.removeSortedWidget(groupWidget);
|
||||
groupWidget->setName(newName);
|
||||
groupLayout.addSortedWidget(groupWidget);
|
||||
@ -133,7 +128,7 @@ void FriendListWidget::renameCircleWidget(const QString &newName)
|
||||
CircleWidget* circleWidget = dynamic_cast<CircleWidget*>(sender());
|
||||
assert(circleWidget != nullptr);
|
||||
|
||||
// Rename before removing so you can find it successfully.
|
||||
// Rename after removing so you can find it successfully.
|
||||
circleLayout.removeSortedWidget(circleWidget);
|
||||
circleWidget->setName(newName);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
|
@ -56,7 +56,7 @@ signals:
|
||||
void onCompactChanged(bool compact);
|
||||
|
||||
public slots:
|
||||
void renameGroupWidget(const QString& newName);
|
||||
void renameGroupWidget(GroupWidget* groupWidget, const QString& newName);
|
||||
void renameCircleWidget(const QString& newName);
|
||||
void onGroupchatPositionChanged(bool top);
|
||||
void moveWidget(FriendWidget* w, Status s, bool add = false);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "src/persistence/settings.h"
|
||||
#include "form/groupchatform.h"
|
||||
#include "maskablepixmapwidget.h"
|
||||
#include "friendlistwidget.h"
|
||||
#include "src/widget/style.h"
|
||||
#include "src/core/core.h"
|
||||
#include <QPalette>
|
||||
@ -51,13 +52,12 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
connect(nameLabel, &CroppingLabel::textChanged, [this](const QString &newName, const QString &oldName)
|
||||
connect(nameLabel, &CroppingLabel::editFinished, [this](const QString &newName)
|
||||
{
|
||||
Group* g = GroupList::findGroup(groupId);
|
||||
if (newName != oldName)
|
||||
if (!newName.isEmpty())
|
||||
{
|
||||
nameLabel->setText(oldName);
|
||||
emit renameRequested(newName);
|
||||
Group* g = GroupList::findGroup(groupId);
|
||||
emit renameRequested(this, newName);
|
||||
emit g->getChatForm()->groupTitleChanged(groupId, newName.left(128));
|
||||
}
|
||||
/* according to agilob:
|
||||
@ -77,6 +77,9 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||
QAction* setTitle = menu.addAction(tr("Set title..."));
|
||||
QAction* quitGroup = menu.addAction(tr("Quit group","Menu to quit a groupchat"));
|
||||
|
||||
FriendListWidget *friendList = static_cast<FriendListWidget*>(parentWidget());
|
||||
friendList->reDraw();
|
||||
|
||||
QAction* selectedItem = menu.exec(pos);
|
||||
if (selectedItem)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
|
||||
signals:
|
||||
void groupWidgetClicked(GroupWidget* widget);
|
||||
void renameRequested(const QString& newName);
|
||||
void renameRequested(GroupWidget* widget, const QString& newName);
|
||||
void removeGroup(int groupId);
|
||||
|
||||
protected:
|
||||
|
@ -21,9 +21,6 @@
|
||||
#include <QResizeEvent>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
CroppingLabel::CroppingLabel(QWidget* parent)
|
||||
: QLabel(parent)
|
||||
, blockPaintEvents(false)
|
||||
@ -38,15 +35,11 @@ CroppingLabel::CroppingLabel(QWidget* parent)
|
||||
| Qt::ImhNoPredictiveText
|
||||
| Qt::ImhPreferLatin);
|
||||
|
||||
installEventFilter(this);
|
||||
textEdit->installEventFilter(this);
|
||||
connect(textEdit, &QLineEdit::editingFinished, this, &CroppingLabel::finishTextEdit);
|
||||
}
|
||||
|
||||
void CroppingLabel::editStart()
|
||||
{
|
||||
//if (!parentWidget()->isVisible())
|
||||
// return;
|
||||
showTextEdit();
|
||||
textEdit->selectAll();
|
||||
}
|
||||
@ -100,38 +93,14 @@ void CroppingLabel::mouseReleaseEvent(QMouseEvent *e)
|
||||
QLabel::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
bool CroppingLabel::eventFilter(QObject *obj, QEvent *e)
|
||||
void CroppingLabel::paintEvent(QPaintEvent* paintEvent)
|
||||
{
|
||||
// catch paint events if needed
|
||||
if (obj == this)
|
||||
if (blockPaintEvents)
|
||||
{
|
||||
if (e->type() == QEvent::Paint && blockPaintEvents)
|
||||
return true;
|
||||
paintEvent->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
// events fired by the QLineEdit
|
||||
if (obj == textEdit)
|
||||
{
|
||||
if (!textEdit->isVisible())
|
||||
return false;
|
||||
|
||||
if (e->type() == QEvent::KeyPress)
|
||||
{
|
||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(e);
|
||||
if (keyEvent->key() == Qt::Key_Return)
|
||||
hideTextEdit(true);
|
||||
|
||||
if (keyEvent->key() == Qt::Key_Escape)
|
||||
hideTextEdit(false);
|
||||
}
|
||||
|
||||
if (e->type() == QEvent::FocusOut)
|
||||
{
|
||||
hideTextEdit(true);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
QLabel::paintEvent(paintEvent);
|
||||
}
|
||||
|
||||
void CroppingLabel::setElidedText()
|
||||
@ -145,29 +114,12 @@ void CroppingLabel::setElidedText()
|
||||
QLabel::setText(elidedText);
|
||||
}
|
||||
|
||||
void CroppingLabel::hideTextEdit(bool acceptText)
|
||||
{
|
||||
if (acceptText)
|
||||
{
|
||||
textEdit->setText(textEdit->text().trimmed().remove(QRegExp("[\\t\\n\\v\\f\\r\\x0000]"))); // we should really treat regular names this way as well (*ahem* zetok)
|
||||
QString oldOrigText = origText;
|
||||
setText(textEdit->text()); // set before emitting so we don't override external reactions to signal
|
||||
emit textChanged(textEdit->text(), oldOrigText);
|
||||
emit editFinished(textEdit->text());
|
||||
}
|
||||
|
||||
textEdit->hide();
|
||||
blockPaintEvents = false;
|
||||
}
|
||||
|
||||
void CroppingLabel::showTextEdit()
|
||||
{
|
||||
blockPaintEvents = true;
|
||||
textEdit->show();
|
||||
//textEdit->setFocus();
|
||||
textEdit->setFocus();
|
||||
textEdit->setText(origText);
|
||||
// Set focus when event loop is free.
|
||||
QTimer::singleShot(0, textEdit, SLOT(setFocus()));
|
||||
}
|
||||
|
||||
QString CroppingLabel::fullText()
|
||||
@ -178,10 +130,8 @@ QString CroppingLabel::fullText()
|
||||
void CroppingLabel::finishTextEdit()
|
||||
{
|
||||
QString newText = textEdit->text().trimmed().remove(QRegExp("[\\t\\n\\v\\f\\r\\x0000]"));
|
||||
if (!newText.isEmpty() && origText != newText)
|
||||
if (origText != newText)
|
||||
{
|
||||
setText(textEdit->text()); // set before emitting so we don't override external reactions to signal
|
||||
emit textChanged(textEdit->text(), origText);
|
||||
emit editFinished(textEdit->text());
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* paintEvent) override;
|
||||
void setElidedText();
|
||||
void hideTextEdit(bool acceptText);
|
||||
void showTextEdit();
|
||||
|
@ -197,7 +197,7 @@ void Widget::init()
|
||||
connect(ui->settingsButton, &QPushButton::clicked, this, &Widget::onSettingsClicked);
|
||||
connect(profilePicture, &MaskablePixmapWidget::clicked, this, &Widget::showProfile);
|
||||
connect(ui->nameLabel, &CroppingLabel::clicked, this, &Widget::showProfile);
|
||||
connect(ui->statusLabel, &CroppingLabel::textChanged, this, &Widget::onStatusMessageChanged);
|
||||
connect(ui->statusLabel, &CroppingLabel::editFinished, this, &Widget::onStatusMessageChanged);
|
||||
connect(ui->mainSplitter, &QSplitter::splitterMoved, this, &Widget::onSplitterMoved);
|
||||
connect(addFriendForm, &AddFriendForm::friendRequested, this, &Widget::friendRequested);
|
||||
connect(timer, &QTimer::timeout, this, &Widget::onUserAwayCheck);
|
||||
@ -561,10 +561,9 @@ void Widget::setUsername(const QString& username)
|
||||
sanitizedNameMention = QRegExp("\\b" + QRegExp::escape(sanename) + "\\b", Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
void Widget::onStatusMessageChanged(const QString& newStatusMessage, const QString& oldStatusMessage)
|
||||
void Widget::onStatusMessageChanged(const QString& newStatusMessage)
|
||||
{
|
||||
ui->statusLabel->setText(oldStatusMessage); // restore old status message until Core tells us to set it
|
||||
ui->statusLabel->setToolTip(oldStatusMessage); // for overlength messsages
|
||||
// Keep old status message until Core tells us to set it.
|
||||
Nexus::getCore()->setStatusMessage(newStatusMessage);
|
||||
}
|
||||
|
||||
@ -588,7 +587,7 @@ void Widget::addFriend(int friendId, const QString &userId)
|
||||
contactListWidget->addFriendWidget(newfriend->getFriendWidget(),Status::Offline,Settings::getInstance().getFriendCircleID(newfriend->getToxId()));
|
||||
|
||||
Core* core = Nexus::getCore();
|
||||
connect(newfriend, &Friend::displayedNameChanged, contactListWidget, &FriendListWidget::moveWidget);
|
||||
connect(newfriend, &Friend::displayedNameChanged, this, &Widget::onFriendDisplayChanged);
|
||||
connect(settingsWidget, &SettingsWidget::compactToggled, newfriend->getFriendWidget(), &GenericChatroomWidget::setCompact);
|
||||
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
||||
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||
@ -720,6 +719,19 @@ void Widget::onFriendUsernameChanged(int friendId, const QString& username)
|
||||
QString str = username; str.replace('\n', ' ');
|
||||
str.remove('\r'); str.remove(QChar((char)0)); // null terminator...
|
||||
f->setName(str);
|
||||
}
|
||||
|
||||
void Widget::onFriendDisplayChanged(FriendWidget *friendWidget, Status s)
|
||||
{
|
||||
contactListWidget->moveWidget(friendWidget, s);
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
switch (s)
|
||||
{
|
||||
case Status::Offline:
|
||||
friendWidget->searchName(ui->searchContactText->text(), filterOffline(filter));
|
||||
default:
|
||||
friendWidget->searchName(ui->searchContactText->text(), filterOnline(filter));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -994,10 +1006,10 @@ void Widget::onGroupTitleChanged(int groupnumber, const QString& author, const Q
|
||||
if (!g)
|
||||
return;
|
||||
|
||||
g->setName(title);
|
||||
if (!author.isEmpty())
|
||||
g->getChatForm()->addSystemInfoMessage(tr("%1 has set the title to %2").arg(author, title), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||
|
||||
contactListWidget->renameGroupWidget(g->getGroupWidget(), title);
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
g->getGroupWidget()->searchName(ui->searchContactText->text(), filterGroups(filter));
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class MainWindow;
|
||||
}
|
||||
|
||||
class GenericChatroomWidget;
|
||||
class FriendWidget;
|
||||
class Group;
|
||||
class Friend;
|
||||
class QSplitter;
|
||||
@ -100,6 +101,7 @@ public slots:
|
||||
void onFriendStatusChanged(int friendId, Status status);
|
||||
void onFriendStatusMessageChanged(int friendId, const QString& message);
|
||||
void onFriendUsernameChanged(int friendId, const QString& username);
|
||||
void onFriendDisplayChanged(FriendWidget* friendWidget, Status s);
|
||||
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
|
||||
void onFriendRequestReceived(const QString& userId, const QString& message);
|
||||
void onMessageSendResult(uint32_t friendId, const QString& message, int messageId);
|
||||
@ -138,7 +140,7 @@ private slots:
|
||||
void onTransferClicked();
|
||||
void showProfile();
|
||||
void onUsernameChanged(const QString& newUsername, const QString& oldUsername);
|
||||
void onStatusMessageChanged(const QString& newStatusMessage, const QString& oldStatusMessage);
|
||||
void onStatusMessageChanged(const QString& newStatusMessage);
|
||||
void onChatroomWidgetClicked(GenericChatroomWidget *);
|
||||
void removeFriend(int friendId);
|
||||
void copyFriendIdToClipboard(int friendId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user