Compare commits
No commits in common. "249c294926c5eec6431939f5434a39d0693b6523" and "c92d807ec1b785a2baa73089275641e415380f44" have entirely different histories.
249c294926
...
c92d807ec1
|
@ -397,7 +397,7 @@ FluObject{
|
||||||
onTap:{ navigationView.push(url) }
|
onTap:{ navigationView.push(url) }
|
||||||
}
|
}
|
||||||
FluPaneItem{
|
FluPaneItem{
|
||||||
title:"Screenshot(Todo)"
|
title:"Screenshot"
|
||||||
url:"qrc:/example/qml/page/T_Screenshot.qml"
|
url:"qrc:/example/qml/page/T_Screenshot.qml"
|
||||||
onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) }
|
onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) }
|
||||||
onTap:{ navigationView.push(url) }
|
onTap:{ navigationView.push(url) }
|
||||||
|
|
|
@ -56,10 +56,12 @@ FluContentPage{
|
||||||
onSuccess:
|
onSuccess:
|
||||||
(result)=>{
|
(result)=>{
|
||||||
text_info.text = result
|
text_info.text = result
|
||||||
|
console.debug(result)
|
||||||
}
|
}
|
||||||
onCache:
|
onCache:
|
||||||
(result)=>{
|
(result)=>{
|
||||||
text_info.text = result
|
text_info.text = result
|
||||||
|
console.debug(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +86,7 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "Get请求"
|
text: "Get请求"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/get")
|
http.get("https://httpbingo.org/get",callable)
|
||||||
http.get(request,callable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -93,13 +94,11 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "Post表单请求"
|
text: "Post表单请求"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
var params = {}
|
param.custname = "朱子楚"
|
||||||
params.custname = "朱子楚"
|
param.custtel = "1234567890"
|
||||||
params.custtel = "1234567890"
|
param.custemail = "zhuzichu520@gmail.com"
|
||||||
params.custemail = "zhuzichu520@gmail.com"
|
http.post("https://httpbingo.org/post",callable,param)
|
||||||
request.params = params
|
|
||||||
http.post(request,callable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -107,13 +106,11 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "Post Json请求"
|
text: "Post Json请求"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
var params = {}
|
param.custname = "朱子楚"
|
||||||
params.custname = "朱子楚"
|
param.custtel = "1234567890"
|
||||||
params.custtel = "1234567890"
|
param.custemail = "zhuzichu520@gmail.com"
|
||||||
params.custemail = "zhuzichu520@gmail.com"
|
http.postJson("https://httpbingo.org/post",callable,param)
|
||||||
request.params = params
|
|
||||||
http.postJson(request,callable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -121,9 +118,8 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "Post String请求"
|
text: "Post String请求"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = "我命由我不由天"
|
||||||
request.params = "我命由我不由天"
|
http.postString("https://httpbingo.org/post",callable,param)
|
||||||
http.postString(request,callable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluProgressButton{
|
FluProgressButton{
|
||||||
|
@ -137,6 +133,8 @@ FluContentPage{
|
||||||
}
|
}
|
||||||
FluProgressButton{
|
FluProgressButton{
|
||||||
property bool downloading: false
|
property bool downloading: false
|
||||||
|
property string saveFilePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
|
||||||
|
property string resourcePath: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
||||||
id:btn_breakpoint_download
|
id:btn_breakpoint_download
|
||||||
implicitWidth: parent.width
|
implicitWidth: parent.width
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
|
@ -152,11 +150,6 @@ FluContentPage{
|
||||||
return "继续下载"
|
return "继续下载"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HttpRequest{
|
|
||||||
id:request_breakpoint_download
|
|
||||||
url: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
|
||||||
downloadSavePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
|
|
||||||
}
|
|
||||||
HttpCallable{
|
HttpCallable{
|
||||||
id:callable_breakpoint_download
|
id:callable_breakpoint_download
|
||||||
onStart: {
|
onStart: {
|
||||||
|
@ -179,7 +172,7 @@ FluContentPage{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
progress = http_breakpoint_download.getBreakPointProgress(request_breakpoint_download)
|
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath)
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(downloading){
|
if(downloading){
|
||||||
|
@ -187,9 +180,9 @@ FluContentPage{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(progress === 1){
|
if(progress === 1){
|
||||||
FluTools.showFileInFolder(request_breakpoint_download.downloadSavePath)
|
FluTools.showFileInFolder(saveFilePath)
|
||||||
}else{
|
}else{
|
||||||
http_breakpoint_download.download(request_breakpoint_download,callable_breakpoint_download)
|
http_breakpoint_download.download(resourcePath,callable_breakpoint_download,saveFilePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluMenu{
|
FluMenu{
|
||||||
|
@ -198,7 +191,7 @@ FluContentPage{
|
||||||
FluMenuItem{
|
FluMenuItem{
|
||||||
text: "删除文件"
|
text: "删除文件"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(FluTools.removeFile(request_breakpoint_download.downloadSavePath)){
|
if(FluTools.removeFile(btn_breakpoint_download.saveFilePath)){
|
||||||
btn_breakpoint_download.progress = 0
|
btn_breakpoint_download.progress = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,9 +221,9 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "FirstCacheThenRequest缓存"
|
text: "FirstCacheThenRequest缓存"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
request.params = {cacheMode:"FirstCacheThenRequest"}
|
param.cacheMode = "FirstCacheThenRequest"
|
||||||
http_cache_firstcachethenrequest.post(request,callable)
|
http_cache_firstcachethenrequest.post("https://httpbingo.org/post",callable,param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -238,9 +231,9 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "RequestFailedReadCache缓存"
|
text: "RequestFailedReadCache缓存"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
request.params = {cacheMode:"RequestFailedReadCache"}
|
param.cacheMode = "RequestFailedReadCache"
|
||||||
http_cache_requestfailedreadcache.post(request,callable)
|
http_cache_requestfailedreadcache.post("https://httpbingo.org/post",callable,param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,9 +242,9 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "IfNoneCacheRequest缓存"
|
text: "IfNoneCacheRequest缓存"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
request.params = {cacheMode:"IfNoneCacheRequest"}
|
param.cacheMode = "IfNoneCacheRequest"
|
||||||
http_cache_ifnonecacherequest.post(request,callable)
|
http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -307,16 +300,14 @@ FluContentPage{
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: file_dialog
|
id: file_dialog
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
var params = {}
|
|
||||||
for(var i=0;i<selectedFiles.length;i++){
|
for(var i=0;i<selectedFiles.length;i++){
|
||||||
var fileUrl = selectedFiles[i]
|
var fileUrl = selectedFiles[i]
|
||||||
var fileName = FluTools.getFileNameByUrl(fileUrl)
|
var fileName = FluTools.getFileNameByUrl(fileUrl)
|
||||||
var filePath = FluTools.toLocalPath(fileUrl)
|
var filePath = FluTools.toLocalPath(fileUrl)
|
||||||
params[fileName] = filePath
|
param[fileName] = filePath
|
||||||
}
|
}
|
||||||
request.params = params
|
http.upload("https://httpbingo.org/post",callable_upload,param)
|
||||||
http.upload(request,callable_upload)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,11 +339,11 @@ FluContentPage{
|
||||||
id: folder_dialog
|
id: folder_dialog
|
||||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
var request = http.newRequest("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
|
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
||||||
request.downloadSavePath = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable_download,path)
|
||||||
http.download(request,callable_download)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FluArea{
|
FluArea{
|
||||||
anchors{
|
anchors{
|
||||||
top: layout_flick.top
|
top: layout_flick.top
|
||||||
|
|
|
@ -334,9 +334,21 @@ CustomWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// HttpRequest{
|
||||||
|
// id:reuqest
|
||||||
|
// url: "https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest"
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
function checkUpdate(){
|
function checkUpdate(){
|
||||||
var request = http.newRequest("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest")
|
var request = http.newRequest()
|
||||||
http.get(request,callable);
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,7 +397,7 @@ FluObject{
|
||||||
onTap:{ navigationView.push(url) }
|
onTap:{ navigationView.push(url) }
|
||||||
}
|
}
|
||||||
FluPaneItem{
|
FluPaneItem{
|
||||||
title:"Screenshot(Todo)"
|
title:"Screenshot"
|
||||||
url:"qrc:/example/qml/page/T_Screenshot.qml"
|
url:"qrc:/example/qml/page/T_Screenshot.qml"
|
||||||
onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) }
|
onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) }
|
||||||
onTap:{ navigationView.push(url) }
|
onTap:{ navigationView.push(url) }
|
||||||
|
|
|
@ -57,10 +57,12 @@ FluContentPage{
|
||||||
onSuccess:
|
onSuccess:
|
||||||
(result)=>{
|
(result)=>{
|
||||||
text_info.text = result
|
text_info.text = result
|
||||||
|
console.debug(result)
|
||||||
}
|
}
|
||||||
onCache:
|
onCache:
|
||||||
(result)=>{
|
(result)=>{
|
||||||
text_info.text = result
|
text_info.text = result
|
||||||
|
console.debug(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +87,7 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "Get请求"
|
text: "Get请求"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/get")
|
http.get("https://httpbingo.org/get",callable)
|
||||||
http.get(request,callable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -94,13 +95,11 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "Post表单请求"
|
text: "Post表单请求"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
var params = {}
|
param.custname = "朱子楚"
|
||||||
params.custname = "朱子楚"
|
param.custtel = "1234567890"
|
||||||
params.custtel = "1234567890"
|
param.custemail = "zhuzichu520@gmail.com"
|
||||||
params.custemail = "zhuzichu520@gmail.com"
|
http.post("https://httpbingo.org/post",callable,param)
|
||||||
request.params = params
|
|
||||||
http.post(request,callable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -108,13 +107,11 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "Post Json请求"
|
text: "Post Json请求"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
var params = {}
|
param.custname = "朱子楚"
|
||||||
params.custname = "朱子楚"
|
param.custtel = "1234567890"
|
||||||
params.custtel = "1234567890"
|
param.custemail = "zhuzichu520@gmail.com"
|
||||||
params.custemail = "zhuzichu520@gmail.com"
|
http.postJson("https://httpbingo.org/post",callable,param)
|
||||||
request.params = params
|
|
||||||
http.postJson(request,callable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -122,9 +119,8 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "Post String请求"
|
text: "Post String请求"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = "我命由我不由天"
|
||||||
request.params = "我命由我不由天"
|
http.postString("https://httpbingo.org/post",callable,param)
|
||||||
http.postString(request,callable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluProgressButton{
|
FluProgressButton{
|
||||||
|
@ -138,6 +134,8 @@ FluContentPage{
|
||||||
}
|
}
|
||||||
FluProgressButton{
|
FluProgressButton{
|
||||||
property bool downloading: false
|
property bool downloading: false
|
||||||
|
property string saveFilePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
|
||||||
|
property string resourcePath: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
||||||
id:btn_breakpoint_download
|
id:btn_breakpoint_download
|
||||||
implicitWidth: parent.width
|
implicitWidth: parent.width
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
|
@ -153,11 +151,6 @@ FluContentPage{
|
||||||
return "继续下载"
|
return "继续下载"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HttpRequest{
|
|
||||||
id:request_breakpoint_download
|
|
||||||
url: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
|
|
||||||
downloadSavePath: FluTools.getApplicationDirPath()+ "/download/big_buck_bunny.mp4"
|
|
||||||
}
|
|
||||||
HttpCallable{
|
HttpCallable{
|
||||||
id:callable_breakpoint_download
|
id:callable_breakpoint_download
|
||||||
onStart: {
|
onStart: {
|
||||||
|
@ -180,7 +173,7 @@ FluContentPage{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
progress = http_breakpoint_download.getBreakPointProgress(request_breakpoint_download)
|
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath)
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(downloading){
|
if(downloading){
|
||||||
|
@ -188,9 +181,9 @@ FluContentPage{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(progress === 1){
|
if(progress === 1){
|
||||||
FluTools.showFileInFolder(request_breakpoint_download.downloadSavePath)
|
FluTools.showFileInFolder(saveFilePath)
|
||||||
}else{
|
}else{
|
||||||
http_breakpoint_download.download(request_breakpoint_download,callable_breakpoint_download)
|
http_breakpoint_download.download(resourcePath,callable_breakpoint_download,saveFilePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluMenu{
|
FluMenu{
|
||||||
|
@ -199,7 +192,7 @@ FluContentPage{
|
||||||
FluMenuItem{
|
FluMenuItem{
|
||||||
text: "删除文件"
|
text: "删除文件"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(FluTools.removeFile(request_breakpoint_download.downloadSavePath)){
|
if(FluTools.removeFile(btn_breakpoint_download.saveFilePath)){
|
||||||
btn_breakpoint_download.progress = 0
|
btn_breakpoint_download.progress = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,9 +222,9 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "FirstCacheThenRequest缓存"
|
text: "FirstCacheThenRequest缓存"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
request.params = {cacheMode:"FirstCacheThenRequest"}
|
param.cacheMode = "FirstCacheThenRequest"
|
||||||
http_cache_firstcachethenrequest.post(request,callable)
|
http_cache_firstcachethenrequest.post("https://httpbingo.org/post",callable,param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -239,9 +232,9 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "RequestFailedReadCache缓存"
|
text: "RequestFailedReadCache缓存"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
request.params = {cacheMode:"RequestFailedReadCache"}
|
param.cacheMode = "RequestFailedReadCache"
|
||||||
http_cache_requestfailedreadcache.post(request,callable)
|
http_cache_requestfailedreadcache.post("https://httpbingo.org/post",callable,param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,9 +243,9 @@ FluContentPage{
|
||||||
implicitHeight: 36
|
implicitHeight: 36
|
||||||
text: "IfNoneCacheRequest缓存"
|
text: "IfNoneCacheRequest缓存"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
request.params = {cacheMode:"IfNoneCacheRequest"}
|
param.cacheMode = "IfNoneCacheRequest"
|
||||||
http_cache_ifnonecacherequest.post(request,callable)
|
http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluButton{
|
FluButton{
|
||||||
|
@ -308,16 +301,14 @@ FluContentPage{
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: file_dialog
|
id: file_dialog
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
var request = http.newRequest("https://httpbingo.org/post")
|
var param = {}
|
||||||
var params = {}
|
|
||||||
for(var i=0;i<selectedFiles.length;i++){
|
for(var i=0;i<selectedFiles.length;i++){
|
||||||
var fileUrl = selectedFiles[i]
|
var fileUrl = selectedFiles[i]
|
||||||
var fileName = FluTools.getFileNameByUrl(fileUrl)
|
var fileName = FluTools.getFileNameByUrl(fileUrl)
|
||||||
var filePath = FluTools.toLocalPath(fileUrl)
|
var filePath = FluTools.toLocalPath(fileUrl)
|
||||||
params[fileName] = filePath
|
param[fileName] = filePath
|
||||||
}
|
}
|
||||||
request.params = params
|
http.upload("https://httpbingo.org/post",callable_upload,param)
|
||||||
http.upload(request,callable_upload)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,11 +340,11 @@ FluContentPage{
|
||||||
id: folder_dialog
|
id: folder_dialog
|
||||||
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
var request = http.newRequest("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
|
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
||||||
request.downloadSavePath = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
|
http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable_download,path)
|
||||||
http.download(request,callable_download)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FluArea{
|
FluArea{
|
||||||
anchors{
|
anchors{
|
||||||
top: layout_flick.top
|
top: layout_flick.top
|
||||||
|
|
|
@ -139,7 +139,7 @@ CustomWindow {
|
||||||
id:loader
|
id:loader
|
||||||
lazy: true
|
lazy: true
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
source: "https://zhu-zichu.gitee.io/Qt6_156_LieflatPage.qml"
|
source: "https://zhu-zichu.gitee.io/Qt5_156_LieflatPage.qml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
front: Item{
|
front: Item{
|
||||||
|
@ -336,8 +336,7 @@ CustomWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUpdate(){
|
function checkUpdate(){
|
||||||
var request = http.newRequest("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest")
|
http.get("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest",callable)
|
||||||
http.get(request,callable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
215
src/FluHttp.cpp
215
src/FluHttp.cpp
|
@ -17,42 +17,8 @@
|
||||||
HttpRequest::HttpRequest(QObject *parent)
|
HttpRequest::HttpRequest(QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
{
|
{
|
||||||
}
|
params({});
|
||||||
|
headers({});
|
||||||
QMap<QString, QVariant> HttpRequest::toMap(){
|
|
||||||
QVariant _params;
|
|
||||||
bool isPostString = method() == "postString";
|
|
||||||
if(params().isNull()){
|
|
||||||
if(isPostString){
|
|
||||||
_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()},
|
|
||||||
{"headers",_headers.toMap()},
|
|
||||||
{"method",method()},
|
|
||||||
{"downloadSavePath",downloadSavePath()}
|
|
||||||
};
|
|
||||||
if(isPostString){
|
|
||||||
request.insert("params",_params.toString());
|
|
||||||
}else{
|
|
||||||
request.insert("params",_params.toMap());
|
|
||||||
}
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString HttpRequest::httpId(){
|
|
||||||
return FluTools::getInstance()->sha256(QJsonDocument::fromVariant(QVariant(toMap())).toJson(QJsonDocument::Compact));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpCallable::HttpCallable(QObject *parent)
|
HttpCallable::HttpCallable(QObject *parent)
|
||||||
|
@ -82,27 +48,26 @@ void FluHttp::cancel(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluHttp::post(HttpRequest* request,HttpCallable* callable){
|
void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
request->method("post");
|
auto requestMap = toRequest(url,params,headers,"post");
|
||||||
auto requestMap = request->toMap();
|
auto httpId = toHttpId(requestMap);
|
||||||
auto httpId = request->httpId();
|
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
onStart(callable);
|
onStart(callable);
|
||||||
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
onCache(callable,readCache(httpId));
|
onCache(callable,readCache(httpId));
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
||||||
onCache(callable,readCache(httpId));
|
onCache(callable,readCache(httpId));
|
||||||
}
|
}
|
||||||
QNetworkAccessManager manager;
|
|
||||||
manager.setTransferTimeout(timeout());
|
|
||||||
for (int i = 0; i < retry(); ++i) {
|
for (int i = 0; i < retry(); ++i) {
|
||||||
QUrl url(request->url());
|
QNetworkAccessManager manager;
|
||||||
QNetworkRequest req(url);
|
manager.setTransferTimeout(timeout());
|
||||||
addHeaders(&req,data["headers"].toMap());
|
QUrl _url(url);
|
||||||
|
QNetworkRequest request(_url);
|
||||||
|
addHeaders(&request,data["headers"].toMap());
|
||||||
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
|
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
|
||||||
for (const auto& each : data["params"].toMap().toStdMap())
|
for (const auto& each : data["params"].toMap().toStdMap())
|
||||||
{
|
{
|
||||||
|
@ -115,7 +80,7 @@ void FluHttp::post(HttpRequest* request,HttpCallable* callable){
|
||||||
multiPart.append(part);
|
multiPart.append(part);
|
||||||
}
|
}
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QNetworkReply* reply = manager.post(req,&multiPart);
|
QNetworkReply* reply = manager.post(request,&multiPart);
|
||||||
_cacheReply.append(reply);
|
_cacheReply.append(reply);
|
||||||
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
||||||
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
||||||
|
@ -139,36 +104,34 @@ void FluHttp::post(HttpRequest* request,HttpCallable* callable){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluHttp::postString(HttpRequest* request,HttpCallable* callable){
|
void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<QString, QVariant> headers){
|
||||||
request->method("postString");
|
auto requestMap = toRequest(url,params,headers,"postString");
|
||||||
auto requestMap = request->toMap();
|
auto httpId = toHttpId(requestMap);
|
||||||
auto httpId = request->httpId();
|
|
||||||
QString params = request->params().toString();
|
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
onStart(callable);
|
onStart(callable);
|
||||||
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
onCache(callable,readCache(httpId));
|
onCache(callable,readCache(httpId));
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
||||||
onCache(callable,readCache(httpId));
|
onCache(callable,readCache(httpId));
|
||||||
}
|
}
|
||||||
QNetworkAccessManager manager;
|
|
||||||
manager.setTransferTimeout(timeout());
|
|
||||||
for (int i = 0; i < retry(); ++i) {
|
for (int i = 0; i < retry(); ++i) {
|
||||||
QUrl url(request->url());
|
QNetworkAccessManager manager;
|
||||||
QNetworkRequest req(url);
|
manager.setTransferTimeout(timeout());
|
||||||
addHeaders(&req,data["headers"].toMap());
|
QUrl _url(url);
|
||||||
|
QNetworkRequest request(_url);
|
||||||
|
addHeaders(&request,data["headers"].toMap());
|
||||||
QString contentType = QString("text/plain;charset=utf-8");
|
QString contentType = QString("text/plain;charset=utf-8");
|
||||||
req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
|
request.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QNetworkReply* reply = manager.post(req,params.toUtf8());
|
QNetworkReply* reply = manager.post(request,params.toUtf8());
|
||||||
_cacheReply.append(reply);
|
_cacheReply.append(reply);
|
||||||
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
||||||
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
||||||
|
@ -192,35 +155,34 @@ void FluHttp::postString(HttpRequest* request,HttpCallable* callable){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluHttp::postJson(HttpRequest* request,HttpCallable* callable){
|
void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
request->method("postJson");
|
auto requestMap = toRequest(url,params,headers,"postJson");
|
||||||
auto requestMap = request->toMap();
|
auto httpId = toHttpId(requestMap);
|
||||||
auto httpId = request->httpId();
|
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
onStart(callable);
|
onStart(callable);
|
||||||
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
onCache(callable,readCache(httpId));
|
onCache(callable,readCache(httpId));
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
|
||||||
onCache(callable,readCache(httpId));
|
onCache(callable,readCache(httpId));
|
||||||
}
|
}
|
||||||
QNetworkAccessManager manager;
|
|
||||||
manager.setTransferTimeout(timeout());
|
|
||||||
for (int i = 0; i < retry(); ++i) {
|
for (int i = 0; i < retry(); ++i) {
|
||||||
QUrl url(request->url());
|
QNetworkAccessManager manager;
|
||||||
QNetworkRequest req(url);
|
manager.setTransferTimeout(timeout());
|
||||||
addHeaders(&req,data["headers"].toMap());
|
QUrl _url(url);
|
||||||
|
QNetworkRequest request(_url);
|
||||||
|
addHeaders(&request,data["headers"].toMap());
|
||||||
QString contentType = QString("application/json;charset=utf-8");
|
QString contentType = QString("application/json;charset=utf-8");
|
||||||
req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
|
request.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QNetworkReply* reply = manager.post(req,QJsonDocument::fromVariant(data["params"]).toJson());
|
QNetworkReply* reply = manager.post(request,QJsonDocument::fromVariant(data["params"]).toJson());
|
||||||
_cacheReply.append(reply);
|
_cacheReply.append(reply);
|
||||||
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
||||||
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
||||||
|
@ -244,15 +206,20 @@ void FluHttp::postJson(HttpRequest* request,HttpCallable* callable){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(HttpRequest* request,HttpCallable* callable){
|
void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
request->method("get");
|
auto requestMap = toRequest(url,params,headers,"get");
|
||||||
auto requestMap = request->toMap();
|
auto httpId = toHttpId(requestMap);
|
||||||
auto httpId = request->httpId();
|
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
onStart(callable);
|
onStart(callable);
|
||||||
|
@ -261,18 +228,18 @@ void FluHttp::get(HttpRequest* request,HttpCallable* callable){
|
||||||
}
|
}
|
||||||
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
|
||||||
onCache(callable,readCache(httpId));
|
onCache(callable,readCache(httpId));
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QNetworkAccessManager manager;
|
|
||||||
manager.setTransferTimeout(timeout());
|
|
||||||
for (int i = 0; i < retry(); ++i) {
|
for (int i = 0; i < retry(); ++i) {
|
||||||
QUrl url(request->url());
|
QNetworkAccessManager manager;
|
||||||
addQueryParam(&url,data["params"].toMap());
|
manager.setTransferTimeout(timeout());
|
||||||
QNetworkRequest req(url);
|
QUrl _url(url);
|
||||||
addHeaders(&req,data["headers"].toMap());
|
addQueryParam(&_url,data["params"].toMap());
|
||||||
|
QNetworkRequest request(_url);
|
||||||
|
addHeaders(&request,data["headers"].toMap());
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QNetworkReply* reply = manager.get(req);
|
QNetworkReply* reply = manager.get(request);
|
||||||
_cacheReply.append(reply);
|
_cacheReply.append(reply);
|
||||||
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
||||||
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
||||||
|
@ -296,23 +263,22 @@ void FluHttp::get(HttpRequest* request,HttpCallable* callable){
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
reply = nullptr;
|
reply = nullptr;
|
||||||
}
|
}
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluHttp::download(HttpRequest* request,HttpCallable* callable){
|
void FluHttp::download(QString url,HttpCallable* callable,QString savePath,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
request->method("download");
|
auto requestMap = toRequest(url,params,headers,"download");
|
||||||
auto requestMap = request->toMap();
|
requestMap.insert("savePath",savePath);
|
||||||
auto httpId = request->httpId();
|
auto httpId = toHttpId(requestMap);
|
||||||
auto savePath = request->downloadSavePath();
|
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
onStart(callable);
|
onStart(callable);
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
QUrl url(request->url());
|
QUrl _url(url);
|
||||||
addQueryParam(&url,data["params"].toMap());
|
addQueryParam(&_url,data["params"].toMap());
|
||||||
QNetworkRequest req(url);
|
QNetworkRequest request(_url);
|
||||||
addHeaders(&req,data["headers"].toMap());
|
addHeaders(&request,data["headers"].toMap());
|
||||||
QSharedPointer<QFile> file(new QFile(savePath));
|
QSharedPointer<QFile> file(new QFile(savePath));
|
||||||
QDir dir = QFileInfo(savePath).path();
|
QDir dir = QFileInfo(savePath).path();
|
||||||
if (!dir.exists(dir.path())){
|
if (!dir.exists(dir.path())){
|
||||||
|
@ -331,11 +297,11 @@ void FluHttp::download(HttpRequest* request,HttpCallable* callable){
|
||||||
if(fileSize == contentLength && file->size() == contentLength){
|
if(fileSize == contentLength && file->size() == contentLength){
|
||||||
onDownloadProgress(callable,fileSize,contentLength);
|
onDownloadProgress(callable,fileSize,contentLength);
|
||||||
onSuccess(callable,savePath);
|
onSuccess(callable,savePath);
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(fileSize==file->size()){
|
if(fileSize==file->size()){
|
||||||
req.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8());
|
request.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8());
|
||||||
seek = fileSize;
|
seek = fileSize;
|
||||||
file->open(QIODevice::WriteOnly|QIODevice::Append);
|
file->open(QIODevice::WriteOnly|QIODevice::Append);
|
||||||
}else{
|
}else{
|
||||||
|
@ -344,7 +310,7 @@ void FluHttp::download(HttpRequest* request,HttpCallable* callable){
|
||||||
}else{
|
}else{
|
||||||
file->open(QIODevice::WriteOnly|QIODevice::Truncate);
|
file->open(QIODevice::WriteOnly|QIODevice::Truncate);
|
||||||
}
|
}
|
||||||
QNetworkReply* reply = manager.get(req);
|
QNetworkReply* reply = manager.get(request);
|
||||||
_cacheReply.append(reply);
|
_cacheReply.append(reply);
|
||||||
if (!fileCache->open(QIODevice::WriteOnly|QIODevice::Truncate))
|
if (!fileCache->open(QIODevice::WriteOnly|QIODevice::Truncate))
|
||||||
{
|
{
|
||||||
|
@ -376,23 +342,21 @@ void FluHttp::download(HttpRequest* request,HttpCallable* callable){
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
reply = nullptr;
|
reply = nullptr;
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
|
void FluHttp::upload(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
request->method("upload");
|
auto requestMap = toRequest(url,params,headers,"upload");
|
||||||
auto requestMap = request->toMap();
|
|
||||||
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
|
||||||
QThreadPool::globalInstance()->start([=](){
|
QThreadPool::globalInstance()->start([=](){
|
||||||
onStart(callable);
|
onStart(callable);
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
manager.setTransferTimeout(timeout());
|
manager.setTransferTimeout(timeout());
|
||||||
QUrl url(request->url());
|
QUrl _url(url);
|
||||||
QNetworkRequest req(url);
|
QNetworkRequest request(_url);
|
||||||
addHeaders(&req,data["headers"].toMap());
|
addHeaders(&request,data["headers"].toMap());
|
||||||
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
|
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
|
||||||
qDebug()<<data["params"].toMap();
|
|
||||||
for (const auto& each : data["params"].toMap().toStdMap())
|
for (const auto& each : data["params"].toMap().toStdMap())
|
||||||
{
|
{
|
||||||
const QString& key = each.first;
|
const QString& key = each.first;
|
||||||
|
@ -408,7 +372,7 @@ void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
|
||||||
multiPart.append(part);
|
multiPart.append(part);
|
||||||
}
|
}
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QNetworkReply* reply = manager.post(req,&multiPart);
|
QNetworkReply* reply = manager.post(request,&multiPart);
|
||||||
_cacheReply.append(reply);
|
_cacheReply.append(reply);
|
||||||
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
|
||||||
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
|
||||||
|
@ -427,10 +391,20 @@ void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
|
||||||
}else{
|
}else{
|
||||||
onError(callable,status,errorString,result);
|
onError(callable,status,errorString,result);
|
||||||
}
|
}
|
||||||
onFinish(callable,request);
|
onFinish(callable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, QVariant> FluHttp::toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method){
|
||||||
|
QMap<QString, QVariant> request = {
|
||||||
|
{"url",url},
|
||||||
|
{"params",params},
|
||||||
|
{"headers",headers},
|
||||||
|
{"method",method}
|
||||||
|
};
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant FluHttp::invokeIntercept(QMap<QString, QVariant> request){
|
QVariant FluHttp::invokeIntercept(QMap<QString, QVariant> request){
|
||||||
if(!FluApp::getInstance()->httpInterceptor()){
|
if(!FluApp::getInstance()->httpInterceptor()){
|
||||||
return request;
|
return request;
|
||||||
|
@ -501,10 +475,11 @@ void FluHttp::handleCache(const QString& httpId,const QString& result){
|
||||||
file->write(FluTools::getInstance()->toBase64(result).toUtf8());
|
file->write(FluTools::getInstance()->toBase64(result).toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal FluHttp::getBreakPointProgress(HttpRequest* request){
|
qreal FluHttp::breakPointDownloadProgress(QString url,QString savePath,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
|
||||||
request->method("download");
|
auto requestMap = toRequest(url,params,headers,"download");
|
||||||
auto httpId = request->httpId();
|
requestMap.insert("savePath",savePath);
|
||||||
QSharedPointer<QFile> file(new QFile(request->downloadSavePath()));
|
auto httpId = toHttpId(requestMap);
|
||||||
|
QSharedPointer<QFile> file(new QFile(savePath));
|
||||||
auto filePath = getCacheFilePath(httpId);
|
auto filePath = getCacheFilePath(httpId);
|
||||||
QSharedPointer<QFile> fileCache(new QFile(filePath));
|
QSharedPointer<QFile> fileCache(new QFile(filePath));
|
||||||
if(fileCache->exists() && file->exists() && _breakPointDownload){
|
if(fileCache->exists() && file->exists() && _breakPointDownload){
|
||||||
|
@ -524,25 +499,25 @@ qreal FluHttp::getBreakPointProgress(HttpRequest* request){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRequest* FluHttp::newRequest(QString url){
|
HttpRequest* FluHttp::newRequest(){
|
||||||
HttpRequest* request = new HttpRequest();
|
HttpRequest* request = new HttpRequest();
|
||||||
request->url(url);
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FluHttp::toHttpId(const QMap<QString, QVariant>& map){
|
||||||
|
return FluTools::getInstance()->sha256(QJsonDocument::fromVariant(QVariant(map)).toJson());
|
||||||
|
}
|
||||||
|
|
||||||
void FluHttp::onStart(QPointer<HttpCallable> callable){
|
void FluHttp::onStart(QPointer<HttpCallable> callable){
|
||||||
if(callable){
|
if(callable){
|
||||||
Q_EMIT callable->start();
|
Q_EMIT callable->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluHttp::onFinish(QPointer<HttpCallable> callable,HttpRequest* request){
|
void FluHttp::onFinish(QPointer<HttpCallable> callable){
|
||||||
if(callable){
|
if(callable){
|
||||||
Q_EMIT callable->finish();
|
Q_EMIT callable->finish();
|
||||||
}
|
}
|
||||||
if(!request->parent()){
|
|
||||||
delete request;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluHttp::onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result){
|
void FluHttp::onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result){
|
||||||
|
|
|
@ -13,12 +13,12 @@ class HttpRequest : public QObject{
|
||||||
Q_PROPERTY_AUTO(QVariant,params);
|
Q_PROPERTY_AUTO(QVariant,params);
|
||||||
Q_PROPERTY_AUTO(QVariant,headers);
|
Q_PROPERTY_AUTO(QVariant,headers);
|
||||||
Q_PROPERTY_AUTO(QString,method);
|
Q_PROPERTY_AUTO(QString,method);
|
||||||
Q_PROPERTY_AUTO(QString,downloadSavePath);
|
|
||||||
QML_NAMED_ELEMENT(HttpRequest)
|
QML_NAMED_ELEMENT(HttpRequest)
|
||||||
public:
|
public:
|
||||||
explicit HttpRequest(QObject *parent = nullptr);
|
explicit HttpRequest(QObject *parent = nullptr);
|
||||||
QMap<QString, QVariant> toMap();
|
~HttpRequest(){
|
||||||
Q_INVOKABLE QString httpId();
|
qDebug()<<"------------析构了"<<url();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class HttpCallable : public QObject{
|
class HttpCallable : public QObject{
|
||||||
|
@ -46,6 +46,8 @@ class FluHttp : public QObject
|
||||||
QML_NAMED_ELEMENT(FluHttp)
|
QML_NAMED_ELEMENT(FluHttp)
|
||||||
private:
|
private:
|
||||||
QVariant invokeIntercept(QMap<QString, QVariant> request);
|
QVariant invokeIntercept(QMap<QString, QVariant> request);
|
||||||
|
QMap<QString, QVariant> toRequest(const QString& url,const QVariant& params,const QVariant& headers,const QString& method);
|
||||||
|
QString toHttpId(const QMap<QString, QVariant>& map);
|
||||||
void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params);
|
void addQueryParam(QUrl* url,const QMap<QString, QVariant>& params);
|
||||||
void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& params);
|
void addHeaders(QNetworkRequest* request,const QMap<QString, QVariant>& params);
|
||||||
void handleCache(const QString& httpId, const QString& result);
|
void handleCache(const QString& httpId, const QString& result);
|
||||||
|
@ -53,7 +55,7 @@ private:
|
||||||
bool cacheExists(const QString& httpId);
|
bool cacheExists(const QString& httpId);
|
||||||
QString getCacheFilePath(const QString& httpId);
|
QString getCacheFilePath(const QString& httpId);
|
||||||
void onStart(QPointer<HttpCallable> callable);
|
void onStart(QPointer<HttpCallable> callable);
|
||||||
void onFinish(QPointer<HttpCallable> callable,HttpRequest* request);
|
void onFinish(QPointer<HttpCallable> callable);
|
||||||
void onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result);
|
void onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result);
|
||||||
void onSuccess(QPointer<HttpCallable> callable,QString result);
|
void onSuccess(QPointer<HttpCallable> callable,QString result);
|
||||||
void onCache(QPointer<HttpCallable> callable,QString result);
|
void onCache(QPointer<HttpCallable> callable,QString result);
|
||||||
|
@ -62,14 +64,16 @@ private:
|
||||||
public:
|
public:
|
||||||
explicit FluHttp(QObject *parent = nullptr);
|
explicit FluHttp(QObject *parent = nullptr);
|
||||||
~FluHttp();
|
~FluHttp();
|
||||||
Q_INVOKABLE HttpRequest* newRequest(QString url = "");
|
Q_INVOKABLE HttpRequest* newRequest();
|
||||||
Q_INVOKABLE void get(HttpRequest* request,HttpCallable* callable);
|
Q_INVOKABLE void get2(HttpRequest* request,HttpCallable* callable);
|
||||||
Q_INVOKABLE void post(HttpRequest* request,HttpCallable* callable);
|
//神坑!!! 如果参数使用QVariantMap会有问题,在6.4.3版本中QML一调用就会编译失败。所以改用QMap<QString, QVariant>
|
||||||
Q_INVOKABLE void postString(HttpRequest* request,HttpCallable* callable);
|
Q_INVOKABLE void get(QString url,HttpCallable* callable,QMap<QString, QVariant> params= {},QMap<QString, QVariant> headers = {});
|
||||||
Q_INVOKABLE void postJson(HttpRequest* request,HttpCallable* callable);
|
Q_INVOKABLE void post(QString url,HttpCallable* callable,QMap<QString, QVariant> params= {},QMap<QString, QVariant> headers = {});
|
||||||
Q_INVOKABLE void download(HttpRequest* request,HttpCallable* callable);
|
Q_INVOKABLE void postString(QString url,HttpCallable* callable,QString params = "",QMap<QString, QVariant> headers = {});
|
||||||
Q_INVOKABLE void upload(HttpRequest* request,HttpCallable* callable);
|
Q_INVOKABLE void postJson(QString url,HttpCallable* callable,QMap<QString, QVariant> params = {},QMap<QString, QVariant> headers = {});
|
||||||
Q_INVOKABLE qreal getBreakPointProgress(HttpRequest* request);
|
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 void cancel();
|
Q_INVOKABLE void cancel();
|
||||||
private:
|
private:
|
||||||
QList<QPointer<QNetworkReply>> _cacheReply;
|
QList<QPointer<QNetworkReply>> _cacheReply;
|
||||||
|
|
|
@ -26,7 +26,7 @@ Item{
|
||||||
Component{
|
Component{
|
||||||
id:com_screen
|
id:com_screen
|
||||||
Window{
|
Window{
|
||||||
property bool isZeroPos: screenshot.start.x === 0 && screenshot.start.y === 0 && screenshot.end.x === 0 && screenshot.end.y === 0
|
property bool isZeroPos: screenshot.start == Qt.point(0,0) && screenshot.end == Qt.point(0,0)
|
||||||
id:window_screen
|
id:window_screen
|
||||||
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
|
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
|
||||||
x:-1
|
x:-1
|
||||||
|
@ -123,7 +123,7 @@ Item{
|
||||||
MouseArea{
|
MouseArea{
|
||||||
property point clickPos: Qt.point(0,0)
|
property point clickPos: Qt.point(0,0)
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
|
cursorShape: Qt.SizeAllCursor
|
||||||
onPressed:
|
onPressed:
|
||||||
(mouse)=>{
|
(mouse)=>{
|
||||||
clickPos = Qt.point(mouse.x, mouse.y)
|
clickPos = Qt.point(mouse.x, mouse.y)
|
||||||
|
@ -134,7 +134,7 @@ Item{
|
||||||
var w = Math.abs(screenshot.end.x - screenshot.start.x)
|
var w = Math.abs(screenshot.end.x - screenshot.start.x)
|
||||||
var h = Math.abs(screenshot.end.y - screenshot.start.y)
|
var h = Math.abs(screenshot.end.y - screenshot.start.y)
|
||||||
var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
|
var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
|
||||||
var y = Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
|
var y =Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
|
||||||
screenshot.start = Qt.point(x,y)
|
screenshot.start = Qt.point(x,y)
|
||||||
screenshot.end = Qt.point(x+w,y+h)
|
screenshot.end = Qt.point(x+w,y+h)
|
||||||
}
|
}
|
||||||
|
@ -477,7 +477,7 @@ Item{
|
||||||
width: 100
|
width: 100
|
||||||
height: 40
|
height: 40
|
||||||
visible: {
|
visible: {
|
||||||
if(isZeroPos){
|
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if(d.enablePosition){
|
if(d.enablePosition){
|
||||||
|
|
|
@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
|
||||||
// It is used for QML tooling purposes only.
|
// It is used for QML tooling purposes only.
|
||||||
//
|
//
|
||||||
// This file was auto-generated by:
|
// This file was auto-generated by:
|
||||||
// 'qmlplugindump -nonrelocatable FluentUI 1.0 D:\QtProjects\build-FluentUI-Desktop_Qt_5_15_2_MSVC2019_64bit-Release\src'
|
// 'qmlplugindump -nonrelocatable FluentUI 1.0 D:/QtProjects/build-FluentUI-Desktop_Qt_5_15_2_MSVC2019_64bit-Release/src'
|
||||||
|
|
||||||
Module {
|
Module {
|
||||||
dependencies: ["QtQuick 2.0"]
|
dependencies: ["QtQuick 2.0"]
|
||||||
|
@ -74,45 +74,136 @@ Module {
|
||||||
Property { name: "cacheDir"; type: "string" }
|
Property { name: "cacheDir"; type: "string" }
|
||||||
Property { name: "breakPointDownload"; type: "bool" }
|
Property { name: "breakPointDownload"; type: "bool" }
|
||||||
Method {
|
Method {
|
||||||
name: "newRequest"
|
name: "get"
|
||||||
type: "HttpRequest*"
|
|
||||||
Parameter { name: "url"; type: "string" }
|
Parameter { name: "url"; type: "string" }
|
||||||
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
|
Parameter { name: "params"; type: "QVariantMap" }
|
||||||
|
Parameter { name: "headers"; type: "QVariantMap" }
|
||||||
}
|
}
|
||||||
Method { name: "newRequest"; type: "HttpRequest*" }
|
|
||||||
Method {
|
Method {
|
||||||
name: "get"
|
name: "get"
|
||||||
Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
|
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: "callable"; type: "HttpCallable"; isPointer: true }
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
}
|
}
|
||||||
Method {
|
Method {
|
||||||
name: "post"
|
name: "post"
|
||||||
Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
|
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: "callable"; type: "HttpCallable"; isPointer: true }
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
}
|
}
|
||||||
Method {
|
Method {
|
||||||
name: "postString"
|
name: "postString"
|
||||||
Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
|
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: "callable"; type: "HttpCallable"; isPointer: true }
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
}
|
}
|
||||||
Method {
|
Method {
|
||||||
name: "postJson"
|
name: "postJson"
|
||||||
Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
|
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: "callable"; type: "HttpCallable"; isPointer: true }
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
}
|
}
|
||||||
Method {
|
Method {
|
||||||
name: "download"
|
name: "download"
|
||||||
Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
|
Parameter { name: "url"; type: "string" }
|
||||||
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
|
Parameter { name: "savePath"; type: "string" }
|
||||||
|
Parameter { name: "params"; type: "QVariantMap" }
|
||||||
|
Parameter { name: "headers"; type: "QVariantMap" }
|
||||||
|
}
|
||||||
|
Method {
|
||||||
|
name: "download"
|
||||||
|
Parameter { name: "url"; type: "string" }
|
||||||
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
|
Parameter { name: "savePath"; type: "string" }
|
||||||
|
Parameter { name: "params"; type: "QVariantMap" }
|
||||||
|
}
|
||||||
|
Method {
|
||||||
|
name: "download"
|
||||||
|
Parameter { name: "url"; type: "string" }
|
||||||
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
|
Parameter { name: "savePath"; type: "string" }
|
||||||
}
|
}
|
||||||
Method {
|
Method {
|
||||||
name: "upload"
|
name: "upload"
|
||||||
Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
|
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: "callable"; type: "HttpCallable"; isPointer: true }
|
Parameter { name: "callable"; type: "HttpCallable"; isPointer: true }
|
||||||
}
|
}
|
||||||
Method {
|
Method {
|
||||||
name: "getBreakPointProgress"
|
name: "breakPointDownloadProgress"
|
||||||
type: "double"
|
type: "double"
|
||||||
Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
|
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" }
|
||||||
}
|
}
|
||||||
Method { name: "cancel" }
|
Method { name: "cancel" }
|
||||||
}
|
}
|
||||||
|
@ -1748,22 +1839,10 @@ Module {
|
||||||
}
|
}
|
||||||
Signal {
|
Signal {
|
||||||
name: "uploadProgress"
|
name: "uploadProgress"
|
||||||
Parameter { name: "sent"; type: "qlonglong" }
|
Parameter { name: "recv"; type: "qlonglong" }
|
||||||
Parameter { name: "total"; type: "qlonglong" }
|
Parameter { name: "total"; type: "qlonglong" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Component {
|
|
||||||
name: "HttpRequest"
|
|
||||||
prototype: "QObject"
|
|
||||||
exports: ["FluentUI/HttpRequest 1.0"]
|
|
||||||
exportMetaObjectRevisions: [0]
|
|
||||||
Property { name: "url"; type: "string" }
|
|
||||||
Property { name: "params"; type: "QVariant" }
|
|
||||||
Property { name: "headers"; type: "QVariant" }
|
|
||||||
Property { name: "method"; type: "string" }
|
|
||||||
Property { name: "downloadSavePath"; type: "string" }
|
|
||||||
Method { name: "httpId"; type: "string" }
|
|
||||||
}
|
|
||||||
Component {
|
Component {
|
||||||
name: "QRCode"
|
name: "QRCode"
|
||||||
defaultProperty: "data"
|
defaultProperty: "data"
|
||||||
|
@ -1793,6 +1872,7 @@ Module {
|
||||||
exportMetaObjectRevisions: [0]
|
exportMetaObjectRevisions: [0]
|
||||||
Property { name: "saveFolder"; type: "string" }
|
Property { name: "saveFolder"; type: "string" }
|
||||||
Property { name: "captureMode"; type: "int" }
|
Property { name: "captureMode"; type: "int" }
|
||||||
|
Property { name: "hitDrawData"; type: "DrawData"; isPointer: true }
|
||||||
Signal {
|
Signal {
|
||||||
name: "captrueToPixmapCompleted"
|
name: "captrueToPixmapCompleted"
|
||||||
Parameter { name: "captrue"; type: "QPixmap" }
|
Parameter { name: "captrue"; type: "QPixmap" }
|
||||||
|
@ -1806,6 +1886,25 @@ Module {
|
||||||
Parameter { name: "start"; type: "QPoint" }
|
Parameter { name: "start"; type: "QPoint" }
|
||||||
Parameter { name: "end"; type: "QPoint" }
|
Parameter { name: "end"; type: "QPoint" }
|
||||||
}
|
}
|
||||||
|
Method {
|
||||||
|
name: "appendDrawData"
|
||||||
|
type: "DrawData*"
|
||||||
|
Parameter { name: "drawType"; type: "int" }
|
||||||
|
Parameter { name: "start"; type: "QPoint" }
|
||||||
|
Parameter { name: "end"; type: "QPoint" }
|
||||||
|
}
|
||||||
|
Method {
|
||||||
|
name: "updateDrawData"
|
||||||
|
Parameter { name: "data"; type: "DrawData"; isPointer: true }
|
||||||
|
Parameter { name: "start"; type: "QPoint" }
|
||||||
|
Parameter { name: "end"; type: "QPoint" }
|
||||||
|
}
|
||||||
|
Method { name: "clear" }
|
||||||
|
Method {
|
||||||
|
name: "hit"
|
||||||
|
type: "DrawData*"
|
||||||
|
Parameter { name: "point"; type: "QPoint" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Component {
|
Component {
|
||||||
name: "WindowHelper"
|
name: "WindowHelper"
|
||||||
|
|
|
@ -15,6 +15,7 @@ Item{
|
||||||
signal captrueCompleted(var captrue)
|
signal captrueCompleted(var captrue)
|
||||||
QtObject{
|
QtObject{
|
||||||
id:d
|
id:d
|
||||||
|
property bool isEdit: false
|
||||||
property int dotMouseSize: control.dotSize+10
|
property int dotMouseSize: control.dotSize+10
|
||||||
property int dotMargins: -(control.dotSize-control.borderSize)/2
|
property int dotMargins: -(control.dotSize-control.borderSize)/2
|
||||||
property bool enablePosition: false
|
property bool enablePosition: false
|
||||||
|
@ -26,7 +27,7 @@ Item{
|
||||||
Component{
|
Component{
|
||||||
id:com_screen
|
id:com_screen
|
||||||
Window{
|
Window{
|
||||||
property bool isZeroPos: screenshot.start.x === 0 && screenshot.start.y === 0 && screenshot.end.x === 0 && screenshot.end.y === 0
|
property bool isZeroPos: screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)
|
||||||
id:window_screen
|
id:window_screen
|
||||||
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
|
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
|
||||||
x:-1
|
x:-1
|
||||||
|
@ -41,7 +42,8 @@ Item{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
setGeometry(0,0,screenshot_background.width,screenshot_background.height+1)
|
d.isEdit = false
|
||||||
|
setGeometry(0,0,screenshot_background.width,screenshot_background.height)
|
||||||
}
|
}
|
||||||
ScreenshotBackground{
|
ScreenshotBackground{
|
||||||
id:screenshot_background
|
id:screenshot_background
|
||||||
|
@ -108,6 +110,8 @@ Item{
|
||||||
}
|
}
|
||||||
screenshot.start = Qt.point(0,0)
|
screenshot.start = Qt.point(0,0)
|
||||||
screenshot.end = Qt.point(0,0)
|
screenshot.end = Qt.point(0,0)
|
||||||
|
d.isEdit = false
|
||||||
|
screenshot_background.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,21 +126,63 @@ Item{
|
||||||
border.color: control.borderColor
|
border.color: control.borderColor
|
||||||
MouseArea{
|
MouseArea{
|
||||||
property point clickPos: Qt.point(0,0)
|
property point clickPos: Qt.point(0,0)
|
||||||
|
property var currentData
|
||||||
|
property bool enablePositionChanged : false
|
||||||
|
property var hitData
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
|
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
|
||||||
onPressed:
|
onPressed:
|
||||||
(mouse)=>{
|
(mouse)=>{
|
||||||
clickPos = Qt.point(mouse.x, mouse.y)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
onReleased: {
|
||||||
|
enablePositionChanged = false
|
||||||
|
}
|
||||||
|
onCanceled: {
|
||||||
|
enablePositionChanged = false
|
||||||
|
}
|
||||||
|
onClicked: {
|
||||||
|
if(hitData){
|
||||||
|
screenshot_background.hitDrawData = hitData
|
||||||
|
}
|
||||||
|
}
|
||||||
onPositionChanged:
|
onPositionChanged:
|
||||||
(mouse)=>{
|
(mouse)=>{
|
||||||
var delta = Qt.point(mouse.x - clickPos.x,mouse.y - clickPos.y)
|
|
||||||
var w = Math.abs(screenshot.end.x - screenshot.start.x)
|
if(!enablePositionChanged){
|
||||||
var h = Math.abs(screenshot.end.y - screenshot.start.y)
|
hitData = screenshot_background.hit(Qt.point(rect_capture.x + mouse.x,rect_capture.y + mouse.y))
|
||||||
var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
|
if(hitData){
|
||||||
var y = Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
|
FluTools.setOverrideCursor(Qt.SizeAllCursor)
|
||||||
screenshot.start = Qt.point(x,y)
|
}else{
|
||||||
screenshot.end = Qt.point(x+w,y+h)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,10 +520,10 @@ Item{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pane{
|
Pane{
|
||||||
width: 100
|
width: 140
|
||||||
height: 40
|
height: 40
|
||||||
visible: {
|
visible: {
|
||||||
if(isZeroPos){
|
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if(d.enablePosition){
|
if(d.enablePosition){
|
||||||
|
@ -498,6 +544,12 @@ Item{
|
||||||
RowLayout{
|
RowLayout{
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
FluIconButton{
|
||||||
|
iconSource: FluentIcons.Stop
|
||||||
|
onClicked: {
|
||||||
|
d.isEdit = true
|
||||||
|
}
|
||||||
|
}
|
||||||
FluIconButton{
|
FluIconButton{
|
||||||
iconSource: FluentIcons.Cancel
|
iconSource: FluentIcons.Cancel
|
||||||
iconSize: 18
|
iconSize: 18
|
||||||
|
|
|
@ -43,17 +43,72 @@ ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedIt
|
||||||
}
|
}
|
||||||
setWidth(w);
|
setWidth(w);
|
||||||
setHeight(h);
|
setHeight(h);
|
||||||
|
connect(this,&ScreenshotBackground::hitDrawDataChanged,this,[=]{update();});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenshotBackground::paint(QPainter* painter)
|
void ScreenshotBackground::paint(QPainter* painter)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
_sourcePixmap = _desktopPixmap.copy();
|
_sourcePixmap = _desktopPixmap.copy();
|
||||||
|
foreach (auto item, _drawList) {
|
||||||
|
if(item->drawType == 0){
|
||||||
|
QPainter p(&_sourcePixmap);
|
||||||
|
QPen pen;
|
||||||
|
pen.setWidth(item->lineWidth);
|
||||||
|
pen.setColor(QColor(255,0,0));
|
||||||
|
pen.setStyle(Qt::SolidLine);
|
||||||
|
p.setPen(pen);
|
||||||
|
QRect rect(item->start.x(), item->start.y(), item->end.x()-item->start.x(), item->end.y()-item->start.y());
|
||||||
|
p.drawRect(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
painter->drawPixmap(_desktopGeometry,_sourcePixmap);
|
painter->drawPixmap(_desktopGeometry,_sourcePixmap);
|
||||||
|
foreach (auto item, _drawList) {
|
||||||
|
if(item->drawType == 0){
|
||||||
|
if(item == _hitDrawData){
|
||||||
|
painter->setPen(QPen(QColor(255,0,0),3));
|
||||||
|
painter->setBrush(QColor(255,255,255));
|
||||||
|
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()-4,8,8));
|
||||||
|
painter->drawEllipse(QRect(item->start.x()+item->getWidth()/2-4,item->start.y()-4,8,8));
|
||||||
|
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()-4,8,8));
|
||||||
|
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()+item->getHeight()/2-4,8,8));
|
||||||
|
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()+item->getHeight()-4,8,8));
|
||||||
|
painter->drawEllipse(QRect(item->start.x()+item->getWidth()/2-4,item->start.y()+item->getHeight()-4,8,8));
|
||||||
|
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()+item->getHeight()-4,8,8));
|
||||||
|
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()+item->getHeight()/2-4,8,8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScreenshotBackground::clear(){
|
||||||
|
_drawList.clear();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawData* ScreenshotBackground::hit(const QPoint& point){
|
||||||
|
foreach (auto item, _drawList) {
|
||||||
|
if(item->drawType == 0){
|
||||||
|
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->start.x()+item->lineWidth+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->start.y()+item->lineWidth+mouseSpacing){
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
if(point.x()>=item->end.x()-item->lineWidth-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->end.y()-item->lineWidth-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
|
void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
|
||||||
|
hitDrawData(nullptr);
|
||||||
update();
|
update();
|
||||||
auto pixelRatio = qApp->primaryScreen()->devicePixelRatio();
|
auto pixelRatio = qApp->primaryScreen()->devicePixelRatio();
|
||||||
auto x = qMin(start.x(),end.x()) * pixelRatio;
|
auto x = qMin(start.x(),end.x()) * pixelRatio;
|
||||||
|
@ -74,3 +129,21 @@ void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
|
||||||
Q_EMIT captrueToFileCompleted(QUrl::fromLocalFile(filePath));
|
Q_EMIT captrueToFileCompleted(QUrl::fromLocalFile(filePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DrawData* ScreenshotBackground::appendDrawData(int drawType,QPoint start,QPoint end){
|
||||||
|
DrawData *data = new DrawData(this);
|
||||||
|
data->drawType = drawType;
|
||||||
|
data->start = start;
|
||||||
|
data->end = end;
|
||||||
|
data->lineWidth = 3;
|
||||||
|
_drawList.append(data);
|
||||||
|
update();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenshotBackground::updateDrawData(DrawData* data,QPoint start,QPoint end){
|
||||||
|
data->start = start;
|
||||||
|
data->end = end;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,40 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
|
class DrawData:public QObject{
|
||||||
|
Q_OBJECT;
|
||||||
|
public:
|
||||||
|
explicit DrawData(QObject *parent = nullptr): QObject{parent}{};
|
||||||
|
int drawType;
|
||||||
|
int lineWidth;
|
||||||
|
QPoint start;
|
||||||
|
QPoint end;
|
||||||
|
Q_INVOKABLE int getLineWidth(){
|
||||||
|
return lineWidth;
|
||||||
|
}
|
||||||
|
Q_INVOKABLE int getWidth(){
|
||||||
|
return end.x()-start.x();
|
||||||
|
}
|
||||||
|
Q_INVOKABLE int getHeight(){
|
||||||
|
return end.y()-start.y();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ScreenshotBackground : public QQuickPaintedItem
|
class ScreenshotBackground : public QQuickPaintedItem
|
||||||
{
|
{
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
QML_NAMED_ELEMENT(ScreenshotBackground)
|
QML_NAMED_ELEMENT(ScreenshotBackground)
|
||||||
Q_PROPERTY_AUTO(QString,saveFolder);
|
Q_PROPERTY_AUTO(QString,saveFolder);
|
||||||
Q_PROPERTY_AUTO(int,captureMode);
|
Q_PROPERTY_AUTO(int,captureMode);
|
||||||
|
Q_PROPERTY_AUTO(DrawData*,hitDrawData);
|
||||||
public:
|
public:
|
||||||
ScreenshotBackground(QQuickItem* parent = nullptr);
|
ScreenshotBackground(QQuickItem* parent = nullptr);
|
||||||
void paint(QPainter* painter) override;
|
void paint(QPainter* painter) override;
|
||||||
Q_INVOKABLE void capture(const QPoint& start,const QPoint& end);
|
Q_INVOKABLE void capture(const QPoint& start,const QPoint& end);
|
||||||
|
Q_INVOKABLE DrawData* appendDrawData(int drawType,QPoint start,QPoint end);
|
||||||
|
Q_INVOKABLE void updateDrawData(DrawData* data,QPoint start,QPoint end);
|
||||||
|
Q_INVOKABLE void clear();
|
||||||
|
Q_INVOKABLE DrawData* hit(const QPoint& point);
|
||||||
Q_SIGNAL void captrueToPixmapCompleted(QPixmap captrue);
|
Q_SIGNAL void captrueToPixmapCompleted(QPixmap captrue);
|
||||||
Q_SIGNAL void captrueToFileCompleted(QUrl captrue);
|
Q_SIGNAL void captrueToFileCompleted(QUrl captrue);
|
||||||
private:
|
private:
|
||||||
|
@ -27,6 +51,8 @@ private:
|
||||||
qreal _devicePixelRatio;
|
qreal _devicePixelRatio;
|
||||||
QSharedPointer<QQuickItemGrabResult> _grabResult;
|
QSharedPointer<QQuickItemGrabResult> _grabResult;
|
||||||
QRect _captureRect;
|
QRect _captureRect;
|
||||||
|
QList<DrawData*> _drawList;
|
||||||
|
int mouseSpacing = 3;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ void FluentUIPlugin::registerTypes(const char *uri)
|
||||||
qmlRegisterType<FluHttpInterceptor>(uri,major,minor,"FluHttpInterceptor");
|
qmlRegisterType<FluHttpInterceptor>(uri,major,minor,"FluHttpInterceptor");
|
||||||
qmlRegisterType<FluHttp>(uri,major,minor,"FluHttp");
|
qmlRegisterType<FluHttp>(uri,major,minor,"FluHttp");
|
||||||
qmlRegisterType<HttpCallable>(uri,major,minor,"HttpCallable");
|
qmlRegisterType<HttpCallable>(uri,major,minor,"HttpCallable");
|
||||||
qmlRegisterType<HttpRequest>(uri,major,minor,"HttpRequest");
|
|
||||||
qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only");
|
qmlRegisterUncreatableMetaObject(Fluent_Awesome::staticMetaObject, uri,major,minor,"FluentIcons", "Access to enums & flags only");
|
||||||
qmlRegisterUncreatableMetaObject(FluHttpType::staticMetaObject, uri,major,minor,"FluHttpType", "Access to enums & flags only");
|
qmlRegisterUncreatableMetaObject(FluHttpType::staticMetaObject, uri,major,minor,"FluHttpType", "Access to enums & flags only");
|
||||||
qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only");
|
qmlRegisterUncreatableMetaObject(FluThemeType::staticMetaObject, uri,major,minor,"FluThemeType", "Access to enums & flags only");
|
||||||
|
|
Loading…
Reference in New Issue