mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
refactor: 大规模调整项目目录结构,将ChatClient和ChatServer整合为Monorepo结构,并分为两个独立文件夹:chatclient/ 和 chatserver/。更新了ChatClient的CMakeLists.txt配置以适配新结构。
This commit is contained in:
141
ChatClient/include/sessionfriendarea.h
Normal file
141
ChatClient/include/sessionfriendarea.h
Normal file
@ -0,0 +1,141 @@
|
||||
#ifndef SESSIONFRIENDAREA_H
|
||||
#define SESSIONFRIENDAREA_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QScrollArea>
|
||||
#include <QScrollBar>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QIcon>
|
||||
#include <QString>
|
||||
// #include <iostream>
|
||||
#include <QStyleOption>
|
||||
#include <QPainter>
|
||||
#include <QEnterEvent>
|
||||
#include "model/data.h"
|
||||
#include <QLabel>
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 滚动区域的Item的类型
|
||||
////////////////////////////////////////
|
||||
enum ItemType{
|
||||
SessionItemType,
|
||||
FriendItemType,
|
||||
ApplyItemType
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 整个滚动区域的实现
|
||||
////////////////////////////////////////
|
||||
class SessionFriendArea : public QScrollArea
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SessionFriendArea(QWidget *parent = nullptr);
|
||||
|
||||
//清空区域内所有的Item
|
||||
void clear();
|
||||
|
||||
//添加一个Item
|
||||
void addItem(ItemType itemType, const QString& id, const QIcon& avatar, const QString& name, const QString& text);
|
||||
|
||||
//选中某一个指定的item,通过index下标来访问item
|
||||
void clickItem(int index);
|
||||
|
||||
private:
|
||||
//后续向container中的layout添加元素,就会有QScrollArea的滚动
|
||||
QWidget* container;
|
||||
|
||||
signals:
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 滚动区域的Item的实现
|
||||
////////////////////////////////////////
|
||||
|
||||
class SessionFriendItem : public QWidget {
|
||||
//可以使当前的类使用信号与槽相关的操作
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SessionFriendItem(QWidget* owner, const QIcon& avatar, const QString& name, const QString& text);
|
||||
|
||||
//通过显式绘制控件的基础样式,解决了自定义控件因未正确处理Qt样式表机制导致的QSS不生效问题
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void enterEvent(QEnterEvent* event) override;
|
||||
void leaveEvent(QEvent* event) override;
|
||||
|
||||
void select();
|
||||
|
||||
//Active实现Item被点击后的业务逻辑
|
||||
virtual void active();
|
||||
|
||||
private:
|
||||
//owner 就是指向了 SessionFriendArea
|
||||
QWidget* owner;
|
||||
|
||||
//表示当前的Item是否是选中的状态(选中时其背景色会有所不同)
|
||||
bool selected = false;
|
||||
|
||||
protected:
|
||||
QLabel* messageLabel;
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 会话Item的实现
|
||||
////////////////////////////////////////
|
||||
class SessionItem : public SessionFriendItem {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SessionItem(QWidget* owner, const QString& chatSessionId, const QIcon& avatar,
|
||||
const QString& name, const QString& lastmessage);
|
||||
|
||||
void active() override;
|
||||
|
||||
void updateLastMessage(const QString& chatSessionId);
|
||||
private:
|
||||
//当前会话Id
|
||||
QString chatSessionId;
|
||||
|
||||
//最后一条消息的文本预览
|
||||
QString text;
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 好友Item的实现
|
||||
////////////////////////////////////////
|
||||
class FriendItem : public SessionFriendItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FriendItem(QWidget* owner, const QString& userId, const QIcon& avatar, const QString& name, const QString& description);
|
||||
void active() override;
|
||||
private:
|
||||
// 好友的用户Id
|
||||
QString userId;
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 好友申请Item的实现
|
||||
////////////////////////////////////////
|
||||
class ApplyItem : public SessionFriendItem {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ApplyItem(QWidget* owner, const QString& userId, const QIcon& avatar, const QString& name);
|
||||
void acceptFriendApply();
|
||||
void rejectFriendApply();
|
||||
|
||||
void active() override;
|
||||
private:
|
||||
//好友申请Id
|
||||
QString userId;
|
||||
};
|
||||
|
||||
#endif // SESSIONFRIENDAREA_H
|
||||
Reference in New Issue
Block a user