Commit 01efc761 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Fix scaling of the vanishing points in the 4-point transform tool

BUG:343791
parent 0d2747e8
......@@ -214,11 +214,6 @@ void KisPerspectiveTransformStrategy::paint(QPainter &gc)
gc.restore();
// Draw Handles
QRectF handleRect =
KisTransformUtils::handleRect(KisTransformUtils::handleVisualRadius,
m_d->handlesTransform,
m_d->transaction.originalRect());
QPainterPath handles;
handles.moveTo(m_d->transaction.originalTopLeft());
......@@ -227,11 +222,20 @@ void KisPerspectiveTransformStrategy::paint(QPainter &gc)
handles.lineTo(m_d->transaction.originalBottomLeft());
handles.lineTo(m_d->transaction.originalTopLeft());
handles.addRect(handleRect.translated(m_d->transaction.originalTopLeft()));
handles.addRect(handleRect.translated(m_d->transaction.originalTopRight()));
handles.addRect(handleRect.translated(m_d->transaction.originalBottomLeft()));
handles.addRect(handleRect.translated(m_d->transaction.originalBottomRight()));
auto addHandleRectFunc =
[&](const QPointF &pt) {
handles.addRect(
KisTransformUtils::handleRect(KisTransformUtils::handleVisualRadius,
m_d->handlesTransform,
m_d->transaction.originalRect(), pt)
.translated(pt));
};
addHandleRectFunc(m_d->transaction.originalTopLeft());
addHandleRectFunc(m_d->transaction.originalTopRight());
addHandleRectFunc(m_d->transaction.originalBottomLeft());
addHandleRectFunc(m_d->transaction.originalBottomRight());
gc.save();
......@@ -264,6 +268,11 @@ void KisPerspectiveTransformStrategy::paint(QPainter &gc)
{ // painting perspective handles
QPainterPath perspectiveHandles;
QRectF handleRect =
KisTransformUtils::handleRect(KisTransformUtils::handleVisualRadius,
QTransform(),
m_d->transaction.originalRect());
if (m_d->transformedHandles.xVanishingExists) {
QRectF rc = handleRect.translated(m_d->transformedHandles.xVanishing);
perspectiveHandles.addEllipse(rc);
......
......@@ -63,11 +63,11 @@ qreal KisTransformUtils::effectiveSize(const QRectF &rc) {
return 0.5 * (rc.width(), rc.height());
}
QRectF KisTransformUtils::handleRect(qreal radius, const QTransform &t, const QRectF &limitingRect, qreal *dOut) {
QRectF handleRectImpl(qreal radius, const QTransform &t, const QRectF &limitingRect, const QPointF &basePoint, qreal *dOut) {
qreal handlesExtraScale =
scaleFromPerspectiveMatrix(t, limitingRect.center());
KisTransformUtils::scaleFromPerspectiveMatrix(t, basePoint);
const qreal maxD = 0.2 * effectiveSize(limitingRect);
const qreal maxD = 0.2 * KisTransformUtils::effectiveSize(limitingRect);
const qreal d = qMin(maxD, radius / handlesExtraScale);
QRectF handleRect(-0.5 * d, -0.5 * d, d, d);
......@@ -77,6 +77,15 @@ QRectF KisTransformUtils::handleRect(qreal radius, const QTransform &t, const QR
}
return handleRect;
}
QRectF KisTransformUtils::handleRect(qreal radius, const QTransform &t, const QRectF &limitingRect, qreal *dOut) {
return handleRectImpl(radius, t, limitingRect, limitingRect.center(), dOut);
}
QRectF KisTransformUtils::handleRect(qreal radius, const QTransform &t, const QRectF &limitingRect, const QPointF &basePoint) {
return handleRectImpl(radius, t, limitingRect, basePoint, 0);
}
QPointF KisTransformUtils::clipInRect(QPointF p, QRectF r)
......
......@@ -63,6 +63,7 @@ public:
static qreal effectiveSize(const QRectF &rc);
static QRectF handleRect(qreal radius, const QTransform &t, const QRectF &limitingSize, qreal *d = 0);
static QRectF handleRect(qreal radius, const QTransform &t, const QRectF &limitingRect, const QPointF &basePoint);
static QPointF clipInRect(QPointF p, QRectF r);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment