ソースを参照

修改 控件

zhuizhu 9 ヶ月 前
コミット
06326c6719

+ 2 - 2
AvRecorder/ui/audio_widget.cpp

@@ -33,7 +33,7 @@ void AudioWidget::_CreateUi()
 
 void AudioWidget::_CreateConnect()
 {
-    connect(_mutebox, &QCheckBox::stateChanged, [this](int) {
+    connect(_mutebox, &QCheckBox::stateChanged, this, [this](int) {
         if (_mutebox->isChecked()) {
             emit SetVolumeScale(0);
             _volumeBox->setEnabled(false);
@@ -43,7 +43,7 @@ void AudioWidget::_CreateConnect()
         }
     });
 
-    connect(_volumeBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [this] {
+    connect(_volumeBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, [this] {
         emit SetVolumeScale(_volumeBox->value());
     });
 }

+ 29 - 52
AvRecorder/ui/av_recorder.cpp

@@ -18,8 +18,6 @@ AvRecorder::AvRecorder(QWidget* parent)
 
     m_glWidget = new OpenGLVideoWidget(this);
 
-    WgcCapturer::Init();
-
     auto layout = new QVBoxLayout;
     auto hLayout = new QHBoxLayout;
 
@@ -28,7 +26,6 @@ AvRecorder::AvRecorder(QWidget* parent)
     hLayout->addLayout(initOtherUi(), 1);
 
     initStatusBarUi();
-    updateCaptureList();
 
     initConnect();
 
@@ -36,6 +33,9 @@ AvRecorder::AvRecorder(QWidget* parent)
     layout->addLayout(hLayout, 1);
     layout->addWidget(m_statusBar, 0);
     setLayout(layout);
+
+    // 初始化数据信息
+    updateCaptureList();
 }
 
 void AvRecorder::setSettings(const SettingsPage::Param& param)
@@ -50,7 +50,7 @@ void AvRecorder::setSettings(const SettingsPage::Param& param)
 }
 void AvRecorder::initConnect()
 {
-    connect(m_recordBtn, &QPushButton::released, [this] {
+    connect(m_recordBtn, &QPushButton::released, this, [this] {
         if (!m_isRecord) {
             auto fileName = m_settingsParam.outputDir;
             if (fileName.back() != '\\') {
@@ -70,7 +70,7 @@ void AvRecorder::initConnect()
         }
         m_isRecord = !m_isRecord;
     });
-    connect(m_liveBtn, &QPushButton::released, [this] {
+    connect(m_liveBtn, &QPushButton::released, this, [this] {
         if (!m_isLive) {
             auto fileName = m_settingsParam.liveUrl + "/" + m_settingsParam.liveName;
             bool isRtsp = m_settingsParam.liveUrl.find("rtsp") != std::string::npos;
@@ -94,14 +94,14 @@ void AvRecorder::initConnect()
         }
         m_isLive = !m_isLive;
     });
-    connect(m_microphoneWidget, &AudioWidget::SetVolumeScale, [this](float scale) {
+    connect(m_microphoneWidget, &AudioWidget::SetVolumeScale, this, [this](float scale) {
         m_audioRecorder.SetVolumeScale(scale, MICROPHONE_INDEX);
     });
-    connect(m_speakerWidget, &AudioWidget::SetVolumeScale, [this](float scale) {
+    connect(m_speakerWidget, &AudioWidget::SetVolumeScale, this, [this](float scale) {
         m_audioRecorder.SetVolumeScale(scale, SPEAKER_INDEX);
     });
-    connect(m_updateListBtn, &QPushButton::released, [this] { updateCaptureList(); });
-    connect(m_captureListWidget, &QListWidget::currentTextChanged, [this](const QString& text) {
+    connect(m_updateListBtn, &QPushButton::released, this, [this] { updateCaptureList(); });
+    connect(m_captureComboBox, &QComboBox::currentTextChanged, this, [this](const QString& text) {
         if (text.isEmpty() || m_isLocked) {
             return;
         }
@@ -112,10 +112,10 @@ void AvRecorder::initConnect()
         startPreview();
         m_isLocked = false;
     });
-    connect(m_isDrawCursorBox, &QCheckBox::stateChanged, [this] {
+    connect(m_isDrawCursorBox, &QCheckBox::stateChanged, this, [this] {
         m_videoRecorder.SetIsDrawCursor(m_isDrawCursorBox->isChecked());
     });
-    connect(m_captureMethodBox, &QComboBox::currentTextChanged, [this](const QString& text) {
+    connect(m_captureMethodBox, &QComboBox::currentTextChanged, this, [this](const QString& text) {
         if (m_isLocked || text.isEmpty()) {
             return;
         }
@@ -130,7 +130,7 @@ void AvRecorder::initConnect()
         }
         startPreview();
     });
-    connect(m_settingsBtn, &QPushButton::released, [this] {
+    connect(m_settingsBtn, &QPushButton::released, this, [this] {
         auto settingsPage = std::make_unique<SettingsPage>(&m_settingsParam, this);
         settingsPage->exec();
         m_isLocked = true;
@@ -184,7 +184,7 @@ AvRecorder::~AvRecorder()
 bool AvRecorder::start()
 {
     auto timer = new QTimer(this);
-    connect(timer, &QTimer::timeout, [this, timer] {
+    connect(timer, &QTimer::timeout, this, [this, timer] {
         m_isLocked = true;
         stopPreview();
         stopCapture();
@@ -203,43 +203,27 @@ void AvRecorder::startCapture(VideoCapturer::Method method)
         m_captureMethodBox->clear();
         m_captureMethodBox->addItem("WGC");
     }
-    QListWidgetItem* item = m_captureListWidget->currentItem();
-    if (!item) {
-        return;
-    }
-
-    const QString type = item->data(Qt::UserRole + 1).toString();
-
-    // 判断是要捕获屏幕还是窗口
-    int idx = m_captureListWidget->currentRow();
+    int idx = m_captureComboBox->currentIndex();
     if (idx < 0) {
-        idx = 0;
-        m_captureListWidget->setCurrentRow(idx);
+        return;
     }
-
-    int monitorCnt = (int) MonitorFinder::GetList().size();
+    int monitorCnt = (int)MonitorFinder::GetList().size();
+    QString type = (idx < monitorCnt) ? "monitor" : "window";
+    qintptr ptrHwnd = m_captureComboBox->currentData().value<qintptr>();
     if (idx < monitorCnt) { // 捕获屏幕
         if (m_captureMethodBox->count() < 2) {
             m_captureMethodBox->addItem("DXGI");
         }
-
         m_videoRecorder.Open(idx, m_settingsParam.videoParam, method);
-
     } else {
         if (m_captureMethodBox->count() < 2) {
             m_captureMethodBox->addItem("GDI");
         }
-
         if (type == "window") {
-            qintptr ptrHwnd = item->data(Qt::UserRole + 2).value<qintptr>();
-            if (::IsWindow((HWND) ptrHwnd)) {
-                m_videoRecorder.Open((HWND) ptrHwnd, m_settingsParam.videoParam, method);
+            if (::IsWindow((HWND)ptrHwnd)) {
+                m_videoRecorder.Open((HWND)ptrHwnd, m_settingsParam.videoParam, method);
             }
         }
-
-        // auto hwnd = WindowFinder::GetList()[idx - monitorCnt].hwnd;
-
-        // m_videoRecorder.Open(hwnd, m_settingsParam.videoParam, method);
     }
     dealCapture();
     m_isDrawCursorBox->setEnabled(true);
@@ -302,7 +286,7 @@ bool AvRecorder::startStream(std::string_view path, std::string_view format)
     m_recordTime = QTime::currentTime();
     m_captureStatusLabel->setText("状态: 正在工作");
     m_settingsBtn->setEnabled(false);
-    m_captureListWidget->setEnabled(false);
+    m_captureComboBox->setEnabled(false);
     m_updateListBtn->setEnabled(false);
     m_captureMethodBox->setEnabled(false);
     return true;
@@ -322,7 +306,7 @@ void AvRecorder::stopStream()
 
     m_captureStatusLabel->setText("状态: 正常");
     m_settingsBtn->setEnabled(true);
-    m_captureListWidget->setEnabled(true);
+    m_captureComboBox->setEnabled(true);
     m_updateListBtn->setEnabled(true);
     m_captureMethodBox->setEnabled(true);
 }
@@ -353,31 +337,24 @@ void AvRecorder::stopSyncRecord()
 }
 void AvRecorder::updateCaptureList()
 {
-    m_captureListWidget->clear();
+    m_captureComboBox->clear();
     auto&& monitorList = MonitorFinder::GetList(true);
     for (auto&& monitor : monitorList) {
-        QListWidgetItem* item = new QListWidgetItem("屏幕: "
-                                                    + QString::fromStdWString(monitor.title));
-
-        item->setData(Qt::UserRole + 1, "monitor");
-        item->setData(Qt::UserRole + 2, qintptr(monitor.monitor));
-        m_captureListWidget->addItem(item);
+        QString text = "屏幕: " + QString::fromStdWString(monitor.title);
+        m_captureComboBox->addItem(text, QVariant::fromValue(qintptr(monitor.monitor)));
     }
     auto&& windowList = WindowFinder::GetList(true);
     for (auto&& window : windowList) {
-        QListWidgetItem* item = new QListWidgetItem("窗口: "
-                                                    + QString::fromStdWString(window.title));
-        item->setData(Qt::UserRole + 1, "window");
-        item->setData(Qt::UserRole + 2, qintptr(window.hwnd));
-        m_captureListWidget->addItem(item);
+        QString text = "窗口: " + QString::fromStdWString(window.title);
+        m_captureComboBox->addItem(text, QVariant::fromValue(qintptr(window.hwnd)));
     }
 }
 
 QVBoxLayout* AvRecorder::initListUi()
 {
     auto layout = new QVBoxLayout;
-    m_captureListWidget = new QListWidget;
-    layout->addWidget(m_captureListWidget);
+    m_captureComboBox = new QComboBox;
+    layout->addWidget(m_captureComboBox);
     return layout;
 }
 

+ 23 - 18
AvRecorder/ui/av_recorder.h

@@ -2,13 +2,13 @@
 
 #include <QCheckBox>
 #include <QLayout>
-#include <QListWidget>
 #include <QPushButton>
 #include <QTime>
 #include <QTimer>
 #include <QWidget>
 
 #include "audio_widget.h"
+#include "qcombobox.h"
 #include "qstatusbar.h"
 #include "recorder/audio_recorder.h"
 #include "recorder/video_recorder.h"
@@ -28,6 +28,25 @@ public:
 
     void setSettings(const SettingsPage::Param& param);
 
+private:
+    SettingsPage::Param m_settingsParam;
+    QVBoxLayout* initListUi();
+    QVBoxLayout* initAudioUi();
+    QVBoxLayout* initOtherUi();
+
+    void initStatusBarUi();
+    void updateCaptureList();
+    void startCapture(VideoCapturer::Method method);
+    void stopCapture();
+    void startPreview();
+    void dealCapture();
+    void stopPreview();
+    bool startStream(std::string_view path, std::string_view format);
+    void stopStream();
+    bool startSyncRecord(); // 开始同步录像
+    void stopSyncRecord();  // 停止同步录像
+    void initConnect();
+
 private:
     AudioRecorder m_audioRecorder;
     VideoRecorder m_videoRecorder;
@@ -44,7 +63,8 @@ private:
     QCheckBox* m_syncRecordBox = nullptr; // 添加同步录像的复选框
     Timer m_videoRenderTimer;
     QTimer m_otherTimer;
-    QListWidget* m_captureListWidget = nullptr;
+    QComboBox* m_captureComboBox = nullptr;
+
     QPushButton* m_updateListBtn = nullptr;
     bool m_isRecord = false;
     bool m_isLive = false;
@@ -55,23 +75,8 @@ private:
     QLabel* m_fpsLabel = nullptr;
     QLabel* m_videoEncodeLabel = nullptr;
     QLabel* m_videolossRate = nullptr;
-    SettingsPage::Param m_settingsParam;
-    QVBoxLayout* initListUi();
-    QVBoxLayout* initAudioUi();
-    QVBoxLayout* initOtherUi();
+
     QTime m_recordTime;
     bool m_isLocked = false;
     QStatusBar* m_statusBar = nullptr;
-    void initStatusBarUi();
-    void updateCaptureList();
-    void startCapture(VideoCapturer::Method method);
-    void stopCapture();
-    void startPreview();
-    void dealCapture();
-    void stopPreview();
-    bool startStream(std::string_view path, std::string_view format);
-    void stopStream();
-    bool startSyncRecord(); // 开始同步录像
-    void stopSyncRecord();  // 停止同步录像
-    void initConnect();
 };

+ 10 - 0
appevent.cpp

@@ -57,6 +57,7 @@ public:
 
     QStringList roles;
     QString userId;
+    QString userName;
 };
 
 AppEvent::AppEvent(QObject *parent)
@@ -245,6 +246,15 @@ QString AppEvent::userId() const
     return d->userId;
 }
 
+void AppEvent::setUserName(const QString &name)
+{
+    d->userName = name;
+}
+QString AppEvent::userName() const
+{
+    return d->userName;
+}
+
 void AppEvent::setRoles(const QStringList &roles)
 {
     d->roles = roles;

+ 3 - 0
appevent.h

@@ -46,6 +46,9 @@ public:
     void setUserId(const QString &id);
     QString userId() const;
 
+    void setUserName(const QString &id);
+    QString userName() const;
+
     void setRoles(const QStringList &roles);
     QStringList roles() const;
     bool hasRole(const QString &role);

+ 5 - 0
main.cpp

@@ -15,6 +15,8 @@
 #include <QDateTime>
 #include <QMutex>
 
+#include <AvRecorder/capturer/video/wgc_capturer.h>
+
 QFile g_logFile;
 QTextStream* g_logStream = nullptr;
 QMutex g_logMutex;
@@ -68,6 +70,9 @@ int main(int argc, char* argv[])
     void initRoomType();
     initRoomType();
 
+    // 初始化wgc
+    WgcCapturer::Init();
+
     /*
 docker run -itd  --name zlmediakit --restart=always
 -p 1935:1935 -p 8080:80 -p 8443:443

+ 1 - 0
mainwindow.cpp

@@ -306,6 +306,7 @@ void MainWindow::authLogin()
             qDebug() << "当前ID:" << user.id;
             AppEvent::instance()->setRoles(user.roleName);
             AppEvent::instance()->setUserId(user.id);
+            AppEvent::instance()->setUserName(user.username);
             createMainWindow();
 
             checkRoom();

+ 2 - 0
network/websocketclient.cpp

@@ -143,6 +143,7 @@ void WebSocketClient::onTextMessageReceived(const QString& message)
     if (doc.isObject()) {
         QJsonObject obj = doc.object();
 
+        qDebug() << "----------------------------->" << obj;
         // 处理心跳响应
         if (obj.contains("type") && obj["type"].toString() == "pong") {
             return;
@@ -164,6 +165,7 @@ void WebSocketClient::onTextMessageReceived(const QString& message)
 
         // 设置消息内容
         chatMessage.text = content;
+        chatMessage.senderName = obj["fromUserName"].toString();
 
         // 设置时间(如果服务器提供)
         if (obj.contains("time") && !obj["time"].toString().isEmpty()) {

+ 45 - 14
widgets/chatView/chat1/chatmessagedelegate.cpp

@@ -93,6 +93,13 @@ void ChatMessageDelegate::paint(QPainter *painter,
         return;
     }
 
+    // 计算名字高度
+    QFont nameFont = option.font;
+    nameFont.setPointSize(std::max(option.font.pointSize() - 2, 8));
+    QFontMetrics nameFm(nameFont);
+    int nameHeight = message.senderName.isEmpty() ? 0 : nameFm.height();
+    int nameSpacing = message.senderName.isEmpty() ? 0 : 2;
+
     // 计算各个元素的位置
     QSize textSize = calculateTextSize(option.fontMetrics, message.text);
 
@@ -100,13 +107,13 @@ void ChatMessageDelegate::paint(QPainter *painter,
     QRectF avatarRect;
     if (message.type == MessageType::Left) {
         avatarRect = QRectF(option.rect.left() + ChatConstants::BUBBLE_SPACING,
-                            option.rect.top(),
+                            option.rect.top() + nameHeight + nameSpacing,
                             ChatConstants::AVATAR_SIZE,
                             ChatConstants::AVATAR_SIZE);
     } else {
         avatarRect = QRectF(option.rect.right() - ChatConstants::AVATAR_SIZE
                                 - ChatConstants::BUBBLE_SPACING,
-                            option.rect.top(),
+                            option.rect.top() + nameHeight + nameSpacing,
                             ChatConstants::AVATAR_SIZE,
                             ChatConstants::AVATAR_SIZE);
     }
@@ -115,18 +122,43 @@ void ChatMessageDelegate::paint(QPainter *painter,
     QRectF bubbleRect;
     if (message.type == MessageType::Left) {
         bubbleRect = QRectF(avatarRect.right() + ChatConstants::BUBBLE_SPACING,
-                            option.rect.top(),
+                            option.rect.top() + nameHeight + nameSpacing,
                             textSize.width() + 2 * ChatConstants::BUBBLE_PADDING,
                             textSize.height() + 2 * ChatConstants::BUBBLE_PADDING);
     } else {
         bubbleRect = QRectF(option.rect.right() - textSize.width()
                                 - 2 * ChatConstants::BUBBLE_PADDING - ChatConstants::AVATAR_SIZE
                                 - 2 * ChatConstants::BUBBLE_SPACING,
-                            option.rect.top(),
+                            option.rect.top() + nameHeight + nameSpacing,
                             textSize.width() + 2 * ChatConstants::BUBBLE_PADDING,
                             textSize.height() + 2 * ChatConstants::BUBBLE_PADDING);
     }
 
+    // 绘制名字
+    if (!message.senderName.isEmpty()) {
+        painter->save();
+        painter->setFont(nameFont);
+        painter->setPen(QColor(120, 120, 120));
+        int nameX, nameWidth;
+        QRect nameRect;
+        if (message.type == MessageType::Left) {
+            // 左侧消息,名字左对齐,紧贴头像右侧
+            nameX = avatarRect.right() + ChatConstants::BUBBLE_SPACING;
+            nameWidth = bubbleRect.width();
+            nameRect = QRect(nameX, option.rect.top(), nameWidth, nameHeight);
+            painter->drawText(nameRect, Qt::AlignLeft | Qt::AlignVCenter, message.senderName);
+        } else {
+            // 右侧消息,名字右对齐,紧贴头像左侧
+            nameWidth = nameFm.horizontalAdvance(message.senderName);
+            // 名字宽度不超过气泡宽度
+            nameWidth = std::min(nameWidth, static_cast<int>(bubbleRect.width()));
+            nameX = bubbleRect.right() - nameWidth;
+            nameRect = QRect(nameX, option.rect.top(), nameWidth, nameHeight);
+            painter->drawText(nameRect, Qt::AlignRight | Qt::AlignVCenter, message.senderName);
+        }
+        painter->restore();
+    }
+
     // 绘制气泡
     drawBubble(painter, bubbleRect, message.type == MessageType::Left);
 
@@ -143,15 +175,6 @@ void ChatMessageDelegate::paint(QPainter *painter,
     // 检查是否是当前选中的消息
     bool isCurrentMessage = (index == m_currentMessageIndex);
     drawTextWithSelection(painter, textRect, message.text, option.fontMetrics, isCurrentMessage);
-
-    // // 绘制时间戳
-    // QRectF timestampRect(bubbleRect.left(),
-    //                      bubbleRect.bottom(),
-    //                      bubbleRect.width(),
-    //                      ChatConstants::TIMESTAMP_HEIGHT);
-    // painter->setPen(ThemeManager::instance().color("colorTextSecondary"));
-    // painter->setFont(QFont(option.font.family(), option.font.pointSize() - 2));
-    // painter->drawText(timestampRect, Qt::AlignCenter, message.timestamp.toString("HH:mm"));
 }
 
 QSize ChatMessageDelegate::sizeHint(const QStyleOptionViewItem &option,
@@ -168,11 +191,19 @@ QSize ChatMessageDelegate::sizeHint(const QStyleOptionViewItem &option,
         return QSize(width, height);
     }
 
+    // 计算名字高度
+    QFont nameFont = option.font;
+    nameFont.setPointSize(std::max(option.font.pointSize() - 2, 8));
+    QFontMetrics nameFm(nameFont);
+    int nameHeight = message.senderName.isEmpty() ? 0 : nameFm.height();
+    int nameSpacing = message.senderName.isEmpty() ? 0 : 2;
+
     int width = textSize.width() + 2 * ChatConstants::BUBBLE_PADDING + ChatConstants::AVATAR_SIZE
                 + 2 * ChatConstants::BUBBLE_SPACING;
     int height = qMax(textSize.height() + 2 * ChatConstants::BUBBLE_PADDING,
                       ChatConstants::AVATAR_SIZE)
-                 + ChatConstants::TIMESTAMP_HEIGHT;
+                 + ChatConstants::TIMESTAMP_HEIGHT
+                 + nameHeight + nameSpacing;
 
     return QSize(qMin(width, viewportWidth()), height + ChatConstants::BUBBLE_SPACING);
 }

+ 8 - 3
widgets/chatView/chat1/chatview.cpp

@@ -7,6 +7,7 @@
 #include <QClipboard>
 #include <QMouseEvent>
 #include <QTimer>
+#include <utility>
 
 // 在构造函数中添加
 ChatView::ChatView(QWidget *parent)
@@ -253,7 +254,7 @@ void ChatView::keyPressEvent(QKeyEvent *event)
         QStringList selectedTexts;
         QModelIndexList selection = selectionModel()->selectedIndexes();
 
-        for (const QModelIndex &index : selection) {
+        for (const QModelIndex &index : std::as_const(selection)) {
             ChatMessage message = index.data().value<ChatMessage>();
             selectedTexts << message.text;
         }
@@ -267,9 +268,13 @@ void ChatView::keyPressEvent(QKeyEvent *event)
     }
     QListView::keyPressEvent(event);
 }
-void ChatView::addMessage(const QString &text, const QString &avatar, bool isLeft)
+void ChatView::addMessage(const QString &text, const QString &avatar, const QString &senderName, bool isLeft)
 {
-    ChatMessage message(text, isLeft ? MessageType::Left : MessageType::Right);
+    ChatMessage message;
+    message.text = text;
+    message.avatar = avatar;
+    message.senderName = senderName;
+    message.type = isLeft ? MessageType::Left : MessageType::Right;
     m_model->addMessage(message);
     scrollToBottom();
 }

+ 1 - 2
widgets/chatView/chat1/chatview.h

@@ -4,14 +4,13 @@
 #include <QListView>
 #include "chatmessagedelegate.h"
 #include "chatmessagemodel.h"
-#include "network/websocketclient.h"
 
 class ChatView : public QListView
 {
     Q_OBJECT
 public:
     explicit ChatView(QWidget *parent = nullptr);
-    void addMessage(const QString &text, const QString &avatar, bool isLeft);
+    void addMessage(const QString &text, const QString &avatar, const QString &senderName, bool isLeft);
     void addSystemMessage(const QString &text);
     void clear();
 

+ 12 - 12
widgets/chatView/chatwindow.cpp

@@ -46,15 +46,15 @@ ChatWindow::ChatWindow(QWidget *parent)
     connect(fileButton, &QPushButton::clicked, this, &ChatWindow::onFileClicked);
     connect(recallButton, &QPushButton::clicked, this, &ChatWindow::onRecallClicked);
 
-    // 添加一些示例消息
-    m_messageView->addMessage(QDateTime::currentDateTime().toString(), "", true);
-    m_messageView->addMessage("你好,这是一条测试文本消息!", "", true);
-    m_messageView->addMessage(
-        "你好,这是一条测试文本消息!你好,这是一条测试文本消息!你好,这是一条测试文本消息!你好,"
-        "这是一条测试文本消息!你好,这是一条测试文本消息!你好,这是一条测试文本消息!你好,这是一"
-        "条测试文本消息!你好,这是一条测试文本消息!你好,这是一条测试文本消息!",
-        "",
-        true);
+    // // 添加一些示例消息
+    // m_messageView->addMessage(QDateTime::currentDateTime().toString(), "", true);
+    // m_messageView->addMessage("你好,这是一条测试文本消息!", "", true);
+    // m_messageView->addMessage(
+    //     "你好,这是一条测试文本消息!你好,这是一条测试文本消息!你好,这是一条测试文本消息!你好,"
+    //     "这是一条测试文本消息!你好,这是一条测试文本消息!你好,这是一条测试文本消息!你好,这是一"
+    //     "条测试文本消息!你好,这是一条测试文本消息!你好,这是一条测试文本消息!",
+    //     "",
+    //     true);
 
     // initWebsocket();
     // m_messageView->addSuccessMessage("操作成功完成", BubbleMessage::Sent);
@@ -66,9 +66,9 @@ ChatWindow::ChatWindow(QWidget *parent)
             [this](const ChatMessage &message) {
                 qDebug() << message.text;
                 if (message.isLeft()) {
-                    m_messageView->addMessage(message.text, "", true);
+                    m_messageView->addMessage(message.text, "", message.senderName, true);
                 } else if (message.isRight()) {
-                    m_messageView->addMessage(message.text, "", false);
+                    m_messageView->addMessage(message.text, "", message.senderName, false);
                 } else {
                     m_messageView->addSystemMessage(message.text);
                 }
@@ -107,7 +107,7 @@ void ChatWindow::onSendClicked()
 
     m_webSocketClient->sendMessage(text, "room");
 
-    m_messageView->addMessage(text, "", false);
+    m_messageView->addMessage(text, "", AppEvent::instance()->userName(), false);
 
     m_inputEdit->clear();
 }