update winodws

This commit is contained in:
xyz
2025-05-30 19:49:58 +08:00
parent 51f0b4941f
commit 8b3290b755
10 changed files with 442 additions and 30 deletions

View File

@ -34,6 +34,10 @@ set(PROJECT_SOURCES
messageeditarea.cpp
SelfInfoWidget.h
SelfInfoWidget.cpp
userinfowidget.h
userinfowidget.cpp
sessiondetailwidget.h
sessiondetailwidget.cpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
@ -51,8 +55,6 @@ endif()
target_link_libraries(ClientChat PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
# Bundle设置
include(GNUInstallDirs)
install(TARGETS ClientChat
BUNDLE DESTINATION .

View File

@ -4,7 +4,7 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
: QDialog(parent)
{
//设置整个窗口的属性
this->setFixedSize(450, 250);
this->setFixedSize(500, 200);
this->setWindowTitle("个人信息");
this->setWindowIcon(QIcon(":/resource/image/logo.png"));
//窗口被关闭时,自动销毁这个对话框对象
@ -14,8 +14,10 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
//创建布局管理器
QGridLayout* layout = new QGridLayout();
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
//layout->setSpacing(0);
layout->setHorizontalSpacing(10);
layout->setVerticalSpacing(3);
layout->setContentsMargins(20, 20, 20, 0);
layout->setAlignment(Qt::AlignTop);
this->setLayout(layout);
@ -29,6 +31,7 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
QString labelStyle = "QLabel { font-size: 14px; font-weight: 800; }";
QString btnStyle = "QPushButton {border: none; background-color: transparent; }";
btnStyle += "QPushButton:pressed { background-color: rgb(210, 210, 210); }";
QString editStyle = "QLineEdit { border: none; background-color: rgb(255 ,255, 255); border-radius: 5px; padding-left: 2px; }";
int height = 30;
@ -36,7 +39,7 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
idTag = new QLabel();
idTag->setFixedSize(50, height);
idTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
idTag->setText("序号");
idTag->setText("ID");
idTag->setStyleSheet(labelStyle);
idLabel = new QLabel();
@ -55,7 +58,7 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
nameModifyBtn = new QPushButton();
nameModifyBtn->setFixedSize(25, 25);
nameModifyBtn->setFixedSize(70, 25);
nameModifyBtn->setIconSize(QSize(20, 20));
nameModifyBtn->setIcon(QIcon(":/resource/image/modify.png"));
nameModifyBtn->setStyleSheet(btnStyle);
@ -63,10 +66,11 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
nameEdit = new QLineEdit();
nameEdit->setFixedHeight(height);
nameEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
nameEdit->setStyleSheet(btnStyle);
nameEdit->hide();
nameSubmitBtn = new QPushButton();
nameSubmitBtn->setFixedSize(25, 25);
nameSubmitBtn->setFixedSize(70, 25);
nameSubmitBtn->setIconSize(QSize(20, 20));
nameSubmitBtn->setIcon(QIcon(":/resource/image/submit.png"));
nameSubmitBtn->setStyleSheet(btnStyle);
@ -84,7 +88,7 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
descLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
descModifyBtn = new QPushButton();
descModifyBtn->setFixedSize(25, 25);
descModifyBtn->setFixedSize(70, 25);
descModifyBtn->setIconSize(QSize(20, 20));
descModifyBtn->setIcon(QIcon(":/resource/image/modify.png"));
descModifyBtn->setStyleSheet(btnStyle);
@ -92,12 +96,13 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
descEdit = new QLineEdit();
descEdit->setFixedHeight(height);
descEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
descEdit->setStyleSheet(btnStyle);
descEdit->hide();
descSubmitBtn = new QPushButton();
descSubmitBtn->setFixedSize(25, 25);
descSubmitBtn->setFixedSize(70, 25);
descSubmitBtn->setIconSize(QSize(20, 20));
descSubmitBtn->setIcon(QIcon(":/resource/image/modify.png"));
descSubmitBtn->setIcon(QIcon(":/resource/image/submit.png"));
descSubmitBtn->setStyleSheet(btnStyle);
descSubmitBtn->hide();
@ -113,7 +118,7 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
phoneLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
phoneModifyBtn = new QPushButton();
phoneModifyBtn->setFixedSize(25, 25);
phoneModifyBtn->setFixedSize(70, 25);
phoneModifyBtn->setIconSize(QSize(20, 20));
phoneModifyBtn->setIcon(QIcon(":/resource/image/modify.png"));
phoneModifyBtn->setStyleSheet(btnStyle);
@ -121,10 +126,11 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
phoneEdit = new QLineEdit();
phoneEdit->setFixedHeight(height);
phoneEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
phoneEdit->setStyleSheet(btnStyle);
phoneEdit->hide();
phoneSubmitBtn = new QPushButton();
phoneSubmitBtn->setFixedSize(25, 25);
phoneSubmitBtn->setFixedSize(70, 25);
phoneSubmitBtn->setIconSize(QSize(20, 20));
phoneSubmitBtn->setIcon(QIcon(":/resource/image/submit.png"));
phoneSubmitBtn->setStyleSheet(btnStyle);
@ -135,16 +141,26 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
verifyCodeTag = new QLabel();
verifyCodeTag->setFixedSize(50, height);
verifyCodeTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
verifyCodeTag->setText("输入验证码:");
verifyCodeTag->setText("验证码:");
verifyCodeTag->setStyleSheet(labelStyle);
verifyCodeTag->hide();
verifyCodeEdit = new QLineEdit();
verifyCodeEdit->setFixedHeight(height);
verifyCodeEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
//verifyCodeEdit->hide();
verifyCodeEdit->setStyleSheet(editStyle);
verifyCodeEdit->hide();
getVerifyCodeBtn = new QPushButton();
getVerifyCodeBtn->setText("获取验证码");
getVerifyCodeBtn->setFixedSize(70, height);
getVerifyCodeBtn->setStyleSheet(R"(QPushButton {
border: none;
background-color: transparent;
color: rgb(0, 0, 0); }
QPushButton:pressed { background-color: rgb(231, 231, 231); }
)");
getVerifyCodeBtn->hide();
layout->addWidget(avatarBtn, 0, 0, 3, 1);
@ -163,9 +179,9 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
layout->addWidget(phoneLabel, 3, 2);
layout->addWidget(phoneModifyBtn, 3, 3);
layout->addWidget(verifyCodeTag, 4, 1);
/*layout->addWidget(verifyCodeTag, 4, 1);
layout->addWidget(verifyCodeEdit, 4, 2);
layout->addWidget(getVerifyCodeBtn, 4, 3);
layout->addWidget(getVerifyCodeBtn, 4, 3);*/
#if TEST_UI
idLabel->setText("12345");
@ -173,4 +189,62 @@ SelfInfoWidget::SelfInfoWidget(QWidget *parent)
descLabel->setText("It didn't matter that i lived another day.");
phoneLabel->setText("12345678900");
#endif
//添加连接的槽函数
connect(nameModifyBtn, &QPushButton::clicked, this, [=]() {
//把当前的nameLabel和nameModifyBtn隐藏起来
nameLabel->hide();
nameModifyBtn->hide();
layout->removeWidget(nameLabel);
layout->removeWidget(nameModifyBtn);
//把nameEdit和nameSubmitBtn显示出来
nameEdit->show();
nameSubmitBtn->show();
layout->addWidget(nameEdit, 1, 2);
layout->addWidget(nameSubmitBtn, 1, 3);
//把输入框的内容进行设置
nameEdit->setText(nameLabel->text());
});
connect(descModifyBtn, &QPushButton::clicked, this, [=]() {
descLabel->hide();
descModifyBtn->hide();
layout->removeWidget(descLabel);
layout->removeWidget(descModifyBtn);
descEdit->show();
descSubmitBtn->show();
layout->addWidget(descEdit, 2, 2);
layout->addWidget(descSubmitBtn, 2, 3);
descEdit->setText(descLabel->text());
});
connect(phoneModifyBtn, &QPushButton::clicked, this, [=]() {
phoneLabel->hide();
phoneModifyBtn->hide();
layout->removeWidget(phoneLabel);
layout->removeWidget(phoneModifyBtn);
phoneEdit->show();
phoneSubmitBtn->show();
layout->addWidget(phoneEdit, 3, 2);
layout->addWidget(phoneSubmitBtn, 3, 3);
verifyCodeTag->show();
verifyCodeEdit->show();
getVerifyCodeBtn->show();
layout->addWidget(verifyCodeTag, 4, 1);
layout->addWidget(verifyCodeEdit, 4, 2);
layout->addWidget(getVerifyCodeBtn, 4, 3);
phoneEdit->setText(phoneLabel->text());
});
/*connect(nameSubmitBtn, &QPushButton::clicked, this, &SelfInfoWidget::clickNameSubmitBtn);
connect(descSubmitBtn, &QPushButton::clicked, this, &SelfInfoWidget::clickDescSubmitBtn);
connect(getVerifyCodeBtn, &QPushButton::clicked, this, &SelfInfoWidget::clickGetVerifyCodeBtn);
connect(phoneSubmitBtn, &QPushButton::clicked, this, &SelfInfoWidget::clickPhoneSubmitBtn);
connect(avatarBtn, &QPushButton::clicked, this, &SelfInfoWidget::clickAvatarBtn);*/
}

View File

@ -3,7 +3,7 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "sessionfriendarea.h"
#include "sessiondetailwidget.h"
MainWidget *MainWidget::instance = nullptr;
@ -197,7 +197,7 @@ void MainWidget::initRightWindow()
hlayout->addWidget(sessionTitleLabel);
QPushButton* extraBtn = new QPushButton();
extraBtn = new QPushButton();
extraBtn->setFixedSize(30, 30);
extraBtn->setIconSize(QSize(30, 30));
extraBtn->setIcon(QIcon(":/resource/image/more.png"));
@ -232,10 +232,19 @@ void MainWidget::initSignalSlot()
/////////////////////////////////////
connect(userAvatar, &QPushButton::clicked, this, [=]()->void {
SelfInfoWidget* selfInfoWidget = new SelfInfoWidget(this);
selfInfoWidget->setStyleSheet("QDialog { background-color: rgb(255, 255, 255); }");
selfInfoWidget->setStyleSheet("QDialog { background-color: rgb(245, 245, 245); }");
selfInfoWidget->exec(); //弹出模态对话框
//selfInfoWidget->show(); //弹出非模态对加框
});
/////////////////////////////////////
// 点击右上角的更多按钮,扩展会话的详细信息
/////////////////////////////////////
connect(extraBtn, &QPushButton::clicked, this, [=]() {
SessionDetailWidget* sessionDetailWidget = new SessionDetailWidget(this);
sessionDetailWidget->exec();
});
}
void MainWidget::switchTabToSession()

View File

@ -4,11 +4,13 @@
#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QMainWindow>
#include "debug.h"
#include "messageeditarea.h"
#include "messageshowarea.h"
#include "SelfInfoWidget.h"
#include "sessionfriendarea.h"
QT_BEGIN_NAMESPACE
namespace Ui {
@ -53,6 +55,9 @@ private:
//添加好友按钮
QPushButton* addFriendBtn;
//显示会话详情按钮
QPushButton* extraBtn;
//消息展示区
MessageShowArea* messageShowArea;

View File

@ -1,5 +1,8 @@
#include "messageshowarea.h"
#include "mainwidget.h"
#include "userinfowidget.h"
MessageShowArea::MessageShowArea() {
//初始化基本属性
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@ -22,25 +25,31 @@ MessageShowArea::MessageShowArea() {
// 添加测试数据
#if TEST_UI
//测试长消息
model::UserInfo userInfo;
userInfo.nickname = "???";
userInfo.userId = "4862";
userInfo.phone = "00000000000";
userInfo.description = "A test description.";
const QString s = R"(The starry sky is just a few years ago. And the past may no longer exist,The only thing that remains is light years away, it's just an ethereal phantom.)";
userInfo.avatar = QIcon(":/resource/image/defaultAvatar.png");
Message message = Message::makeMessage(model::TEXT_TYPE, "", userInfo, s.toUtf8(), "");
this->addMessage(false, message);
bool k = true;
for(int i = 0; i < 8; i++) {
model::UserInfo userInfo;
userInfo.userId = QString::number(i);
userInfo.phone = "12345678900";
userInfo.description = "A test description.";
userInfo.nickname = "xyz" + QString::number(i);
userInfo.avatar = QIcon(":/resource/image/defaultAvatar.png");
Message message = Message::makeMessage(model::TEXT_TYPE, "", userInfo, (QString("this is a test message...") + QString::number(i)).toUtf8(), "");
k = !k;
this->addMessage(k, message);
}
//测试长消息
model::UserInfo userInfo;
userInfo.nickname = "???";
const QString s = R"(The starry sky is just a few years ago. And the past may no longer exist,The only thing that remains is light years away, it's just an ethereal phantom.)";
userInfo.avatar = QIcon(":/resource/image/defaultAvatar.png");
Message message = Message::makeMessage(model::TEXT_TYPE, "", userInfo, s.toUtf8(), "");
this->addMessage(false, message);
#endif
}
@ -137,6 +146,14 @@ MessageItem *MessageItem::makeMessageItem(bool isLeft, const Message &message)
layout->addWidget(contentWidget, 1, 0);
}
//连接信号槽,处理用户点击头像的操作
connect(avatarBtn, &QPushButton::clicked, messageItem, [=]() {
MainWidget* mainWidget = MainWidget::getInstance();
UserInfoWidget* userInfoWidget = new UserInfoWidget(message.sender, mainWidget);
userInfoWidget->setStyleSheet("QDialog { background-color: rgb(245, 245, 245); }");
userInfoWidget->exec();
});
return messageItem;
}

View File

@ -11,6 +11,7 @@
#include <QPainter>
#include <QPainterPath>
#include "model/data.h"
#include "debug.h"

97
sessiondetailwidget.cpp Normal file
View File

@ -0,0 +1,97 @@
#include "sessiondetailwidget.h"
//右上角详情的会话人员列表
AvatarItem::AvatarItem(const QIcon& avatar, const QString& name)
{
// 设置自身的基本属性
this->setFixedSize(70, 80);
// 创建布局管理器
QVBoxLayout* layout = new QVBoxLayout();
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignHCenter);
this->setLayout(layout);
// 创建头像
avatarBtn = new QPushButton();
avatarBtn->setFixedSize(45, 45);
avatarBtn->setIconSize(QSize(45, 45));
avatarBtn->setIcon(avatar);
avatarBtn->setStyleSheet("QPushButton { border: none; }");
// 创建名字
nameLabel = new QLabel();
nameLabel->setText(name);
QFont font("微软雅黑", 12);
nameLabel->setFont(font);
nameLabel->setAlignment(Qt::AlignCenter);
// 对名字做 "截断操作"
const int MAX_WIDTH = 65;
QFontMetrics metrics(font);
int totalWidth = metrics.horizontalAdvance(name);//测量水平的宽度
if (totalWidth >= MAX_WIDTH) {
// 说明需要截断
QString tail = "...";
int tailWidth = metrics.horizontalAdvance(tail);
int availableWidth = MAX_WIDTH - tailWidth;
int availableSize = name.size() * ((double)availableWidth / totalWidth);
QString newName = name.left(availableSize);
nameLabel->setText(newName + tail);
}
// 添加
layout->addWidget(avatarBtn);
layout->addWidget(nameLabel);
}
SessionDetailWidget::SessionDetailWidget(QWidget *parent)
//:userInfo(userInfo),
: QDialog(parent)
{
// 1. 设置基本属性
this->setWindowTitle("会话详情");
this->setWindowIcon(QIcon(":/resource/image/logo.png"));
this->setFixedSize(300, 300);
this->setStyleSheet("QWidget { background-color: rgb(255, 255, 255); }");
this->setAttribute(Qt::WA_DeleteOnClose);
// 2. 创建布局管理器
QGridLayout* layout = new QGridLayout();
layout->setSpacing(10);
layout->setContentsMargins(50, 0, 50, 0);
this->setLayout(layout);
// 3. 添加 "创建群聊" 按钮
AvatarItem* createGroupBtn = new AvatarItem(QIcon(":/resource/image/cross.png"), "添加");
layout->addWidget(createGroupBtn, 0, 0);
// 4. 添加当前用户的信息 (临时构造的假数据)
#if TEST_UI
AvatarItem* currentUser = new AvatarItem(QIcon(":/resource/image/defaultAvatar.png"), "张三123456");
layout->addWidget(currentUser, 0, 1);
#endif
//AvatarItem* currentUser = new AvatarItem(userInfo.avatar, userInfo.nickname);
//layout->addWidget(currentUser, 0, 1);
// 5. 添加 "删除好友" 按钮
deleteFriendBtn = new QPushButton();
deleteFriendBtn->setFixedHeight(50);
deleteFriendBtn->setText("删除好友");
QString style = "QPushButton { border: 1px solid rgb(90, 90, 90); border-radius: 5px; color: rgb(0, 0, 0); } ";
style += "QPushButton:pressed { background-color: rgb(235, 235, 235); }";
deleteFriendBtn->setStyleSheet(style);
layout->addWidget(deleteFriendBtn, 1, 0, 1, 3);
//// 6. 添加信号槽, 处理点击 "创建群聊" 按钮
//connect(createGroupBtn->getAvatar(), &QPushButton::clicked, this, [=]() {
// ChooseFriendDialog* chooseFriendDialog = new ChooseFriendDialog(this, userInfo.userId);
// chooseFriendDialog->exec();
// });
//connect(deleteFriendBtn, &QPushButton::clicked, this, &SessionDetailWidget::clickDeleteFriendBtn);
}

