diff --git a/example/qml/App.qml b/example/qml/App.qml index 1550ac96..f0af5371 100644 --- a/example/qml/App.qml +++ b/example/qml/App.qml @@ -19,6 +19,7 @@ Window { } request.headers["token"] ="yyds" request.headers["os"] ="pc" + console.debug(JSON.stringify(request)) return request } } diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index c2918f09..921c166e 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -166,7 +166,7 @@ CustomWindow { //Stack模式,每次切换都会将页面压入栈中,随着栈的页面增多,消耗的内存也越多,内存消耗多就会卡顿,这时候就需要按返回将页面pop掉,释放内存。该模式可以配合FluPage中的launchMode属性,设置页面的启动模式 pageMode: FluNavigationViewType.Stack //NoStack模式,每次切换都会销毁之前的页面然后创建一个新的页面,只需消耗少量内存(推荐) -// pageMode: FluNavigationViewType.NoStack + // pageMode: FluNavigationViewType.NoStack items: ItemsOriginal footerItems:ItemsFooter topPadding:FluTools.isMacos() ? 20 : 5 @@ -201,15 +201,27 @@ CustomWindow { } } - CircularReveal{ - id:reveal - target:window.contentItem - anchors.fill: parent - onImageChanged: { - changeDark() + Component{ + id:com_reveal + CircularReveal{ + id:reveal + target:window.contentItem + anchors.fill: parent + onAnimationFinished:{ + //动画结束后释放资源 + loader_reveal.sourceComponent = undefined + } + onImageChanged: { + changeDark() + } } } + Loader{ + id:loader_reveal + anchors.fill: parent + } + function distance(x1,y1,x2,y2){ return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) } @@ -218,11 +230,13 @@ CustomWindow { if(FluTools.isMacos() || !FluTheme.enableAnimation){ changeDark() }else{ + loader_reveal.sourceComponent = com_reveal var target = window.contentItem var pos = button.mapToItem(target,0,0) var mouseX = pos.x var mouseY = pos.y var radius = Math.max(distance(mouseX,mouseY,0,0),distance(mouseX,mouseY,target.width,0),distance(mouseX,mouseY,0,target.height),distance(mouseX,mouseY,target.width,target.height)) + var reveal = loader_reveal.item reveal.start(reveal.width*Screen.devicePixelRatio,reveal.height*Screen.devicePixelRatio,Qt.point(mouseX,mouseY),radius) } } @@ -245,5 +259,4 @@ CustomWindow { } } - } diff --git a/example/src/component/CircularReveal.cpp b/example/src/component/CircularReveal.cpp index 29464197..48aef669 100644 --- a/example/src/component/CircularReveal.cpp +++ b/example/src/component/CircularReveal.cpp @@ -6,11 +6,12 @@ CircularReveal::CircularReveal(QQuickItem* parent) : QQuickPaintedItem(parent) { setVisible(false); - _anim = new QPropertyAnimation(this, "radius", this); - _anim->setDuration(333); - _anim->setEasingCurve(QEasingCurve::OutCubic); - connect(_anim, &QPropertyAnimation::finished,this,[=](){ + _anim.setDuration(333); + _anim.setEasingCurve(QEasingCurve::OutCubic); + connect(&_anim, &QPropertyAnimation::finished,this,[=](){ + update(); setVisible(false); + Q_EMIT animationFinished(); }); connect(this,&CircularReveal::radiusChanged,this,[=](){ update(); @@ -31,8 +32,8 @@ void CircularReveal::paint(QPainter* painter) } void CircularReveal::start(int w,int h,const QPoint& center,int radius){ - _anim->setStartValue(0); - _anim->setEndValue(radius); + _anim.setStartValue(0); + _anim.setEndValue(radius); _center = center; _grabResult = _target->grabToImage(QSize(w,h)); connect(_grabResult.data(), &QQuickItemGrabResult::ready, this, &CircularReveal::handleGrabResult); @@ -43,5 +44,5 @@ void CircularReveal::handleGrabResult(){ update(); setVisible(true); Q_EMIT imageChanged(); - _anim->start(); + _anim.start(); } diff --git a/example/src/component/CircularReveal.h b/example/src/component/CircularReveal.h index 5084b165..9262b044 100644 --- a/example/src/component/CircularReveal.h +++ b/example/src/component/CircularReveal.h @@ -18,10 +18,11 @@ public: void paint(QPainter* painter) override; Q_INVOKABLE void start(int w,int h,const QPoint& center,int radius); Q_SIGNAL void imageChanged(); + Q_SIGNAL void animationFinished(); Q_SLOT void handleGrabResult(); private: QImage _source; - QPropertyAnimation* _anim; + QPropertyAnimation _anim = QPropertyAnimation(this, "radius", this); QPoint _center; QSharedPointer _grabResult; }; diff --git a/src/FluHttp.cpp b/src/FluHttp.cpp index 47f88543..a18a76c4 100644 --- a/src/FluHttp.cpp +++ b/src/FluHttp.cpp @@ -204,13 +204,11 @@ void FluHttp::download(QString path,QVariantMap params,QVariantMap headers){ addQueryParam(&url,data["params"].toMap()); QNetworkRequest request(url); addHeaders(&request,data["headers"].toMap()); - QFile *file = new QFile(path); + QSharedPointer file(new QFile(path)); QIODevice::OpenMode mode = QIODevice::WriteOnly|QIODevice::Truncate; if (!file->open(mode)) { Q_EMIT error(-1,QString("Url: %1 %2 Non-Writable").arg(request.url().toString(),file->fileName())); - file->deleteLater(); - file = nullptr; Q_EMIT finish(); return; } @@ -234,9 +232,7 @@ void FluHttp::download(QString path,QVariantMap params,QVariantMap headers){ } _cache.removeOne(reply); file->close(); - file->deleteLater(); reply->deleteLater(); - file = nullptr; reply = nullptr; Q_EMIT finish(); });