Files
energy_storage/src/qt/MainWeb.cpp

105 lines
3.3 KiB
C++
Raw Normal View History

#include "MainWeb.h"
#include "app/Config.h"
#include <QCoreApplication>
#include <QLabel>
#include <QThread>
#include <QWebEngineSettings>
#include <QWebEngineProfile>
#include <QAction>
#include <QToolBar>
void MySplash(MainWeb* mainWin)
{
//===动态程序启动画面===
QPixmap pixmap("./assets/ui/splash.png");
QSplashScreen splash(pixmap);
splash.show();
QCoreApplication::processEvents();
QLabel label(&splash);
label.setStyleSheet("background-color: gray");
label.setGeometry(100, 480, 800, 20);
label.show();
QLabel labelProgress(&splash);
labelProgress.setStyleSheet("background-color: rgb(29, 54, 102)");
labelProgress.setGeometry(10, 10, 0, 20);
labelProgress.show();
int i = 0;
while ((++i)<500)
{
splash.showMessage(QString("Loading... %1 ms").arg(i), Qt::AlignBottom | Qt::AlignRight, Qt::black);
labelProgress.setGeometry(100, 480, i*2*0.8, 20);
QCoreApplication::processEvents();
QThread::msleep(10);
}
splash.finish(mainWin);//程序启动画面结束
}
MainWeb::MainWeb()
{
this->setWindowTitle("光储充站监控与运营管理平台");
this->setGeometry(0, 0, 1920, 1080);
this->hide();
// 在加载页面之前清除缓存
//QWebEngineProfile::defaultProfile()->clearHttpCache();
//QWebEngineSettings* settings = webView.settings();
//settings->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
//settings->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
//settings->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, true); // 解决http资源加载问题
//settings->setAttribute(QWebEngineSettings::PluginsEnabled, true);
webView.setGeometry(0, 0, 1920, 1080);
// 默认设置透明, 解决加载时的白屏闪烁
//webView.page()->setBackgroundColor(Qt::transparent);
//webView.setContextMenuPolicy(Qt::NoContextMenu);
webView.load(QUrl(Config::option.webSrvUrl.c_str()));
this->setCentralWidget(&webView);
//===动态程序启动画面===
splash = std::make_shared<QSplashScreen>(QPixmap("./assets/ui/splash.png"));
QCoreApplication::processEvents();
label1.setParent(splash.get());
label1.setStyleSheet("background-color: gray");
label1.setGeometry(100, 480, 800, 20);
labelProgress.setParent(splash.get());
labelProgress.setStyleSheet("background-color: rgb(29, 54, 102)");
labelProgress.setGeometry(10, 10, 0, 20);
splash->show();
label1.show();
labelProgress.show();
QObject::connect(&webView, &QWebEngineView::loadFinished, [=](bool ok)
{
if (ok)
{
int i = 0;
while ((++i)<100)
{
splash->showMessage(QString("Loading... %1 ms").arg(i), Qt::AlignBottom | Qt::AlignRight, Qt::black);
labelProgress.setGeometry(100, 480, i*10*0.8, 20);
QCoreApplication::processEvents();
QThread::msleep(20);
}
splash->finish(this);//程序启动画面结束
this->show();
}
else
{
qDebug() << "页面加载失败!";
// 这里可以执行加载失败后的处理
}
});
//this->show();
}