Warning, /education/analitza/declarative/qml/Graph2D.qml is written in an unsupported language. File is not indexed.
0001 /************************************************************************************* 0002 * Copyright (C) 2013-2017 by Aleix Pol <aleixpol@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program 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 General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU 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 import QtQuick 2.0 0020 import org.kde.analitza 1.0 0021 0022 Graph2DView { 0023 id: view 0024 anchors.fill: parent 0025 0026 showGrid: true 0027 ticksShown: true 0028 0029 PinchArea { 0030 anchors.fill: parent 0031 property double thePreviousScale: 1 0032 0033 function distance(p1, p2) 0034 { 0035 var w=p2.x-p1.x 0036 var h=p2.y-p1.y 0037 return Math.sqrt(w*w+h*h) 0038 } 0039 0040 onPinchStarted: thePreviousScale=1 0041 0042 onPinchUpdated: pinch => { 0043 var currentDistance = distance(pinch.point1, pinch.point2) 0044 if(currentDistance>0) { 0045 var doScale = thePreviousScale/pinch.scale 0046 view.scale(doScale, pinch.center.x, pinch.center.y) 0047 thePreviousScale = pinch.scale 0048 } 0049 } 0050 0051 MouseArea { 0052 id: mouse 0053 anchors.fill: parent 0054 property int lastX: 0 0055 property int lastY: 0 0056 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton 0057 0058 onPressed: mouse => { lastX=mouse.x; lastY=mouse.y } 0059 0060 onPositionChanged: mouse => { 0061 view.translate(mouse.x-lastX, mouse.y-lastY) 0062 0063 lastX=mouse.x 0064 lastY=mouse.y 0065 } 0066 0067 onWheel: wheel => { 0068 view.scale(wheel.angleDelta.y>0 ? 0.9 : 1.1, wheel.x, wheel.y) 0069 } 0070 } 0071 } 0072 }