File indexing completed on 2024-04-28 05:52:37

0001 /*
0002     This file is part of the Okteta Gui library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2021 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "zoompinchcontroller.hpp"
0010 
0011 // lib
0012 #include <abstractbytearrayview.hpp>
0013 // Qt
0014 #include <QPinchGesture>
0015 
0016 namespace Okteta {
0017 
0018 ZoomPinchController::ZoomPinchController(AbstractByteArrayView* view)
0019     : mView(view)
0020 {
0021 }
0022 
0023 bool ZoomPinchController::handlePinchGesture(QPinchGesture* pinchGesture)
0024 {
0025     switch (pinchGesture->state()) {
0026         case Qt::GestureStarted :
0027             mOriginalZoomLevel = mView->zoomLevel();
0028             break;
0029         case Qt::GestureCanceled :
0030             mView->setZoomLevel(mOriginalZoomLevel);
0031             break;
0032         case Qt::GestureUpdated:
0033         case Qt::GestureFinished:
0034             if (pinchGesture->changeFlags() & QPinchGesture::ScaleFactorChanged) {
0035                 mView->setZoomLevel(pinchGesture->totalScaleFactor() * mOriginalZoomLevel);
0036             }
0037             break;
0038         default:
0039             break;
0040     }
0041 
0042     return true;
0043 }
0044 
0045 }