This commit is contained in:
朱子楚\zhuzi 2023-09-08 00:21:28 +08:00
parent c92d807ec1
commit 573898149a
14 changed files with 266 additions and 490 deletions

View File

@ -397,7 +397,7 @@ FluObject{
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }
} }
FluPaneItem{ FluPaneItem{
title:"Screenshot" title:"Screenshot(Todo)"
url:"qrc:/example/qml/page/T_Screenshot.qml" url:"qrc:/example/qml/page/T_Screenshot.qml"
onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) } onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) }
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }

View File

@ -56,7 +56,6 @@ FluContentPage{
onSuccess: onSuccess:
(result)=>{ (result)=>{
text_info.text = result text_info.text = result
console.debug(result)
} }
onCache: onCache:
(result)=>{ (result)=>{
@ -86,7 +85,8 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "Get请求" text: "Get请求"
onClicked: { onClicked: {
http.get("https://httpbingo.org/get",callable) var request = http.newRequest("https://httpbingo.org/get")
http.get(request,callable)
} }
} }
FluButton{ FluButton{
@ -94,11 +94,13 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "Post表单请求" text: "Post表单请求"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.custname = "朱子楚" var params = {}
param.custtel = "1234567890" params.custname = "朱子楚"
param.custemail = "zhuzichu520@gmail.com" params.custtel = "1234567890"
http.post("https://httpbingo.org/post",callable,param) params.custemail = "zhuzichu520@gmail.com"
request.params = params
http.post(request,callable)
} }
} }
FluButton{ FluButton{
@ -106,11 +108,13 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "Post Json请求" text: "Post Json请求"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.custname = "朱子楚" var params = {}
param.custtel = "1234567890" params.custname = "朱子楚"
param.custemail = "zhuzichu520@gmail.com" params.custtel = "1234567890"
http.postJson("https://httpbingo.org/post",callable,param) params.custemail = "zhuzichu520@gmail.com"
request.params = params
http.postJson(request,callable)
} }
} }
FluButton{ FluButton{
@ -118,8 +122,9 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "Post String请求" text: "Post String请求"
onClicked: { onClicked: {
var param = "我命由我不由天" var request = http.newRequest("https://httpbingo.org/post")
http.postString("https://httpbingo.org/post",callable,param) request.params = "我命由我不由天"
http.postString(request,callable)
} }
} }
FluProgressButton{ FluProgressButton{
@ -133,8 +138,6 @@ FluContentPage{
} }
FluProgressButton{ FluProgressButton{
property bool downloading: false property bool downloading: false
property string saveFilePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
property string resourcePath: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
id:btn_breakpoint_download id:btn_breakpoint_download
implicitWidth: parent.width implicitWidth: parent.width
implicitHeight: 36 implicitHeight: 36
@ -150,6 +153,11 @@ FluContentPage{
return "继续下载" return "继续下载"
} }
} }
HttpRequest{
id:request_breakpoint_download
url: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
downloadSavePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
}
HttpCallable{ HttpCallable{
id:callable_breakpoint_download id:callable_breakpoint_download
onStart: { onStart: {
@ -172,7 +180,7 @@ FluContentPage{
} }
} }
Component.onCompleted: { Component.onCompleted: {
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath) progress = http_breakpoint_download.getBreakPointProgress(request_breakpoint_download)
} }
onClicked: { onClicked: {
if(downloading){ if(downloading){
@ -180,9 +188,9 @@ FluContentPage{
return return
} }
if(progress === 1){ if(progress === 1){
FluTools.showFileInFolder(saveFilePath) FluTools.showFileInFolder(request_breakpoint_download.downloadSavePath)
}else{ }else{
http_breakpoint_download.download(resourcePath,callable_breakpoint_download,saveFilePath) http_breakpoint_download.download(request_breakpoint_download,callable_breakpoint_download)
} }
} }
FluMenu{ FluMenu{
@ -191,7 +199,7 @@ FluContentPage{
FluMenuItem{ FluMenuItem{
text: "删除文件" text: "删除文件"
onClicked: { onClicked: {
if(FluTools.removeFile(btn_breakpoint_download.saveFilePath)){ if(FluTools.removeFile(request_breakpoint_download.downloadSavePath)){
btn_breakpoint_download.progress = 0 btn_breakpoint_download.progress = 0
} }
} }
@ -221,9 +229,9 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "FirstCacheThenRequest缓存" text: "FirstCacheThenRequest缓存"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.cacheMode = "FirstCacheThenRequest" request.params = {cacheMode:"FirstCacheThenRequest"}
http_cache_firstcachethenrequest.post("https://httpbingo.org/post",callable,param) http_cache_firstcachethenrequest.post(request,callable)
} }
} }
FluButton{ FluButton{
@ -231,9 +239,9 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "RequestFailedReadCache缓存" text: "RequestFailedReadCache缓存"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.cacheMode = "RequestFailedReadCache" request.params = {cacheMode:"RequestFailedReadCache"}
http_cache_requestfailedreadcache.post("https://httpbingo.org/post",callable,param) http_cache_requestfailedreadcache.post(request,callable)
} }
} }
@ -242,9 +250,9 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "IfNoneCacheRequest缓存" text: "IfNoneCacheRequest缓存"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.cacheMode = "IfNoneCacheRequest" request.params = {cacheMode:"IfNoneCacheRequest"}
http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param) http_cache_ifnonecacherequest.post(request,callable)
} }
} }
FluButton{ FluButton{
@ -300,14 +308,16 @@ FluContentPage{
FileDialog { FileDialog {
id: file_dialog id: file_dialog
onAccepted: { onAccepted: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
var params = {}
for(var i=0;i<selectedFiles.length;i++){ for(var i=0;i<selectedFiles.length;i++){
var fileUrl = selectedFiles[i] var fileUrl = selectedFiles[i]
var fileName = FluTools.getFileNameByUrl(fileUrl) var fileName = FluTools.getFileNameByUrl(fileUrl)
var filePath = FluTools.toLocalPath(fileUrl) var filePath = FluTools.toLocalPath(fileUrl)
param[fileName] = filePath params[fileName] = filePath
} }
http.upload("https://httpbingo.org/post",callable_upload,param) request.params = params
http.upload(request,callable_upload)
} }
} }
@ -339,11 +349,11 @@ FluContentPage{
id: folder_dialog id: folder_dialog
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0] currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
onAccepted: { onAccepted: {
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4" var request = http.newRequest("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable_download,path) request.downloadSavePath = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
http.download(request,callable_download)
} }
} }
FluArea{ FluArea{
anchors{ anchors{
top: layout_flick.top top: layout_flick.top

View File

@ -334,21 +334,9 @@ CustomWindow {
} }
} }
// HttpRequest{
// id:reuqest
// url: "https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest"
// }
function checkUpdate(){ function checkUpdate(){
var request = http.newRequest() var request = http.newRequest("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest")
console.debug("-------------------->"+request) http.get(request,callable);
request.url = "https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest"
console.debug("-------------------->"+request.url)
http.get2(request,callable);
// http.get("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest",callable)
} }
} }

