Skip to content

Commit

Permalink
Merge pull request #85 from NekoSilverFox/MengJianing
Browse files Browse the repository at this point in the history
Implement font style change function
  • Loading branch information
nekosilverfox authored Dec 8, 2022
2 parents c2feb15 + 343be63 commit d4e21bc
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
7 changes: 7 additions & 0 deletions PolyChatApp/loginwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="btnInfo">
<property name="text">
<string>🍖</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
Expand Down
51 changes: 49 additions & 2 deletions PolyChatApp/uil_chatboxwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "dal_polychat.h"
#include <QDataStream>
#include <QDateTime>
#include <QColorDialog>

ChatBoxWidget::ChatBoxWidget(QWidget* parent, QString name, qint16 port)
: QWidget(parent)
Expand Down Expand Up @@ -43,6 +44,49 @@ ChatBoxWidget::ChatBoxWidget(QWidget* parent, QString name, qint16 port)
/* 点击退出按钮,关闭窗口 */
connect(ui->btnExit, &QPushButton::clicked,
this, [=](){this->close();});

//////////////////////////////////////////////// 辅助功能 ////////////////////////////////////////////////
/* 字体 */
connect(ui->cbxFontType, &QFontComboBox::currentFontChanged,
[=](const QFont& font){
ui->msgTextEdit->setCurrentFont(font);
ui->msgTextEdit->setFocus();
});

/* 字号 */
void(QComboBox::* cbxSingal)(const QString &text) = &QComboBox::currentTextChanged;
connect(ui->cbxFontSize, cbxSingal,
[=](const QString &text){
ui->msgTextEdit->setFontPointSize(text.toDouble());
ui->msgTextEdit->setFocus();
});

/* 加粗 */
connect(ui->btnBold, &QToolButton::clicked,
[=](bool isCheck){
if (isCheck) ui->msgTextEdit->setFontWeight(QFont::Bold);
else ui->msgTextEdit->setFontWeight(QFont::Normal);
});

/* 倾斜 */
connect(ui->btnItalic, &QToolButton::clicked,
[=](bool isCheck){
ui->msgTextEdit->setFontItalic(isCheck);
});


/* 下划线 */
connect(ui->btnUnderLine, &QToolButton::clicked,
[=](bool isCheck){
ui->msgTextEdit->setFontUnderline(isCheck);
});

/* 更改颜色 */
connect(ui->btnColor, &QToolButton::clicked,
[=](){
QColor color = QColorDialog::getColor(Qt::black);
ui->msgTextEdit->setTextColor(color);
});
}

ChatBoxWidget::~ChatBoxWidget()
Expand Down Expand Up @@ -244,12 +288,15 @@ QString ChatBoxWidget::getAndCleanMsg()
void ChatBoxWidget::closeEvent(QCloseEvent* event)
{
emit this->signalClose();
sendUDPSignal(SignalType::UserLeft);

if (1 == ui->tbUser->rowCount())
{
sendUDPSignal(SignalType::ChatDestory);
} // TODO
}
else
{
sendUDPSignal(SignalType::UserLeft);
}

udpSocketOnPortChatList->close(); // 关闭套接字
udpSocketOnPortChatList->destroyed();
Expand Down
11 changes: 11 additions & 0 deletions PolyChatApp/uil_loginwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ LoginWidget::LoginWidget(QWidget *parent) :
connect(ui->btnLogin, &QPushButton::clicked,
this, &LoginWidget::userLogin);

connect(ui->btnInfo, &QPushButton::clicked,
this, [=](){
QMessageBox::information(this, "About Polychat",
"Project SPbSTU<br><br>"
"Source Code:<br>"
"<a href=\"https://github.com/NekoSilverFox/PolyChat\">[Github] PolyChat</a>"
"<br><br>"
"License: Apache License 2.0"
"<br><br>"
"Made on Qt 6.2");
});
}


Expand Down

0 comments on commit d4e21bc

Please sign in to comment.