mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-06-02 14:39:49 +08:00
fix: incorrect download water drop animation start position
use rect().center() instead of event->rect().center() in WaterDrop::paintEvent; all coordinate calculation should use float instead of int Log: fix incorrect download water drop animation start position
This commit is contained in:
parent
fb01686527
commit
f4fa07d589
src
@ -190,15 +190,17 @@ void MainWindow::initTitleBar()
|
|||||||
|
|
||||||
QHBoxLayout *customWidgetLayout = new QHBoxLayout(customWidget);
|
QHBoxLayout *customWidgetLayout = new QHBoxLayout(customWidget);
|
||||||
customWidgetLayout->setContentsMargins(8, 0, 0, 0);
|
customWidgetLayout->setContentsMargins(8, 0, 0, 0);
|
||||||
customWidgetLayout->setSpacing(8);
|
customWidgetLayout->setSpacing(0);
|
||||||
customWidgetLayout->addWidget(titleLabel, 0, Qt::AlignLeft);
|
customWidgetLayout->addWidget(titleLabel, 0, Qt::AlignLeft);
|
||||||
|
customWidgetLayout->addSpacing(8);
|
||||||
customWidgetLayout->addWidget(backButton, 0, Qt::AlignLeft);
|
customWidgetLayout->addWidget(backButton, 0, Qt::AlignLeft);
|
||||||
|
customWidgetLayout->setSpacing(20);
|
||||||
QWidget *centralWidget = new QWidget(customWidget);
|
QWidget *centralWidget = new QWidget(customWidget);
|
||||||
centralWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
centralWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
customWidgetLayout->addWidget(centralWidget, 1, Qt::AlignHCenter);
|
customWidgetLayout->addWidget(centralWidget, 1, Qt::AlignHCenter);
|
||||||
|
|
||||||
QHBoxLayout *centralLayout = new QHBoxLayout(centralWidget);
|
QHBoxLayout *centralLayout = new QHBoxLayout(centralWidget);
|
||||||
centralLayout->setContentsMargins(0, 0, 10, 0);
|
centralLayout->setContentsMargins(0, 0, 20, 0);
|
||||||
centralLayout->setSpacing(0);
|
centralLayout->setSpacing(0);
|
||||||
|
|
||||||
centralLayout->addWidget(searchEdit, 0, Qt::AlignHCenter);
|
centralLayout->addWidget(searchEdit, 0, Qt::AlignHCenter);
|
||||||
|
@ -33,7 +33,7 @@ void ProgressButton::setProgress(int progress)
|
|||||||
buttonState = state::closeProgress;
|
buttonState = state::closeProgress;
|
||||||
update();
|
update();
|
||||||
WaterDrop *waterDrop = new WaterDrop(parentWidget());
|
WaterDrop *waterDrop = new WaterDrop(parentWidget());
|
||||||
waterDrop->move(geometry().center());
|
waterDrop->move(QRectF(geometry()).center());
|
||||||
waterDrop->show();
|
waterDrop->show();
|
||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
@ -124,12 +124,12 @@ void ProgressButton::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
QRect rect = event->rect();
|
QRectF rect = this->rect();
|
||||||
|
|
||||||
if (buttonState == state::normal || buttonState == state::hover)
|
if (buttonState == state::normal || buttonState == state::hover)
|
||||||
{
|
{
|
||||||
qreal radius = rect.height() / 2.0;
|
qreal radius = rect.height() / 2;
|
||||||
painter.translate(QRectF(rect).center());
|
painter.translate(rect.center());
|
||||||
painter.setPen(Qt::transparent);
|
painter.setPen(Qt::transparent);
|
||||||
painter.setBrush(backColor);
|
painter.setBrush(backColor);
|
||||||
painter.drawEllipse(QPointF(0, 0), radius, radius);
|
painter.drawEllipse(QPointF(0, 0), radius, radius);
|
||||||
@ -140,8 +140,8 @@ void ProgressButton::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
else if (buttonState == state::openProgress)
|
else if (buttonState == state::openProgress)
|
||||||
{
|
{
|
||||||
qreal radius = rect.height() / 2.0 - 1;
|
qreal radius = rect.height() / 2 - 1;
|
||||||
painter.translate(QRectF(rect).center());
|
painter.translate(rect.center());
|
||||||
painter.setPen(QPen(backColor.darker(), 2));
|
painter.setPen(QPen(backColor.darker(), 2));
|
||||||
painter.setBrush(backColor);
|
painter.setBrush(backColor);
|
||||||
painter.drawEllipse(QPointF(0, 0), radius, radius);
|
painter.drawEllipse(QPointF(0, 0), radius, radius);
|
||||||
@ -157,8 +157,8 @@ void ProgressButton::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
else if (buttonState == state::closeProgress)
|
else if (buttonState == state::closeProgress)
|
||||||
{
|
{
|
||||||
qreal radius = rect.height() / 2.0 - 1;
|
qreal radius = rect.height() / 2 - 1;
|
||||||
painter.translate(QRectF(rect).center());
|
painter.translate(rect.center());
|
||||||
painter.setPen(QPen(color.darker(100), 2));
|
painter.setPen(QPen(color.darker(100), 2));
|
||||||
painter.setBrush(backColor);
|
painter.setBrush(backColor);
|
||||||
painter.drawEllipse(QPointF(0, 0), radius, radius);
|
painter.drawEllipse(QPointF(0, 0), radius, radius);
|
||||||
@ -176,7 +176,7 @@ void ProgressButton::operationProcessing()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const int RADIUS = 60;
|
const int RADIUS = 30;
|
||||||
WaterDrop::WaterDrop(QWidget *parent)
|
WaterDrop::WaterDrop(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_waterDropAnimation(new QVariantAnimation(this))
|
, m_waterDropAnimation(new QVariantAnimation(this))
|
||||||
@ -191,16 +191,16 @@ WaterDrop::WaterDrop(QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 把鼠标点击的点转换为圆心点坐标
|
// 把鼠标点击的点转换为圆心点坐标
|
||||||
void WaterDrop::move(const QPoint &point)
|
void WaterDrop::move(const QPointF &point)
|
||||||
{
|
{
|
||||||
QPoint translatePoint = point - rect().center();
|
QPointF translatePoint = point - QRectF(rect()).center();
|
||||||
QWidget::move(translatePoint);
|
QWidget::move(qRound(translatePoint.x()), qRound(translatePoint.y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaterDrop::show()
|
void WaterDrop::show()
|
||||||
{
|
{
|
||||||
m_waterDropAnimation->setStartValue(0);
|
m_waterDropAnimation->setStartValue(0);
|
||||||
m_waterDropAnimation->setEndValue(RADIUS);
|
m_waterDropAnimation->setEndValue(RADIUS - 2);
|
||||||
m_waterDropAnimation->setDuration(350);
|
m_waterDropAnimation->setDuration(350);
|
||||||
|
|
||||||
connect(m_waterDropAnimation, &QVariantAnimation::valueChanged, this, &WaterDrop::onRadiusChanged);
|
connect(m_waterDropAnimation, &QVariantAnimation::valueChanged, this, &WaterDrop::onRadiusChanged);
|
||||||
@ -213,10 +213,9 @@ void WaterDrop::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
QPen pen(QBrush(QColor("#ffff80")), 5.0);
|
QPen pen(QBrush(QColor("#ffff80")), 4.0);
|
||||||
pen.setWidth(5);
|
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
painter.drawEllipse(event->rect().center(), m_animationRadius, m_animationRadius);
|
painter.drawEllipse(QRectF(rect()).center(), m_animationRadius, m_animationRadius);
|
||||||
|
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ class WaterDrop : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit WaterDrop(QWidget *parent = nullptr);
|
explicit WaterDrop(QWidget *parent = nullptr);
|
||||||
void show();
|
void show();
|
||||||
void move(const QPoint &point);
|
void move(const QPointF &point);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user