修改 web控件

This commit is contained in:
Maicss 2020-08-26 09:26:59 +08:00
parent 18c3965742
commit 4e4f55995e
9 changed files with 209 additions and 352 deletions

6
progress_load.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "progress_load.h"
progress_load::progress_load()
{
}

12
progress_load.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef PROGRESS_LOAD_H
#define PROGRESS_LOAD_H
#include <QWidget>
class progress_load
{
public:
progress_load();
};
#endif // PROGRESS_LOAD_H

21
progressload.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "progressload.h"
ProgressLoad::ProgressLoad(QWidget *parent) : QWidget(parent)
{
m_progess=new QWidget;
m_progess->setStyleSheet("background-color:#999999");
m_progess->move(0,0);
timer=new QTimer;
value=0;
timer->setInterval(100);
timer->start();
connect(timer,&QTimer::timeout,[=](){
m_progess->setFixedWidth(width()/100*value);
});
}
void ProgressLoad::setValue(int v)
{
value=v;
m_progess->setFixedWidth(width()/100*value);
}

21
progressload.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef PROGRESSLOAD_H
#define PROGRESSLOAD_H
#include <QWidget>
#include <QTimer>
class ProgressLoad : public QWidget
{
Q_OBJECT
public:
explicit ProgressLoad(QWidget *parent = nullptr);
void setValue(int v);
signals:
public slots:
private:
QWidget *m_progess;
int value;
QTimer *timer;
};
#endif // PROGRESSLOAD_H

View File

@ -4,10 +4,13 @@
#
#-------------------------------------------------
QT += core gui webkitwidgets network concurrent
QT += core gui webkitwidgets network concurrent webenginewidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += link_pkgconfig
PKGCONFIG += dtkwidget
TARGET = spark-store
TEMPLATE = app
@ -27,16 +30,17 @@ SOURCES += main.cpp\
widget.cpp \
downloadlist.cpp \
image_show.cpp \
big_image.cpp
big_image.cpp \
progressload.cpp
HEADERS += \
widget.h \
downloadlist.h \
image_show.h \
big_image.h
big_image.h \
progressload.h
CONFIG += link_pkgconfig
PKGCONFIG += dtkwidget
CONFIG += c++11

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.2, 2020-08-10T12:35:10. -->
<!-- Written by QtCreator 4.8.2, 2020-08-26T09:22:50. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -293,14 +293,15 @@
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Executable</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">spark-store</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/maicss/git/spark/spark-store/spark-store.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">spark-store.pro</value>
<value type="QString" key="RunConfiguration.Arguments"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>

View File

