Compare commits

..

No commits in common. "249c294926c5eec6431939f5434a39d0693b6523" and "c92d807ec1b785a2baa73089275641e415380f44" have entirely different histories.

14 changed files with 492 additions and 271 deletions

View File

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

View File

@ -56,10 +56,12 @@ FluContentPage{
onSuccess:
(result)=>{
text_info.text = result
console.debug(result)
}
onCache:
(result)=>{
text_info.text = result
console.debug(result)
}
}
@ -84,8 +86,7 @@ FluContentPage{
implicitHeight: 36
text: "Get请求"
onClicked: {
var request = http.newRequest("https://httpbingo.org/get")
http.get(request,callable)
http.get("https://httpbingo.org/get",callable)
}
}
FluButton{
@ -93,13 +94,11 @@ FluContentPage{
implicitHeight: 36
text: "Post表单请求"
onClicked: {
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)
var param = {}
param.custname = "朱子楚"
param.custtel = "1234567890"
param.custemail = "zhuzichu520@gmail.com"
http.post("https://httpbingo.org/post",callable,param)
}
}
FluButton{
@ -107,13 +106,11 @@ FluContentPage{
implicitHeight: 36
text: "Post Json请求"
onClicked: {
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)
var param = {}
param.custname = "朱子楚"
param.custtel = "1234567890"
param.custemail = "zhuzichu520@gmail.com"
http.postJson("https://httpbingo.org/post",callable,param)
}
}
FluButton{
@ -121,9 +118,8 @@ FluContentPage{
implicitHeight: 36
text: "Post String请求"
onClicked: {
var request = http.newRequest("https://httpbingo.org/post")
request.params = "我命由我不由天"
http.postString(request,callable)
var param = "我命由我不由天"
http.postString("https://httpbingo.org/post",callable,param)
}
}
FluProgressButton{
@ -137,6 +133,8 @@ 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
@ -152,11 +150,6 @@ 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: {
@ -179,7 +172,7 @@ FluContentPage{
}
}
Component.onCompleted: {
progress = http_breakpoint_download.getBreakPointProgress(request_breakpoint_download)
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath)
}
onClicked: {
if(downloading){
@ -187,9 +180,9 @@ FluContentPage{
return
}
if(progress === 1){
FluTools.showFileInFolder(request_breakpoint_download.downloadSavePath)
FluTools.showFileInFolder(saveFilePath)
}else{
http_breakpoint_download.download(request_breakpoint_download,callable_breakpoint_download)
http_breakpoint_download.download(resourcePath,callable_breakpoint_download,saveFilePath)
}
}
FluMenu{
@ -198,7 +191,7 @@ FluContentPage{
FluMenuItem{
text: "删除文件"
onClicked: {
if(FluTools.removeFile(request_breakpoint_download.downloadSavePath)){
if(FluTools.removeFile(btn_breakpoint_download.saveFilePath)){
btn_breakpoint_download.progress = 0
}
}
@ -228,9 +221,9 @@ FluContentPage{
implicitHeight: 36
text: "FirstCacheThenRequest缓存"
onClicked: {
var request = http.newRequest("https://httpbingo.org/post")
request.params = {cacheMode:"FirstCacheThenRequest"}
http_cache_firstcachethenrequest.post(request,callable)
var param = {}
param.cacheMode = "FirstCacheThenRequest"
http_cache_firstcachethenrequest.post("https://httpbingo.org/post",callable,param)
}
}
FluButton{
@ -238,9 +231,9 @@ FluContentPage{
implicitHeight: 36
text: "RequestFailedReadCache缓存"
onClicked: {
var request = http.newRequest("https://httpbingo.org/post")
request.params = {cacheMode:"RequestFailedReadCache"}
http_cache_requestfailedreadcache.post(request,callable)
var param = {}
param.cacheMode = "RequestFailedReadCache"
http_cache_requestfailedreadcache.post("https://httpbingo.org/post",callable,param)
}
}
@ -249,9 +242,9 @@ FluContentPage{
implicitHeight: 36
text: "IfNoneCacheRequest缓存"
onClicked: {
var request = http.newRequest("https://httpbingo.org/post")
request.params = {cacheMode:"IfNoneCacheRequest"}
http_cache_ifnonecacherequest.post(request,callable)
var param = {}
param.cacheMode = "IfNoneCacheRequest"
http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param)
}
}
FluButton{
@ -307,16 +300,14 @@ FluContentPage{
FileDialog {
id: file_dialog
onAccepted: {
var request = http.newRequest("https://httpbingo.org/post")
var params = {}
var param = {}
for(var i=0;i<selectedFiles.length;i++){
var fileUrl = selectedFiles[i]
var fileName = FluTools.getFileNameByUrl(fileUrl)
var filePath = FluTools.toLocalPath(fileUrl)
params[fileName] = filePath
param[fileName] = filePath
}
request.params = params
http.upload(request,callable_upload)
http.upload("https://httpbingo.org/post",callable_upload,param)
}
}
@ -348,11 +339,11 @@ FluContentPage{
id: folder_dialog
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
onAccepted: {
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)
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable_download,path)
}
}
FluArea{
anchors{
top: layout_flick.top

View File

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

View File

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

View File

@ -57,10 +57,12 @@ FluContentPage{
onSuccess:
(result)=>{
text_info.text = result
console.debug(result)
}
onCache:
(result)=>{
text_info.text = result
console.debug(result)
}
}
@ -85,8 +87,7 @@ FluContentPage{
implicitHeight: 36
text: "Get请求"
onClicked: {
var request = http.newRequest("https://httpbingo.org/get")
http.get(request,callable)
http.get("https://httpbingo.org/get",callable)
}
}
FluButton{
@ -94,13 +95,11 @@ FluContentPage{
implicitHeight: 36
text: "Post表单请求"
onClicked: {
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)
var param = {}
param.custname = "朱子楚"
param.custtel = "1234567890"
param.custemail = "zhuzichu520@gmail.com"
http.post("https://httpbingo.org/post",callable,param)
}
}
FluButton{
@ -108,13 +107,11 @@ FluContentPage{
implicitHeight: 36
text: "Post Json请求"
onClicked: {
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)
var param = {}
param.custname = "朱子楚"
param.custtel = "1234567890"
param.custemail = "zhuzichu520@gmail.com"
http.postJson("https://httpbingo.org/post",callable,param)
}
}
FluButton{
@ -122,9 +119,8 @@ FluContentPage{
implicitHeight: 36
text: "Post String请求"
onClicked: {
var request = http.newRequest("https://httpbingo.org/post")
request.params = "我命由我不由天"
http.postString(request,callable)
var param = "我命由我不由天"
http.postString("https://httpbingo.org/post",callable,param)
}
}
FluProgressButton{
@ -138,6 +134,8 @@ 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
@ -153,11 +151,6 @@ 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: {
@ -180,7 +173,7 @@ FluContentPage{
}
}
Component.onCompleted: {
progress = http_breakpoint_download.getBreakPointProgress(request_breakpoint_download)
progress = http_breakpoint_download.breakPointDownloadProgress(resourcePath,saveFilePath)
}
onClicked: {
if(downloading){
@ -188,9 +181,9 @@ FluContentPage{
return
}
if(progress === 1){
FluTools.showFileInFolder(request_breakpoint_download.downloadSavePath)
FluTools.showFileInFolder(saveFilePath)
}else{
http_breakpoint_download.download(request_breakpoint_download,callable_breakpoint_download)
http_breakpoint_download.download(resourcePath,callable_breakpoint_download,saveFilePath)
}
}
FluMenu{
@ -199,7 +192,7 @@ FluContentPage{
FluMenuItem{
text: "删除文件"
onClicked: {
if(FluTools.removeFile(request_breakpoint_download.downloadSavePath)){
if(FluTools.removeFile(btn_breakpoint_download.saveFilePath)){
btn_breakpoint_download.progress = 0
}
}
@ -229,9 +222,9 @@ FluContentPage{
implicitHeight: 36
text: "FirstCacheThenRequest缓存"
onClicked: {
var request = http.newRequest("https://httpbingo.org/post")
request.params = {cacheMode:"FirstCacheThenRequest"}
http_cache_firstcachethenrequest.post(request,callable)
var param = {}
param.cacheMode = "FirstCacheThenRequest"
http_cache_firstcachethenrequest.post("https://httpbingo.org/post",callable,param)
}
}
FluButton{
@ -239,9 +232,9 @@ FluContentPage{
implicitHeight: 36
text: "RequestFailedReadCache缓存"
onClicked: {
var request = http.newRequest("https://httpbingo.org/post")
request.params = {cacheMode:"RequestFailedReadCache"}
http_cache_requestfailedreadcache.post(request,callable)
var param = {}
param.cacheMode = "RequestFailedReadCache"
http_cache_requestfailedreadcache.post("https://httpbingo.org/post",callable,param)
}
}
@ -250,9 +243,9 @@ FluContentPage{
implicitHeight: 36
text: "IfNoneCacheRequest缓存"
onClicked: {
var request = http.newRequest("https://httpbingo.org/post")
request.params = {cacheMode:"IfNoneCacheRequest"}
http_cache_ifnonecacherequest.post(request,callable)
var param = {}
param.cacheMode = "IfNoneCacheRequest"
http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param)
}
}
FluButton{
@ -308,16 +301,14 @@ FluContentPage{
FileDialog {
id: file_dialog
onAccepted: {
var request = http.newRequest("https://httpbingo.org/post")
var params = {}
var param = {}
for(var i=0;i<selectedFiles.length;i++){
var fileUrl = selectedFiles[i]
var fileName = FluTools.getFileNameByUrl(fileUrl)
var filePath = FluTools.toLocalPath(fileUrl)
params[fileName] = filePath
param[fileName] = filePath
}
request.params = params
http.upload(request,callable_upload)
http.upload("https://httpbingo.org/post",callable_upload,param)
}
}
@ -349,11 +340,11 @@ FluContentPage{
id: folder_dialog
currentFolder: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
onAccepted: {
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)
var path = FluTools.toLocalPath(currentFolder)+ "/big_buck_bunny.mp4"
http.download("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",callable_download,path)
}
}
FluArea{
anchors{
top: layout_flick.top

View File

@ -139,7 +139,7 @@ CustomWindow {
id:loader
lazy: true
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{
@ -336,8 +336,7 @@ CustomWindow {
}
function checkUpdate(){
var request = http.newRequest("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest")
http.get(request,callable);
http.get("https://api.github.com/repos/zhuzichu520/FluentUI/releases/latest",callable)
}
}

View File

@ -17,42 +17,8 @@
HttpRequest::HttpRequest(QObject *parent)
: QObject{parent}
{
}
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));
params({});
headers({});
}
HttpCallable::HttpCallable(QObject *parent)
@ -82,27 +48,26 @@ void FluHttp::cancel(){
}
}
void FluHttp::post(HttpRequest* request,HttpCallable* callable){
request->method("post");
auto requestMap = request->toMap();
auto httpId = request->httpId();
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);
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,request);
onFinish(callable);
return;
}
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId));
}
for (int i = 0; i < retry(); ++i) {
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
for (int i = 0; i < retry(); ++i) {
QUrl url(request->url());
QNetworkRequest req(url);
addHeaders(&req,data["headers"].toMap());
QUrl _url(url);
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
for (const auto& each : data["params"].toMap().toStdMap())
{
@ -115,7 +80,7 @@ void FluHttp::post(HttpRequest* request,HttpCallable* callable){
multiPart.append(part);
}
QEventLoop loop;
QNetworkReply* reply = manager.post(req,&multiPart);
QNetworkReply* reply = manager.post(request,&multiPart);
_cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){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){
request->method("postString");
auto requestMap = request->toMap();
auto httpId = request->httpId();
QString params = request->params().toString();
void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<QString, QVariant> headers){
auto requestMap = toRequest(url,params,headers,"postString");
auto httpId = toHttpId(requestMap);
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,request);
onFinish(callable);
return;
}
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId));
}
for (int i = 0; i < retry(); ++i) {
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
for (int i = 0; i < retry(); ++i) {
QUrl url(request->url());
QNetworkRequest req(url);
addHeaders(&req,data["headers"].toMap());
QUrl _url(url);
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QString contentType = QString("text/plain;charset=utf-8");
req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
request.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
QEventLoop loop;
QNetworkReply* reply = manager.post(req,params.toUtf8());
QNetworkReply* reply = manager.post(request,params.toUtf8());
_cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){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){
request->method("postJson");
auto requestMap = request->toMap();
auto httpId = request->httpId();
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);
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,request);
onFinish(callable);
return;
}
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId));
}
for (int i = 0; i < retry(); ++i) {
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
for (int i = 0; i < retry(); ++i) {
QUrl url(request->url());
QNetworkRequest req(url);
addHeaders(&req,data["headers"].toMap());
QUrl _url(url);
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QString contentType = QString("application/json;charset=utf-8");
req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
request.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
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);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){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){
request->method("get");
auto requestMap = request->toMap();
auto httpId = request->httpId();
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);
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){
onStart(callable);
@ -261,18 +228,18 @@ void FluHttp::get(HttpRequest* request,HttpCallable* callable){
}
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(httpId)){
onCache(callable,readCache(httpId));
onFinish(callable,request);
onFinish(callable);
return;
}
for (int i = 0; i < retry(); ++i) {
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
for (int i = 0; i < retry(); ++i) {
QUrl url(request->url());
addQueryParam(&url,data["params"].toMap());
QNetworkRequest req(url);
addHeaders(&req,data["headers"].toMap());
QUrl _url(url);
addQueryParam(&_url,data["params"].toMap());
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QEventLoop loop;
QNetworkReply* reply = manager.get(req);
QNetworkReply* reply = manager.get(request);
_cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
@ -296,23 +263,22 @@ void FluHttp::get(HttpRequest* request,HttpCallable* callable){
reply->deleteLater();
reply = nullptr;
}
onFinish(callable,request);
onFinish(callable);
});
}
void FluHttp::download(HttpRequest* request,HttpCallable* callable){
request->method("download");
auto requestMap = request->toMap();
auto httpId = request->httpId();
auto savePath = request->downloadSavePath();
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);
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){
onStart(callable);
QNetworkAccessManager manager;
QUrl url(request->url());
addQueryParam(&url,data["params"].toMap());
QNetworkRequest req(url);
addHeaders(&req,data["headers"].toMap());
QUrl _url(url);
addQueryParam(&_url,data["params"].toMap());
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QSharedPointer<QFile> file(new QFile(savePath));
QDir dir = QFileInfo(savePath).path();
if (!dir.exists(dir.path())){
@ -331,11 +297,11 @@ void FluHttp::download(HttpRequest* request,HttpCallable* callable){
if(fileSize == contentLength && file->size() == contentLength){
onDownloadProgress(callable,fileSize,contentLength);
onSuccess(callable,savePath);
onFinish(callable,request);
onFinish(callable);
return;
}
if(fileSize==file->size()){
req.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8());
request.setRawHeader("Range", QString("bytes=%1-").arg(fileSize).toUtf8());
seek = fileSize;
file->open(QIODevice::WriteOnly|QIODevice::Append);
}else{
@ -344,7 +310,7 @@ void FluHttp::download(HttpRequest* request,HttpCallable* callable){
}else{
file->open(QIODevice::WriteOnly|QIODevice::Truncate);
}
QNetworkReply* reply = manager.get(req);
QNetworkReply* reply = manager.get(request);
_cacheReply.append(reply);
if (!fileCache->open(QIODevice::WriteOnly|QIODevice::Truncate))
{
@ -376,23 +342,21 @@ void FluHttp::download(HttpRequest* request,HttpCallable* callable){
}
reply->deleteLater();
reply = nullptr;
onFinish(callable,request);
onFinish(callable);
});
}
void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
request->method("upload");
auto requestMap = request->toMap();
void FluHttp::upload(QString url,HttpCallable* callable,QMap<QString, QVariant> params,QMap<QString, QVariant> headers){
auto requestMap = toRequest(url,params,headers,"upload");
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
QThreadPool::globalInstance()->start([=](){
onStart(callable);
QNetworkAccessManager manager;
manager.setTransferTimeout(timeout());
QUrl url(request->url());
QNetworkRequest req(url);
addHeaders(&req,data["headers"].toMap());
QUrl _url(url);
QNetworkRequest request(_url);
addHeaders(&request,data["headers"].toMap());
QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
qDebug()<<data["params"].toMap();
for (const auto& each : data["params"].toMap().toStdMap())
{
const QString& key = each.first;
@ -408,7 +372,7 @@ void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
multiPart.append(part);
}
QEventLoop loop;
QNetworkReply* reply = manager.post(req,&multiPart);
QNetworkReply* reply = manager.post(request,&multiPart);
_cacheReply.append(reply);
connect(&manager,&QNetworkAccessManager::finished,&manager,[&loop](QNetworkReply *reply){loop.quit();});
connect(qApp,&QGuiApplication::aboutToQuit,&manager, [&loop](){loop.quit();});
@ -427,10 +391,20 @@ void FluHttp::upload(HttpRequest* request,HttpCallable* callable){
}else{
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){
if(!FluApp::getInstance()->httpInterceptor()){
return request;
@ -501,10 +475,11 @@ void FluHttp::handleCache(const QString& httpId,const QString& result){
file->write(FluTools::getInstance()->toBase64(result).toUtf8());
}
qreal FluHttp::getBreakPointProgress(HttpRequest* request){
request->method("download");
auto httpId = request->httpId();
QSharedPointer<QFile> file(new QFile(request->downloadSavePath()));
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));
auto filePath = getCacheFilePath(httpId);
QSharedPointer<QFile> fileCache(new QFile(filePath));
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();
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,HttpRequest* request){
void FluHttp::onFinish(QPointer<HttpCallable> callable){
if(callable){
Q_EMIT callable->finish();
}
if(!request->parent()){
delete request;
}
}
void FluHttp::onError(QPointer<HttpCallable> callable,int status,QString errorString,QString result){

View File

@ -13,12 +13,12 @@ class HttpRequest : public QObject{
Q_PROPERTY_AUTO(QVariant,params);
Q_PROPERTY_AUTO(QVariant,headers);
Q_PROPERTY_AUTO(QString,method);
Q_PROPERTY_AUTO(QString,downloadSavePath);
QML_NAMED_ELEMENT(HttpRequest)
public:
explicit HttpRequest(QObject *parent = nullptr);
QMap<QString, QVariant> toMap();
Q_INVOKABLE QString httpId();
~HttpRequest(){
qDebug()<<"------------析构了"<<url();
}
};
class HttpCallable : public QObject{
@ -46,6 +46,8 @@ 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);
@ -53,7 +55,7 @@ private:
bool cacheExists(const QString& httpId);
QString getCacheFilePath(const QString& httpId);
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 onSuccess(QPointer<HttpCallable> callable,QString result);
void onCache(QPointer<HttpCallable> callable,QString result);
@ -62,14 +64,16 @@ private:
public:
explicit FluHttp(QObject *parent = nullptr);
~FluHttp();
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 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 void cancel();
private:
QList<QPointer<QNetworkReply>> _cacheReply;

View File

@ -26,7 +26,7 @@ Item{
Component{
id:com_screen
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
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
x:-1
@ -123,7 +123,7 @@ Item{
MouseArea{
property point clickPos: Qt.point(0,0)
anchors.fill: parent
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
cursorShape: Qt.SizeAllCursor
onPressed:
(mouse)=>{
clickPos = Qt.point(mouse.x, mouse.y)
@ -477,7 +477,7 @@ Item{
width: 100
height: 40
visible: {
if(isZeroPos){
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){
return false
}
if(d.enablePosition){

View File

@ -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,45 +74,136 @@ Module {
Property { name: "cacheDir"; type: "string" }
Property { name: "breakPointDownload"; type: "bool" }
Method {
name: "newRequest"
type: "HttpRequest*"
name: "get"
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: "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 }
}
Method {
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 }
}
Method {
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 }
}
Method {
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 }
}
Method {
name: "download"
Parameter { name: "request"; type: "HttpRequest"; isPointer: true }
Parameter { name: "url"; type: "string" }
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: "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 }
}
Method {
name: "getBreakPointProgress"
name: "breakPointDownloadProgress"
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" }
}
@ -1748,22 +1839,10 @@ Module {
}
Signal {
name: "uploadProgress"
Parameter { name: "sent"; type: "qlonglong" }
Parameter { name: "recv"; 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"
@ -1793,6 +1872,7 @@ 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" }
@ -1806,6 +1886,25 @@ 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"

View File

@ -15,6 +15,7 @@ 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
@ -26,7 +27,7 @@ Item{
Component{
id:com_screen
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
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
x:-1
@ -41,7 +42,8 @@ Item{
}
}
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{
id:screenshot_background
@ -108,6 +110,8 @@ Item{
}
screenshot.start = Qt.point(0,0)
screenshot.end = Qt.point(0,0)
d.isEdit = false
screenshot_background.clear()
}
}
}
@ -122,14 +126,55 @@ 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)
}
}
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)
@ -140,6 +185,7 @@ Item{
}
}
}
}
Rectangle{
id:rect_top_left
width: control.dotSize
@ -474,10 +520,10 @@ Item{
}
}
Pane{
width: 100
width: 140
height: 40
visible: {
if(isZeroPos){
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){
return false
}
if(d.enablePosition){
@ -498,6 +544,12 @@ Item{
RowLayout{
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
FluIconButton{
iconSource: FluentIcons.Stop
onClicked: {
d.isEdit = true
}
}
FluIconButton{
iconSource: FluentIcons.Cancel
iconSize: 18

View File

@ -43,17 +43,72 @@ 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;
@ -74,3 +129,21 @@ 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();
}

View File

@ -8,16 +8,40 @@
#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:
@ -27,6 +51,8 @@ private:
qreal _devicePixelRatio;
QSharedPointer<QQuickItemGrabResult> _grabResult;
QRect _captureRect;
QList<DrawData*> _drawList;
int mouseSpacing = 3;
};

View File

@ -39,7 +39,6 @@ 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");