View File

@ -397,7 +397,7 @@ FluObject{
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }
} }
FluPaneItem{ FluPaneItem{
title:"Screenshot" title:"Screenshot(Todo)"
url:"qrc:/example/qml/page/T_Screenshot.qml" url:"qrc:/example/qml/page/T_Screenshot.qml"
onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) } onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) }
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }

View File

@ -57,7 +57,6 @@ FluContentPage{
onSuccess: onSuccess:
(result)=>{ (result)=>{
text_info.text = result text_info.text = result
console.debug(result)
} }
onCache: onCache:
(result)=>{ (result)=>{
@ -87,7 +86,8 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "Get请求" text: "Get请求"
onClicked: { onClicked: {
http.get("https://httpbingo.org/get",callable) var request = http.newRequest("https://httpbingo.org/get")
http.get(request,callable)
} }
} }
FluButton{ FluButton{
@ -95,11 +95,13 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "Post表单请求" text: "Post表单请求"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.custname = "朱子楚" var params = {}
param.custtel = "1234567890" params.custname = "朱子楚"
param.custemail = "zhuzichu520@gmail.com" params.custtel = "1234567890"
http.post("https://httpbingo.org/post",callable,param) params.custemail = "zhuzichu520@gmail.com"
request.params = params
http.post(request,callable)
} }
} }
FluButton{ FluButton{
@ -107,11 +109,13 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "Post Json请求" text: "Post Json请求"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.custname = "朱子楚" var params = {}
param.custtel = "1234567890" params.custname = "朱子楚"
param.custemail = "zhuzichu520@gmail.com" params.custtel = "1234567890"
http.postJson("https://httpbingo.org/post",callable,param) params.custemail = "zhuzichu520@gmail.com"
request.params = params
http.postJson(request,callable)
} }
} }
FluButton{ FluButton{
@ -119,8 +123,9 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "Post String请求" text: "Post String请求"
onClicked: { onClicked: {
var param = "我命由我不由天" var request = http.newRequest("https://httpbingo.org/post")
http.postString("https://httpbingo.org/post",callable,param) request.params = "我命由我不由天"
http.postString(request,callable)
} }
} }
FluProgressButton{ FluProgressButton{
@ -134,8 +139,6 @@ FluContentPage{
} }
FluProgressButton{ FluProgressButton{
property bool downloading: false property bool downloading: false
property string saveFilePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
property string resourcePath: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
id:btn_breakpoint_download id:btn_breakpoint_download
implicitWidth: parent.width implicitWidth: parent.width
implicitHeight: 36 implicitHeight: 36
@ -151,6 +154,11 @@ FluContentPage{
return "继续下载" return "继续下载"
} }
} }
HttpRequest{
id:request_breakpoint_download
url: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
downloadSavePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
}
HttpCallable{ HttpCallable{
id:callable_breakpoint_download id:callable_breakpoint_download
onStart: { onStart: {
@ -173,7 +181,7 @@ FluContentPage{
} }
} }
Component.onCompleted: { Component.onCompleted: {
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath) progress = http_breakpoint_download.getBreakPointProgress(request_breakpoint_download)
} }
onClicked: { onClicked: {
if(downloading){ if(downloading){
@ -181,9 +189,9 @@ FluContentPage{
return return
} }
if(progress === 1){ if(progress === 1){
FluTools.showFileInFolder(saveFilePath) FluTools.showFileInFolder(request_breakpoint_download.downloadSavePath)
}else{ }else{
http_breakpoint_download.download(resourcePath,callable_breakpoint_download,saveFilePath) http_breakpoint_download.download(request_breakpoint_download,callable_breakpoint_download)
} }
} }
FluMenu{ FluMenu{
@ -192,7 +200,7 @@ FluContentPage{
FluMenuItem{ FluMenuItem{
text: "删除文件" text: "删除文件"
onClicked: { onClicked: {
if(FluTools.removeFile(btn_breakpoint_download.saveFilePath)){ if(FluTools.removeFile(request_breakpoint_download.downloadSavePath)){
btn_breakpoint_download.progress = 0 btn_breakpoint_download.progress = 0
} }
} }
@ -222,9 +230,9 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "FirstCacheThenRequest缓存" text: "FirstCacheThenRequest缓存"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.cacheMode = "FirstCacheThenRequest" request.params = {cacheMode:"FirstCacheThenRequest"}
http_cache_firstcachethenrequest.post("https://httpbingo.org/post",callable,param) http_cache_firstcachethenrequest.post(request,callable)
} }
} }
FluButton{ FluButton{
@ -232,9 +240,9 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "RequestFailedReadCache缓存" text: "RequestFailedReadCache缓存"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.cacheMode = "RequestFailedReadCache" request.params = {cacheMode:"RequestFailedReadCache"}
http_cache_requestfailedreadcache.post("https://httpbingo.org/post",callable,param) http_cache_requestfailedreadcache.post(request,callable)
} }
} }
@ -243,9 +251,9 @@ FluContentPage{
implicitHeight: 36 implicitHeight: 36
text: "IfNoneCacheRequest缓存" text: "IfNoneCacheRequest缓存"
onClicked: { onClicked: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
param.cacheMode = "IfNoneCacheRequest" request.params = {cacheMode:"IfNoneCacheRequest"}
http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param) http_cache_ifnonecacherequest.post(request,callable)
} }
} }
FluButton{ FluButton{
@ -301,14 +309,16 @@ FluContentPage{
FileDialog { FileDialog {
id: file_dialog id: file_dialog
onAccepted: { onAccepted: {
var param = {} var request = http.newRequest("https://httpbingo.org/post")
var params = {}
for(var i=0;i<selectedFiles.length;i++){ for(var i=0;i<selectedFiles.length;i++){
var fileUrl = selectedFiles[i] var fileUrl = selectedFiles[i]
var fileName = FluTools.getFileNameByUrl(fileUrl) var fileName = FluTools.getFileNameByUrl(fileUrl)
var filePath = FluTools.toLocalPath(fileUrl) var filePath = FluTools.toLocalPath(fileUrl)
param[fileName] = filePath params[fileName] = filePath
} }
http.upload("https://httpbingo.org/post",callable_upload,param) request.params = params
http.upload(request,callable_upload)
} }
} }
@ -340,11 +350,11 @@ FluContentPage{
id: folder_dialog id: folder_dialog
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0] currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
onAccepted: { onAccepted: {
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4" var request = http.newRequest("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable_download,path) request.downloadSavePath = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
http.download(request,callable_download)
} }
} }
FluArea{ FluArea{
anchors{ anchors{
top: layout_flick.top top: layout_flick.top

View File

@ -139,7 +139,7 @@ CustomWindow {
id:loader id:loader
lazy: true lazy: true
anchors.fill: parent anchors.fill: parent
source: "https://zhu-zichu.gitee.io/Qt5_156_LieflatPage.qml" source: "https://zhu-zichu.gitee.io/Qt6_156_LieflatPage.qml"
} }
} }
front: Item{ front: Item{
@ -336,7 +336,8 @@ CustomWindow {
} }
function checkUpdate(){ function checkUpdate(){
http.get("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest",callable) var request = http.newRequest("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest")
http.get(request,callable);
} }
} }

