mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-13 16:41:48 +08:00
Compare commits
2 Commits
beda1e32ad
...
51f0b4941f
| Author | SHA1 | Date | |
|---|---|---|---|
| 51f0b4941f | |||
| 38f3a397fd |
14
.gitignore
vendored
14
.gitignore
vendored
@ -2,8 +2,12 @@ build/
|
||||
# 忽略 Qt Creator 的用户配置文件
|
||||
CMakeLists.txt.user
|
||||
*.user
|
||||
|
||||
# 其他常见 IDE 文件(根据实际使用情况添加)
|
||||
.idea/ # CLion
|
||||
.vscode/ # VS Code
|
||||
.vs/ # Visual Studio
|
||||
.idea/
|
||||
.vscode/
|
||||
.vs/
|
||||
*.iml
|
||||
*.suo
|
||||
*.vsidx
|
||||
*.ipch
|
||||
cmake.db
|
||||
slnx.sqlite
|
||||
@ -9,14 +9,31 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
||||
# 查找Qt版本
|
||||
find_package(Qt6 COMPONENTS Widgets QUIET)
|
||||
if(NOT Qt6_FOUND)
|
||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
set(QT_VERSION_MAJOR 5)
|
||||
else()
|
||||
set(QT_VERSION_MAJOR 6)
|
||||
endif()
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
mainwidget.cpp
|
||||
mainwidget.h
|
||||
mainwidget.ui
|
||||
main.cpp
|
||||
mainwidget.cpp
|
||||
mainwidget.h
|
||||
mainwidget.ui
|
||||
model/data.h
|
||||
resource.qrc
|
||||
sessionfriendarea.h
|
||||
sessionfriendarea.cpp
|
||||
debug.h
|
||||
messageshowarea.h
|
||||
messageshowarea.cpp
|
||||
messageeditarea.h
|
||||
messageeditarea.cpp
|
||||
SelfInfoWidget.h
|
||||
SelfInfoWidget.cpp
|
||||
)
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
@ -24,45 +41,17 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
MANUAL_FINALIZATION
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
# set_property(TARGET ClientChat APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||||
else()
|
||||
if(ANDROID)
|
||||
add_library(ClientChat SHARED
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define properties for Android with Qt 5 after find_package() calls as:
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
add_library(ClientChat SHARED ${PROJECT_SOURCES})
|
||||
else()
|
||||
add_executable(ClientChat
|
||||
${PROJECT_SOURCES}
|
||||
model/data.h
|
||||
resource.qrc
|
||||
sessionfriendarea.h sessionfriendarea.cpp
|
||||
debug.h
|
||||
messageshowarea.h messageshowarea.cpp
|
||||
messageeditarea.h messageeditarea.cpp
|
||||
)
|
||||
add_executable(ClientChat ${PROJECT_SOURCES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(ClientChat PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
# explicit, fixed bundle identifier manually though.
|
||||
if(${QT_VERSION} VERSION_LESS 6.1.0)
|
||||
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.ClientChat)
|
||||
endif()
|
||||
set_target_properties(ClientChat PROPERTIES
|
||||
${BUNDLE_ID_OPTION}
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
# Bundle设置(略)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS ClientChat
|
||||
|
||||
22
CMakePresets.json
Normal file
22
CMakePresets.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"hidden": true,
|
||||
"name": "Qt",
|
||||
"cacheVariables": {
|
||||
"CMAKE_PREFIX_PATH": "$env{QTDIR}"
|
||||
},
|
||||
"vendor": {
|
||||
"qt-project.org/Qt": {
|
||||
"checksum": "wVa86FgEkvdCTVp1/nxvrkaemJc="
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"vendor": {
|
||||
"qt-project.org/Presets": {
|
||||
"checksum": "67SmY24ZeVbebyKD0fGfIzb/bGI="
|
||||
}
|
||||
}
|
||||
}
|
||||
76
CMakeUserPresets.json
Normal file
76
CMakeUserPresets.json
Normal file
@ -0,0 +1,76 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "Qt-Debug",
|
||||
"inherits": "Qt-Default",
|
||||
"binaryDir": "${sourceDir}/out/build/debug",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_CXX_FLAGS": "-DQT_QML_DEBUG"
|
||||
},
|
||||
"environment": {
|
||||
"QML_DEBUG_ARGS": "-qmljsdebugger=file:{7e8c2a2f-a445-4c9b-bb42-24fd265a3e1e},block"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Qt-Release",
|
||||
"inherits": "Qt-Default",
|
||||
"binaryDir": "${sourceDir}/out/build/release",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"hidden": true,
|
||||
"name": "Qt-Default",
|
||||
"inherits": "6.9.0",
|
||||
"vendor": {
|
||||
"qt-project.org/Default": {
|
||||
"checksum": "ogzyvXATpX3FyMqBErb6IpyYPKI="
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"hidden": true,
|
||||
"name": "5.14.0",
|
||||
"inherits": "Qt",
|
||||
"environment": {
|
||||
"QTDIR": "E:/Qt/Qt5.14.0/5.14.0/msvc2017_64"
|
||||
},
|
||||
"architecture": {
|
||||
"strategy": "external",
|
||||
"value": "x64"
|
||||
},
|
||||
"generator": "Ninja",
|
||||
"vendor": {
|
||||
"qt-project.org/Version": {
|
||||
"checksum": "3cWOu5Lvdo5oEp6qU2AAXDl3CO8="
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"hidden": true,
|
||||
"name": "6.9.0",
|
||||
"inherits": "Qt",
|
||||
"environment": {
|
||||
"QTDIR": "E:/Qt/Qt6.9.0/6.9.0/msvc2022_64"
|
||||
},
|
||||
"architecture": {
|
||||
"strategy": "external",
|
||||
"value": "x64"
|
||||
},
|
||||
"generator": "Ninja",
|
||||
"vendor": {
|
||||
"qt-project.org/Version": {
|
||||
"checksum": "5GMO6/002JUUngppM/iaIHJADvk="
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"vendor": {
|
||||
"qt-project.org/Presets": {
|
||||
"checksum": "0wzuyL8qCbVtFSbq9ZO9Fr8MNQU="
|
||||
}
|
||||
}
|
||||
}
|
||||
176
SelfInfoWidget.cpp
Normal file
176
SelfInfoWidget.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
#include "SelfInfoWidget.h"
|
||||
|
||||
SelfInfoWidget::SelfInfoWidget(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
//设置整个窗口的属性
|
||||
this->setFixedSize(450, 250);
|
||||
this->setWindowTitle("个人信息");
|
||||
this->setWindowIcon(QIcon(":/resource/image/logo.png"));
|
||||
//窗口被关闭时,自动销毁这个对话框对象
|
||||
this->setAttribute(Qt::WA_DeleteOnClose);
|
||||
//把窗口移动到鼠标当前的位置
|
||||
this->move(QCursor::pos());
|
||||
|
||||
//创建布局管理器
|
||||
QGridLayout* layout = new QGridLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
this->setLayout(layout);
|
||||
|
||||
//创建头像
|
||||
avatarBtn = new QPushButton();
|
||||
avatarBtn->setFixedSize(75, 75);
|
||||
avatarBtn->setIconSize(QSize(75, 75));
|
||||
avatarBtn->setIcon(QIcon(":/resource/image/defaultAvatar.png"));
|
||||
avatarBtn->setStyleSheet("QPushButton { border: none; background-color: transparent; }");
|
||||
|
||||
QString labelStyle = "QLabel { font-size: 14px; font-weight: 800; }";
|
||||
QString btnStyle = "QPushButton {border: none; background-color: transparent; }";
|
||||
btnStyle += "QPushButton:pressed { background-color: rgb(210, 210, 210); }";
|
||||
|
||||
int height = 30;
|
||||
|
||||
//添加用户的ID的显示
|
||||
idTag = new QLabel();
|
||||
idTag->setFixedSize(50, height);
|
||||
idTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
idTag->setText("序号");
|
||||
idTag->setStyleSheet(labelStyle);
|
||||
|
||||
idLabel = new QLabel();
|
||||
idLabel->setFixedHeight(height);
|
||||
idLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
||||
//添加新的用户的名字的显示
|
||||
nameTag = new QLabel();
|
||||
nameTag->setFixedSize(50, height);
|
||||
nameTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
nameTag->setText("昵称");
|
||||
nameTag->setStyleSheet(labelStyle);
|
||||
|
||||
nameLabel = new QLabel();
|
||||
nameLabel->setFixedHeight(height);
|
||||
nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
||||
nameModifyBtn = new QPushButton();
|
||||
nameModifyBtn->setFixedSize(25, 25);
|
||||
nameModifyBtn->setIconSize(QSize(20, 20));
|
||||
nameModifyBtn->setIcon(QIcon(":/resource/image/modify.png"));
|
||||
nameModifyBtn->setStyleSheet(btnStyle);
|
||||
|
||||
nameEdit = new QLineEdit();
|
||||
nameEdit->setFixedHeight(height);
|
||||
nameEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
nameEdit->hide();
|
||||
|
||||
nameSubmitBtn = new QPushButton();
|
||||
nameSubmitBtn->setFixedSize(25, 25);
|
||||
nameSubmitBtn->setIconSize(QSize(20, 20));
|
||||
nameSubmitBtn->setIcon(QIcon(":/resource/image/submit.png"));
|
||||
nameSubmitBtn->setStyleSheet(btnStyle);
|
||||
nameSubmitBtn->hide();
|
||||
|
||||
//添加个性签名
|
||||
descTag = new QLabel();
|
||||
descTag->setFixedSize(50, height);
|
||||
descTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
descTag->setText("签名");
|
||||
descTag->setStyleSheet(labelStyle);
|
||||
|
||||
descLabel = new QLabel();
|
||||
descLabel->setFixedHeight(height);
|
||||
descLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
descModifyBtn = new QPushButton();
|
||||
descModifyBtn->setFixedSize(25, 25);
|
||||
descModifyBtn->setIconSize(QSize(20, 20));
|
||||
descModifyBtn->setIcon(QIcon(":/resource/image/modify.png"));
|
||||
descModifyBtn->setStyleSheet(btnStyle);
|
||||
|
||||
descEdit = new QLineEdit();
|
||||
descEdit->setFixedHeight(height);
|
||||
descEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
descEdit->hide();
|
||||
|
||||
descSubmitBtn = new QPushButton();
|
||||
descSubmitBtn->setFixedSize(25, 25);
|
||||
descSubmitBtn->setIconSize(QSize(20, 20));
|
||||
descSubmitBtn->setIcon(QIcon(":/resource/image/modify.png"));
|
||||
descSubmitBtn->setStyleSheet(btnStyle);
|
||||
descSubmitBtn->hide();
|
||||
|
||||
// 7. 添加电话
|
||||
phoneTag = new QLabel();
|
||||
phoneTag->setFixedSize(50, height);
|
||||
phoneTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
phoneTag->setText("电话");
|
||||
phoneTag->setStyleSheet(labelStyle);
|
||||
|
||||
phoneLabel = new QLabel();
|
||||
phoneLabel->setFixedHeight(height);
|
||||
phoneLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
||||
phoneModifyBtn = new QPushButton();
|
||||
phoneModifyBtn->setFixedSize(25, 25);
|
||||
phoneModifyBtn->setIconSize(QSize(20, 20));
|
||||
phoneModifyBtn->setIcon(QIcon(":/resource/image/modify.png"));
|
||||
phoneModifyBtn->setStyleSheet(btnStyle);
|
||||
|
||||
phoneEdit = new QLineEdit();
|
||||
phoneEdit->setFixedHeight(height);
|
||||
phoneEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
phoneEdit->hide();
|
||||
|
||||
phoneSubmitBtn = new QPushButton();
|
||||
phoneSubmitBtn->setFixedSize(25, 25);
|
||||
phoneSubmitBtn->setIconSize(QSize(20, 20));
|
||||
phoneSubmitBtn->setIcon(QIcon(":/resource/image/submit.png"));
|
||||
phoneSubmitBtn->setStyleSheet(btnStyle);
|
||||
phoneSubmitBtn->hide();
|
||||
|
||||
|
||||
// 8. 添加验证码
|
||||
verifyCodeTag = new QLabel();
|
||||
verifyCodeTag->setFixedSize(50, height);
|
||||
verifyCodeTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
verifyCodeTag->setText("输入验证码:");
|
||||
verifyCodeTag->setStyleSheet(labelStyle);
|
||||
|
||||
verifyCodeEdit = new QLineEdit();
|
||||
verifyCodeEdit->setFixedHeight(height);
|
||||
verifyCodeEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
//verifyCodeEdit->hide();
|
||||
|
||||
getVerifyCodeBtn = new QPushButton();
|
||||
getVerifyCodeBtn->setText("获取验证码");
|
||||
|
||||
|
||||
layout->addWidget(avatarBtn, 0, 0, 3, 1);
|
||||
layout->addWidget(idTag, 0, 1);
|
||||
layout->addWidget(idLabel, 0, 2);
|
||||
|
||||
layout->addWidget(nameTag, 1, 1);
|
||||
layout->addWidget(nameLabel, 1, 2);
|
||||
layout->addWidget(nameModifyBtn, 1, 3);
|
||||
|
||||
layout->addWidget(descTag, 2, 1);
|
||||
layout->addWidget(descLabel, 2, 2);
|
||||
layout->addWidget(descModifyBtn, 2, 3);
|
||||
|
||||
layout->addWidget(phoneTag, 3, 1);
|
||||
layout->addWidget(phoneLabel, 3, 2);
|
||||
layout->addWidget(phoneModifyBtn, 3, 3);
|
||||
|
||||
layout->addWidget(verifyCodeTag, 4, 1);
|
||||
layout->addWidget(verifyCodeEdit, 4, 2);
|
||||
layout->addWidget(getVerifyCodeBtn, 4, 3);
|
||||
|
||||
#if TEST_UI
|
||||
idLabel->setText("12345");
|
||||
nameLabel->setText("xyz");
|
||||
descLabel->setText("It didn't matter that i lived another day.");
|
||||
phoneLabel->setText("12345678900");
|
||||
#endif
|
||||
}
|
||||
46
SelfInfoWidget.h
Normal file
46
SelfInfoWidget.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <qlineedit.h>
|
||||
#include <QCursor>
|
||||
#include <QGridLayout>
|
||||
#include <QPushButton>
|
||||
#include "debug.h"
|
||||
|
||||
class SelfInfoWidget : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SelfInfoWidget(QWidget *parent);
|
||||
//~SelfInfoWidget();
|
||||
|
||||
private:
|
||||
QPushButton* avatarBtn;
|
||||
QLabel* idTag; //序号标签
|
||||
QLabel* idLabel; //序号
|
||||
|
||||
QLabel* nameTag;//昵称标签
|
||||
QLabel* nameLabel;//名字
|
||||
QLineEdit* nameEdit;//编辑昵称
|
||||
QPushButton* nameModifyBtn;//修改昵称
|
||||
QPushButton* nameSubmitBtn;//提交修改
|
||||
|
||||
QLabel* descTag;//签名标签
|
||||
QLabel* descLabel;//签名
|
||||
QLineEdit* descEdit;//编辑签名
|
||||
QPushButton* descModifyBtn;//修改签名
|
||||
QPushButton* descSubmitBtn;//提交修改
|
||||
|
||||
QLabel* phoneTag;//电话标签
|
||||
QLabel* phoneLabel;//电话号码
|
||||
QLineEdit* phoneEdit;//编辑电话
|
||||
QPushButton* phoneModifyBtn;//修改电话
|
||||
QPushButton* phoneSubmitBtn;//提交修改
|
||||
|
||||
QLabel* verifyCodeTag;//显示验证码
|
||||
QLineEdit* verifyCodeEdit;//输入验证码
|
||||
QPushButton* getVerifyCodeBtn;//获取验证码按钮
|
||||
};
|
||||
5
main.cpp
5
main.cpp
@ -1,5 +1,6 @@
|
||||
#include "mainwidget.h"
|
||||
#include <QApplication>
|
||||
#include <QStyleFactory>
|
||||
|
||||
#include "model/data.h"
|
||||
|
||||
@ -9,6 +10,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
LOG() << "Hello";
|
||||
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::WindowText, Qt::black);// 窗口文字颜色
|
||||
QApplication::setPalette(palette);
|
||||
|
||||
MainWidget* w = MainWidget::getInstance();
|
||||
w->show();
|
||||
return a.exec();
|
||||
|
||||
@ -39,6 +39,7 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
initRightWindow();
|
||||
//初始化信号槽
|
||||
initSignalSlot();
|
||||
|
||||
}
|
||||
|
||||
MainWidget::~MainWidget()
|
||||
@ -224,6 +225,17 @@ void MainWidget::initSignalSlot()
|
||||
connect(sessionTabBtn, &QPushButton::clicked, this, &MainWidget::switchTabToSession);
|
||||
connect(friendTabBtn, &QPushButton::clicked, this, &MainWidget::switchTabToFriend);
|
||||
connect(applyTabBtn, &QPushButton::clicked, this, &MainWidget::switchTabToApply);
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// 点击自己的头像,弹出对话框显示个人的主页
|
||||
/////////////////////////////////////
|
||||
connect(userAvatar, &QPushButton::clicked, this, [=]()->void {
|
||||
SelfInfoWidget* selfInfoWidget = new SelfInfoWidget(this);
|
||||
selfInfoWidget->setStyleSheet("QDialog { background-color: rgb(255, 255, 255); }");
|
||||
selfInfoWidget->exec(); //弹出模态对话框
|
||||
//selfInfoWidget->show(); //弹出非模态对加框
|
||||
});
|
||||
}
|
||||
|
||||
void MainWidget::switchTabToSession()
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include "debug.h"
|
||||
#include "messageeditarea.h"
|
||||
#include "messageshowarea.h"
|
||||
#include "SelfInfoWidget.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
|
||||
@ -1,5 +1,206 @@
|
||||
#include "messageeditarea.h"
|
||||
#include "messageeditarea.h"
|
||||
|
||||
|
||||
MessageEditArea::MessageEditArea(QWidget *parent)
|
||||
: QWidget{parent}
|
||||
{}
|
||||
{
|
||||
//设置必要的属性
|
||||
this->setFixedHeight(250);
|
||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
||||
//创建垂直方向的布局管理器
|
||||
QVBoxLayout* vlayout = new QVBoxLayout();
|
||||
vlayout->setSpacing(0);
|
||||
vlayout->setContentsMargins(0, 0, 30, 10);
|
||||
this->setLayout(vlayout);
|
||||
|
||||
//创建水平方向的布局管理器
|
||||
QHBoxLayout* hlayout = new QHBoxLayout();
|
||||
hlayout->setSpacing(0);
|
||||
hlayout->setContentsMargins(10, 0, 0, 0);
|
||||
hlayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
vlayout->addLayout(hlayout);
|
||||
|
||||
//将上方的四个按钮,创建好并添加到layout中
|
||||
QString btnStyle = R"(QPushButton { background-color: rgb(245, 245, 245); border: none; }
|
||||
QPushButton:pressed {background-color: rgb(255, 255, 255); })";
|
||||
QSize btnSize(35, 35);
|
||||
QSize iconSize(25, 25);
|
||||
|
||||
sendImageBtn = new QPushButton();
|
||||
sendImageBtn->setFixedSize(btnSize);
|
||||
sendImageBtn->setIconSize(iconSize);
|
||||
sendImageBtn->setIcon(QIcon(":/resource/image/image.png"));
|
||||
sendImageBtn->setStyleSheet(btnStyle);
|
||||
hlayout->addWidget(sendImageBtn);
|
||||
|
||||
sendFileBtn = new QPushButton();
|
||||
sendFileBtn->setFixedSize(btnSize);
|
||||
sendFileBtn->setIconSize(iconSize);
|
||||
sendFileBtn->setIcon(QIcon(":/resource/image/file.png"));
|
||||
sendFileBtn->setStyleSheet(btnStyle);
|
||||
hlayout->addWidget(sendFileBtn);
|
||||
|
||||
sendSpeechBtn = new QPushButton();
|
||||
sendSpeechBtn->setFixedSize(btnSize);
|
||||
sendSpeechBtn->setIconSize(iconSize);
|
||||
sendSpeechBtn->setIcon(QIcon(":/resource/image/sound.png"));
|
||||
sendSpeechBtn->setStyleSheet(btnStyle);
|
||||
hlayout->addWidget(sendSpeechBtn);
|
||||
|
||||
showHistoryBtn = new QPushButton();
|
||||
showHistoryBtn->setFixedSize(btnSize);
|
||||
showHistoryBtn->setIconSize(iconSize);
|
||||
showHistoryBtn->setIcon(QIcon(":/resource/image/history.png"));
|
||||
showHistoryBtn->setStyleSheet(btnStyle);
|
||||
hlayout->addWidget(showHistoryBtn);
|
||||
|
||||
//添加多行编辑框
|
||||
textEdit = new QPlainTextEdit();
|
||||
textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
textEdit->setStyleSheet(R"( QPlainTextEdit {
|
||||
color: black;
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
font-size: 14px;
|
||||
padding: 10px; }
|
||||
)");
|
||||
textEdit->verticalScrollBar()->setStyleSheet(R"(
|
||||
QScrollBar:vertical {
|
||||
background-color: rgb(228, 228, 228); /* 滚动条背景透明 */
|
||||
width: 6px; /* 默认宽度 */
|
||||
margin: 0px 0px 0px 0px; /* 边距清零 */
|
||||
}
|
||||
QScrollBar::handle:vertical {
|
||||
background: #CCCCCC; /* 滑块颜色(浅灰色) */
|
||||
min-height: 30px; /* 滑块最小高度 */
|
||||
border-radius: 3px; /* 圆角 */
|
||||
}
|
||||
QScrollBar::handle:vertical:hover {
|
||||
background: #999999; /* 悬停时滑块颜色加深 */
|
||||
width: 10px; /* 悬停时宽度增大 */
|
||||
}
|
||||
QScrollBar::handle:vertical:pressed {
|
||||
background: #666666; /* 按下时颜色更深 */
|
||||
}
|
||||
QScrollBar::add-line:vertical,
|
||||
QScrollBar::sub-line:vertical {
|
||||
height: 0px; /* 隐藏上下箭头按钮 */
|
||||
background: none;
|
||||
}
|
||||
QScrollBar::add-page:vertical,
|
||||
QScrollBar::sub-page:vertical {
|
||||
background: none; /* 滚动条背景区域透明 */
|
||||
}
|
||||
|
||||
)");
|
||||
|
||||
vlayout->addWidget(textEdit);
|
||||
|
||||
|
||||
//添加发送消息文本的按钮
|
||||
sendTextButton = new QPushButton();
|
||||
sendTextButton->setText("发送");
|
||||
sendTextButton->setFixedSize(120, 40);
|
||||
//仿Wechat的标准样式
|
||||
sendTextButton->setStyleSheet(R"(QPushButton {
|
||||
font-size: 16px;
|
||||
color: rgb(7, 193, 96);
|
||||
border: none;
|
||||
background-color: rgb(233, 233, 233);
|
||||
border-radius: 5px; }
|
||||
QPushButton:hover {
|
||||
background-color: rgb(210, 210, 210); }
|
||||
QPushButton:pressed {
|
||||
background-color: rgb(190, 190, 190); }
|
||||
)");
|
||||
|
||||
|
||||
//// 创建阴影效果
|
||||
// shadowEffect = new QGraphicsDropShadowEffect;
|
||||
// shadowEffect->setBlurRadius(12);
|
||||
// shadowEffect->setOffset(0, 5);
|
||||
// shadowEffect->setColor(QColor(0, 0, 0, 150));
|
||||
// sendTextButton->setGraphicsEffect(shadowEffect);
|
||||
//
|
||||
//// 设置按钮样式表
|
||||
// sendTextButton->setStyleSheet(R"(
|
||||
// QPushButton {
|
||||
// background: qlineargradient(spread:pad,
|
||||
// x1:0, y1:0, x2:1, y2:0,
|
||||
// stop:0 #9b59b6,
|
||||
// stop:1 #8e44ad);
|
||||
// border-radius: 10px;
|
||||
// color: white;
|
||||
// font: bold 14px;
|
||||
// border: none;
|
||||
// margin: 5px;
|
||||
// box-shadow: 0 5px 15px rgba(0,0,0,0.3);
|
||||
// }
|
||||
// QPushButton:hover {
|
||||
// background: qlineargradient(spread:pad,
|
||||
// x1:0, y1:0, x2:1, y2:0,
|
||||
// stop:0 #e67e22,
|
||||
// stop:1 #d35400);
|
||||
// box-shadow: 0 7px 20px rgba(0,0,0,0.4);
|
||||
// }
|
||||
// QPushButton:pressed {
|
||||
// background: qlineargradient(spread:pad,
|
||||
// x1:0, y1:0, x2:1, y2:0,
|
||||
// stop:0 #e74c3c,
|
||||
// stop:1 #c0392b);
|
||||
// }
|
||||
//)");
|
||||
//
|
||||
// // 连接按钮的按下和释放事件
|
||||
// connect(sendTextButton, &QPushButton::pressed, [=]() {
|
||||
// QPropertyAnimation* anim = new QPropertyAnimation(shadowEffect, "offset");
|
||||
// anim->setDuration(100);
|
||||
// anim->setStartValue(shadowEffect->offset());
|
||||
// anim->setEndValue(QPointF(0, 1));
|
||||
// anim->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
// });
|
||||
//
|
||||
// connect(sendTextButton, &QPushButton::released, [=]() {
|
||||
// QPropertyAnimation* anim = new QPropertyAnimation(shadowEffect, "offset");
|
||||
// anim->setDuration(150);
|
||||
// anim->setStartValue(shadowEffect->offset());
|
||||
// anim->setEndValue(QPointF(0, sendTextButton->underMouse() ? 3 : 5)); // 根据是否悬停决定最终位置
|
||||
// anim->setEasingCurve(QEasingCurve::OutBack);
|
||||
// anim->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
// });
|
||||
//
|
||||
// // 安装事件过滤器
|
||||
// sendTextButton->installEventFilter(this);
|
||||
|
||||
|
||||
|
||||
vlayout->addWidget(sendTextButton, 0, Qt::AlignRight | Qt::AlignVCenter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//bool MessageEditArea::eventFilter(QObject* obj, QEvent* event)
|
||||
//{
|
||||
// if (obj == sendTextButton) {
|
||||
// if (event->type() == QEvent::Enter) {
|
||||
// // 鼠标进入事件
|
||||
// QPropertyAnimation* hoverAnim = new QPropertyAnimation(shadowEffect, "offset");
|
||||
// hoverAnim->setDuration(200);
|
||||
// hoverAnim->setStartValue(shadowEffect->offset());
|
||||
// hoverAnim->setEndValue(QPointF(0, 3));
|
||||
// hoverAnim->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
// return true;
|
||||
// }
|
||||
// else if (event->type() == QEvent::Leave) {
|
||||
// // 鼠标离开事件
|
||||
// QPropertyAnimation* hoverAnim = new QPropertyAnimation(shadowEffect, "offset");
|
||||
// hoverAnim->setDuration(200);
|
||||
// hoverAnim->setStartValue(shadowEffect->offset());
|
||||
// hoverAnim->setEndValue(QPointF(0, 5));
|
||||
// hoverAnim->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return QObject::eventFilter(obj, event);
|
||||
//}
|
||||
@ -1,14 +1,38 @@
|
||||
#ifndef MESSAGEEDITAREA_H
|
||||
#ifndef MESSAGEEDITAREA_H
|
||||
#define MESSAGEEDITAREA_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QScrollBar>
|
||||
//#include <QGraphicsDropShadowEffect>
|
||||
//#include <qpropertyanimation.h>
|
||||
//#include <QEvent>
|
||||
|
||||
//编辑消息的区域
|
||||
class MessageEditArea : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MessageEditArea(QWidget *parent = nullptr);
|
||||
|
||||
//花式按钮事件
|
||||
//bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private:
|
||||
QPushButton* sendImageBtn;
|
||||
QPushButton* sendFileBtn;
|
||||
QPushButton* sendSpeechBtn;
|
||||
QPushButton* showHistoryBtn;
|
||||
QPlainTextEdit* textEdit;
|
||||
QPushButton* sendTextButton;
|
||||
|
||||
//花式按钮
|
||||
//QGraphicsDropShadowEffect* shadowEffect;
|
||||
|
||||
|
||||
signals:
|
||||
};
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ MessageShowArea::MessageShowArea() {
|
||||
// 添加测试数据
|
||||
#if TEST_UI
|
||||
bool k = true;
|
||||
for(int i = 0; i < 30; i++) {
|
||||
for(int i = 0; i < 8; i++) {
|
||||
model::UserInfo userInfo;
|
||||
userInfo.nickname = "xyz" + QString::number(i);
|
||||
userInfo.avatar = QIcon(":/resource/image/defaultAvatar.png");
|
||||
|
||||
@ -142,7 +142,7 @@ void SessionFriendItem::mousePressEvent(QMouseEvent *event)
|
||||
select();
|
||||
}
|
||||
|
||||
void SessionFriendItem::enterEvent(QEvent *event)
|
||||
void SessionFriendItem::enterEvent(QEnterEvent *event)
|
||||
{
|
||||
(void) event;
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ public:
|
||||
//通过显式绘制控件的基础样式,解决了自定义控件因未正确处理Qt样式表机制导致的QSS不生效问题
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void enterEvent(QEvent* event) override;
|
||||
void enterEvent(QEnterEvent* event) override;
|
||||
void leaveEvent(QEvent* event) override;
|
||||
|
||||
void select();
|
||||
|
||||
Reference in New Issue
Block a user