feat: 添加ElaWidgetTool库
This commit is contained in:
45
ElaWidgetTools/DeveloperComponents/ElaMaskWidget.cpp
Normal file
45
ElaWidgetTools/DeveloperComponents/ElaMaskWidget.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "ElaMaskWidget.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
ElaMaskWidget::ElaMaskWidget(QWidget* parent)
|
||||
: QWidget{parent}
|
||||
{
|
||||
setObjectName("ElaMaskWidget");
|
||||
setStyleSheet("#ElaMaskWidget{background-color:transparent;}");
|
||||
_pMaskAlpha = 0;
|
||||
}
|
||||
|
||||
ElaMaskWidget::~ElaMaskWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void ElaMaskWidget::doMaskAnimation(int endValue)
|
||||
{
|
||||
QPropertyAnimation* opacityAnimation = new QPropertyAnimation(this, "pMaskAlpha");
|
||||
connect(opacityAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
|
||||
update();
|
||||
});
|
||||
connect(opacityAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
if (endValue == 0)
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
opacityAnimation->setEasingCurve(QEasingCurve::InOutSine);
|
||||
opacityAnimation->setDuration(250);
|
||||
opacityAnimation->setStartValue(_pMaskAlpha);
|
||||
opacityAnimation->setEndValue(endValue);
|
||||
opacityAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void ElaMaskWidget::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setBrush(QColor(0x00, 0x00, 0x00, _pMaskAlpha));
|
||||
painter.drawRect(rect());
|
||||
painter.restore();
|
||||
}
|
||||
Reference in New Issue
Block a user