44
sessiondetailwidget.h Normal file
View File

@ -0,0 +1,44 @@
#pragma once
#include <QDialog>
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QFontMetrics>
#include <QMessageBox>
#include "debug.h"
#include "model/data.h"
using namespace model;
///////////////////////////////////////
///表示 一个头像 + 一个名字的组合控件
///////////////////////////////////////
class AvatarItem : public QWidget {
public:
AvatarItem(const QIcon& avatar, const QString& name);
private:
QPushButton* avatarBtn;
QLabel* nameLabel;
};
///////////////////////////////////////
///表示“单聊会话详情”窗口
///////////////////////////////////////
class SessionDetailWidget : public QDialog
{
Q_OBJECT
public:
SessionDetailWidget(QWidget *parent);
private:
/*UserInfo userInfo;*/
QPushButton* deleteFriendBtn;
};

122
userinfowidget.cpp Normal file
View File

@ -0,0 +1,122 @@
#include "userinfowidget.h"
UserInfoWidget::UserInfoWidget(const UserInfo& userInfo, QWidget *parent)
:userInfo(userInfo),
QDialog(parent)
{
// 设置基本的属性
this->setFixedSize(400, 200);
this->setWindowTitle("用户详情");
this->setWindowIcon(QIcon(":/resource/image/logo.png"));
this->setAttribute(Qt::WA_DeleteOnClose);
this->move(QCursor::pos());
// 创建布局管理器
QGridLayout* layout = new QGridLayout();
layout->setVerticalSpacing(10);
layout->setHorizontalSpacing(20);
layout->setContentsMargins(50, 20, 0, 0);
layout->setAlignment(Qt::AlignTop);
this->setLayout(layout);
// 添加头像
avatarBtn = new QPushButton();
avatarBtn->setFixedSize(75, 75);
avatarBtn->setIconSize(QSize(75, 75));
avatarBtn->setIcon(userInfo.avatar);
QString labelStyle = "QLabel { font-weight: 800; padding-left: 20px;}";
QString btnStyle = "QPushButton { border: 1px solid rgb(100, 100, 100); border-radius: 5px; background-color: rgb(240, 240, 240); color: rgb(0, 0, 0); }";
btnStyle += "QPushButton:pressed { background-color: rgb(205, 205, 205); }";
int width = 80;
int height = 30;
// 添加用户序号
idTag = new QLabel();
idTag->setText("序号");
idTag->setStyleSheet(labelStyle);
idTag->setFixedSize(width, height);
idTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
idLabel = new QLabel();
idLabel->setText(userInfo.userId);
idLabel->setFixedSize(width, height);
idLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
// 添加用户昵称
nameTag = new QLabel();
nameTag->setText("昵称");
nameTag->setStyleSheet(labelStyle);
nameTag->setFixedSize(width, height);
nameTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
nameLabel = new QLabel();
nameLabel->setText(userInfo.nickname);
nameLabel->setFixedSize(width, height);
nameLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
// 设置电话
phoneTag = new QLabel();
phoneTag->setText("电话");
phoneTag->setStyleSheet(labelStyle);
phoneTag->setFixedSize(width, height);
phoneTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
phoneLabel = new QLabel();
phoneLabel->setText(userInfo.phone);
phoneLabel->setFixedSize(width, height);
phoneLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
// 添加功能按钮
applyBtn = new QPushButton();
applyBtn->setText("申请好友");
applyBtn->setFixedSize(80, 30);
applyBtn->setStyleSheet(btnStyle);
applyBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sendMessageBtn = new QPushButton();
sendMessageBtn->setText("发送消息");
sendMessageBtn->setFixedSize(80, 30);
sendMessageBtn->setStyleSheet(btnStyle);
sendMessageBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
deleteFriendBtn = new QPushButton();
deleteFriendBtn->setText("删除好友");
deleteFriendBtn->setFixedSize(80, 30);
deleteFriendBtn->setStyleSheet(btnStyle);
deleteFriendBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
// 添加上述内容到布局管理器中
layout->addWidget(avatarBtn, 0, 0, 3, 1);
layout->addWidget(idTag, 0, 1);
layout->addWidget(idLabel, 0, 2);
layout->addWidget(nameTag, 1, 1);
layout->addWidget(nameLabel, 1, 2);
layout->addWidget(phoneTag, 2, 1);
layout->addWidget(phoneLabel, 2, 2);
layout->addWidget(applyBtn, 3, 0);
layout->addWidget(sendMessageBtn, 3, 1);
layout->addWidget(deleteFriendBtn, 3, 2);
// 9. 初始化按钮的禁用关系
// 判定依据就是拿着当前用户的 userId, 在 DataCenter 的好友列表中, 查询即可.
//DataCenter* dataCenter = DataCenter::getInstance();
//auto* myFriend = dataCenter->findFriendById(this->userInfo.userId);
//if (myFriend == nullptr) {
// // 不是好友
// sendMessageBtn->setEnabled(false);
// deleteFriendBtn->setEnabled(false);
//}
//else {
// // 是好友
// applyBtn->setEnabled(false);
//}
}

41
userinfowidget.h Normal file
View File

@ -0,0 +1,41 @@
#pragma once
#include <QDialog>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QGridLayout>
#include <QMessageBox>
#include "mainwidget.h"
#include "model/data.h"
//using model::Message;
using namespace model;
class UserInfoWidget : public QDialog
{
Q_OBJECT
public:
UserInfoWidget(const UserInfo& userInfo, QWidget *parent);
private:
////保存对应的Message对象暂时先放在这里
//Message message;
const UserInfo& userInfo;
QPushButton* avatarBtn;
QLabel* idTag;
QLabel* idLabel;
QLabel* nameTag;
QLabel* nameLabel;
QLabel* phoneTag;
QLabel* phoneLabel;
QPushButton* applyBtn;
QPushButton* sendMessageBtn;
QPushButton* deleteFriendBtn;
};