diff --git a/example/qml-Qt6/global/ItemsOriginal.qml b/example/qml-Qt6/global/ItemsOriginal.qml index 2d066760..f19c7bef 100644 --- a/example/qml-Qt6/global/ItemsOriginal.qml +++ b/example/qml-Qt6/global/ItemsOriginal.qml @@ -397,7 +397,7 @@ FluObject{ onTap:{ navigationView.push(url) } } FluPaneItem{ - title:"Screenshot" + title:"Screenshot(Todo)" url:"qrc:/example/qml/page/T_Screenshot.qml" onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) } onTap:{ navigationView.push(url) } diff --git a/example/qml-Qt6/page/T_Http.qml b/example/qml-Qt6/page/T_Http.qml index 99a9b1dd..057862b9 100644 --- a/example/qml-Qt6/page/T_Http.qml +++ b/example/qml-Qt6/page/T_Http.qml @@ -56,7 +56,6 @@ FluContentPage{ onSuccess: (result)=>{ text_info.text = result - console.debug(result) } onCache: (result)=>{ @@ -86,7 +85,8 @@ FluContentPage{ implicitHeight: 36 text: "Get请求" onClicked: { - http.get("https://httpbingo.org/get",callable) + var request = http.newRequest("https://httpbingo.org/get") + http.get(request,callable) } } FluButton{ @@ -94,11 +94,13 @@ FluContentPage{ implicitHeight: 36 text: "Post表单请求" onClicked: { - var param = {} - param.custname = "朱子楚" - param.custtel = "1234567890" - param.custemail = "zhuzichu520@gmail.com" - http.post("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + var params = {} + params.custname = "朱子楚" + params.custtel = "1234567890" + params.custemail = "zhuzichu520@gmail.com" + request.params = params + http.post(request,callable) } } FluButton{ @@ -106,11 +108,13 @@ FluContentPage{ implicitHeight: 36 text: "Post Json请求" onClicked: { - var param = {} - param.custname = "朱子楚" - param.custtel = "1234567890" - param.custemail = "zhuzichu520@gmail.com" - http.postJson("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + var params = {} + params.custname = "朱子楚" + params.custtel = "1234567890" + params.custemail = "zhuzichu520@gmail.com" + request.params = params + http.postJson(request,callable) } } FluButton{ @@ -118,8 +122,9 @@ FluContentPage{ implicitHeight: 36 text: "Post String请求" onClicked: { - var param = "我命由我不由天" - http.postString("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + request.params = "我命由我不由天" + http.postString(request,callable) } } FluProgressButton{ @@ -133,8 +138,6 @@ FluContentPage{ } FluProgressButton{ 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 implicitWidth: parent.width implicitHeight: 36 @@ -150,6 +153,11 @@ FluContentPage{ 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{ id:callable_breakpoint_download onStart: { @@ -172,7 +180,7 @@ FluContentPage{ } } Component.onCompleted: { - progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath) + progress = http_breakpoint_download.getBreakPointProgress(request_breakpoint_download) } onClicked: { if(downloading){ @@ -180,9 +188,9 @@ FluContentPage{ return } if(progress === 1){ - FluTools.showFileInFolder(saveFilePath) + FluTools.showFileInFolder(request_breakpoint_download.downloadSavePath) }else{ - http_breakpoint_download.download(resourcePath,callable_breakpoint_download,saveFilePath) + http_breakpoint_download.download(request_breakpoint_download,callable_breakpoint_download) } } FluMenu{ @@ -191,7 +199,7 @@ FluContentPage{ FluMenuItem{ text: "删除文件" onClicked: { - if(FluTools.removeFile(btn_breakpoint_download.saveFilePath)){ + if(FluTools.removeFile(request_breakpoint_download.downloadSavePath)){ btn_breakpoint_download.progress = 0 } } @@ -221,9 +229,9 @@ FluContentPage{ implicitHeight: 36 text: "FirstCacheThenRequest缓存" onClicked: { - var param = {} - param.cacheMode = "FirstCacheThenRequest" - http_cache_firstcachethenrequest.post("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + request.params = {cacheMode:"FirstCacheThenRequest"} + http_cache_firstcachethenrequest.post(request,callable) } } FluButton{ @@ -231,9 +239,9 @@ FluContentPage{ implicitHeight: 36 text: "RequestFailedReadCache缓存" onClicked: { - var param = {} - param.cacheMode = "RequestFailedReadCache" - http_cache_requestfailedreadcache.post("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + request.params = {cacheMode:"RequestFailedReadCache"} + http_cache_requestfailedreadcache.post(request,callable) } } @@ -242,9 +250,9 @@ FluContentPage{ implicitHeight: 36 text: "IfNoneCacheRequest缓存" onClicked: { - var param = {} - param.cacheMode = "IfNoneCacheRequest" - http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + request.params = {cacheMode:"IfNoneCacheRequest"} + http_cache_ifnonecacherequest.post(request,callable) } } FluButton{ @@ -300,14 +308,16 @@ FluContentPage{ FileDialog { id: file_dialog onAccepted: { - var param = {} + var request = http.newRequest("https://httpbingo.org/post") + var params = {} for(var i=0;i"+request) - 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) + var request = http.newRequest("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest") + http.get(request,callable); } } diff --git a/example/qml/global/ItemsOriginal.qml b/example/qml/global/ItemsOriginal.qml index 8ba1b729..138a4cac 100644 --- a/example/qml/global/ItemsOriginal.qml +++ b/example/qml/global/ItemsOriginal.qml @@ -397,7 +397,7 @@ FluObject{ onTap:{ navigationView.push(url) } } FluPaneItem{ - title:"Screenshot" + title:"Screenshot(Todo)" url:"qrc:/example/qml/page/T_Screenshot.qml" onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) } onTap:{ navigationView.push(url) } diff --git a/example/qml/page/T_Http.qml b/example/qml/page/T_Http.qml index 7ab9e324..7a71889a 100644 --- a/example/qml/page/T_Http.qml +++ b/example/qml/page/T_Http.qml @@ -57,7 +57,6 @@ FluContentPage{ onSuccess: (result)=>{ text_info.text = result - console.debug(result) } onCache: (result)=>{ @@ -87,7 +86,8 @@ FluContentPage{ implicitHeight: 36 text: "Get请求" onClicked: { - http.get("https://httpbingo.org/get",callable) + var request = http.newRequest("https://httpbingo.org/get") + http.get(request,callable) } } FluButton{ @@ -95,11 +95,13 @@ FluContentPage{ implicitHeight: 36 text: "Post表单请求" onClicked: { - var param = {} - param.custname = "朱子楚" - param.custtel = "1234567890" - param.custemail = "zhuzichu520@gmail.com" - http.post("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + var params = {} + params.custname = "朱子楚" + params.custtel = "1234567890" + params.custemail = "zhuzichu520@gmail.com" + request.params = params + http.post(request,callable) } } FluButton{ @@ -107,11 +109,13 @@ FluContentPage{ implicitHeight: 36 text: "Post Json请求" onClicked: { - var param = {} - param.custname = "朱子楚" - param.custtel = "1234567890" - param.custemail = "zhuzichu520@gmail.com" - http.postJson("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + var params = {} + params.custname = "朱子楚" + params.custtel = "1234567890" + params.custemail = "zhuzichu520@gmail.com" + request.params = params + http.postJson(request,callable) } } FluButton{ @@ -119,8 +123,9 @@ FluContentPage{ implicitHeight: 36 text: "Post String请求" onClicked: { - var param = "我命由我不由天" - http.postString("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + request.params = "我命由我不由天" + http.postString(request,callable) } } FluProgressButton{ @@ -134,8 +139,6 @@ FluContentPage{ } FluProgressButton{ 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 implicitWidth: parent.width implicitHeight: 36 @@ -151,6 +154,11 @@ FluContentPage{ 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{ id:callable_breakpoint_download onStart: { @@ -173,7 +181,7 @@ FluContentPage{ } } Component.onCompleted: { - progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath) + progress = http_breakpoint_download.getBreakPointProgress(request_breakpoint_download) } onClicked: { if(downloading){ @@ -181,9 +189,9 @@ FluContentPage{ return } if(progress === 1){ - FluTools.showFileInFolder(saveFilePath) + FluTools.showFileInFolder(request_breakpoint_download.downloadSavePath) }else{ - http_breakpoint_download.download(resourcePath,callable_breakpoint_download,saveFilePath) + http_breakpoint_download.download(request_breakpoint_download,callable_breakpoint_download) } } FluMenu{ @@ -192,7 +200,7 @@ FluContentPage{ FluMenuItem{ text: "删除文件" onClicked: { - if(FluTools.removeFile(btn_breakpoint_download.saveFilePath)){ + if(FluTools.removeFile(request_breakpoint_download.downloadSavePath)){ btn_breakpoint_download.progress = 0 } } @@ -222,9 +230,9 @@ FluContentPage{ implicitHeight: 36 text: "FirstCacheThenRequest缓存" onClicked: { - var param = {} - param.cacheMode = "FirstCacheThenRequest" - http_cache_firstcachethenrequest.post("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + request.params = {cacheMode:"FirstCacheThenRequest"} + http_cache_firstcachethenrequest.post(request,callable) } } FluButton{ @@ -232,9 +240,9 @@ FluContentPage{ implicitHeight: 36 text: "RequestFailedReadCache缓存" onClicked: { - var param = {} - param.cacheMode = "RequestFailedReadCache" - http_cache_requestfailedreadcache.post("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + request.params = {cacheMode:"RequestFailedReadCache"} + http_cache_requestfailedreadcache.post(request,callable) } } @@ -243,9 +251,9 @@ FluContentPage{ implicitHeight: 36 text: "IfNoneCacheRequest缓存" onClicked: { - var param = {} - param.cacheMode = "IfNoneCacheRequest" - http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param) + var request = http.newRequest("https://httpbingo.org/post") + request.params = {cacheMode:"IfNoneCacheRequest"} + http_cache_ifnonecacherequest.post(request,callable) } } FluButton{ @@ -301,14 +309,16 @@ FluContentPage{ FileDialog { id: file_dialog onAccepted: { - var param = {} + var request = http.newRequest("https://httpbingo.org/post") + var params = {} for(var i=0;i HttpRequest::toMap(){ + QVariant _params; + if(params().isNull()){ + if(method() == "postString"){ + _params = ""; + }else{ + _params = QMap(); + } + }else{ + _params = params(); + } + QVariant _headers; + if(headers().isNull()){ + _headers = QMap(); + }else{ + _params = params(); + } + QMap 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) @@ -48,26 +77,27 @@ void FluHttp::cancel(){ } } -void FluHttp::post(QString url,HttpCallable* callable,QMap params,QMap headers){ - auto requestMap = toRequest(url,params,headers,"post"); - auto httpId = toHttpId(requestMap); +void FluHttp::post(HttpRequest* request,HttpCallable* callable){ + request->method("post"); + auto requestMap = request->toMap(); + auto httpId = request->httpId(); QMap data = invokeIntercept(requestMap).toMap(); QThreadPool::globalInstance()->start([=](){ onStart(callable); if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){ onCache(callable,readCache(httpId)); - onFinish(callable); + onFinish(callable,request); return; } if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){ onCache(callable,readCache(httpId)); } + QNetworkAccessManager manager; + manager.setTransferTimeout(timeout()); for (int i = 0; i < retry(); ++i) { - QNetworkAccessManager manager; - manager.setTransferTimeout(timeout()); - QUrl _url(url); - QNetworkRequest request(_url); - addHeaders(&request,data["headers"].toMap()); + QUrl url(request->url()); + QNetworkRequest req(url); + addHeaders(&req,data["headers"].toMap()); QHttpMultiPart multiPart(QHttpMultiPart::FormDataType); for (const auto& each : data["params"].toMap().toStdMap()) { @@ -80,7 +110,7 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap pa multiPart.append(part); } QEventLoop loop; - QNetworkReply* reply = manager.post(request,&multiPart); + QNetworkReply* reply = manager.post(req,&multiPart); _cacheReply.append(reply); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); @@ -104,34 +134,36 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap pa } } } - onFinish(callable); + onFinish(callable,request); }); } -void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap headers){ - auto requestMap = toRequest(url,params,headers,"postString"); - auto httpId = toHttpId(requestMap); +void FluHttp::postString(HttpRequest* request,HttpCallable* callable){ + request->method("postString"); + auto requestMap = request->toMap(); + auto httpId = request->httpId(); + QString params = request->params().toString(); QMap data = invokeIntercept(requestMap).toMap(); QThreadPool::globalInstance()->start([=](){ onStart(callable); if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){ onCache(callable,readCache(httpId)); - onFinish(callable); + onFinish(callable,request); return; } if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){ onCache(callable,readCache(httpId)); } + QNetworkAccessManager manager; + manager.setTransferTimeout(timeout()); for (int i = 0; i < retry(); ++i) { - QNetworkAccessManager manager; - manager.setTransferTimeout(timeout()); - QUrl _url(url); - QNetworkRequest request(_url); - addHeaders(&request,data["headers"].toMap()); + QUrl url(request->url()); + QNetworkRequest req(url); + addHeaders(&req,data["headers"].toMap()); QString contentType = QString("text/plain;charset=utf-8"); - request.setHeader(QNetworkRequest::ContentTypeHeader, contentType); + req.setHeader(QNetworkRequest::ContentTypeHeader, contentType); QEventLoop loop; - QNetworkReply* reply = manager.post(request,params.toUtf8()); + QNetworkReply* reply = manager.post(req,params.toUtf8()); _cacheReply.append(reply); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){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 params,QMap headers){ - auto requestMap = toRequest(url,params,headers,"postJson"); - auto httpId = toHttpId(requestMap); +void FluHttp::postJson(HttpRequest* request,HttpCallable* callable){ + request->method("postJson"); + auto requestMap = request->toMap(); + auto httpId = request->httpId(); QMap data = invokeIntercept(requestMap).toMap(); QThreadPool::globalInstance()->start([=](){ onStart(callable); if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){ onCache(callable,readCache(httpId)); - onFinish(callable); + onFinish(callable,request); return; } if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){ onCache(callable,readCache(httpId)); } + QNetworkAccessManager manager; + manager.setTransferTimeout(timeout()); for (int i = 0; i < retry(); ++i) { - QNetworkAccessManager manager; - manager.setTransferTimeout(timeout()); - QUrl _url(url); - QNetworkRequest request(_url); - addHeaders(&request,data["headers"].toMap()); + QUrl url(request->url()); + QNetworkRequest req(url); + addHeaders(&req,data["headers"].toMap()); QString contentType = QString("application/json;charset=utf-8"); - request.setHeader(QNetworkRequest::ContentTypeHeader, contentType); + req.setHeader(QNetworkRequest::ContentTypeHeader, contentType); 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); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); @@ -206,20 +239,15 @@ void FluHttp::postJson(QString url,HttpCallable* callable,QMapurl(); - QMap params = request->params().toMap(); - QMap headers = request->headers().toMap(); - get(url,callable,params,headers); -} -void FluHttp::get(QString url,HttpCallable* callable,QMap params,QMap headers){ - auto requestMap = toRequest(url,params,headers,"get"); - auto httpId = toHttpId(requestMap); +void FluHttp::get(HttpRequest* request,HttpCallable* callable){ + request->method("get"); + auto requestMap = request->toMap(); + auto httpId = request->httpId(); QMap data = invokeIntercept(requestMap).toMap(); QThreadPool::globalInstance()->start([=](){ onStart(callable); @@ -228,18 +256,18 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap par } if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){ onCache(callable,readCache(httpId)); - onFinish(callable); + onFinish(callable,request); return; } + QNetworkAccessManager manager; + manager.setTransferTimeout(timeout()); for (int i = 0; i < retry(); ++i) { - QNetworkAccessManager manager; - manager.setTransferTimeout(timeout()); - QUrl _url(url); - addQueryParam(&_url,data["params"].toMap()); - QNetworkRequest request(_url); - addHeaders(&request,data["headers"].toMap()); + QUrl url(request->url()); + addQueryParam(&url,data["params"].toMap()); + QNetworkRequest req(url); + addHeaders(&req,data["headers"].toMap()); QEventLoop loop; - QNetworkReply* reply = manager.get(request); + QNetworkReply* reply = manager.get(req); _cacheReply.append(reply); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); @@ -263,22 +291,23 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap par reply->deleteLater(); reply = nullptr; } - onFinish(callable); + onFinish(callable,request); }); } -void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap params,QMap headers){ - auto requestMap = toRequest(url,params,headers,"download"); - requestMap.insert("savePath",savePath); - auto httpId = toHttpId(requestMap); +void FluHttp::download(HttpRequest* request,HttpCallable* callable){ + request->method("download"); + auto requestMap = request->toMap(); + auto httpId = request->httpId(); + auto savePath = request->downloadSavePath(); QMap data = invokeIntercept(requestMap).toMap(); QThreadPool::globalInstance()->start([=](){ onStart(callable); QNetworkAccessManager manager; - QUrl _url(url); - addQueryParam(&_url,data["params"].toMap()); - QNetworkRequest request(_url); - addHeaders(&request,data["headers"].toMap()); + QUrl url(request->url()); + addQueryParam(&url,data["params"].toMap()); + QNetworkRequest req(url); + addHeaders(&req,data["headers"].toMap()); QSharedPointer file(new QFile(savePath)); QDir dir = QFileInfo(savePath).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){ onDownloadProgress(callable,fileSize,contentLength); onSuccess(callable,savePath); - onFinish(callable); + onFinish(callable,request); return; } if(fileSize==file->size()){ - request.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8()); + req.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8()); seek = fileSize; file->open(QIODevice::WriteOnly|QIODevice::Append); }else{ @@ -310,7 +339,7 @@ void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap< }else{ file->open(QIODevice::WriteOnly|QIODevice::Truncate); } - QNetworkReply* reply = manager.get(request); + QNetworkReply* reply = manager.get(req); _cacheReply.append(reply); if (!fileCache->open(QIODevice::WriteOnly|QIODevice::Truncate)) { @@ -342,21 +371,23 @@ void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap< } reply->deleteLater(); reply = nullptr; - onFinish(callable); + onFinish(callable,request); }); } -void FluHttp::upload(QString url,HttpCallable* callable,QMap params,QMap headers){ - auto requestMap = toRequest(url,params,headers,"upload"); +void FluHttp::upload(HttpRequest* request,HttpCallable* callable){ + request->method("upload"); + auto requestMap = request->toMap(); QMap data = invokeIntercept(requestMap).toMap(); QThreadPool::globalInstance()->start([=](){ onStart(callable); QNetworkAccessManager manager; manager.setTransferTimeout(timeout()); - QUrl _url(url); - QNetworkRequest request(_url); - addHeaders(&request,data["headers"].toMap()); + QUrl url(request->url()); + QNetworkRequest req(url); + addHeaders(&req,data["headers"].toMap()); QHttpMultiPart multiPart(QHttpMultiPart::FormDataType); + qDebug()< multiPart.append(part); } QEventLoop loop; - QNetworkReply* reply = manager.post(request,&multiPart); + QNetworkReply* reply = manager.post(req,&multiPart); _cacheReply.append(reply); connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();}); connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();}); @@ -391,20 +422,10 @@ void FluHttp::upload(QString url,HttpCallable* callable,QMap }else{ onError(callable,status,errorString,result); } - onFinish(callable); + onFinish(callable,request); }); } -QMap FluHttp::toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method){ - QMap request = { - {"url",url}, - {"params",params}, - {"headers",headers}, - {"method",method} - }; - return request; -} - QVariant FluHttp::invokeIntercept(QMap request){ if(!FluApp::getInstance()->httpInterceptor()){ return request; @@ -475,11 +496,10 @@ void FluHttp::handleCache(const QString& httpId,const QString& result){ file->write(FluTools::getInstance()->toBase64(result).toUtf8()); } -qreal FluHttp::breakPointDownloadProgress(QString url,QString savePath,QMap params,QMap headers){ - auto requestMap = toRequest(url,params,headers,"download"); - requestMap.insert("savePath",savePath); - auto httpId = toHttpId(requestMap); - QSharedPointer file(new QFile(savePath)); +qreal FluHttp::getBreakPointProgress(HttpRequest* request){ + request->method("download"); + auto httpId = request->httpId(); + QSharedPointer file(new QFile(request->downloadSavePath())); auto filePath = getCacheFilePath(httpId); QSharedPointer fileCache(new QFile(filePath)); if(fileCache->exists() && file->exists() && _breakPointDownload){ @@ -499,25 +519,25 @@ qreal FluHttp::breakPointDownloadProgress(QString url,QString savePath,QMapurl(url); return request; } -QString FluHttp::toHttpId(const QMap& map){ - return FluTools::getInstance()->sha256(QJsonDocument::fromVariant(QVariant(map)).toJson()); -} - void FluHttp::onStart(QPointer callable){ if(callable){ Q_EMIT callable->start(); } } -void FluHttp::onFinish(QPointer callable){ +void FluHttp::onFinish(QPointer callable,HttpRequest* request){ if(callable){ Q_EMIT callable->finish(); } + if(!request->parent()){ + delete request; + } } void FluHttp::onError(QPointer callable,int status,QString errorString,QString result){ diff --git a/src/FluHttp.h b/src/FluHttp.h index 2e8e1013..5d9c1863 100644 --- a/src/FluHttp.h +++ b/src/FluHttp.h @@ -13,12 +13,12 @@ class HttpRequest : public QObject{ Q_PROPERTY_AUTO(QVariant,params); Q_PROPERTY_AUTO(QVariant,headers); Q_PROPERTY_AUTO(QString,method); + Q_PROPERTY_AUTO(QString,downloadSavePath); QML_NAMED_ELEMENT(HttpRequest) public: explicit HttpRequest(QObject *parent = nullptr); - ~HttpRequest(){ - qDebug()<<"------------析构了"< toMap(); + Q_INVOKABLE QString httpId(); }; class HttpCallable : public QObject{ @@ -46,8 +46,6 @@ class FluHttp : public QObject QML_NAMED_ELEMENT(FluHttp) private: QVariant invokeIntercept(QMap request); - QMap toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method); - QString toHttpId(const QMap& map); void addQueryParam(QUrl* url,const QMap& params); void addHeaders(QNetworkRequest* request,const QMap& params); void handleCache(const QString& httpId, const QString& result); @@ -55,7 +53,7 @@ private: bool cacheExists(const QString& httpId); QString getCacheFilePath(const QString& httpId); void onStart(QPointer callable); - void onFinish(QPointer callable); + void onFinish(QPointer callable,HttpRequest* request); void onError(QPointer callable,int status,QString errorString,QString result); void onSuccess(QPointer callable,QString result); void onCache(QPointer callable,QString result); @@ -64,16 +62,14 @@ private: public: explicit FluHttp(QObject *parent = nullptr); ~FluHttp(); - Q_INVOKABLE HttpRequest* newRequest(); - Q_INVOKABLE void get2(HttpRequest* request,HttpCallable* callable); - //神坑!!! 如果参数使用QVariantMap会有问题,在6.4.3版本中QML一调用就会编译失败。所以改用QMap - Q_INVOKABLE void get(QString url,HttpCallable* callable,QMap params= {},QMap headers = {}); - Q_INVOKABLE void post(QString url,HttpCallable* callable,QMap params= {},QMap headers = {}); - Q_INVOKABLE void postString(QString url,HttpCallable* callable,QString params = "",QMap headers = {}); - Q_INVOKABLE void postJson(QString url,HttpCallable* callable,QMap params = {},QMap headers = {}); - Q_INVOKABLE void download(QString url,HttpCallable* callable,QString savePath,QMap params = {},QMap headers = {}); - Q_INVOKABLE void upload(QString url,HttpCallable* callable,QMap params = {},QMap headers = {}); - Q_INVOKABLE qreal breakPointDownloadProgress(QString url,QString savePath,QMap params = {},QMap headers = {}); + Q_INVOKABLE HttpRequest* newRequest(QString url = ""); + Q_INVOKABLE void get(HttpRequest* request,HttpCallable* callable); + Q_INVOKABLE void post(HttpRequest* request,HttpCallable* callable); + Q_INVOKABLE void postString(HttpRequest* request,HttpCallable* callable); + Q_INVOKABLE void postJson(HttpRequest* request,HttpCallable* callable); + Q_INVOKABLE void download(HttpRequest* request,HttpCallable* callable); + Q_INVOKABLE void upload(HttpRequest* request,HttpCallable* callable); + Q_INVOKABLE qreal getBreakPointProgress(HttpRequest* request); Q_INVOKABLE void cancel(); private: QList> _cacheReply; diff --git a/src/Qt5/imports/FluentUI/Controls/FluScreenshot.qml b/src/Qt5/imports/FluentUI/Controls/FluScreenshot.qml index 55f5dc53..c2f987d9 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluScreenshot.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluScreenshot.qml @@ -26,7 +26,7 @@ Item{ Component{ id:com_screen 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 flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint x:-1 @@ -123,7 +123,7 @@ Item{ MouseArea{ property point clickPos: Qt.point(0,0) anchors.fill: parent - cursorShape: Qt.SizeAllCursor + cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor onPressed: (mouse)=>{ clickPos = Qt.point(mouse.x, mouse.y) @@ -134,7 +134,7 @@ Item{ 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) + 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) } @@ -477,7 +477,7 @@ Item{ width: 100 height: 40 visible: { - if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){ + if(isZeroPos){ return false } if(d.enablePosition){ diff --git a/src/Qt5/imports/FluentUI/plugins.qmltypes b/src/Qt5/imports/FluentUI/plugins.qmltypes index 82a4c78d..c2b3c972 100644 --- a/src/Qt5/imports/FluentUI/plugins.qmltypes +++ b/src/Qt5/imports/FluentUI/plugins.qmltypes @@ -4,7 +4,7 @@ import QtQuick.tooling 1.2 // It is used for QML tooling purposes only. // // 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 { dependencies: ["QtQuick 2.0"] @@ -74,136 +74,45 @@ Module { Property { name: "cacheDir"; type: "string" } Property { name: "breakPointDownload"; type: "bool" } Method { - name: "get" + name: "newRequest" + type: "HttpRequest*" 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 { name: "get" - Parameter { name: "url"; type: "string" } - Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } - Parameter { name: "params"; type: "QVariantMap" } - } - Method { - name: "get" - Parameter { name: "url"; type: "string" } + Parameter { name: "request"; type: "HttpRequest"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } } Method { name: "post" - Parameter { name: "url"; type: "string" } - 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: "request"; type: "HttpRequest"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } } Method { name: "postString" - Parameter { name: "url"; type: "string" } - 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: "request"; type: "HttpRequest"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } } Method { name: "postJson" - Parameter { name: "url"; type: "string" } - 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: "request"; type: "HttpRequest"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } } Method { name: "download" - Parameter { name: "url"; type: "string" } + Parameter { name: "request"; type: "HttpRequest"; 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 { name: "upload" - Parameter { name: "url"; type: "string" } - 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: "request"; type: "HttpRequest"; isPointer: true } Parameter { name: "callable"; type: "HttpCallable"; isPointer: true } } Method { - name: "breakPointDownloadProgress" + name: "getBreakPointProgress" type: "double" - Parameter { name: "url"; type: "string" } - 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" } + Parameter { name: "request"; type: "HttpRequest"; isPointer: true } } Method { name: "cancel" } } @@ -1839,10 +1748,22 @@ Module { } Signal { name: "uploadProgress" - Parameter { name: "recv"; type: "qlonglong" } + Parameter { name: "sent"; 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 { name: "QRCode" defaultProperty: "data" @@ -1872,7 +1793,6 @@ Module { exportMetaObjectRevisions: [0] Property { name: "saveFolder"; type: "string" } Property { name: "captureMode"; type: "int" } - Property { name: "hitDrawData"; type: "DrawData"; isPointer: true } Signal { name: "captrueToPixmapCompleted" Parameter { name: "captrue"; type: "QPixmap" } @@ -1886,25 +1806,6 @@ Module { Parameter { name: "start"; 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 { name: "WindowHelper" diff --git a/src/Qt6/imports/FluentUI/Controls/FluScreenshot.qml b/src/Qt6/imports/FluentUI/Controls/FluScreenshot.qml index e8ad744b..e080a0db 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluScreenshot.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluScreenshot.qml @@ -15,7 +15,6 @@ Item{ signal captrueCompleted(var captrue) QtObject{ id:d - property bool isEdit: false property int dotMouseSize: control.dotSize+10 property int dotMargins: -(control.dotSize-control.borderSize)/2 property bool enablePosition: false @@ -27,7 +26,7 @@ Item{ Component{ id:com_screen 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 flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint x:-1 @@ -42,8 +41,7 @@ Item{ } } Component.onCompleted: { - d.isEdit = false - setGeometry(0,0,screenshot_background.width,screenshot_background.height) + setGeometry(0,0,screenshot_background.width,screenshot_background.height+1) } ScreenshotBackground{ id:screenshot_background @@ -110,8 +108,6 @@ Item{ } screenshot.start = 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 MouseArea{ property point clickPos: Qt.point(0,0) - property var currentData - property bool enablePositionChanged : false - property var hitData anchors.fill: parent - hoverEnabled: true cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor onPressed: (mouse)=>{ - if(hitData){ - 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) - } + clickPos = Qt.point(mouse.x, mouse.y) } - onReleased: { - enablePositionChanged = false - } - onCanceled: { - enablePositionChanged = false - } - onClicked: { - if(hitData){ - screenshot_background.hitDrawData = hitData - } - } onPositionChanged: (mouse)=>{ - - if(!enablePositionChanged){ - hitData = screenshot_background.hit(Qt.point(rect_capture.x + mouse.x,rect_capture.y + mouse.y)) - if(hitData){ - FluTools.setOverrideCursor(Qt.SizeAllCursor) - }else{ - FluTools.restoreOverrideCursor() - } - 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) - } + 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{ - width: 140 + width: 100 height: 40 visible: { - if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){ + if(isZeroPos){ return false } if(d.enablePosition){ @@ -544,12 +498,6 @@ Item{ RowLayout{ anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right - FluIconButton{ - iconSource: FluentIcons.Stop - onClicked: { - d.isEdit = true - } - } FluIconButton{ iconSource: FluentIcons.Cancel iconSize: 18 diff --git a/src/Screenshot.cpp b/src/Screenshot.cpp index e5a43507..ccb9f024 100644 --- a/src/Screenshot.cpp +++ b/src/Screenshot.cpp @@ -43,72 +43,17 @@ ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedIt } setWidth(w); setHeight(h); - connect(this,&ScreenshotBackground::hitDrawDataChanged,this,[=]{update();}); } void ScreenshotBackground::paint(QPainter* painter) { painter->save(); _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); - 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(); } -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){ - hitDrawData(nullptr); update(); auto pixelRatio = qApp->primaryScreen()->devicePixelRatio(); 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)); } } - -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(); -} - diff --git a/src/Screenshot.h b/src/Screenshot.h index f393bdfd..96ec7b64 100644 --- a/src/Screenshot.h +++ b/src/Screenshot.h @@ -8,40 +8,16 @@ #include "stdafx.h" #include -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 { Q_OBJECT; QML_NAMED_ELEMENT(ScreenshotBackground) Q_PROPERTY_AUTO(QString,saveFolder); Q_PROPERTY_AUTO(int,captureMode); - Q_PROPERTY_AUTO(DrawData*,hitDrawData); public: ScreenshotBackground(QQuickItem* parent = nullptr); void paint(QPainter* painter) override; 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 captrueToFileCompleted(QUrl captrue); private: @@ -51,8 +27,6 @@ private: qreal _devicePixelRatio; QSharedPointer _grabResult; QRect _captureRect; - QList _drawList; - int mouseSpacing = 3; }; diff --git a/src/fluentuiplugin.cpp b/src/fluentuiplugin.cpp index 307b2f69..35b88a9c 100644 --- a/src/fluentuiplugin.cpp +++ b/src/fluentuiplugin.cpp @@ -39,6 +39,7 @@ void FluentUIPlugin::registerTypes(const char *uri) qmlRegisterType(uri,major,minor,"FluHttpInterceptor"); qmlRegisterType(uri,major,minor,"FluHttp"); qmlRegisterType(uri,major,minor,"HttpCallable"); + qmlRegisterType(uri,major,minor,"HttpRequest"); 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(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only");