@ -37,6 +37,7 @@ Widget::Widget(DBlurEffectWidget *parent) :
initUI();
initConfig();
manager = new QNetworkAccessManager(this);//下载管理
m_loadweb=ui->progressload;
connect(ui->menu_main,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(0);});
connect(ui->menu_network,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(1);});
@ -99,6 +100,11 @@ Widget::Widget(DBlurEffectWidget *parent) :
size2=download_size;
}
});
//
m_loadweb->show();
m_loadweb->setValue(50);
}
@ -173,19 +179,20 @@ void Widget::initUI()
//初始化web加载动画
QHBoxLayout *m_weblayout=new QHBoxLayout;
m_weblayout->addWidget(m_loadweb);
m_weblayout->addWidget(m_loaderror);
m_loadweb->hide();
m_loaderror->hide();
m_loadweb->start();
m_loadweb->setMaximumSize(50,50);
m_loadweb->setMinimumSize(50,50);
m_loadweb->setTextVisible(false);
m_loaderror->setPixmap(QIcon::fromTheme("dialog-error").pixmap(50,50));
m_loaderror->setAlignment(Qt::AlignCenter);
// QHBoxLayout *m_weblayout=new QHBoxLayout;
// m_weblayout->addWidget(m_loadweb);
// m_weblayout->addWidget(m_loaderror);
// m_loadweb->hide();
// m_loadweb->setParent(ui->webEngineView);
// m_loaderror->hide();
// m_loadweb->start();
// m_loadweb->setMaximumSize(50,50);
// m_loadweb->setMinimumSize(50,50);
// m_loadweb->setTextVisible(false);
// m_loaderror->setPixmap(QIcon::fromTheme("dialog-error").pixmap(50,50));
// m_loaderror->setAlignment(Qt::AlignCenter);
ui->webView->setLayout(m_weblayout);
// ui->webEngineView->setLayout(m_weblayout);
// ui->stackedWidget->setLayout(m_weblayout);
ui->label_show->hide();
@ -233,12 +240,13 @@ void Widget::initConfig()
//web控件初始化
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); //用来激活接受linkClicked信号
ui->webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled,true);
// ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); //用来激活接受linkClicked信号
// ui->webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled,true);
ui->webfoot->hide();
//初始化首页
ui->webView->setUrl(menuUrl[0]);
ui->webEngineView->setUrl(menuUrl[0]);
// ui->webEngineView->setUrl(menuUrl[1]);
chooseLeftMenu(0);
//给下载列表赋值到数组,方便调用
@ -265,7 +273,7 @@ void Widget::setTheme(bool isDark,QColor color)
if(isDark){
//黑色模式
themeIsDark=true;
ui->webView->setStyleSheet("background-color:#282828");
ui->webEngineView->setStyleSheet("background-color:#282828");
ui->btn_openDir->setStyleSheet("color:#8B91A1;background-color:#2E2F30;border:0px");
ui->webfoot->setStyleSheet("background-color:#252525");
ui->label->setStyleSheet("background-color:#252525");
@ -278,7 +286,7 @@ void Widget::setTheme(bool isDark,QColor color)
}else {
//亮色模式
themeIsDark=false;
ui->webView->setStyleSheet("background-color:#FFFFFF");
ui->webEngineView->setStyleSheet("background-color:#FFFFFF");
ui->webfoot->setStyleSheet("background-color:#FFFFFF");
ui->btn_openDir->setStyleSheet("color:#505050;background-color:#FBFBFB;border:0px");
ui->label->setStyleSheet("background-color:#FFFFFF");
@ -300,35 +308,6 @@ DTitlebar* Widget::getTitlebar()
{
return ui->titlebar;
}
void Widget::on_webView_loadStarted()
{
m_loadweb->setValue(0);
m_loadweb->show();
m_loaderror->hide();
ui->label_show->hide();
//分析出服务器中的分类名称
QUrl arg1=ui->webView->page()->mainFrame()->requestedUrl().toString();
QStringList url_=arg1.path().split("/");
if(url_.size()>3){
type_name=url_[2];
}
//如果是app.json就打开详情页
if(arg1.path().right(8)=="app.json"){
load.cancel();//打开并发加载线程前关闭正在执行的线程
ui->label_more->setText("");//清空详情介绍
ui->label_info->setText("");
ui->label_appname->setText("");
ui->pushButton_download->setEnabled(false);
ui->stackedWidget->setCurrentIndex(2);
load.cancel();//打开并发加载线程前关闭正在执行的线程
load = QtConcurrent::run([=](){
loadappinfo(arg1);
});
}
}
void Widget::updateUI()
{
if(themeIsDark){
@ -423,8 +402,6 @@ void Widget::chooseLeftMenu(int index)
{
nowMenu=index;
// setfoot();
// updatefoot();
updateUI();
left_list[index]->setStyleSheet("color:#FFFFFF;background-color:"+main_color.name()+";border-radius:8;border:0px");
@ -437,10 +414,11 @@ void Widget::chooseLeftMenu(int index)
darkurl+=tmp[i]+"/";
}
darkurl+="dark"+tmp[tmp.size()-1];
ui->webView->setUrl(darkurl);
ui->webEngineView->setUrl(darkurl);
qDebug()<<darkurl;
}else {
ui->webView->setUrl(menuUrl[index]);
ui->webEngineView->setUrl(menuUrl[index]);
}
ui->stackedWidget->setCurrentIndex(0);
@ -475,6 +453,7 @@ void Widget::loadappinfo(QUrl arg1)
ui->screen_2->hide();
ui->screen_3->hide();
ui->screen_4->hide();
ui->label_appicon->clear();
//置UI状态
ui->pushButton_uninstall->hide();
@ -881,7 +860,7 @@ void Widget::opensetting()
void Widget::openUrl(QUrl u)
{
QString app=serverUrl + "store"+u.path()+"/app.json";
ui->webView->setUrl(app);
ui->webEngineView->setUrl(app);
}
@ -892,25 +871,6 @@ void Widget::on_pushButton_website_clicked()
}
void Widget::on_webView_loadFinished(bool arg1)
{
if(arg1){
m_loadweb->hide();
}else {
m_loadweb->hide();
m_loaderror->show();
}
}
void Widget::on_webView_loadProgress(int progress)
{
m_loadweb->setValue(progress);
if(progress>=90){
m_loadweb->hide();
}
}
void Widget::on_pushButton_clicked()
{
QString share_url;
@ -936,3 +896,57 @@ void Widget::on_stackedWidget_currentChanged(int arg1)
ui->pushButton_return->setEnabled(true);
}
}
void Widget::on_webEngineView_urlChanged(const QUrl &arg1)
{
//分析出服务器中的分类名称
QStringList url_=arg1.path().split("/");
QString pname;
if(url_.size()>3){
type_name=url_[2];
pname=url_[3];
}
//如果是app.json就打开详情页
if(arg1.path().right(8)=="app.json"){
load.cancel();//打开并发加载线程前关闭正在执行的线程
ui->label_more->setText("");//清空详情介绍
ui->label_info->setText("");
ui->label_appname->setText("");
ui->pushButton_download->setEnabled(false);
ui->stackedWidget->setCurrentIndex(2);
qDebug()<<"https://demo-one-vert.vercel.app/"+type_name+"/"+pname;
load.cancel();//打开并发加载线程前关闭正在执行的线程
load = QtConcurrent::run([=](){
loadappinfo(arg1);
});
}
}
void Widget::on_webEngineView_loadStarted()
{
// m_loadweb->setValue(0);
// m_loadweb->show();
// m_loaderror->hide();
// ui->label_show->hide();
}
void Widget::on_webEngineView_loadProgress(int progress)
{
// m_loadweb->setValue(progress);
// if(progress>=90){
// m_loadweb->hide();
// }
}
void Widget::on_webEngineView_loadFinished(bool arg1)
{
// if(arg1){
// m_loadweb->hide();
// }else {
// m_loadweb->hide();
// m_loaderror->show();
// }
}

