File indexing completed on 2024-05-12 05:46:34
0001 /* 0002 * Copyright (c) 2019 Kuntal Majumder <hellozee@disroot.org> 0003 * 0004 * This library is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Lesser General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this program; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include "KisSnapPixelStrategy.h" 0020 0021 #include <QPainterPath> 0022 #include "kis_global.h" 0023 #include "kis_canvas2.h" 0024 #include "KoSnapProxy.h" 0025 0026 KisSnapPixelStrategy::KisSnapPixelStrategy(KoSnapGuide::Strategy type): 0027 KoSnapStrategy(type) 0028 { 0029 } 0030 0031 KisSnapPixelStrategy::~KisSnapPixelStrategy() 0032 { 0033 } 0034 0035 bool KisSnapPixelStrategy::snap(const QPointF &mousePosition, KoSnapProxy *proxy, qreal maxSnapDistance) 0036 { 0037 Q_UNUSED(maxSnapDistance); 0038 KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2*>(proxy->canvas()); 0039 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas2, false); 0040 0041 const QPointF imagePos = canvas2->coordinatesConverter()->documentToImage(mousePosition); 0042 const QPointF alignedDocPoint = canvas2->coordinatesConverter()->imageToDocument(imagePos.toPoint()); 0043 setSnappedPosition(alignedDocPoint); 0044 0045 return true; 0046 } 0047 0048 QPainterPath KisSnapPixelStrategy::decoration(const KoViewConverter &converter) const 0049 { 0050 QSizeF unzoomedSize = converter.viewToDocument(QSizeF(5, 5)); 0051 QPainterPath decoration; 0052 decoration.moveTo(snappedPosition() - QPointF(unzoomedSize.width(), 0)); 0053 decoration.lineTo(snappedPosition() + QPointF(unzoomedSize.width(), 0)); 0054 decoration.moveTo(snappedPosition() - QPointF(0, unzoomedSize.height())); 0055 decoration.lineTo(snappedPosition() + QPointF(0, unzoomedSize.height())); 0056 return decoration; 0057 }