2023-06-29 23:36:36 +08:00
|
|
|
#include "CircularReveal.h"
|
2023-06-30 12:08:57 +08:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQuickItemGrabResult>
|
|
|
|
#include <QPainterPath>
|
2023-06-29 23:36:36 +08:00
|
|
|
|
2023-06-30 12:08:57 +08:00
|
|
|
CircularReveal::CircularReveal(QQuickItem* parent) : QQuickPaintedItem(parent)
|
2023-06-29 23:36:36 +08:00
|
|
|
{
|
2023-12-13 17:31:08 +08:00
|
|
|
_anim = new QPropertyAnimation(this, "radius", this);
|
2023-07-05 21:34:08 +08:00
|
|
|
setVisible(false);
|
2023-12-13 17:31:08 +08:00
|
|
|
_anim->setDuration(333);
|
|
|
|
_anim->setEasingCurve(QEasingCurve::OutCubic);
|
|
|
|
connect(_anim, &QPropertyAnimation::finished,this,[=](){
|
2023-07-25 21:24:45 +08:00
|
|
|
update();
|
2023-06-30 12:08:57 +08:00
|
|
|
setVisible(false);
|
2023-07-25 21:24:45 +08:00
|
|
|
Q_EMIT animationFinished();
|
2023-06-30 12:08:57 +08:00
|
|
|
});
|
|
|
|
connect(this,&CircularReveal::radiusChanged,this,[=](){
|
|
|
|
update();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CircularReveal::paint(QPainter* painter)
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
painter->drawImage(QRect(0, 0, static_cast<int>(width()), static_cast<int>(height())), _source);
|
|
|
|
QPainterPath path;
|
|
|
|
path.moveTo(_center.x(),_center.y());
|
|
|
|
path.addEllipse(QPointF(_center.x(),_center.y()), _radius, _radius);
|
|
|
|
painter->setCompositionMode(QPainter::CompositionMode_Clear);
|
|
|
|
painter->fillPath(path, Qt::black);
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CircularReveal::start(int w,int h,const QPoint& center,int radius){
|
2023-12-13 17:31:08 +08:00
|
|
|
_anim->setStartValue(0);
|
|
|
|
_anim->setEndValue(radius);
|
2023-06-30 12:08:57 +08:00
|
|
|
_center = center;
|
|
|
|
_grabResult = _target->grabToImage(QSize(w,h));
|
|
|
|
connect(_grabResult.data(), &QQuickItemGrabResult::ready, this, &CircularReveal::handleGrabResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CircularReveal::handleGrabResult(){
|
|
|
|
_grabResult.data()->image().swap(_source);
|
|
|
|
update();
|
|
|
|
setVisible(true);
|
|
|
|
Q_EMIT imageChanged();
|
2023-12-13 17:31:08 +08:00
|
|
|
_anim->start();
|
2023-06-29 23:36:36 +08:00
|
|
|
}
|