mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 09:01:50 +08:00
has been completed.
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
#include "addfrienddialog.h"
|
||||
|
||||
#include "model/datacenter.h"
|
||||
|
||||
using namespace model;
|
||||
|
||||
/////////////////////////////////////////
|
||||
//表示一个好友搜索的结果
|
||||
@ -23,6 +26,7 @@ FriendResultItem::FriendResultItem(const UserInfo& userInfo)
|
||||
avatarBtn->setFixedSize(50, 50);
|
||||
avatarBtn->setIconSize(QSize(50, 50));
|
||||
avatarBtn->setIcon(userInfo.avatar);
|
||||
avatarBtn->setStyleSheet("QPushButton { background-color: transparent; }");
|
||||
|
||||
// 4. 创建昵称
|
||||
QLabel* nameLabel = new QLabel();
|
||||
@ -55,10 +59,22 @@ FriendResultItem::FriendResultItem(const UserInfo& userInfo)
|
||||
layout->addWidget(addBtn, 0, 2, 2, 1);
|
||||
|
||||
// 8. 连接信号槽
|
||||
//connect(addBtn, &QPushButton::clicked, this, &FriendResultItem::clickAddBtn);
|
||||
connect(addBtn, &QPushButton::clicked, this, &FriendResultItem::clickAddBtn);
|
||||
|
||||
}
|
||||
|
||||
void FriendResultItem::clickAddBtn()
|
||||
{
|
||||
//发送好友申请
|
||||
DataCenter* dataCenter = DataCenter::getInstance();
|
||||
dataCenter->addFriendApplyAsync(this->userInfo.userId);
|
||||
|
||||
//设置按钮为禁用状态
|
||||
addBtn->setEnabled(false);
|
||||
addBtn->setText("申请已发送");
|
||||
addBtn->setStyleSheet("QPushButton { border: none; color: rgb(255, 255, 255); background-color: rgb(200, 200, 200); border-radius: 10px;}");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
//整个搜索好友的窗口
|
||||
/////////////////////////////////////////
|
||||
@ -115,8 +131,8 @@ AddFriendDialog::AddFriendDialog(QWidget *parent)
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// // 6. 连接信号槽
|
||||
// connect(searchBtn, &QPushButton::clicked, this, &AddFriendDialog::clickSearchBtn);
|
||||
// 6. 连接信号槽
|
||||
connect(searchBtn, &QPushButton::clicked, this, &AddFriendDialog::clickSearchBtn);
|
||||
|
||||
}
|
||||
|
||||
@ -170,3 +186,32 @@ void AddFriendDialog::setSearchKey(const QString& searcheKey)
|
||||
searchEdit->setText(searcheKey);
|
||||
}
|
||||
|
||||
void AddFriendDialog::clickSearchBtn()
|
||||
{
|
||||
//拿到输入框的内容
|
||||
const QString& text = searchEdit->text();
|
||||
if (text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//给服务器发送请求
|
||||
DataCenter* dataCenter = DataCenter::getInstance();
|
||||
connect(dataCenter, &DataCenter::searchUserDone, this, &AddFriendDialog::clickSearchDone, Qt::UniqueConnection);
|
||||
dataCenter->searchUserAsync(text);
|
||||
}
|
||||
|
||||
void AddFriendDialog::clickSearchDone()
|
||||
{
|
||||
//拿到DataCenter中的搜索结果
|
||||
DataCenter* dataCenter = DataCenter::getInstance();
|
||||
QList<UserInfo>* searchResult = dataCenter->getSearchUserResult();
|
||||
if (searchResult == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->clear();
|
||||
for (const auto& u : *searchResult) {
|
||||
this->addResult(u);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user