File indexing completed on 2024-12-22 04:16:52
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_cage_transform_strategy.h" 0008 #include "tool_transform_args.h" 0009 0010 #include <QPointF> 0011 #include <QPainter> 0012 0013 #include "kis_painting_tweaks.h" 0014 #include "kis_cursor.h" 0015 #include <kis_cage_transform_worker.h> 0016 0017 0018 struct KisCageTransformStrategy::Private 0019 { 0020 Private(KisCageTransformStrategy *_q) 0021 : q(_q) 0022 { 0023 } 0024 0025 KisCageTransformStrategy * const q; 0026 }; 0027 0028 0029 KisCageTransformStrategy::KisCageTransformStrategy(const KisCoordinatesConverter *converter, 0030 KoSnapGuide *snapGuide, 0031 ToolTransformArgs ¤tArgs, 0032 TransformTransactionProperties &transaction) 0033 : KisWarpTransformStrategy(converter, snapGuide, currentArgs, transaction), 0034 m_d(new Private(this)) 0035 { 0036 overrideDrawingItems(true, false, true); 0037 setCloseOnStartPointClick(true); 0038 setClipOriginalPointsPosition(false); 0039 setTransformType(TransformType::CAGE_TRANSFORM); 0040 0041 } 0042 0043 KisCageTransformStrategy::~KisCageTransformStrategy() 0044 { 0045 } 0046 0047 void KisCageTransformStrategy::drawConnectionLines(QPainter &gc, 0048 const QVector<QPointF> &origPoints, 0049 const QVector<QPointF> &transfPoints, 0050 bool isEditingPoints) 0051 { 0052 const int numPoints = origPoints.size(); 0053 if (numPoints <= 1) return; 0054 0055 QPen antsPen; 0056 QPen outlinePen; 0057 0058 KisPaintingTweaks::initAntsPen(&antsPen, &outlinePen); 0059 antsPen.setWidth(qMax(1, decorationThickness())); 0060 outlinePen.setWidth(qMax(1, decorationThickness())); 0061 0062 const int iterateLimit = isEditingPoints ? numPoints : numPoints + 1; 0063 0064 for (int i = 1; i < iterateLimit; ++i) { 0065 int idx = i % numPoints; 0066 int prevIdx = (i - 1) % numPoints; 0067 0068 gc.setPen(outlinePen); 0069 gc.drawLine(transfPoints[prevIdx], transfPoints[idx]); 0070 gc.setPen(antsPen); 0071 gc.drawLine(transfPoints[prevIdx], transfPoints[idx]); 0072 } 0073 } 0074 0075 QImage KisCageTransformStrategy::calculateTransformedImage(ToolTransformArgs ¤tArgs, 0076 const QImage &srcImage, 0077 const QVector<QPointF> &origPoints, 0078 const QVector<QPointF> &transfPoints, 0079 const QPointF &srcOffset, 0080 QPointF *dstOffset) 0081 { 0082 KisCageTransformWorker worker(srcImage, 0083 srcOffset, 0084 origPoints, 0085 0, 0086 currentArgs.previewPixelPrecision()); 0087 worker.prepareTransform(); 0088 worker.setTransformedCage(transfPoints); 0089 return worker.runOnQImage(dstOffset); 0090 }