View File

@ -19,6 +19,7 @@
#include <QLabel>
#include <DTitlebar>
#include <DSearchEdit>
#include <progressload.h>
#define LIST_MAX 99 //一次最多下载数量
#define TMP_PATH "/tmp/spark-store"
@ -53,15 +54,12 @@ private slots:
void updateDataReadProgress(qint64,qint64);
void on_pushButton_download_clicked();
void on_pushButton_return_clicked();
void on_webView_loadStarted();
void on_comboBox_server_currentIndexChanged(const QString &arg1);
void on_pushButton_updateServer_clicked();
void on_pushButton_updateApt_clicked();
void on_pushButton_uninstall_clicked();
void on_pushButton_clear_clicked();
void on_pushButton_website_clicked();
void on_webView_loadFinished(bool arg1);
void on_webView_loadProgress(int progress);
void on_pushButton_clicked();
@ -69,6 +67,14 @@ private slots:
void on_stackedWidget_currentChanged(int arg1);
void on_webEngineView_urlChanged(const QUrl &arg1);
void on_webEngineView_loadStarted();
void on_webEngineView_loadProgress(int progress);
void on_webEngineView_loadFinished(bool arg1);
public:
QUrl url;
@ -101,7 +107,7 @@ private:
private:
QPushButton * left_list[15];
QUrl menuUrl[13];
DWaterProgress *m_loadweb=new DWaterProgress;
ProgressLoad *m_loadweb;
QLabel *m_loaderror=new QLabel;
QString serverUrl;
bool configCanSave=false;

