Commit 54642e65 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implemented dummy UI for the upcoming Cage Transform tool

parent 96640155
......@@ -6,6 +6,7 @@ set(kritatooltransform_PART_SRCS
kis_tool_transform_config_widget.cpp
kis_transform_strategy_base.cpp
kis_warp_transform_strategy.cpp
kis_cage_transform_strategy.cpp
kis_free_transform_strategy.cpp
kis_free_transform_strategy_gsl_helpers.cpp
kis_perspective_transform_strategy.cpp
......
/*
* Copyright (c) 2014 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_cage_transform_strategy.h"
#include <QPointF>
#include <QPainter>
#include "krita_utils.h"
#include "kis_cursor.h"
struct KisCageTransformStrategy::Private
{
Private(KisCageTransformStrategy *_q)
: q(_q)
{
}
KisCageTransformStrategy * const q;
};
KisCageTransformStrategy::KisCageTransformStrategy(const KisCoordinatesConverter *converter,
ToolTransformArgs &currentArgs,
TransformTransactionProperties &transaction)
: KisWarpTransformStrategy(converter, currentArgs, transaction),
m_d(new Private(this))
{
overrideDrawingItems(true, false, true);
setCloseOnStartPointClick(true);
}
KisCageTransformStrategy::~KisCageTransformStrategy()
{
}
void KisCageTransformStrategy::drawConnectionLines(QPainter &gc,
const QVector<QPointF> &origPoints,
const QVector<QPointF> &transfPoints,
bool isEditingPoints)
{
const int numPoints = origPoints.size();
if (numPoints <= 1) return;
QPen antsPen;
QPen outlinePen;
KritaUtils::initAntsPen(&antsPen, &outlinePen);
const int iterateLimit = isEditingPoints ? numPoints : numPoints + 1;
for (int i = 1; i < iterateLimit; ++i) {
int idx = i % numPoints;
int prevIdx = (i - 1) % numPoints;
gc.setPen(outlinePen);
gc.drawLine(transfPoints[prevIdx], transfPoints[idx]);
gc.setPen(antsPen);
gc.drawLine(transfPoints[prevIdx], transfPoints[idx]);
}
}
/*
* Copyright (c) 2014 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __KIS_CAGE_TRANSFORM_STRATEGY_H
#define __KIS_CAGE_TRANSFORM_STRATEGY_H
#include <QObject>
#include <QScopedPointer>
#include "kis_warp_transform_strategy.h"
class QPointF;
class QPainter;
class KisCoordinatesConverter;
class ToolTransformArgs;
class QTransform;
class TransformTransactionProperties;
class QCursor;
class QImage;
class KisCageTransformStrategy : public KisWarpTransformStrategy
{
Q_OBJECT
public:
KisCageTransformStrategy(const KisCoordinatesConverter *converter,
ToolTransformArgs &currentArgs,
TransformTransactionProperties &transaction);
~KisCageTransformStrategy();
protected:
void drawConnectionLines(QPainter &gc,
const QVector<QPointF> &origPoints,
const QVector<QPointF> &transfPoints,
bool isEditingPoints);
private:
class Private;
const QScopedPointer<Private> m_d;
};
#endif /* __KIS_CAGE_TRANSFORM_STRATEGY_H */
......@@ -80,6 +80,7 @@
#include "kis_transform_utils.h"
#include "kis_warp_transform_strategy.h"
#include "kis_cage_transform_strategy.h"
#include "kis_free_transform_strategy.h"
#include "kis_perspective_transform_strategy.h"
......@@ -94,6 +95,10 @@ KisToolTransform::KisToolTransform(KoCanvasBase * canvas)
new KisWarpTransformStrategy(
dynamic_cast<KisCanvas2*>(canvas)->coordinatesConverter(),
m_currentArgs, m_transaction))
, m_cageStrategy(
new KisCageTransformStrategy(
dynamic_cast<KisCanvas2*>(canvas)->coordinatesConverter(),
m_currentArgs, m_transaction))
, m_freeStrategy(
new KisFreeTransformStrategy(
dynamic_cast<KisCanvas2*>(canvas)->coordinatesConverter(),
......@@ -111,6 +116,7 @@ KisToolTransform::KisToolTransform(KoCanvasBase * canvas)
m_optionsWidget = 0;
connect(m_warpStrategy.data(), SIGNAL(requestCanvasUpdate()), SLOT(canvasUpdateRequested()));
connect(m_cageStrategy.data(), SIGNAL(requestCanvasUpdate()), SLOT(canvasUpdateRequested()));
connect(m_freeStrategy.data(), SIGNAL(requestCanvasUpdate()), SLOT(canvasUpdateRequested()));
connect(m_freeStrategy.data(), SIGNAL(requestResetRotationCenterButtons()), SLOT(resetRotationCenterButtonsRequested()));
connect(m_freeStrategy.data(), SIGNAL(requestShowImageTooBig(bool)), SLOT(imageTooBigRequested(bool)));
......@@ -155,6 +161,8 @@ KisTransformStrategyBase* KisToolTransform::currentStrategy() const
return m_freeStrategy.data();
} else if (m_currentArgs.mode() == ToolTransformArgs::WARP) {
return m_warpStrategy.data();
} else if (m_currentArgs.mode() == ToolTransformArgs::CAGE) {
return m_cageStrategy.data();
} else /* if (m_currentArgs.mode() == ToolTransformArgs::PERSPECTIVE_4POINT) */ {
return m_perspectiveStrategy.data();
}
......@@ -310,6 +318,9 @@ KisToolTransform::TransformToolMode KisToolTransform::transformMode() const
case ToolTransformArgs::WARP:
mode = WarpTransformMode;
break;
case ToolTransformArgs::CAGE:
mode = CageTransformMode;
break;
case ToolTransformArgs::PERSPECTIVE_4POINT:
mode = PerspectiveTransformMode;
break;
......@@ -400,6 +411,9 @@ void KisToolTransform::setTransformMode(KisToolTransform::TransformToolMode newM
case WarpTransformMode:
mode = ToolTransformArgs::WARP;
break;
case CageTransformMode:
mode = ToolTransformArgs::CAGE;
break;
case PerspectiveTransformMode:
mode = ToolTransformArgs::PERSPECTIVE_4POINT;
break;
......@@ -411,7 +425,9 @@ void KisToolTransform::setTransformMode(KisToolTransform::TransformToolMode newM
if( newMode == FreeTransformMode ) {
m_optionsWidget->slotSetFreeTransformModeButtonClicked( true );
} else if( newMode == WarpTransformMode ) {
m_optionsWidget->slotSetWrapModeButtonClicked( true );
m_optionsWidget->slotSetWarpModeButtonClicked( true );
} else if( newMode == CageTransformMode ) {
m_optionsWidget->slotSetCageModeButtonClicked( true );
} else if( newMode == PerspectiveTransformMode ) {
m_optionsWidget->slotSetPerspectiveModeButtonClicked( true );
}
......@@ -488,13 +504,17 @@ void KisToolTransform::mouseReleaseEvent(KoPointerEvent *event)
setMode(KisTool::HOVER_MODE);
if (m_actuallyMoveWhileSelected) {
if (m_actuallyMoveWhileSelected ||
currentStrategy()->acceptsClicks()) {
if (currentStrategy()->endPrimaryAction()) {
commitChanges();
} else {
outlineChanged();
}
}
updateOptionWidget();
updateApplyResetAvailability();
}
......@@ -514,6 +534,9 @@ void KisToolTransform::initTransformMode(ToolTransformArgs::TransformMode mode)
} else if (mode == ToolTransformArgs::WARP) {
m_currentArgs.setMode(ToolTransformArgs::WARP);
m_optionsWidget->setDefaultWarpPoints();
} else if (mode == ToolTransformArgs::CAGE) {
m_currentArgs.setMode(ToolTransformArgs::CAGE);
m_transaction.setEditWarpPoints(true);
} else if (mode == ToolTransformArgs::PERSPECTIVE_4POINT) {
m_currentArgs.setMode(ToolTransformArgs::PERSPECTIVE_4POINT);
}
......@@ -585,6 +608,7 @@ void KisToolTransform::initThumbnailImage(KisPaintDeviceSP previewDevice)
m_freeStrategy->setThumbnailImage(origImg, thumbToImageTransform);
m_perspectiveStrategy->setThumbnailImage(origImg, thumbToImageTransform);
m_warpStrategy->setThumbnailImage(origImg, thumbToImageTransform);
m_cageStrategy->setThumbnailImage(origImg, thumbToImageTransform);
}
void KisToolTransform::activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes)
......
......@@ -57,6 +57,7 @@ class KisCanvas2;
class QTouchEvent;
class KisTransformStrategyBase;
class KisWarpTransformStrategy;
class KisCageTransformStrategy;
class KisFreeTransformStrategy;
class KisPerspectiveTransformStrategy;
......@@ -107,6 +108,7 @@ public:
enum TransformToolMode {
FreeTransformMode,
WarpTransformMode,
CageTransformMode,
PerspectiveTransformMode
};
Q_ENUMS(TransformToolMode)
......@@ -263,6 +265,7 @@ private:
QRectF m_refRect;
QScopedPointer<KisWarpTransformStrategy> m_warpStrategy;
QScopedPointer<KisCageTransformStrategy> m_cageStrategy;
QScopedPointer<KisFreeTransformStrategy> m_freeStrategy;
QScopedPointer<KisPerspectiveTransformStrategy> m_perspectiveStrategy;
KisTransformStrategyBase* currentStrategy() const;
......
......@@ -117,8 +117,8 @@ KisToolTransformConfigWidget::KisToolTransformConfigWidget(TransformTransactionP
connect(aZBox, SIGNAL(valueChanged(double)), this, SLOT(slotSetAZ(double)));
connect(aspectButton, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(slotSetKeepAspectRatio(bool)));
// Init Wrap Transform Values
connect(alphaBox, SIGNAL(valueChanged(double)), this, SLOT(slotSetWrapAlpha(double)));
// Init Warp Transform Values
connect(alphaBox, SIGNAL(valueChanged(double)), this, SLOT(slotSetWarpAlpha(double)));
connect(densityBox, SIGNAL(valueChanged(int)), this, SLOT(slotSetWarpDensity(int)));
connect(defaultRadioButton, SIGNAL(clicked(bool)), this, SLOT(slotWarpDefaultPointsButtonClicked(bool)));
......@@ -126,6 +126,8 @@ KisToolTransformConfigWidget::KisToolTransformConfigWidget(TransformTransactionP
connect(lockUnlockPointsButton, SIGNAL(clicked()), this, SLOT(slotWarpLockPointsButtonClicked()));
connect(resetPointsButton, SIGNAL(clicked()), this, SLOT(slotWarpResetPointsButtonClicked()));
// Init Cage Transform Values
connect(chkEditCage, SIGNAL(clicked(bool)), this, SLOT(slotEditCagePoints(bool)));
// Connect all edit boxes to the Editing Finished signal
connect(scaleXBox, SIGNAL(editingFinished()), this, SLOT(notifyEditingFinished()));
......@@ -151,6 +153,7 @@ KisToolTransformConfigWidget::KisToolTransformConfigWidget(TransformTransactionP
connect(customRadioButton, SIGNAL(clicked(bool)), this, SLOT(notifyEditingFinished()));
connect(lockUnlockPointsButton, SIGNAL(clicked()), this, SLOT(notifyEditingFinished()));
connect(resetPointsButton, SIGNAL(clicked()), this, SLOT(notifyEditingFinished()));
connect(chkEditCage, SIGNAL(clicked(bool)), this, SLOT(notifyEditingFinished()));
// Connect Apply/Reset buttons
......@@ -158,7 +161,8 @@ KisToolTransformConfigWidget::KisToolTransformConfigWidget(TransformTransactionP
// Mode switch buttons
connect(freeTransformButton, SIGNAL(clicked(bool)), this, SLOT(slotSetFreeTransformModeButtonClicked(bool)));
connect(warpButton, SIGNAL(clicked(bool)), this, SLOT(slotSetWrapModeButtonClicked(bool)));
connect(warpButton, SIGNAL(clicked(bool)), this, SLOT(slotSetWarpModeButtonClicked(bool)));
connect(cageButton, SIGNAL(clicked(bool)), this, SLOT(slotSetCageModeButtonClicked(bool)));
connect(perspectiveTransformButton, SIGNAL(clicked(bool)), this, SLOT(slotSetPerspectiveModeButtonClicked(bool)));
// Connect Decorations switcher
......@@ -203,9 +207,11 @@ void KisToolTransformConfigWidget::updateConfig(const ToolTransformArgs &config)
bool freeTransformIsActive = config.mode() == ToolTransformArgs::FREE_TRANSFORM;
freeTransformButton->setChecked(freeTransformIsActive);
perspectiveTransformButton->setChecked(!freeTransformIsActive);
warpButton->setChecked(false);
if (freeTransformIsActive) {
freeTransformButton->setChecked(true);
} else {
perspectiveTransformButton->setChecked(true);
}
aXBox->setEnabled(freeTransformIsActive);
aYBox->setEnabled(freeTransformIsActive);
......@@ -238,11 +244,10 @@ void KisToolTransformConfigWidget::updateConfig(const ToolTransformArgs &config)
break;
}
}
} else {
} else if (config.mode() == ToolTransformArgs::WARP) {
stackedWidget->setCurrentIndex(1);
freeTransformButton->setChecked(false);
warpButton->setChecked(true);
alphaBox->setValue(config.alpha());
if (config.defaultPoints()) {
densityBox->setValue(config.numPoints());
......@@ -255,6 +260,13 @@ void KisToolTransformConfigWidget::updateConfig(const ToolTransformArgs &config)
customWarpWidget->setEnabled(!config.defaultPoints());
updateLockPointsButtonCaption();
} else if (config.mode() == ToolTransformArgs::CAGE) {
stackedWidget->setCurrentIndex(2);
cageButton->setChecked(true);
chkEditCage->setChecked(m_transaction->editWarpPoints());
}
unblockUiSlots();
......@@ -362,13 +374,20 @@ void KisToolTransformConfigWidget::slotSetFreeTransformModeButtonClicked(bool)
emit sigResetTransform();
}
void KisToolTransformConfigWidget::slotSetWrapModeButtonClicked(bool)
void KisToolTransformConfigWidget::slotSetWarpModeButtonClicked(bool)
{
ToolTransformArgs *config = m_transaction->currentConfig();
config->setMode(ToolTransformArgs::WARP);
emit sigResetTransform();
}
void KisToolTransformConfigWidget::slotSetCageModeButtonClicked(bool)
{
ToolTransformArgs *config = m_transaction->currentConfig();
config->setMode(ToolTransformArgs::CAGE);
emit sigResetTransform();
}
void KisToolTransformConfigWidget::slotSetPerspectiveModeButtonClicked(bool)
{
ToolTransformArgs *config = m_transaction->currentConfig();
......@@ -521,7 +540,7 @@ void KisToolTransformConfigWidget::slotSetKeepAspectRatio(bool value)
notifyConfigChanged();
}
void KisToolTransformConfigWidget::slotSetWrapAlpha(double value)
void KisToolTransformConfigWidget::slotSetWarpAlpha(double value)
{
if (m_uiSlotsBlocked) return;
......@@ -650,3 +669,14 @@ void KisToolTransformConfigWidget::slotWarpTypeChanged(int index)
notifyConfigChanged();
}
void KisToolTransformConfigWidget::slotEditCagePoints(bool value)
{
if (m_uiSlotsBlocked) return;
ToolTransformArgs *config = m_transaction->currentConfig();
config->refTransformedPoints() = config->origPoints();
m_transaction->setEditWarpPoints(value);
notifyConfigChanged();
}
......@@ -69,7 +69,7 @@ public slots:
void slotSetAY(double value);
void slotSetAZ(double value);
void slotSetWrapAlpha(double value);
void slotSetWarpAlpha(double value);
void slotSetWarpDensity(int value);
void slotSetKeepAspectRatio(bool value);
......@@ -80,10 +80,13 @@ public slots:
void slotWarpResetPointsButtonClicked();
void slotSetFreeTransformModeButtonClicked(bool);
void slotSetWrapModeButtonClicked(bool);
void slotSetWarpModeButtonClicked(bool);
void slotSetCageModeButtonClicked(bool);
void slotSetPerspectiveModeButtonClicked(bool);
void slotButtonBoxClicked(QAbstractButton *button);
void slotEditCagePoints(bool value);
void notifyEditingFinished();
private:
......
......@@ -53,3 +53,8 @@ void KisTransformStrategyBase::setThumbnailImage(const QImage &image, QTransform
m_d->originalImage = image;
m_d->thumbToImageTransform = thumbToImageTransform;
}
bool KisTransformStrategyBase::acceptsClicks() const
{
return false;
}
......@@ -42,6 +42,8 @@ public:
public:
virtual bool acceptsClicks() const;
virtual void setTransformFunction(const QPointF &mousePos, bool perspectiveModifierActive) = 0;
virtual void paint(QPainter &gc) = 0;
virtual QCursor getCurrentCursor() const = 0;
......
......@@ -38,7 +38,12 @@ struct KisWarpTransformStrategy::Private
: q(_q),
converter(_converter),
currentArgs(_currentArgs),
transaction(_transaction)
transaction(_transaction),
drawConnectionLines(true),
drawOrigPoints(true),
drawTransfPoints(true),
closeOnStartPointClick(false),
pointWasDragged(false)
{
}
......@@ -65,10 +70,18 @@ struct KisWarpTransformStrategy::Private
bool cursorOverPoint;
int pointIndexUnderCursor;
bool drawConnectionLines;
bool drawOrigPoints;
bool drawTransfPoints;
bool closeOnStartPointClick;
QPointF pointPosOnClick;
bool pointWasDragged;
void recalculateTransformations();
inline QPointF imageToThumb(const QPointF &pt, bool useFlakeOptimization);
};
bool shouldCloseTheCage() const;
};
KisWarpTransformStrategy::KisWarpTransformStrategy(const KisCoordinatesConverter *converter,
ToolTransformArgs &currentArgs,
......@@ -109,11 +122,45 @@ QCursor KisWarpTransformStrategy::getCurrentCursor() const
}
}
void KisWarpTransformStrategy::paint(QPainter &gc)
void KisWarpTransformStrategy::overrideDrawingItems(bool drawConnectionLines,
bool drawOrigPoints,
bool drawTransfPoints)
{
m_d->drawConnectionLines = drawConnectionLines;
m_d->drawOrigPoints = drawOrigPoints;
m_d->drawTransfPoints = drawTransfPoints;
}
void KisWarpTransformStrategy::setCloseOnStartPointClick(bool value)
{
m_d->closeOnStartPointClick = value;
}
void KisWarpTransformStrategy::drawConnectionLines(QPainter &gc,
const QVector<QPointF> &origPoints,
const QVector<QPointF> &transfPoints,
bool isEditingPoints)
{
// Draw handles
Q_UNUSED(isEditingPoints);
QPen antsPen;
QPen outlinePen;
KritaUtils::initAntsPen(&antsPen, &outlinePen);
int numPoints = m_d->currentArgs.origPoints().size();
const int numPoints = origPoints.size();
for (int i = 0; i < numPoints; ++i) {
gc.setPen(outlinePen);
gc.drawLine(transfPoints[i], origPoints[i]);
gc.setPen(antsPen);
gc.drawLine(transfPoints[i], origPoints[i]);
}
}
void KisWarpTransformStrategy::paint(QPainter &gc)
{
// Draw preview image
gc.save();
......@@ -128,24 +175,19 @@ void KisWarpTransformStrategy::paint(QPainter &gc)
gc.setTransform(m_d->handlesTransform, true);
// draw connecting lines
{
QPen antsPen;
QPen outlinePen;
KritaUtils::initAntsPen(&antsPen, &outlinePen);
if (m_d->drawConnectionLines) {
gc.setOpacity(0.5);
for (int i = 0; i < numPoints; ++i) {
gc.setPen(outlinePen);
gc.drawLine(m_d->currentArgs.transfPoints()[i], m_d->currentArgs.origPoints()[i]);
gc.setPen(antsPen);
gc.drawLine(m_d->currentArgs.transfPoints()[i], m_d->currentArgs.origPoints()[i]);
}
drawConnectionLines(gc,
m_d->currentArgs.origPoints(),
m_d->currentArgs.transfPoints(),
m_d->transaction.editWarpPoints());
}
// draw handles themselves
// draw handles
{
const int numPoints = m_d->currentArgs.origPoints().size();
QPen mainPen(Qt::black);
QPen outlinePen(Qt::white);
......@@ -159,35 +201,39 @@ void KisWarpTransformStrategy::paint(QPainter &gc)
QRectF handleRect1(-0.5 * dstIn, -0.5 * dstIn, dstIn, dstIn);
QRectF handleRect2(-0.5 * dstOut, -0.5 * dstOut, dstOut, dstOut);
gc.setOpacity(1.0);
if (m_d->drawTransfPoints) {
gc.setOpacity(1.0);
for (int i = 0; i < numPoints; ++i) {
gc.setPen(outlinePen);
gc.drawEllipse(handleRect2.translated(m_d->currentArgs.transfPoints()[i]));
gc.setPen(mainPen);
gc.drawEllipse(handleRect1.translated(m_d->currentArgs.transfPoints()[i]));
for (int i = 0; i < numPoints; ++i) {
gc.setPen(outlinePen);
gc.drawEllipse(handleRect2.translated(m_d->currentArgs.transfPoints()[i]));
gc.setPen(mainPen);
gc.drawEllipse(handleRect1.translated(m_d->currentArgs.transfPoints()[i]));
}
}
QPainterPath inLine;
inLine.moveTo(-0.5 * srcIn, 0);
inLine.lineTo( 0.5 * srcIn, 0);
inLine.moveTo( 0, -0.5 * srcIn);
inLine.lineTo( 0, 0.5 * srcIn);
QPainterPath outLine;
outLine.moveTo(-0.5 * srcOut, -0.5 * srcOut);
outLine.lineTo( 0.5 * srcOut, -0.5 * srcOut);
outLine.lineTo( 0.5 * srcOut, 0.5 * srcOut);
outLine.lineTo(-0.5 * srcOut, 0.5 * srcOut);
outLine.lineTo(-0.5 * srcOut, -0.5 * srcOut);
gc.setOpacity(0.5);
for (int i = 0; i < numPoints; ++i) {
gc.setPen(outlinePen);
gc.drawPath(outLine.translated(m_d->currentArgs.origPoints()[i]));
gc.setPen(mainPen);
gc.drawPath(inLine.translated(m_d->currentArgs.origPoints()[i]));
if (m_d->drawOrigPoints) {
QPainterPath inLine;
inLine.moveTo(-0.5 * srcIn, 0);
inLine.lineTo( 0.5 * srcIn, 0);
inLine.moveTo( 0, -0.5 * srcIn);
inLine.lineTo( 0, 0.5 * srcIn);
QPainterPath outLine;
outLine.moveTo(-0.5 * srcOut, -0.5 * srcOut);
outLine.lineTo( 0.5 * srcOut, -0.5 * srcOut);
outLine.lineTo( 0.5 * srcOut, 0.5 * srcOut);
outLine.lineTo(-0.5 * srcOut, 0.5 * srcOut);
outLine.lineTo(-0.5 * srcOut, -0.5 * srcOut);
gc.setOpacity(0.5);
for (int i = 0; i < numPoints; ++i) {
gc.setPen(outlinePen);
gc.drawPath(outLine.translated(m_d->currentArgs.origPoints()[i]));
gc.setPen(mainPen);
gc.drawPath(inLine.translated(m_d->currentArgs.origPoints()[i]));
}
}
}
......@@ -201,11 +247,12 @@ void KisWarpTransformStrategy::externalConfigChanged()
bool KisWarpTransformStrategy::beginPrimaryAction(const QPointF &pt)
{
if (m_d->cursorOverPoint) return true;
const bool isEditingPoints = m_d->transaction.editWarpPoints();
bool retval = false;
bool hasSomethingToDrag = m_d->transaction.editWarpPoints();
if (hasSomethingToDrag) {
if (m_d->cursorOverPoint) {
retval = true;
} else if (isEditingPoints) {
m_d->currentArgs.refOriginalPoints().append(pt);
m_d->currentArgs.refTransformedPoints().append(pt);
......@@ -215,9 +262,17 @@ bool KisWarpTransformStrategy::beginPrimaryAction(const QPointF &pt)
m_d->recalculateTransformations();
emit requestCanvasUpdate();
retval = true;
}
return hasSomethingToDrag;
if (m_d->cursorOverPoint) {
m_d->pointPosOnClick =
m_d->currentArgs.transfPoints()[m_d->pointIndexUnderCursor];
m_d->pointWasDragged = false;
}
return retval;
}
void KisWarpTransformStrategy::continuePrimaryAction(const QPointF &pt, bool specialModifierActve)
......@@ -229,20 +284,48 @@ void KisWarpTransformStrategy::continuePrimaryAction(const QPointF &pt, bool spe
if (m_d->transaction.editWarpPoints()) {
QPointF newPos = KisTransformUtils::clipInRect(pt, m_d->transaction.originalRect());
m_d->currentArgs.origPoint(m_d->pointIndexUnderCursor) = newPos;
m_d->currentArgs.transfPoint(m_d->pointIndexUnderCursor) = newPos;
}
else {
} else {
m_d->currentArgs.transfPoint(m_d->pointIndexUnderCursor) = pt;
}
const qreal handleRadiusSq = pow2(KisTransformUtils::effectiveHandleGrabRadius(m_d->converter));
qreal dist =
kisSquareDistance(
m_d->currentArgs.transfPoint(m_d->pointIndexUnderCursor),
m_d->pointPosOnClick);
if (dist > handleRadiusSq) {
m_d->pointWasDragged = true;
}
m_d->recalculateTransformations();
emit requestCanvasUpdate();
}
bool KisWarpTransformStrategy::Private::shouldCloseTheCage() const
{
return transaction.editWarpPoints() &&
closeOnStartPointClick &&
pointIndexUnderCursor == 0 &&
currentArgs.origPoints().size() > 1 &&
!pointWasDragged;
}
bool KisWarpTransformStrategy::acceptsClicks() const
{
return m_d->shouldCloseTheCage();
}