View File

@ -17,8 +17,37 @@
HttpRequest::HttpRequest(QObject *parent) HttpRequest::HttpRequest(QObject *parent)
: QObject{parent} : QObject{parent}
{ {
params({}); }
headers({});
QMap<QString, QVariant> HttpRequest::toMap(){
QVariant _params;
if(params().isNull()){
if(method() == "postString"){
_params = "";
}else{
_params = QMap<QString,QVariant>();
}
}else{
_params = params();
}
QVariant _headers;
if(headers().isNull()){
_headers = QMap<QString,QVariant>();
}else{
_params = params();
}
QMap<QString, QVariant> request = {
{"url",url()},
{"params",_params},
{"headers",_headers},
{"method",method()},
{"downloadSavePath",downloadSavePath()}
};
return request;
}
QString HttpRequest::httpId(){
return FluTools::getInstance()->sha256(QJsonDocument::fromVariant(QVariant(toMap())).toJson());
} }
HttpCallable::HttpCallable(QObject *parent) HttpCallable::HttpCallable(QObject *parent)
@ -48,26 +77,27 @@ void FluHttp::cancel(){
} }
} }
void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){ void FluHttp::post(HttpRequest* request,HttpCallable* callable){
auto requestMap = toRequest(url,params,headers,"post"); request->method("post");
auto httpId = toHttpId(requestMap); auto requestMap = request->toMap();
auto httpId = request->httpId();
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap(); QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){ QThreadPool::globalInstance()->start([=](){
onStart(callable); onStart(callable);
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){ if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId)); onCache(callable,readCache(httpId));
onFinish(callable); onFinish(callable,request);
return; return;
} }
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){ if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId)); onCache(callable,readCache(httpId));
} }
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
for (int i = 0; i < retry(); ++i) { for (int i = 0; i < retry(); ++i) {
QNetworkAccessManager manager; QUrl url(request->url());
manager.setTransferTimeout(timeout()); QNetworkRequest req(url);
QUrl _url(url); addHeaders(&req,data["headers"].toMap());
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType); QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
for (const auto& each : data["params"].toMap().toStdMap()) for (const auto& each : data["params"].toMap().toStdMap())
{ {
@ -80,7 +110,7 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> pa
multiPart.append(part); multiPart.append(part);
} }
QEventLoop loop; QEventLoop loop;
QNetworkReply* reply = manager.post(request,&multiPart); QNetworkReply* reply = manager.post(req,&multiPart);
_cacheReply.append(reply); _cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
@ -104,34 +134,36 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> pa
} }
} }
} }
onFinish(callable); onFinish(callable,request);
}); });
} }
void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<QString, QVariant> headers){ void FluHttp::postString(HttpRequest* request,HttpCallable* callable){
auto requestMap = toRequest(url,params,headers,"postString"); request->method("postString");
auto httpId = toHttpId(requestMap); auto requestMap = request->toMap();
auto httpId = request->httpId();
QString params = request->params().toString();
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap(); QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){ QThreadPool::globalInstance()->start([=](){
onStart(callable); onStart(callable);
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){ if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId)); onCache(callable,readCache(httpId));
onFinish(callable); onFinish(callable,request);
return; return;
} }
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){ if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId)); onCache(callable,readCache(httpId));
} }
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
for (int i = 0; i < retry(); ++i) { for (int i = 0; i < retry(); ++i) {
QNetworkAccessManager manager; QUrl url(request->url());
manager.setTransferTimeout(timeout()); QNetworkRequest req(url);
QUrl _url(url); addHeaders(&req,data["headers"].toMap());
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QString contentType = QString("text/plain;charset=utf-8"); QString contentType = QString("text/plain;charset=utf-8");
request.setHeader(QNetworkRequest::ContentTypeHeader, contentType); req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
QEventLoop loop; QEventLoop loop;
QNetworkReply* reply = manager.post(request,params.toUtf8()); QNetworkReply* reply = manager.post(req,params.toUtf8());
_cacheReply.append(reply); _cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
@ -155,34 +187,35 @@ void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<
} }
} }
} }
onFinish(callable); onFinish(callable,request);
}); });
} }
void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){ void FluHttp::postJson(HttpRequest* request,HttpCallable* callable){
auto requestMap = toRequest(url,params,headers,"postJson"); request->method("postJson");
auto httpId = toHttpId(requestMap); auto requestMap = request->toMap();
auto httpId = request->httpId();
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap(); QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){ QThreadPool::globalInstance()->start([=](){
onStart(callable); onStart(callable);
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){ if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId)); onCache(callable,readCache(httpId));
onFinish(callable); onFinish(callable,request);
return; return;
} }
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){ if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId)); onCache(callable,readCache(httpId));
} }
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
for (int i = 0; i < retry(); ++i) { for (int i = 0; i < retry(); ++i) {
QNetworkAccessManager manager; QUrl url(request->url());
manager.setTransferTimeout(timeout()); QNetworkRequest req(url);
QUrl _url(url); addHeaders(&req,data["headers"].toMap());
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QString contentType = QString("application/json;charset=utf-8"); QString contentType = QString("application/json;charset=utf-8");
request.setHeader(QNetworkRequest::ContentTypeHeader, contentType); req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
QEventLoop loop; QEventLoop loop;
QNetworkReply* reply = manager.post(request,QJsonDocument::fromVariant(data["params"]).toJson()); QNetworkReply* reply = manager.post(req,QJsonDocument::fromVariant(data["params"]).toJson());
_cacheReply.append(reply); _cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
@ -206,20 +239,15 @@ void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant
} }
} }
} }
onFinish(callable); onFinish(callable,request);
}); });
} }
void FluHttp::get2(HttpRequest* request,HttpCallable* callable){
QString url = request->url();
QMap<QString, QVariant> params = request->params().toMap();
QMap<QString, QVariant> headers = request->headers().toMap();
get(url,callable,params,headers);
}
void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){ void FluHttp::get(HttpRequest* request,HttpCallable* callable){
auto requestMap = toRequest(url,params,headers,"get"); request->method("get");
auto httpId = toHttpId(requestMap); auto requestMap = request->toMap();
auto httpId = request->httpId();
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap(); QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){ QThreadPool::globalInstance()->start([=](){
onStart(callable); onStart(callable);
@ -228,18 +256,18 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> par
} }
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){ if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId)); onCache(callable,readCache(httpId));
onFinish(callable); onFinish(callable,request);
return; return;
} }
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
for (int i = 0; i < retry(); ++i) { for (int i = 0; i < retry(); ++i) {
QNetworkAccessManager manager; QUrl url(request->url());
manager.setTransferTimeout(timeout()); addQueryParam(&url,data["params"].toMap());
QUrl _url(url); QNetworkRequest req(url);
addQueryParam(&_url,data["params"].toMap()); addHeaders(&req,data["headers"].toMap());
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QEventLoop loop; QEventLoop loop;
QNetworkReply* reply = manager.get(request); QNetworkReply* reply = manager.get(req);
_cacheReply.append(reply); _cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
@ -263,22 +291,23 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> par
reply->deleteLater(); reply->deleteLater();
reply = nullptr; reply = nullptr;
} }
onFinish(callable); onFinish(callable,request);
}); });
} }
void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){ void FluHttp::download(HttpRequest* request,HttpCallable* callable){
auto requestMap = toRequest(url,params,headers,"download"); request->method("download");
requestMap.insert("savePath",savePath); auto requestMap = request->toMap();
auto httpId = toHttpId(requestMap); auto httpId = request->httpId();
auto savePath = request->downloadSavePath();
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap(); QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){ QThreadPool::globalInstance()->start([=](){
onStart(callable); onStart(callable);
QNetworkAccessManager manager; QNetworkAccessManager manager;
QUrl _url(url); QUrl url(request->url());
addQueryParam(&_url,data["params"].toMap()); addQueryParam(&url,data["params"].toMap());
QNetworkRequest request(_url); QNetworkRequest req(url);
addHeaders(&request,data["headers"].toMap()); addHeaders(&req,data["headers"].toMap());
QSharedPointer<QFile> file(new QFile(savePath)); QSharedPointer<QFile> file(new QFile(savePath));
QDir dir = QFileInfo(savePath).path(); QDir dir = QFileInfo(savePath).path();
if (!dir.exists(dir.path())){ if (!dir.exists(dir.path())){
@ -297,11 +326,11 @@ void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap<
if(fileSize == contentLength && file->size() == contentLength){ if(fileSize == contentLength && file->size() == contentLength){
onDownloadProgress(callable,fileSize,contentLength); onDownloadProgress(callable,fileSize,contentLength);
onSuccess(callable,savePath); onSuccess(callable,savePath);
onFinish(callable); onFinish(callable,request);
return; return;
} }
if(fileSize==file->size()){ if(fileSize==file->size()){
request.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8()); req.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8());
seek = fileSize; seek = fileSize;
file->open(QIODevice::WriteOnly|QIODevice::Append); file->open(QIODevice::WriteOnly|QIODevice::Append);
}else{ }else{
@ -310,7 +339,7 @@ void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap<
}else{ }else{
file->open(QIODevice::WriteOnly|QIODevice::Truncate); file->open(QIODevice::WriteOnly|QIODevice::Truncate);
} }
QNetworkReply* reply = manager.get(request); QNetworkReply* reply = manager.get(req);
_cacheReply.append(reply); _cacheReply.append(reply);
if (!fileCache->open(QIODevice::WriteOnly|QIODevice::Truncate)) if (!fileCache->open(QIODevice::WriteOnly|QIODevice::Truncate))
{ {
@ -342,21 +371,23 @@ void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap<
} }
reply->deleteLater(); reply->deleteLater();
reply = nullptr; reply = nullptr;
onFinish(callable); onFinish(callable,request);
}); });
} }
void FluHttp::upload(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){ void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
auto requestMap = toRequest(url,params,headers,"upload"); request->method("upload");
auto requestMap = request->toMap();
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap(); QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){ QThreadPool::globalInstance()->start([=](){
onStart(callable); onStart(callable);
QNetworkAccessManager manager; QNetworkAccessManager manager;
manager.setTransferTimeout(timeout()); manager.setTransferTimeout(timeout());
QUrl _url(url); QUrl url(request->url());
QNetworkRequest request(_url); QNetworkRequest req(url);
addHeaders(&request,data["headers"].toMap()); addHeaders(&req,data["headers"].toMap());
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType); QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
qDebug()<<data["params"].toMap();
for (const auto& each : data["params"].toMap().toStdMap()) for (const auto& each : data["params"].toMap().toStdMap())
{ {
const QString& key = each.first; const QString& key = each.first;
@ -372,7 +403,7 @@ void FluHttp::upload(QString url,HttpCallable* callable,QMap<QString, QVariant>
multiPart.append(part); multiPart.append(part);
} }
QEventLoop loop; QEventLoop loop;
QNetworkReply* reply = manager.post(request,&multiPart); QNetworkReply* reply = manager.post(req,&multiPart);
_cacheReply.append(reply); _cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
@ -391,20 +422,10 @@ void FluHttp::upload(QString url,HttpCallable* callable,QMap<QString, QVariant>
}else{ }else{
onError(callable,status,errorString,result); onError(callable,status,errorString,result);
} }
onFinish(callable); onFinish(callable,request);
}); });
} }
QMap<QString, QVariant> FluHttp::toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method){
QMap<QString, QVariant> request = {
{"url",url},
{"params",params},
{"headers",headers},
{"method",method}
};
return request;
}
QVariant FluHttp::invokeIntercept(QMap<QString, QVariant> request){ QVariant FluHttp::invokeIntercept(QMap<QString, QVariant> request){
if(!FluApp::getInstance()->httpInterceptor()){ if(!FluApp::getInstance()->httpInterceptor()){
return request; return request;
@ -475,11 +496,10 @@ void FluHttp::handleCache(const QString& httpId,const QString& result){
file->write(FluTools::getInstance()->toBase64(result).toUtf8()); file->write(FluTools::getInstance()->toBase64(result).toUtf8());
} }
qreal FluHttp::breakPointDownloadProgress(QString url,QString savePath,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){ qreal FluHttp::getBreakPointProgress(HttpRequest* request){
auto requestMap = toRequest(url,params,headers,"download"); request->method("download");
requestMap.insert("savePath",savePath); auto httpId = request->httpId();
auto httpId = toHttpId(requestMap); QSharedPointer<QFile> file(new QFile(request->downloadSavePath()));
QSharedPointer<QFile> file(new QFile(savePath));
auto filePath = getCacheFilePath(httpId); auto filePath = getCacheFilePath(httpId);
QSharedPointer<QFile> fileCache(new QFile(filePath)); QSharedPointer<QFile> fileCache(new QFile(filePath));
if(fileCache->exists() && file->exists() && _breakPointDownload){ if(fileCache->exists() && file->exists() && _breakPointDownload){
@ -499,25 +519,25 @@ qreal FluHttp::breakPointDownloadProgress(QString url,QString savePath,QMap<QStr
} }
} }
HttpRequest* FluHttp::newRequest(){ HttpRequest* FluHttp::newRequest(QString url){
HttpRequest* request = new HttpRequest(); HttpRequest* request = new HttpRequest();
request->url(url);
return request; return request;
} }
QString FluHttp::toHttpId(const QMap<QString, QVariant>& map){
return FluTools::getInstance()->sha256(QJsonDocument::fromVariant(QVariant(map)).toJson());
}
void FluHttp::onStart(QPointer<HttpCallable> callable){ void FluHttp::onStart(QPointer<HttpCallable> callable){
if(callable){ if(callable){
Q_EMIT callable->start(); Q_EMIT callable->start();
} }
} }
void FluHttp::onFinish(QPointer<HttpCallable> callable){ void FluHttp::onFinish(QPointer<HttpCallable> callable,HttpRequest* request){
if(callable){ if(callable){
Q_EMIT callable->finish(); Q_EMIT callable->finish();
} }
if(!request->parent()){
delete request;
}
} }
void FluHttp::onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result){ void FluHttp::onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result){

View File

@ -13,12 +13,12 @@ class HttpRequest : public QObject{
Q_PROPERTY_AUTO(QVariant,params); Q_PROPERTY_AUTO(QVariant,params);
Q_PROPERTY_AUTO(QVariant,headers); Q_PROPERTY_AUTO(QVariant,headers);
Q_PROPERTY_AUTO(QString,method); Q_PROPERTY_AUTO(QString,method);
Q_PROPERTY_AUTO(QString,downloadSavePath);
QML_NAMED_ELEMENT(HttpRequest) QML_NAMED_ELEMENT(HttpRequest)
public: public:
explicit HttpRequest(QObject *parent = nullptr); explicit HttpRequest(QObject *parent = nullptr);
~HttpRequest(){ QMap<QString, QVariant> toMap();
qDebug()<<"------------析构了"<<url(); Q_INVOKABLE QString httpId();
}
}; };
class HttpCallable : public QObject{ class HttpCallable : public QObject{
@ -46,8 +46,6 @@ class FluHttp : public QObject
QML_NAMED_ELEMENT(FluHttp) QML_NAMED_ELEMENT(FluHttp)
private: private:
QVariant invokeIntercept(QMap<QString, QVariant> request); QVariant invokeIntercept(QMap<QString, QVariant> request);
QMap<QString, QVariant> toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method);
QString toHttpId(const QMap<QString, QVariant>& map);
void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params); void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params);
void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& params); void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& params);
void handleCache(const QString& httpId, const QString& result); void handleCache(const QString& httpId, const QString& result);
@ -55,7 +53,7 @@ private:
bool cacheExists(const QString& httpId); bool cacheExists(const QString& httpId);
QString getCacheFilePath(const QString& httpId); QString getCacheFilePath(const QString& httpId);
void onStart(QPointer<HttpCallable> callable); void onStart(QPointer<HttpCallable> callable);
void onFinish(QPointer<HttpCallable> callable); void onFinish(QPointer<HttpCallable> callable,HttpRequest* request);
void onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result); void onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result);
void onSuccess(QPointer<HttpCallable> callable,QString result); void onSuccess(QPointer<HttpCallable> callable,QString result);
void onCache(QPointer<HttpCallable> callable,QString result); void onCache(QPointer<HttpCallable> callable,QString result);
@ -64,16 +62,14 @@ private:
public: public:
explicit FluHttp(QObject *parent = nullptr); explicit FluHttp(QObject *parent = nullptr);
~FluHttp(); ~FluHttp();
Q_INVOKABLE HttpRequest* newRequest(); Q_INVOKABLE HttpRequest* newRequest(QString url = "");
Q_INVOKABLE void get2(HttpRequest* request,HttpCallable* callable); Q_INVOKABLE void get(HttpRequest* request,HttpCallable* callable);
//神坑!!! 如果参数使用QVariantMap会有问题在6.4.3版本中QML一调用就会编译失败。所以改用QMap<QString, QVariant> Q_INVOKABLE void post(HttpRequest* request,HttpCallable* callable);
Q_INVOKABLE void get(QString url,HttpCallable* callable,QMap<QString, QVariant> params= {},QMap<QString, QVariant> headers = {}); Q_INVOKABLE void postString(HttpRequest* request,HttpCallable* callable);
Q_INVOKABLE void post(QString url,HttpCallable* callable,QMap<QString, QVariant> params= {},QMap<QString, QVariant> headers = {}); Q_INVOKABLE void postJson(HttpRequest* request,HttpCallable* callable);
Q_INVOKABLE void postString(QString url,HttpCallable* callable,QString params = "",QMap<QString, QVariant> headers = {}); Q_INVOKABLE void download(HttpRequest* request,HttpCallable* callable);
Q_INVOKABLE void postJson(QString url,HttpCallable* callable,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {}); Q_INVOKABLE void upload(HttpRequest* request,HttpCallable* callable);
Q_INVOKABLE void download(QString url,HttpCallable* callable,QString savePath,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {}); Q_INVOKABLE qreal getBreakPointProgress(HttpRequest* request);
Q_INVOKABLE void upload(QString url,HttpCallable* callable,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {});
Q_INVOKABLE qreal breakPointDownloadProgress(QString url,QString savePath,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {});
Q_INVOKABLE void cancel(); Q_INVOKABLE void cancel();
private: private:
QList<QPointer<QNetworkReply>> _cacheReply; QList<QPointer<QNetworkReply>> _cacheReply;

