independentchatwindow.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "independentchatwindow.h"
  2. #include "chatwindow.h"
  3. #include "widgetframe/windowbar.h"
  4. #include "widgetframe/windowbutton.h"
  5. #include <QVBoxLayout>
  6. #include <QHBoxLayout>
  7. #include <QLabel>
  8. #include <QPushButton>
  9. #include <QApplication>
  10. IndependentChatWindow::IndependentChatWindow(WebSocketClient *webSocketClient, QWidget *parent)
  11. : TWidget(parent)
  12. , m_chatWindow(nullptr)
  13. , m_webSocketClient(webSocketClient)
  14. {
  15. setWindowTitle("聊天窗口");
  16. resize(800, 600);
  17. setupUI();
  18. setupTitleBar();
  19. }
  20. IndependentChatWindow::~IndependentChatWindow()
  21. {
  22. }
  23. void IndependentChatWindow::setupUI()
  24. {
  25. // 创建聊天窗口组件
  26. m_chatWindow = new ChatWindow(m_webSocketClient, this);
  27. // 添加到主布局
  28. mainLayout()->addWidget(m_chatWindow);
  29. }
  30. void IndependentChatWindow::setupTitleBar()
  31. {
  32. // 创建自定义标题栏
  33. auto titleBar = new QWK::WindowBar(this);
  34. titleBar->setObjectName("win-title-bar");
  35. // 创建标题标签
  36. auto titleLabel = new QLabel("聊天窗口", this);
  37. titleLabel->setAlignment(Qt::AlignCenter);
  38. titleLabel->setObjectName("win-title-label");
  39. // 创建窗口控制按钮
  40. auto minButton = new QWK::WindowButton(this);
  41. minButton->setObjectName("min-button");
  42. minButton->setProperty("system-button", true);
  43. auto maxButton = new QWK::WindowButton(this);
  44. maxButton->setCheckable(true);
  45. maxButton->setObjectName("max-button");
  46. maxButton->setProperty("system-button", true);
  47. auto closeButton = new QWK::WindowButton(this);
  48. closeButton->setObjectName("close-button");
  49. closeButton->setProperty("system-button", true);
  50. // 设置标题栏布局
  51. titleBar->setTitleLabel(titleLabel);
  52. titleBar->setMinButton(minButton);
  53. titleBar->setMaxButton(maxButton);
  54. titleBar->setCloseButton(closeButton);
  55. // 连接信号
  56. connect(titleBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
  57. connect(titleBar, &QWK::WindowBar::maximizeRequested, this, [this](bool max) {
  58. if (max) {
  59. showMaximized();
  60. } else {
  61. showNormal();
  62. }
  63. });
  64. connect(titleBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
  65. // 设置为窗口的标题栏
  66. setMenuWidget(titleBar);
  67. }
  68. void IndependentChatWindow::initWebsocket(const QString &roomId)
  69. {
  70. if (m_chatWindow) {
  71. m_chatWindow->initWebsocket(roomId);
  72. }
  73. }