promote ui

This commit is contained in:
xyz
2025-05-25 19:09:54 +08:00
parent ef7f85e68b
commit 4dcec01d67
9 changed files with 264 additions and 8 deletions

View File

@ -49,7 +49,7 @@ SessionFriendArea::SessionFriendArea(QWidget *parent)
// 把widget创建出来
container = new QWidget();
container->setFixedWidth(310);
container->setMinimumWidth(310);
this->setWidget(container);
//给这个widget添加布局管理器方便后续添加元素进去
@ -68,6 +68,8 @@ SessionFriendArea::SessionFriendArea(QWidget *parent)
// }
//构造一些临时数据作为界面调试的依据
#if TEST_UI
QIcon icon(":/resource/image/defaultAv.png");
for(int i = 0; i < 30; i++) {
@ -81,8 +83,10 @@ SessionFriendItem::SessionFriendItem(QWidget* owner, const QIcon& avatar, const
:owner(owner)
{
this->setFixedHeight(70);
this->setStyleSheet("QWidget { background-color: rgb(231, 231, 231); }");
//创建网格布局管理器
QGridLayout* layout = new QGridLayout();
layout->setContentsMargins(20, 0, 0, 0);
@ -104,21 +108,22 @@ SessionFriendItem::SessionFriendItem(QWidget* owner, const QIcon& avatar, const
//创建名字
QLabel* nameLabel = new QLabel();
nameLabel->setText(name);
nameLabel->setStyleSheet("QLabel { font-size: 18px; fontweight: 600; }");
nameLabel->setStyleSheet("QLabel { font-size: 18px; font-weight: 600; }");
nameLabel->setFixedHeight(35);
nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
//创建消息预览的label
QLabel* messageLabel = new QLabel();
messageLabel->setText(text);
messageLabel->setStyleSheet("QLabel { font-size: 18px; fontweight: 600; }");
messageLabel->setStyleSheet("QLabel { font-size: 18px; font-weight: 600; }");
messageLabel->setFixedHeight(35);
messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
//添加到网格布局
layout->addWidget(avatarBtn, 0, 0, 2, 2);
layout->addWidget(nameLabel, 0, 2, 1, 1);
layout->addWidget(messageLabel, 1, 2, 1, 1);
layout->addWidget(nameLabel, 0, 2, 1, 8);
layout->addWidget(messageLabel, 1, 2, 1, 8);
}
void SessionFriendItem::paintEvent(QPaintEvent *event)
@ -178,6 +183,15 @@ void SessionFriendItem::select()
//点击时修改背景色
this->setStyleSheet("QWidget { background-color: rgb(210, 210, 210); }");
this->selected = true;
//调用Active
this->active();
}
void SessionFriendItem::active()
{
//父类不写
//并不需要实现任何逻辑
}
void SessionFriendArea::clear()
@ -251,6 +265,12 @@ SessionItem::SessionItem(QWidget *owner, const QString &chatSessionId, const QIc
}
void SessionItem::active()
{
//点击之后,要加载会话历史消息的列表
LOG() << "click SessionItem... chatSessionId: " << chatSessionId;
}
////////////////////////////////////////
/// 好友Item的实现
////////////////////////////////////////
@ -261,6 +281,12 @@ FriendItem::FriendItem(QWidget *owner, const QString &userId, const QIcon &avata
}
void FriendItem::active()
{
//点击之后,要激活对应的会话列元素
LOG() << "click FriendItem... userId: " << userId;
}
////////////////////////////////////////
/// 好友申请Item的实现
////////////////////////////////////////
@ -268,5 +294,26 @@ ApplyItem::ApplyItem(QWidget *owner, const QString &userId, const QIcon &avatar,
const QString &name)
:SessionFriendItem(owner, avatar, name, ""), userId(userId)
{
//移除父类的messageLabel
QGridLayout* layout = dynamic_cast<QGridLayout*>(this->layout());
layout->removeWidget(messageLabel);
//要记得释放内存,否则会内存泄露
// delete messageLabel;
//创建两个按钮
QPushButton* acceptBtn = new QPushButton();
acceptBtn->setText("同意");
QPushButton* rejectBtn = new QPushButton();
rejectBtn->setText("拒绝");
//添加到布局管理器中
layout->addWidget(acceptBtn, 1, 2, 1, 1);
layout->addWidget(rejectBtn, 1, 3, 1, 1);
}
void ApplyItem::active()
{
//本就不需要实现任何内容
LOG() << "click ApplyItem... userId: " << userId;
}