QQuickPathRectangle: Align corner radius behavior with QQuickRectangle
This change introduces isCornerRadiusSet flag to track whether each corner radius is explicitly set, mirroring QQuickRectangle's behavior. If a corner radius is unset, it correctly falls back to the global radius, ensuring consistency between QQuickPathRectangle and QQuickRectangle. This update is required because QQuickRectangle was modified to use flags to indicate an unset corner radius instead of -1, which previously caused issues when animating. Since tests verify that both components must behave the same way, QQuickPathRectangle has been updated accordingly. Fixes: QTBUG-134404 Change-Id: Id13401ef264a82c2746744ca5accd72f647c65c8 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
parent
a62ef0f62e
commit
0675e10429
|
@ -2486,13 +2486,13 @@ void QQuickPathRectangle::setRadius(qreal newRadius)
|
|||
return;
|
||||
_extra->radius = newRadius;
|
||||
emit radiusChanged();
|
||||
if (_extra->cornerRadii[Qt::TopLeftCorner] < 0)
|
||||
if (!(_extra->isCornerRadiusSet & (1 << Qt::TopLeftCorner)))
|
||||
emit topLeftRadiusChanged();
|
||||
if (_extra->cornerRadii[Qt::TopRightCorner] < 0)
|
||||
if (!(_extra->isCornerRadiusSet & (1 << Qt::TopRightCorner)))
|
||||
emit topRightRadiusChanged();
|
||||
if (_extra->cornerRadii[Qt::BottomLeftCorner] < 0)
|
||||
if (!(_extra->isCornerRadiusSet & (1 << Qt::BottomLeftCorner)))
|
||||
emit bottomLeftRadiusChanged();
|
||||
if (_extra->cornerRadii[Qt::BottomRightCorner] < 0)
|
||||
if (!(_extra->isCornerRadiusSet & (1 << Qt::BottomRightCorner)))
|
||||
emit bottomRightRadiusChanged();
|
||||
emit changed();
|
||||
}
|
||||
|
@ -2504,24 +2504,27 @@ void QQuickPathRectangle::setRadius(qreal newRadius)
|
|||
qreal QQuickPathRectangle::cornerRadius(Qt::Corner corner) const
|
||||
{
|
||||
if (_extra.isAllocated())
|
||||
return _extra->cornerRadii[corner] < 0 ? _extra->radius : _extra->cornerRadii[corner];
|
||||
return (_extra->isCornerRadiusSet & (1 << corner)) ? _extra->cornerRadii[corner] : _extra->radius;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QQuickPathRectangle::setCornerRadius(Qt::Corner corner, qreal newCornerRadius)
|
||||
{
|
||||
if (newCornerRadius < 0 || _extra.value().cornerRadii[corner] == newCornerRadius)
|
||||
if (_extra.value().cornerRadii[corner] == newCornerRadius
|
||||
&& (_extra->isCornerRadiusSet & (1 << corner)))
|
||||
return;
|
||||
_extra->cornerRadii[corner] = newCornerRadius;
|
||||
_extra->isCornerRadiusSet |= (1 << corner);
|
||||
|
||||
emitCornerRadiusChanged(corner);
|
||||
}
|
||||
|
||||
void QQuickPathRectangle::resetCornerRadius(Qt::Corner corner)
|
||||
{
|
||||
if (!_extra.isAllocated() || _extra->cornerRadii[corner] < 0)
|
||||
if (!_extra.isAllocated() || !(_extra->isCornerRadiusSet & (1 << corner)))
|
||||
return;
|
||||
_extra->cornerRadii[corner] = -1;
|
||||
_extra->isCornerRadiusSet &= ~(1 << corner);
|
||||
emitCornerRadiusChanged(corner);
|
||||
}
|
||||
|
||||
|
@ -2638,7 +2641,7 @@ void QQuickPathRectangle::addToPath(QPainterPath &path, const QQuickPathData &da
|
|||
const qreal generalDiameter = qMax(qreal(0), qMin(maxDiameter, 2 * _extra->radius));
|
||||
auto effectiveDiameter = [&](Qt::Corner corner) {
|
||||
qreal radius = _extra->cornerRadii[corner];
|
||||
return radius < 0 ? generalDiameter : qMin(maxDiameter, 2 * radius);
|
||||
return (_extra->isCornerRadiusSet & ( 1 << corner)) ? qMin(maxDiameter, 2 * radius) : generalDiameter;
|
||||
};
|
||||
const qreal diamTL = effectiveDiameter(Qt::TopLeftCorner);
|
||||
const qreal diamTR = effectiveDiameter(Qt::TopRightCorner);
|
||||
|
|
|
@ -510,11 +510,13 @@ private:
|
|||
struct ExtraData
|
||||
{
|
||||
ExtraData() {
|
||||
std::fill_n(cornerRadii, 4, -1);
|
||||
std::fill_n(cornerRadii, 4, 0);
|
||||
std::fill_n(cornerBevel, 4, std::optional<bool>());
|
||||
isCornerRadiusSet = 0;
|
||||
}
|
||||
qreal radius = 0;
|
||||
qreal cornerRadii[4];
|
||||
unsigned isCornerRadiusSet : 4;
|
||||
bool bevel = false;
|
||||
std::optional<bool> cornerBevel[4];
|
||||
};
|
||||
|
|
|
@ -411,9 +411,8 @@ void tst_QuickPath::rectangleRadii()
|
|||
COMPARE_RADII(pathRectangle, quickRectangle);
|
||||
pathRectangle.setTopLeftRadius(-7);
|
||||
quickRectangle->setTopLeftRadius(-7);
|
||||
QEXPECT_FAIL("", "Need to adapt to changes from QTBUG-120188", Continue);
|
||||
QCOMPARE(pathRectangle.topLeftRadius(), quickRectangle->topLeftRadius());
|
||||
// COMPARE_RADII(pathRectangle, quickRectangle);
|
||||
COMPARE_RADII(pathRectangle, quickRectangle);
|
||||
pathRectangle.setRadius(4);
|
||||
quickRectangle->setRadius(4);
|
||||
pathRectangle.resetBottomLeftRadius();
|
||||
|
|
Loading…
Reference in New Issue