|
3 | 3 | #include "dal_polychat.h" |
4 | 4 | #include <QDataStream> |
5 | 5 | #include <QDateTime> |
| 6 | +#include <QColorDialog> |
6 | 7 |
|
7 | 8 | ChatBoxWidget::ChatBoxWidget(QWidget* parent, QString name, qint16 port) |
8 | 9 | : QWidget(parent) |
@@ -43,6 +44,49 @@ ChatBoxWidget::ChatBoxWidget(QWidget* parent, QString name, qint16 port) |
43 | 44 | /* 点击退出按钮,关闭窗口 */ |
44 | 45 | connect(ui->btnExit, &QPushButton::clicked, |
45 | 46 | this, [=](){this->close();}); |
| 47 | + |
| 48 | + //////////////////////////////////////////////// 辅助功能 //////////////////////////////////////////////// |
| 49 | + /* 字体 */ |
| 50 | + connect(ui->cbxFontType, &QFontComboBox::currentFontChanged, |
| 51 | + [=](const QFont& font){ |
| 52 | + ui->msgTextEdit->setCurrentFont(font); |
| 53 | + ui->msgTextEdit->setFocus(); |
| 54 | + }); |
| 55 | + |
| 56 | + /* 字号 */ |
| 57 | + void(QComboBox::* cbxSingal)(const QString &text) = &QComboBox::currentTextChanged; |
| 58 | + connect(ui->cbxFontSize, cbxSingal, |
| 59 | + [=](const QString &text){ |
| 60 | + ui->msgTextEdit->setFontPointSize(text.toDouble()); |
| 61 | + ui->msgTextEdit->setFocus(); |
| 62 | + }); |
| 63 | + |
| 64 | + /* 加粗 */ |
| 65 | + connect(ui->btnBold, &QToolButton::clicked, |
| 66 | + [=](bool isCheck){ |
| 67 | + if (isCheck) ui->msgTextEdit->setFontWeight(QFont::Bold); |
| 68 | + else ui->msgTextEdit->setFontWeight(QFont::Normal); |
| 69 | + }); |
| 70 | + |
| 71 | + /* 倾斜 */ |
| 72 | + connect(ui->btnItalic, &QToolButton::clicked, |
| 73 | + [=](bool isCheck){ |
| 74 | + ui->msgTextEdit->setFontItalic(isCheck); |
| 75 | + }); |
| 76 | + |
| 77 | + |
| 78 | + /* 下划线 */ |
| 79 | + connect(ui->btnUnderLine, &QToolButton::clicked, |
| 80 | + [=](bool isCheck){ |
| 81 | + ui->msgTextEdit->setFontUnderline(isCheck); |
| 82 | + }); |
| 83 | + |
| 84 | + /* 更改颜色 */ |
| 85 | + connect(ui->btnColor, &QToolButton::clicked, |
| 86 | + [=](){ |
| 87 | + QColor color = QColorDialog::getColor(Qt::black); |
| 88 | + ui->msgTextEdit->setTextColor(color); |
| 89 | + }); |
46 | 90 | } |
47 | 91 |
|
48 | 92 | ChatBoxWidget::~ChatBoxWidget() |
@@ -244,12 +288,15 @@ QString ChatBoxWidget::getAndCleanMsg() |
244 | 288 | void ChatBoxWidget::closeEvent(QCloseEvent* event) |
245 | 289 | { |
246 | 290 | emit this->signalClose(); |
247 | | - sendUDPSignal(SignalType::UserLeft); |
248 | 291 |
|
249 | 292 | if (1 == ui->tbUser->rowCount()) |
250 | 293 | { |
251 | 294 | sendUDPSignal(SignalType::ChatDestory); |
252 | | - } // TODO |
| 295 | + } |
| 296 | + else |
| 297 | + { |
| 298 | + sendUDPSignal(SignalType::UserLeft); |
| 299 | + } |
253 | 300 |
|
254 | 301 | udpSocketOnPortChatList->close(); // 关闭套接字 |
255 | 302 | udpSocketOnPortChatList->destroyed(); |
|
0 commit comments