Compare commits

...

4 Commits

Author SHA1 Message Date
朱子楚\zhuzi 54be482833 update 2023-09-04 22:49:50 +08:00
朱子楚\zhuzi f60eaec07c Merge branch 'main' of https://github.com/zhuzichu520/FluentUI 2023-09-04 20:45:56 +08:00
朱子楚\zhuzi 8583427a49 Merge branch 'main' of https://github.com/zhuzichu520/FluentUI 2023-08-30 18:44:13 +08:00
朱子楚\zhuzi 94a96cf75e update 2023-08-30 18:44:07 +08:00
12 changed files with 207 additions and 24 deletions

View File

@ -164,6 +164,14 @@ FluContentPage{
http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "打开缓存路径"
onClicked: {
Qt.openUrlExternally("file:///"+cacheDirPath)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36

View File

@ -138,7 +138,7 @@ CustomWindow {
id:loader
lazy: true
anchors.fill: parent
source: "https://zhu-zichu.gitee.io/Qt6_155_LieflatPage.qml"
source: "https://zhu-zichu.gitee.io/Qt6_156_LieflatPage.qml"
}
}
front: Item{

View File

@ -165,6 +165,14 @@ FluContentPage{
http_cache_ifnonecacherequest.post("https://httpbingo.org/post",callable,param)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36
text: "打开缓存路径"
onClicked: {
Qt.openUrlExternally("file:///"+cacheDirPath)
}
}
FluButton{
implicitWidth: parent.width
implicitHeight: 36

View File

@ -139,7 +139,7 @@ CustomWindow {
id:loader
lazy: true
anchors.fill: parent
source: "https://zhu-zichu.gitee.io/Qt5_155_LieflatPage.qml"
source: "https://zhu-zichu.gitee.io/Qt5_156_LieflatPage.qml"
}
}
front: Item{

View File

@ -37,7 +37,7 @@ int main(int argc, char *argv[])
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
#ifdef Q_OS_WIN // 此设置仅在Windows下生效
FramelessConfig::instance()->set(Global::Option::ForceHideWindowFrameBorder);
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow,false);
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow,true);
#endif
#ifdef Q_OS_MACOS
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur,false);

View File

