mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-26 13:27:05 +08:00
update
This commit is contained in:
parent
c92d807ec1
commit
573898149a
@ -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) }
|
||||
|
@ -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<selectedFiles.length;i++){
|
||||
var fileUrl = selectedFiles[i]
|
||||
var fileName = FluTools.getFileNameByUrl(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
|
||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
||||
onAccepted: {
|
||||
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
||||
http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable_download,path)
|
||||
var request = http.newRequest("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
|
||||
request.downloadSavePath = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
||||
http.download(request,callable_download)
|
||||
}
|
||||
}
|
||||
|
||||
FluArea{
|
||||
anchors{
|
||||
top: layout_flick.top
|
||||
|
@ -334,21 +334,9 @@ CustomWindow {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// HttpRequest{
|
||||
// id:reuqest
|
||||
// url: "https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest"
|
||||
// }
|
||||
|
||||
|
||||
function checkUpdate(){
|
||||
var request = http.newRequest()
|
||||
console.debug("-------------------->"+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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) }
|
||||
|
@ -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<selectedFiles.length;i++){
|
||||
var fileUrl = selectedFiles[i]
|
||||
var fileName = FluTools.getFileNameByUrl(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
|
||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
||||
onAccepted: {
|
||||
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
||||
http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable_download,path)
|
||||
var request = http.newRequest("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
|
||||
request.downloadSavePath = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
||||
http.download(request,callable_download)
|
||||
}
|
||||
}
|
||||
|
||||
FluArea{
|
||||
anchors{
|
||||
top: layout_flick.top
|
||||
|
@ -139,7 +139,7 @@ CustomWindow {
|
||||
id:loader
|
||||
lazy: true
|
||||
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{
|
||||
@ -336,7 +336,8 @@ CustomWindow {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
210
src/FluHttp.cpp
210
src/FluHttp.cpp
@ -17,8 +17,37 @@
|
||||
HttpRequest::HttpRequest(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)
|
||||
@ -48,26 +77,27 @@ void FluHttp::cancel(){
|
||||
}
|
||||
}
|
||||
|
||||
void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> 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<QString, QVariant> 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<QString, QVariant> 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<QString, QVariant> pa
|
||||
}
|
||||
}
|
||||
}
|
||||
onFinish(callable);
|
||||
onFinish(callable,request);
|
||||
});
|
||||
}
|
||||
|
||||
void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<QString, QVariant> 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<QString, QVariant> 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<QString, QVariant> params,QMap<QString, QVariant> 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<QString, QVariant> 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,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){
|
||||
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<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||
QThreadPool::globalInstance()->start([=](){
|
||||
onStart(callable);
|
||||
@ -228,18 +256,18 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> 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<QString, QVariant> par
|
||||
reply->deleteLater();
|
||||
reply = nullptr;
|
||||
}
|
||||
onFinish(callable);
|
||||
onFinish(callable,request);
|
||||
});
|
||||
}
|
||||
|
||||
void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap<QString, QVariant> params,QMap<QString, QVariant> 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<QString, QVariant> 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<QFile> 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<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||
auto requestMap = toRequest(url,params,headers,"upload");
|
||||
void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
|
||||
request->method("upload");
|
||||
auto requestMap = request->toMap();
|
||||
QMap<QString, QVariant> 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()<<data["params"].toMap();
|
||||
for (const auto& each : data["params"].toMap().toStdMap())
|
||||
{
|
||||
const QString& key = each.first;
|
||||
@ -372,7 +403,7 @@ void FluHttp::upload(QString url,HttpCallable* callable,QMap<QString, QVariant>
|
||||
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<QString, QVariant>
|
||||
}else{
|
||||
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){
|
||||
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<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||
auto requestMap = toRequest(url,params,headers,"download");
|
||||
requestMap.insert("savePath",savePath);
|
||||
auto httpId = toHttpId(requestMap);
|
||||
QSharedPointer<QFile> file(new QFile(savePath));
|
||||
qreal FluHttp::getBreakPointProgress(HttpRequest* request){
|
||||
request->method("download");
|
||||
auto httpId = request->httpId();
|
||||
QSharedPointer<QFile> file(new QFile(request->downloadSavePath()));
|
||||
auto filePath = getCacheFilePath(httpId);
|
||||
QSharedPointer<QFile> fileCache(new QFile(filePath));
|
||||
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();
|
||||
request->url(url);
|
||||
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){
|
||||
if(callable){
|
||||
Q_EMIT callable->start();
|
||||
}
|
||||
}
|
||||
|
||||
void FluHttp::onFinish(QPointer<HttpCallable> callable){
|
||||
void FluHttp::onFinish(QPointer<HttpCallable> callable,HttpRequest* request){
|
||||
if(callable){
|
||||
Q_EMIT callable->finish();
|
||||
}
|
||||
if(!request->parent()){
|
||||
delete request;
|
||||
}
|
||||
}
|
||||
|
||||
void FluHttp::onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result){
|
||||
|
@ -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()<<"------------析构了"<<url();
|
||||
}
|
||||
QMap<QString, QVariant> 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<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 addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& 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<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 onSuccess(QPointer<HttpCallable> callable,QString result);
|
||||
void onCache(QPointer<HttpCallable> 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<QString, QVariant>
|
||||
Q_INVOKABLE void get(QString url,HttpCallable* callable,QMap<QString, QVariant> params= {},QMap<QString, QVariant> headers = {});
|
||||
Q_INVOKABLE void post(QString url,HttpCallable* callable,QMap<QString, QVariant> params= {},QMap<QString, QVariant> headers = {});
|
||||
Q_INVOKABLE void postString(QString url,HttpCallable* callable,QString params = "",QMap<QString, QVariant> headers = {});
|
||||
Q_INVOKABLE void postJson(QString url,HttpCallable* callable,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {});
|
||||
Q_INVOKABLE void download(QString url,HttpCallable* callable,QString savePath,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {});
|
||||
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 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<QPointer<QNetworkReply>> _cacheReply;
|
||||
|
@ -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){
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -8,40 +8,16 @@
|
||||
#include "stdafx.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
|
||||
{
|
||||
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<QQuickItemGrabResult> _grabResult;
|
||||
QRect _captureRect;
|
||||
QList<DrawData*> _drawList;
|
||||
int mouseSpacing = 3;
|
||||
};
|
||||
|
||||
|
||||
|
@ -39,6 +39,7 @@ void FluentUIPlugin::registerTypes(const char *uri)
|
||||
qmlRegisterType<FluHttpInterceptor>(uri,major,minor,"FluHttpInterceptor");
|
||||
qmlRegisterType<FluHttp>(uri,major,minor,"FluHttp");
|
||||
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(FluHttpType::staticMetaObject, uri,major,minor,"FluHttpType", "Access to enums & flags only");
|
||||
qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only");
|
||||
|
Loading…
Reference in New Issue
Block a user