View File

@ -26,7 +26,7 @@ Item{
Component{ Component{
id:com_screen id:com_screen
Window{ Window{
property bool isZeroPos: screenshot.start == Qt.point(0,0) && screenshot.end == Qt.point(0,0) property bool isZeroPos: screenshot.start.x === 0 && screenshot.start.y === 0 && screenshot.end.x === 0 && screenshot.end.y === 0
id:window_screen id:window_screen
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
x:-1 x:-1
@ -123,7 +123,7 @@ Item{
MouseArea{ MouseArea{
property point clickPos: Qt.point(0,0) property point clickPos: Qt.point(0,0)
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.SizeAllCursor cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
onPressed: onPressed:
(mouse)=>{ (mouse)=>{
clickPos = Qt.point(mouse.x, mouse.y) clickPos = Qt.point(mouse.x, mouse.y)
@ -134,7 +134,7 @@ Item{
var w = Math.abs(screenshot.end.x - screenshot.start.x) var w = Math.abs(screenshot.end.x - screenshot.start.x)
var h = Math.abs(screenshot.end.y - screenshot.start.y) var h = Math.abs(screenshot.end.y - screenshot.start.y)
var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w) var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
var y =Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h) var y = Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
screenshot.start = Qt.point(x,y) screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h) screenshot.end = Qt.point(x+w,y+h)
} }
@ -477,7 +477,7 @@ Item{
width: 100 width: 100
height: 40 height: 40
visible: { visible: {
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){ if(isZeroPos){
return false return false
} }
if(d.enablePosition){ if(d.enablePosition){

View File

@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only. // It is used for QML tooling purposes only.
// //
// This file was auto-generated by: // This file was auto-generated by:
// 'qmlplugindump -nonrelocatable FluentUI 1.0 D:/QtProjects/build-FluentUI-Desktop_Qt_5_15_2_MSVC2019_64bit-Release/src' // 'qmlplugindump -nonrelocatable FluentUI 1.0 D:\QtProjects\build-FluentUI-Desktop_Qt_5_15_2_MSVC2019_64bit-Release\src'
Module { Module {
dependencies: ["QtQuick 2.0"] dependencies: ["QtQuick 2.0"]
@ -74,136 +74,45 @@ Module {
Property { name: "cacheDir"; type: "string" } Property { name: "cacheDir"; type: "string" }
Property { name: "breakPointDownload"; type: "bool" } Property { name: "breakPointDownload"; type: "bool" }
Method { Method {
name: "get" name: "newRequest"
type: "HttpRequest*"
Parameter { name: "url"; type: "string" } Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "QVariantMap" }
Parameter { name: "headers"; type: "QVariantMap" }
} }
Method { name: "newRequest"; type: "HttpRequest*" }
Method { Method {
name: "get" name: "get"
Parameter { name: "url"; type: "string" } Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "QVariantMap" }
}
Method {
name: "get"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
} }
Method { Method {
name: "post" name: "post"
Parameter { name: "url"; type: "string" } Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "QVariantMap" }
Parameter { name: "headers"; type: "QVariantMap" }
}
Method {
name: "post"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "QVariantMap" }
}
Method {
name: "post"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
} }
Method { Method {
name: "postString" name: "postString"
Parameter { name: "url"; type: "string" } Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "string" }
Parameter { name: "headers"; type: "QVariantMap" }
}
Method {
name: "postString"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "string" }
}
Method {
name: "postString"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
} }
Method { Method {
name: "postJson" name: "postJson"
Parameter { name: "url"; type: "string" } Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "QVariantMap" }
Parameter { name: "headers"; type: "QVariantMap" }
}
Method {
name: "postJson"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "QVariantMap" }
}
Method {
name: "postJson"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
} }
Method { Method {
name: "download" name: "download"
Parameter { name: "url"; type: "string" } Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "savePath"; type: "string" }
Parameter { name: "params"; type: "QVariantMap" }
Parameter { name: "headers"; type: "QVariantMap" }
}
Method {
name: "download"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "savePath"; type: "string" }
Parameter { name: "params"; type: "QVariantMap" }
}
Method {
name: "download"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "savePath"; type: "string" }
} }
Method { Method {
name: "upload" name: "upload"
Parameter { name: "url"; type: "string" } Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "QVariantMap" }
Parameter { name: "headers"; type: "QVariantMap" }
}
Method {
name: "upload"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
Parameter { name: "params"; type: "QVariantMap" }
}
Method {
name: "upload"
Parameter { name: "url"; type: "string" }
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
} }
Method { Method {
name: "breakPointDownloadProgress" name: "getBreakPointProgress"
type: "double" type: "double"
Parameter { name: "url"; type: "string" } Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
Parameter { name: "savePath"; type: "string" }
Parameter { name: "params"; type: "QVariantMap" }
Parameter { name: "headers"; type: "QVariantMap" }
}
Method {
name: "breakPointDownloadProgress"
type: "double"
Parameter { name: "url"; type: "string" }
Parameter { name: "savePath"; type: "string" }
Parameter { name: "params"; type: "QVariantMap" }
}
Method {
name: "breakPointDownloadProgress"
type: "double"
Parameter { name: "url"; type: "string" }
Parameter { name: "savePath"; type: "string" }
} }
Method { name: "cancel" } Method { name: "cancel" }
} }
@ -1839,10 +1748,22 @@ Module {
} }
Signal { Signal {
name: "uploadProgress" name: "uploadProgress"
Parameter { name: "recv"; type: "qlonglong" } Parameter { name: "sent"; type: "qlonglong" }
Parameter { name: "total"; type: "qlonglong" } Parameter { name: "total"; type: "qlonglong" }
} }
} }
Component {
name: "HttpRequest"
prototype: "QObject"
exports: ["FluentUI/HttpRequest 1.0"]
exportMetaObjectRevisions: [0]
Property { name: "url"; type: "string" }
Property { name: "params"; type: "QVariant" }
Property { name: "headers"; type: "QVariant" }
Property { name: "method"; type: "string" }
Property { name: "downloadSavePath"; type: "string" }
Method { name: "httpId"; type: "string" }
}
Component { Component {
name: "QRCode" name: "QRCode"
defaultProperty: "data" defaultProperty: "data"
@ -1872,7 +1793,6 @@ Module {
exportMetaObjectRevisions: [0] exportMetaObjectRevisions: [0]
Property { name: "saveFolder"; type: "string" } Property { name: "saveFolder"; type: "string" }
Property { name: "captureMode"; type: "int" } Property { name: "captureMode"; type: "int" }
Property { name: "hitDrawData"; type: "DrawData"; isPointer: true }
Signal { Signal {
name: "captrueToPixmapCompleted" name: "captrueToPixmapCompleted"
Parameter { name: "captrue"; type: "QPixmap" } Parameter { name: "captrue"; type: "QPixmap" }
@ -1886,25 +1806,6 @@ Module {
Parameter { name: "start"; type: "QPoint" } Parameter { name: "start"; type: "QPoint" }
Parameter { name: "end"; type: "QPoint" } Parameter { name: "end"; type: "QPoint" }
} }
Method {
name: "appendDrawData"
type: "DrawData*"
Parameter { name: "drawType"; type: "int" }
Parameter { name: "start"; type: "QPoint" }
Parameter { name: "end"; type: "QPoint" }
}
Method {
name: "updateDrawData"
Parameter { name: "data"; type: "DrawData"; isPointer: true }
Parameter { name: "start"; type: "QPoint" }
Parameter { name: "end"; type: "QPoint" }
}
Method { name: "clear" }
Method {
name: "hit"
type: "DrawData*"
Parameter { name: "point"; type: "QPoint" }
}
} }
Component { Component {
name: "WindowHelper" name: "WindowHelper"

View File

@ -15,7 +15,6 @@ Item{
signal captrueCompleted(var captrue) signal captrueCompleted(var captrue)
QtObject{ QtObject{
id:d id:d
property bool isEdit: false
property int dotMouseSize: control.dotSize+10 property int dotMouseSize: control.dotSize+10
property int dotMargins: -(control.dotSize-control.borderSize)/2 property int dotMargins: -(control.dotSize-control.borderSize)/2
property bool enablePosition: false property bool enablePosition: false
@ -27,7 +26,7 @@ Item{
Component{ Component{
id:com_screen id:com_screen
Window{ Window{
property bool isZeroPos: screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0) property bool isZeroPos: screenshot.start.x === 0 && screenshot.start.y === 0 && screenshot.end.x === 0 && screenshot.end.y === 0
id:window_screen id:window_screen
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
x:-1 x:-1
@ -42,8 +41,7 @@ Item{
} }
} }
Component.onCompleted: { Component.onCompleted: {
d.isEdit = false setGeometry(0,0,screenshot_background.width,screenshot_background.height+1)
setGeometry(0,0,screenshot_background.width,screenshot_background.height)
} }
ScreenshotBackground{ ScreenshotBackground{
id:screenshot_background id:screenshot_background
@ -110,8 +108,6 @@ Item{
} }
screenshot.start = Qt.point(0,0) screenshot.start = Qt.point(0,0)
screenshot.end = Qt.point(0,0) screenshot.end = Qt.point(0,0)
d.isEdit = false
screenshot_background.clear()
} }
} }
} }
@ -126,63 +122,21 @@ Item{
border.color: control.borderColor border.color: control.borderColor
MouseArea{ MouseArea{
property point clickPos: Qt.point(0,0) property point clickPos: Qt.point(0,0)
property var currentData
property bool enablePositionChanged : false
property var hitData
anchors.fill: parent anchors.fill: parent
hoverEnabled: true
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
onPressed: onPressed:
(mouse)=>{ (mouse)=>{
if(hitData){ clickPos = Qt.point(mouse.x, mouse.y)
return
}
enablePositionChanged = true
if(d.isEdit){
clickPos = Qt.point(mouse.x, mouse.y)
currentData = screenshot_background.appendDrawData(0,clickPos,clickPos)
}else{
clickPos = Qt.point(mouse.x, mouse.y)
}
} }
onReleased: {
enablePositionChanged = false
}
onCanceled: {
enablePositionChanged = false
}
onClicked: {
if(hitData){
screenshot_background.hitDrawData = hitData
}
}
onPositionChanged: onPositionChanged:
(mouse)=>{ (mouse)=>{
var delta = Qt.point(mouse.x - clickPos.x,mouse.y - clickPos.y)
if(!enablePositionChanged){ var w = Math.abs(screenshot.end.x - screenshot.start.x)
hitData = screenshot_background.hit(Qt.point(rect_capture.x + mouse.x,rect_capture.y + mouse.y)) var h = Math.abs(screenshot.end.y - screenshot.start.y)
if(hitData){ var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
FluTools.setOverrideCursor(Qt.SizeAllCursor) var y = Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
}else{ screenshot.start = Qt.point(x,y)
FluTools.restoreOverrideCursor() screenshot.end = Qt.point(x+w,y+h)
}
return
}
if(d.isEdit){
var start = Qt.point(rect_capture.x + clickPos.x,rect_capture.y + clickPos.y)
var end = Qt.point(Math.min(Math.max(rect_capture.x + mouse.x,rect_capture.x+borderSize),rect_capture.x+rect_capture.width-currentData.getLineWidth()),Math.min(Math.max(rect_capture.y + mouse.y,rect_capture.y+currentData.getLineWidth()+borderSize),rect_capture.y+rect_capture.height)-currentData.getLineWidth())
console.debug("start->"+start)
console.debug("end->"+end)
screenshot_background.updateDrawData(currentData,start,end)
}else{
var delta = Qt.point(mouse.x - clickPos.x,mouse.y - clickPos.y)
var w = Math.abs(screenshot.end.x - screenshot.start.x)
var h = Math.abs(screenshot.end.y - screenshot.start.y)
var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
var y =Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
} }
} }
} }
@ -520,10 +474,10 @@ Item{
} }
} }
Pane{ Pane{
width: 140 width: 100
height: 40 height: 40
visible: { visible: {
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){ if(isZeroPos){
return false return false
} }
if(d.enablePosition){ if(d.enablePosition){
@ -544,12 +498,6 @@ Item{
RowLayout{ RowLayout{
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right anchors.right: parent.right
FluIconButton{
iconSource: FluentIcons.Stop
onClicked: {
d.isEdit = true
}
}
FluIconButton{ FluIconButton{
iconSource: FluentIcons.Cancel iconSource: FluentIcons.Cancel
iconSize: 18 iconSize: 18

View File

@ -43,72 +43,17 @@ ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedIt
} }
setWidth(w); setWidth(w);
setHeight(h); setHeight(h);
connect(this,&ScreenshotBackground::hitDrawDataChanged,this,[=]{update();});
} }
void ScreenshotBackground::paint(QPainter* painter) void ScreenshotBackground::paint(QPainter* painter)
{ {
painter->save(); painter->save();
_sourcePixmap = _desktopPixmap.copy(); _sourcePixmap = _desktopPixmap.copy();
foreach (auto item, _drawList) {
if(item->drawType == 0){
QPainter p(&_sourcePixmap);
QPen pen;
pen.setWidth(item->lineWidth);
pen.setColor(QColor(255,0,0));
pen.setStyle(Qt::SolidLine);
p.setPen(pen);
QRect rect(item->start.x(), item->start.y(), item->end.x()-item->start.x(), item->end.y()-item->start.y());
p.drawRect(rect);
}
}
painter->drawPixmap(_desktopGeometry,_sourcePixmap); painter->drawPixmap(_desktopGeometry,_sourcePixmap);
foreach (auto item, _drawList) {
if(item->drawType == 0){
if(item == _hitDrawData){
painter->setPen(QPen(QColor(255,0,0),3));
painter->setBrush(QColor(255,255,255));
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()-4,8,8));
painter->drawEllipse(QRect(item->start.x()+item->getWidth()/2-4,item->start.y()-4,8,8));
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()-4,8,8));
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()+item->getHeight()/2-4,8,8));
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()+item->getHeight()-4,8,8));
painter->drawEllipse(QRect(item->start.x()+item->getWidth()/2-4,item->start.y()+item->getHeight()-4,8,8));
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()+item->getHeight()-4,8,8));
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()+item->getHeight()/2-4,8,8));
}
}
}
painter->restore(); painter->restore();
} }
void ScreenshotBackground::clear(){
_drawList.clear();
update();
}
DrawData* ScreenshotBackground::hit(const QPoint& point){
foreach (auto item, _drawList) {
if(item->drawType == 0){
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->start.x()+item->lineWidth+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
return item;
}
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->start.y()+item->lineWidth+mouseSpacing){
return item;
}
if(point.x()>=item->end.x()-item->lineWidth-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
return item;
}
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->end.y()-item->lineWidth-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
return item;
}
}
}
return nullptr;
}
void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){ void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
hitDrawData(nullptr);
update(); update();
auto pixelRatio = qApp->primaryScreen()->devicePixelRatio(); auto pixelRatio = qApp->primaryScreen()->devicePixelRatio();
auto x = qMin(start.x(),end.x()) * pixelRatio; auto x = qMin(start.x(),end.x()) * pixelRatio;
@ -129,21 +74,3 @@ void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
Q_EMIT captrueToFileCompleted(QUrl::fromLocalFile(filePath)); Q_EMIT captrueToFileCompleted(QUrl::fromLocalFile(filePath));
} }
} }
DrawData* ScreenshotBackground::appendDrawData(int drawType,QPoint start,QPoint end){
DrawData *data = new DrawData(this);
data->drawType = drawType;
data->start = start;
data->end = end;
data->lineWidth = 3;
_drawList.append(data);
update();
return data;
}
void ScreenshotBackground::updateDrawData(DrawData* data,QPoint start,QPoint end){
data->start = start;
data->end = end;
update();
}