@ -10,7 +10,7 @@ enum CacheMode {
/** 不使用缓存 */
NoCache = 0x0000,
/** 请求网络失败后,读取缓存 */
/** 请求网络失败后,读取缓存 */
RequestFailedReadCache = 0x0001,
/** 如果缓存不存在才请求网络,否则使用缓存 */

View File

@ -10,7 +10,6 @@
#include <QTextStream>
#include <QDir>
#include "Def.h"
#include "MainThread.h"
#include "FluApp.h"
#include "FluTools.h"
@ -54,7 +53,7 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> pa
Q_EMIT callable->finish();
return;
}
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest){
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){
Q_EMIT callable->cache(readCache(requestMap));
}
for (int i = 0; i < retry(); ++i) {
@ -94,7 +93,7 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> pa
break;
}else{
if(i == retry()-1){
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache){
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){
Q_EMIT callable->cache(readCache(requestMap));
}
Q_EMIT callable->error(status,errorString,result);
@ -102,7 +101,6 @@ void FluHttp::post(QString url,HttpCallable* callable,QMap<QString, QVariant> pa
}
}
Q_EMIT callable->finish();
// Q_EMIT callable->finish();
});
}
@ -116,7 +114,7 @@ void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<
Q_EMIT callable->finish();
return;
}
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest){
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){
Q_EMIT callable->cache(readCache(requestMap));
}
for (int i = 0; i < retry(); ++i) {
@ -147,7 +145,7 @@ void FluHttp::postString(QString url,HttpCallable* callable,QString params,QMap<
break;
}else{
if(i == retry()-1){
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache){
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){
Q_EMIT callable->cache(readCache(requestMap));
}
Q_EMIT callable->error(status,errorString,result);
@ -168,7 +166,7 @@ void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant
Q_EMIT callable->finish();
return;
}
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest){
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){
Q_EMIT callable->cache(readCache(requestMap));
}
for (int i = 0; i < retry(); ++i) {
@ -199,7 +197,7 @@ void FluHttp::postJson(QString url,HttpCallable* callable,QMap<QString, QVariant
break;
}else{
if(i == retry()-1){
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache){
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){
Q_EMIT callable->cache(readCache(requestMap));
}
Q_EMIT callable->error(status,errorString,result);
@ -215,7 +213,7 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> par
auto requestMap = toRequest(url,params,headers,"get");
QMap<QString, QVariant> data = invokeIntercept(requestMap).toMap();
Q_EMIT callable->start();
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest){
if(_cacheMode == FluHttpType::CacheMode::FirstCacheThenRequest && cacheExists(requestMap)){
Q_EMIT callable->cache(readCache(requestMap));
}
if(_cacheMode == FluHttpType::CacheMode::IfNoneCacheRequest && cacheExists(requestMap)){
@ -250,7 +248,7 @@ void FluHttp::get(QString url,HttpCallable* callable,QMap<QString, QVariant> par
break;
}else{
if(i == retry()-1){
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache){
if(_cacheMode == FluHttpType::CacheMode::RequestFailedReadCache && cacheExists(requestMap)){
Q_EMIT callable->cache(readCache(requestMap));
}
Q_EMIT callable->error(status,errorString,result);

View File

@ -8,6 +8,21 @@ import QtQuick.tooling 1.2
Module {
dependencies: ["QtQuick 2.0"]
Component {
name: "FluHttpType"
exports: ["FluentUI/FluHttpType 1.0"]
isCreatable: false
exportMetaObjectRevisions: [0]
Enum {
name: "CacheMode"
values: {
"NoCache": 0,
"RequestFailedReadCache": 1,
"IfNoneCacheRequest": 2,
"FirstCacheThenRequest": 4
}
}
}
Component {
name: "FluCalendarViewType"
exports: ["FluentUI/FluCalendarViewType 1.0"]

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
@ -41,6 +42,7 @@ Item{
}
}
Component.onCompleted: {
d.isEdit = false
setGeometry(0,0,screenshot_background.width,screenshot_background.height)
}
ScreenshotBackground{
@ -108,6 +110,8 @@ Item{
}
screenshot.start = 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
MouseArea{
property point clickPos: Qt.point(0,0)
property var currentData
property bool enablePositionChanged : false
property var hitData
anchors.fill: parent
cursorShape: Qt.SizeAllCursor
hoverEnabled: true
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
onPressed:
(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:
(mouse)=>{
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)
if(!enablePositionChanged){
hitData = screenshot_background.hit(Qt.point(rect_capture.x + mouse.x,rect_capture.y + mouse.y))
if(hitData){
FluTools.setOverrideCursor(Qt.SizeAllCursor)
}else{
FluTools.restoreOverrideCursor()
}
return
}
if(d.isEdit){
var start = Qt.point(rect_capture.x + clickPos.x,rect_capture.y + clickPos.y)
var end = Qt.point(Math.min(Math.max(rect_capture.x + mouse.x,rect_capture.x+borderSize),rect_capture.x+rect_capture.width-currentData.getLineWidth()),Math.min(Math.max(rect_capture.y + mouse.y,rect_capture.y+currentData.getLineWidth()+borderSize),rect_capture.y+rect_capture.height)-currentData.getLineWidth())
console.debug("start->"+start)
console.debug("end->"+end)
screenshot_background.updateDrawData(currentData,start,end)
}else{
var delta = Qt.point(mouse.x - clickPos.x,mouse.y - clickPos.y)
var w = Math.abs(screenshot.end.x - screenshot.start.x)
var h = Math.abs(screenshot.end.y - screenshot.start.y)
var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
var y =Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
}
}
}
@ -474,7 +520,7 @@ Item{
}
}
Pane{
width: 100
width: 140
height: 40
visible: {
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){
@ -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

@ -9,6 +9,7 @@
#include "Def.h"
Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent)
{
_desktopGeometry = qApp->primaryScreen()->virtualGeometry();
@ -42,17 +43,73 @@ 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;
auto y = qMin(start.y(),end.y()) * pixelRatio;
@ -73,3 +130,20 @@ void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
}
}
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

@ -6,6 +6,26 @@
#include <QPainter>
#include <QQuickItemGrabResult>
#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
{
@ -13,10 +33,15 @@ class ScreenshotBackground : public QQuickPaintedItem
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:
@ -26,6 +51,8 @@ private:
qreal _devicePixelRatio;
QSharedPointer<QQuickItemGrabResult> _grabResult;
QRect _captureRect;
QList<DrawData*> _drawList;
int mouseSpacing = 3;
};

View File

@ -40,6 +40,7 @@ void FluentUIPlugin::registerTypes(const char *uri)
qmlRegisterType<FluHttp>(uri,major,minor,"FluHttp");
qmlRegisterType<HttpCallable>(uri,major,minor,"HttpCallable");
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");
qmlRegisterUncreatableMetaObject(FluPageType::staticMetaObject, uri,major,minor,"FluPageType", "Access to enums & flags only");
qmlRegisterUncreatableMetaObject(FluWindowType::staticMetaObject, uri,major,minor,"FluWindowType", "Access to enums & flags only");