fun:添加Loading窗口。
This commit is contained in:
@@ -10,8 +10,8 @@ set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_definitions(-DUSE_QT_GUI)
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network Concurrent)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network Concurrent)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(PROJECT_SOURCES main.cpp
|
||||
@@ -26,7 +26,7 @@ Form/Transform.h Form/Transform.cpp Form/Transform.ui
|
||||
Control/cusTableWidget.cpp Control/cusTableWidget.h
|
||||
Control/cpTableWidget.h Control/cpTableWidget.cpp
|
||||
GuiUtil/Config.h GuiUtil/Config.cpp
|
||||
../Res/qss.qrc
|
||||
../Res/qss.qrc Form/Loading.h Form/Loading.cpp
|
||||
)
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
@@ -55,8 +55,9 @@ endif()
|
||||
target_link_libraries(frelayGUI PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
Qt${QT_VERSION_MAJOR}::Concurrent
|
||||
ClientCore Protocol
|
||||
Util
|
||||
Util
|
||||
Struct SingleApplication::SingleApplication
|
||||
)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "Form/Loading.h"
|
||||
#include "GuiUtil/Public.h"
|
||||
#include "ui_CompareControl.h"
|
||||
|
||||
@@ -80,6 +81,13 @@ void Compare::InitControl()
|
||||
connect(ui->btnLoad, &QPushButton::clicked, this, &Compare::Load);
|
||||
connect(ui->btnLeft, &QPushButton::clicked, this, &Compare::TransToLeft);
|
||||
connect(ui->btnRight, &QPushButton::clicked, this, &Compare::TransToRight);
|
||||
|
||||
// 测试代码
|
||||
connect(ui->btnReplace, &QPushButton::clicked, this, [this]() {
|
||||
// auto* loading = new LoadingDialog(this);
|
||||
// loading->exec();
|
||||
});
|
||||
|
||||
LoadTitles();
|
||||
}
|
||||
|
||||
|
||||
139
Gui/Form/Loading.cpp
Normal file
139
Gui/Form/Loading.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#include "Loading.h"
|
||||
|
||||
LoadingDialog::LoadingDialog(QWidget* parent) : QDialog(parent)
|
||||
{
|
||||
// 如果需要显示任务栏对话框则删除Qt::Tool
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
initUi();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LoadingDialog::initUi UI元素初始化
|
||||
*/
|
||||
void LoadingDialog::initUi()
|
||||
{
|
||||
this->setFixedSize(250, 250);
|
||||
m_pCenterFrame = new QFrame(this);
|
||||
m_pCenterFrame->setGeometry(10, 10, 230, 230);
|
||||
|
||||
// 加载Loading动画
|
||||
m_pLoadingMovie = new QMovie(":/ico/loading.gif");
|
||||
m_pLoadingMovie->setScaledSize(QSize(120, 120));
|
||||
m_pMovieLabel = new QLabel(m_pCenterFrame);
|
||||
m_pMovieLabel->setGeometry(55, 10, 120, 120);
|
||||
m_pMovieLabel->setScaledContents(true);
|
||||
m_pMovieLabel->setMovie(m_pLoadingMovie);
|
||||
m_pLoadingMovie->start();
|
||||
|
||||
// 提示文本
|
||||
m_pTipsLabel = new QLabel(m_pCenterFrame);
|
||||
m_pTipsLabel->setGeometry(5, 130, 220, 50);
|
||||
m_pTipsLabel->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
|
||||
m_pTipsLabel->setObjectName("tips");
|
||||
m_pTipsLabel->setText("加载中,请稍候...");
|
||||
m_pTipsLabel->setStyleSheet("QLabel#tips{font-family:\"Microsoft YaHei\";font-size: 15px;color: #333333;}");
|
||||
|
||||
// 取消按钮
|
||||
m_pCancelBtn = new QPushButton(m_pCenterFrame);
|
||||
m_pCancelBtn->setObjectName("cancelBtn");
|
||||
m_pCancelBtn->setText("取消等待");
|
||||
m_pCancelBtn->setStyleSheet("QPushButton#cancelBtn{"
|
||||
"background-color: #edeef6;"
|
||||
"border-radius: 4px;"
|
||||
"font-family: \"Microsoft YaHei\";"
|
||||
"font-size: 14px;"
|
||||
"color: #333333;"
|
||||
"}"
|
||||
"QPushButton#cancelBtn::hover{"
|
||||
"background:#dcdeea"
|
||||
"}");
|
||||
m_pCancelBtn->setGeometry(25, 180, 180, 35);
|
||||
m_pCancelBtn->setEnabled(true);
|
||||
connect(m_pCancelBtn, &QPushButton::clicked, this, &LoadingDialog::cancelBtnClicked);
|
||||
|
||||
// 实例阴影shadow
|
||||
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(this);
|
||||
shadow->setOffset(0, 0);
|
||||
shadow->setColor(QColor(32, 101, 165));
|
||||
shadow->setBlurRadius(10);
|
||||
this->setGraphicsEffect(shadow);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LoadingDialog::setTipsText 设置提示文本
|
||||
* @param strTipsText 提示文本
|
||||
*/
|
||||
void LoadingDialog::setTipsText(QString strTipsText)
|
||||
{
|
||||
m_pTipsLabel->setText(strTipsText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LoadingDialog::setCanCancel 设置是够允许用户点击取消等待按钮
|
||||
* @param bCanCancel 是够允许
|
||||
*/
|
||||
void LoadingDialog::setCanCancel(bool bCanCancel)
|
||||
{
|
||||
m_pCancelBtn->setEnabled(bCanCancel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LoadingDialog::moveToCenter 移动对话框到指定窗口中间
|
||||
* @param pParent 指定窗口指针
|
||||
*/
|
||||
void LoadingDialog::moveToCenter(QWidget* pParent)
|
||||
{
|
||||
if (pParent != nullptr && pParent != NULL) {
|
||||
int nParentWidth = pParent->width();
|
||||
int nParentHeigth = pParent->height();
|
||||
|
||||
int nWidth = this->width();
|
||||
int nHeight = this->height();
|
||||
|
||||
int nParentX = pParent->x();
|
||||
int nParentY = pParent->y();
|
||||
|
||||
int x = (nParentX + (nParentWidth - nWidth) / 2);
|
||||
int y = (nParentY + (nParentHeigth - nHeight) / 2);
|
||||
|
||||
this->move(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LoadingDialog::cancelBtnClicked 取消按钮槽函数
|
||||
*/
|
||||
void LoadingDialog::cancelBtnClicked()
|
||||
{
|
||||
emit cancelWaiting();
|
||||
this->done(USER_CANCEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LoadingDialog::paintEvent 界面绘制
|
||||
* @param event
|
||||
*/
|
||||
void LoadingDialog::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿
|
||||
painter.setBrush(QBrush(Qt::white));
|
||||
painter.setPen(Qt::transparent);
|
||||
QRect rect = this->rect();
|
||||
rect.setLeft(9);
|
||||
rect.setTop(9);
|
||||
rect.setWidth(rect.width() - 9);
|
||||
rect.setHeight(rect.height() - 9);
|
||||
painter.drawRoundedRect(rect, 8, 8);
|
||||
QWidget::paintEvent(event);
|
||||
}
|
||||
|
||||
LoadingDialog::~LoadingDialog()
|
||||
{
|
||||
delete m_pLoadingMovie;
|
||||
delete m_pMovieLabel;
|
||||
delete m_pTipsLabel;
|
||||
delete m_pCancelBtn;
|
||||
delete m_pCenterFrame;
|
||||
}
|
||||
45
Gui/Form/Loading.h
Normal file
45
Gui/Form/Loading.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef LOADINGDIALOG_H
|
||||
#define LOADINGDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QLabel>
|
||||
#include <QMovie>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#define USER_CANCEL -1
|
||||
|
||||
// LoadingDialog 改造来源:https://blog.csdn.net/weixin_42105886/article/details/114665272
|
||||
class LoadingDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LoadingDialog(QWidget* parent = nullptr);
|
||||
~LoadingDialog();
|
||||
// 设置提示文本
|
||||
void setTipsText(QString strTipsText);
|
||||
// 设置是否显示取消等待按钮
|
||||
void setCanCancel(bool bCanCancel);
|
||||
// 移动到指定窗口中间显示
|
||||
void moveToCenter(QWidget* pParent);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
void initUi();
|
||||
|
||||
Q_SIGNALS:
|
||||
void cancelWaiting();
|
||||
|
||||
private slots:
|
||||
void cancelBtnClicked();
|
||||
|
||||
private:
|
||||
QFrame* m_pCenterFrame;
|
||||
QLabel* m_pMovieLabel;
|
||||
QMovie* m_pLoadingMovie;
|
||||
QLabel* m_pTipsLabel;
|
||||
QPushButton* m_pCancelBtn;
|
||||
};
|
||||
#endif // LOADINGDIALOG_H
|
||||
Reference in New Issue
Block a user