View File

@ -8,40 +8,16 @@
#include "stdafx.h" #include "stdafx.h"
#include <qmath.h> #include <qmath.h>
class DrawData:public QObject{
Q_OBJECT;
public:
explicit DrawData(QObject *parent = nullptr): QObject{parent}{};
int drawType;
int lineWidth;
QPoint start;
QPoint end;
Q_INVOKABLE int getLineWidth(){
return lineWidth;
}
Q_INVOKABLE int getWidth(){
return end.x()-start.x();
}
Q_INVOKABLE int getHeight(){
return end.y()-start.y();
}
};
class ScreenshotBackground : public QQuickPaintedItem class ScreenshotBackground : public QQuickPaintedItem
{ {
Q_OBJECT; Q_OBJECT;
QML_NAMED_ELEMENT(ScreenshotBackground) QML_NAMED_ELEMENT(ScreenshotBackground)
Q_PROPERTY_AUTO(QString,saveFolder); Q_PROPERTY_AUTO(QString,saveFolder);
Q_PROPERTY_AUTO(int,captureMode); Q_PROPERTY_AUTO(int,captureMode);
Q_PROPERTY_AUTO(DrawData*,hitDrawData);
public: public:
ScreenshotBackground(QQuickItem* parent = nullptr); ScreenshotBackground(QQuickItem* parent = nullptr);
void paint(QPainter* painter) override; void paint(QPainter* painter) override;
Q_INVOKABLE void capture(const QPoint& start,const QPoint& end); Q_INVOKABLE void capture(const QPoint& start,const QPoint& end);
Q_INVOKABLE DrawData* appendDrawData(int drawType,QPoint start,QPoint end);
Q_INVOKABLE void updateDrawData(DrawData* data,QPoint start,QPoint end);
Q_INVOKABLE void clear();
Q_INVOKABLE DrawData* hit(const QPoint& point);
Q_SIGNAL void captrueToPixmapCompleted(QPixmap captrue); Q_SIGNAL void captrueToPixmapCompleted(QPixmap captrue);
Q_SIGNAL void captrueToFileCompleted(QUrl captrue); Q_SIGNAL void captrueToFileCompleted(QUrl captrue);
private: private:
@ -51,8 +27,6 @@ private:
qreal _devicePixelRatio; qreal _devicePixelRatio;
QSharedPointer<QQuickItemGrabResult> _grabResult; QSharedPointer<QQuickItemGrabResult> _grabResult;
QRect _captureRect; QRect _captureRect;
QList<DrawData*> _drawList;
int mouseSpacing = 3;
}; };

View File

@ -39,6 +39,7 @@ void FluentUIPlugin::registerTypes(const char *uri)
qmlRegisterType<FluHttpInterceptor>(uri,major,minor,"FluHttpInterceptor"); qmlRegisterType<FluHttpInterceptor>(uri,major,minor,"FluHttpInterceptor");
qmlRegisterType<FluHttp>(uri,major,minor,"FluHttp"); qmlRegisterType<FluHttp>(uri,major,minor,"FluHttp");
qmlRegisterType<HttpCallable>(uri,major,minor,"HttpCallable"); qmlRegisterType<HttpCallable>(uri,major,minor,"HttpCallable");
qmlRegisterType<HttpRequest>(uri,major,minor,"HttpRequest");
qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only");
qmlRegisterUncreatableMetaObject(FluHttpType::staticMetaObject, uri,major,minor,"FluHttpType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluHttpType::staticMetaObject, uri,major,minor,"FluHttpType", "Access to enums & flags only");
qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only");