File indexing completed on 2024-05-26 04:26:42
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org> 0003 * SPDX-FileCopyrightText: 2007 C. Boemann <cbo@boemann.dk> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "KoZoomStrategy.h" 0009 #include "KoShapeRubberSelectStrategy_p.h" 0010 #include "KoZoomTool.h" 0011 #include "KoCanvasBase.h" 0012 #include "KoCanvasController.h" 0013 #include "KoViewConverter.h" 0014 0015 #include <FlakeDebug.h> 0016 0017 #include <QTransform> 0018 0019 KoZoomStrategy::KoZoomStrategy(KoZoomTool *tool, KoCanvasController *controller, const QPointF &clicked) 0020 : KoShapeRubberSelectStrategy(tool, clicked, false), 0021 m_controller(controller), 0022 m_forceZoomOut(false) 0023 { 0024 } 0025 0026 void KoZoomStrategy::finishInteraction(Qt::KeyboardModifiers modifiers) 0027 { 0028 Q_D(KoShapeRubberSelectStrategy); 0029 0030 const QTransform documentToWidget = 0031 m_controller->canvas()->viewConverter()->documentToView() * 0032 m_controller->canvas()->viewConverter()->viewToWidget(); 0033 0034 const QRect pixelRect = documentToWidget.mapRect(d->selectedRect()).toRect(); 0035 0036 bool m_zoomOut = m_forceZoomOut; 0037 if (modifiers & Qt::ControlModifier) { 0038 m_zoomOut = !m_zoomOut; 0039 } 0040 if (m_zoomOut) { 0041 m_controller->zoomOut(pixelRect.center()); 0042 } else if (pixelRect.width() > 5 && pixelRect.height() > 5) { 0043 m_controller->zoomTo(pixelRect); 0044 } else { 0045 m_controller->zoomIn(pixelRect.center()); 0046 } 0047 } 0048 0049 void KoZoomStrategy::cancelInteraction() 0050 { 0051 Q_D(KoShapeRubberSelectStrategy); 0052 d->tool->canvas()->updateCanvas(d->selectedRect().normalized() | d->tool->decorationsRect()); 0053 } 0054 0055 KoShapeRubberSelectStrategy::SelectionMode KoZoomStrategy::currentMode() const 0056 { 0057 return CoveringSelection; 0058 } 0059 0060 void KoZoomStrategy::forceZoomOut() 0061 { 0062 m_forceZoomOut = true; 0063 } 0064 0065 void KoZoomStrategy::forceZoomIn() 0066 { 0067 m_forceZoomOut = false; 0068 }