310
widget.ui
View File

@ -29,7 +29,7 @@
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0" rowspan="3">
<item row="0" column="0" rowspan="4">
<widget class="QWidget" name="widget_menuList" native="true">
<property name="minimumSize">
<size>
@ -147,6 +147,13 @@
</property>
</spacer>
</item>
<item row="11" column="0" colspan="5">
<widget class="QPushButton" name="menu_dev">
<property name="text">
<string>编程开发</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="pushButton_return">
<property name="maximumSize">
@ -164,13 +171,6 @@
</property>
</widget>
</item>
<item row="11" column="0" colspan="5">
<widget class="QPushButton" name="menu_dev">
<property name="text">
<string>编程开发</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="5">
<widget class="QPushButton" name="menu_office">
<property name="text">
@ -278,7 +278,7 @@
</layout>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QStackedWidget" name="stackedWidget">
<property name="styleSheet">
<string notr="true"/>
@ -287,7 +287,7 @@
<number>0</number>
</property>
<property name="currentIndex">
<number>3</number>
<number>2</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -307,263 +307,10 @@
<number>0</number>
</property>
<item>
<widget class="QWebView" name="webView">
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>65</red>
<green>77</green>
<blue>104</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>3</red>
<green>3</green>
<blue>3</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>46</red>
<green>46</green>
<blue>46</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>65</red>
<green>77</green>
<blue>104</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>65</red>
<green>77</green>
<blue>104</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="HighlightedText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>28</red>
<green>28</green>
<blue>28</blue>
</color>
</brush>
</colorrole>
<colorrole role="NoRole">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>138</red>
<green>145</green>
<blue>161</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>3</red>
<green>3</green>
<blue>3</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>46</red>
<green>46</green>
<blue>46</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>138</red>
<green>145</green>
<blue>161</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>138</red>
<green>145</green>
<blue>161</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="HighlightedText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>28</red>
<green>28</green>
<blue>28</blue>
</color>
</brush>
</colorrole>
<colorrole role="NoRole">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>46</red>
<green>46</green>
<blue>46</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>3</red>
<green>3</green>
<blue>3</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>46</red>
<green>46</green>
<blue>46</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>46</red>
<green>46</green>
<blue>46</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>46</red>
<green>46</green>
<blue>46</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="HighlightedText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>28</red>
<green>28</green>
<blue>28</blue>
</color>
</brush>
</colorrole>
<colorrole role="NoRole">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<widget class="QWebEngineView" name="webEngineView">
<property name="url">
<url>
<string>http://0.0.0.1/</string>
<string>about:blank</string>
</url>
</property>
</widget>
@ -657,7 +404,7 @@
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
<number>10</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
@ -674,7 +421,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-228</y>
<width>901</width>
<height>849</height>
</rect>
@ -1385,13 +1132,32 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="ProgressLoad" name="progressload" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>10</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>10</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color:#000000</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<class>QWebEngineView</class>
<extends>QWidget</extends>
<header>QtWebKitWidgets/QWebView</header>
<header location="global">QtWebEngineWidgets/QWebEngineView</header>
</customwidget>
<customwidget>
<class>image_show</class>
@ -1405,6 +1171,12 @@
<header location="global">dtitlebar.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ProgressLoad</class>
<extends>QWidget</extends>
<header location="global">progressload.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="icons.qrc"/>