import QtQuick 2.0 import Ubuntu.Components 0.1 /*! \brief MainView with a Label and Button elements. */ MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" applicationName: "InkArea" width: units.gu(100) height: units.gu(75) property var currentPath: null; property string pathString: ""; property string pathCurveString: ""; QtObject { id: lastXY; property int x: 0; property int y: 0; } MouseArea { anchors.fill: parent width: units.gu(40) Canvas { id: inkCanvas anchors.fill: parent contextType: "2d" onPaint: { context.path = currentPath; context.stroke(); } } Path { id: scratchPath } onPositionChanged: { if(pathString == "") { pathString = "import QtQuick 2.0;Path{id:currentPath;startX:XX;startY:YY;".replace("XX",mouse.x).replace("YY",mouse.y) lastXY = [mouse.x,mouse.y] } else { if( (Math.abs(mouse.x - lastXY.x) > 5) | (Math.abs(mouse.y - lastXY.y) > 5 ) ) { lastXY = [mouse.x,mouse.y] pathCurveString += "PathCurve{x:XX;y:YY}".replace("XX",mouse.x).replace("YY",mouse.y) currentPath = Qt.createQmlObject(pathString + pathCurveString + "}", inkCanvas) inkCanvas.requestPaint() } } } onReleased: { currentPath = null pathString = "" pathCurveString = "" } } }