File indexing completed on 2024-06-23 04:28:11

0001 /*
0002  *  SPDX-FileCopyrightText: 2020 Sharaf Zaman <sharafzaz121@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "ShapeMeshGradientEditStrategy.h"
0008 
0009 #include <KoToolBase.h>
0010 #include <KoCanvasBase.h>
0011 
0012 struct ShapeMeshGradientEditStrategy::Private {
0013     Private(const QPointF& start, KoShape *shape, KoFlake::FillVariant fillVariant)
0014         : start(start)
0015         , handles(fillVariant, shape)
0016     {
0017     }
0018 
0019     // TODO: for snapping..
0020     QPointF start;
0021     KoShapeMeshGradientHandles::Handle startHandle;
0022     KoShapeMeshGradientHandles handles;
0023 };
0024 
0025 ShapeMeshGradientEditStrategy::ShapeMeshGradientEditStrategy(KoToolBase *tool,
0026                                                              KoFlake::FillVariant fillVariant,
0027                                                              KoShape *shape,
0028                                                              KoShapeMeshGradientHandles::Handle startHandle,
0029                                                              const QPointF &clicked)
0030     : KoInteractionStrategy(tool)
0031     , m_d(new Private(clicked, shape, fillVariant))
0032 {
0033     m_d->startHandle = startHandle;
0034 }
0035 
0036 ShapeMeshGradientEditStrategy::~ShapeMeshGradientEditStrategy()
0037 {
0038 }
0039 
0040 void ShapeMeshGradientEditStrategy::handleMouseMove(const QPointF &mouseLocation,
0041                                                     Qt::KeyboardModifiers modifiers)
0042 {
0043     Q_UNUSED(modifiers);
0044     tool()->canvas()->addCommand(m_d->handles.moveGradientHandle(m_d->startHandle, mouseLocation));
0045 }
0046 
0047 KUndo2Command* ShapeMeshGradientEditStrategy::createCommand()
0048 {
0049     return nullptr;
0050 }
0051 
0052 void ShapeMeshGradientEditStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
0053 {
0054     Q_UNUSED(modifiers)
0055 }