From a8c540c38d8b3c22b057d81a8dc0d68fee7b1e37 Mon Sep 17 00:00:00 2001 From: Lukas Karas Date: Wed, 14 Dec 2011 22:58:33 +0100 Subject: [PATCH] prepare for whiteboard pinch zoom --- src/ui-mobile/declarative/BoardWidget.qml | 86 ++++++++++++++++++++++--------- src/ui-mobile/main.cpp | 4 +- src/ui-mobile/makneto.cpp | 2 +- src/ui-mobile/whiteboard/js/whiteboard.js | 46 ++++++++++------- 4 files changed, 93 insertions(+), 45 deletions(-) diff --git a/src/ui-mobile/declarative/BoardWidget.qml b/src/ui-mobile/declarative/BoardWidget.qml index 7edf0d5..4170cc3 100644 --- a/src/ui-mobile/declarative/BoardWidget.qml +++ b/src/ui-mobile/declarative/BoardWidget.qml @@ -134,29 +134,6 @@ Rectangle { wrapper.height = board.height; } - - PinchArea{ - id: pinchArea - anchors.fill: parent - - property variant currentZoom : -1 - pinch.minimumScale: currentZoom - pinch.maximumScale: currentZoom - pinch.dragAxis: Pinch.XandYAxis - - onPinchStarted: { - log("onPinchStarted "+pinch.scale); - } - - onPinchUpdated: { - log("onPinchUpdated "+pinch.scale); - } - - onPinchFinished: { - log("onPinchFinished "+pinch.scale); - } - } - WebView { id: wbView anchors{fill: parent} @@ -217,7 +194,10 @@ Rectangle { function calculateZoom(){ var contentWidth = canvasWidth * 3; var contentHeight = canvasHeight * 3; - pinchArea.pinch.minimumScale = Math.max( wbView.width / contentWidth, wbView.height / contentHeight ); + var minimumScale = Math.max( wbView.width / contentWidth, wbView.height / contentHeight ); + if (minimumScale < 0.1) + minimumScale = 0.1; + pinchArea.pinch.minimumScale = minimumScale; pinchArea.pinch.maximumScale = Math.min( (wbView.width *6) / contentWidth, (wbView.height *6)/ contentHeight ); var idealScale = Math.min( wbView.width / canvasWidth, wbView.height / canvasHeight ); if (idealScale < pinchArea.pinch.minimumScale) @@ -243,7 +223,63 @@ Rectangle { //html: "

Qt WebKit!

" url:"qrc:/whiteboard/main.html" - } + + PinchArea{ + id: pinchArea + anchors.fill: parent + + property variant currentZoom : -1 + pinch.minimumScale: currentZoom + pinch.maximumScale: currentZoom + pinch.dragAxis: Pinch.XandYAxis + enabled: true + + onPinchStarted: { + log("pinchArea: onPinchStarted "+pinch.scale); + } + + onPinchUpdated: { + log("pinchArea: onPinchUpdated "+pinch.scale); + } + + onPinchFinished: { + log("pinchArea: onPinchFinished "+pinch.scale); + } + } + + MouseArea { + id: mouseArea + anchors.fill: parent + acceptedButtons: Qt.LeftButton + onPressed:{ + //log("mouseArea: onPressed"); + //mouse.accepted = false; + wbView.evaluateJavaScript("MaknetoWhiteboard.instance.whiteboard.mouseDown2("+mouse.x+", "+mouse.y+",0)"); + } + onDoubleClicked:{ + //log("mouseArea: onDoubleClicked"); + //mouse.accepted = false; + } + onPositionChanged:{ + //log("mouseArea: onPositionChanged"); + //mouse.accepted = false; + } + onPressAndHold:{ + //log("mouseArea: onPressAndHold"); + //mouse.accepted = false; + } + onReleased :{ + //log("mouseArea: onReleased"); + //mouse.accepted = false; + wbView.evaluateJavaScript("MaknetoWhiteboard.instance.whiteboard.mouseUp2()"); + } + onMousePositionChanged: { + //log("mouseArea: onMousePositionChanged"); + wbView.evaluateJavaScript("MaknetoWhiteboard.instance.whiteboard.mouseMove2("+mouse.x+", "+mouse.y+")"); + } + } + + } } onWidthChanged:{ diff --git a/src/ui-mobile/main.cpp b/src/ui-mobile/main.cpp index 91a67bf..8f9e65d 100644 --- a/src/ui-mobile/main.cpp +++ b/src/ui-mobile/main.cpp @@ -40,9 +40,11 @@ int main(int argc, char **argv) { // TODO: this option should be configurable (it is configurable only over param. "--graphicssystem") Other values can be "native", "raster", "opengl1" and "opengl". - QApplication::setGraphicsSystem(QString("raster")); + //QApplication::setGraphicsSystem(QString("raster")); QApplication app(argc, argv); + // Phonon needs QCoreApplication::applicationName to be set to export audio output names through the DBUS interface + app.setApplicationName("MaknetoMobile"); Makneto makneto(&app); if (!makneto.init()) { qWarning() << "Makneto initializing failed, exiting"; diff --git a/src/ui-mobile/makneto.cpp b/src/ui-mobile/makneto.cpp index 9ba2414..48d9f4f 100644 --- a/src/ui-mobile/makneto.cpp +++ b/src/ui-mobile/makneto.cpp @@ -155,7 +155,7 @@ void Makneto::onViewReady() { SIGNAL(finished(MaknetoBackend::TelepathyClient *)), SLOT(onTelepathyInitializerFinished(MaknetoBackend::TelepathyClient *))); - tpInit->createClient("MaknetoMobile"); + tpInit->createClient(_app->applicationName()); } void Makneto::showWindow() { diff --git a/src/ui-mobile/whiteboard/js/whiteboard.js b/src/ui-mobile/whiteboard/js/whiteboard.js index b3b3aea..c7e5abf 100644 --- a/src/ui-mobile/whiteboard/js/whiteboard.js +++ b/src/ui-mobile/whiteboard/js/whiteboard.js @@ -51,21 +51,20 @@ function Whiteboard(canvasWrapper, canvasWidth, canvasHeight, showOutsideCanvas, this.callback = callback; } -Whiteboard.prototype.mouseDown = function(e){ - var xc = ((this.canvasWrapper.scrollLeft() / this.zoom) - this.canvasWidth) + ((e.clientX - this.canvasWrapper.offset().left ) / this.zoom); - var yc = ((this.canvasWrapper.scrollTop() / this.zoom) - this.canvasHeight) + ((e.clientY - this.canvasWrapper.offset().top ) / this.zoom); +Whiteboard.prototype.mouseDown2 = function(clientX,clientY,button){ + var xc = ((this.canvasWrapper.scrollLeft() / this.zoom) - this.canvasWidth) + ((clientX - this.canvasWrapper.offset().left ) / this.zoom); + var yc = ((this.canvasWrapper.scrollTop() / this.zoom) - this.canvasHeight) + ((clientY - this.canvasWrapper.offset().top ) / this.zoom); //console.debug("mousedown"); this.mouseIsDown = true; this.mouseStart = { - clientX: e.clientX, - clientY: e.clientY, + clientX: clientX, + clientY: clientY, scrollLeft : this.canvasWrapper.scrollLeft(), scrollTop : this.canvasWrapper.scrollTop() }; - e.preventDefault(); - if (e.button == 1){ // middle button + if (button == 1){ // middle button this.mouseMode = Whiteboard.mouseMode.CANVAS_MOVE; return; } @@ -99,21 +98,28 @@ Whiteboard.prototype.mouseDown = function(e){ break; } - this.lastXc = xc;this.lastYc = yc; - + this.lastXc = xc;this.lastYc = yc; } -Whiteboard.prototype.mouseUp = function(e){ +Whiteboard.prototype.mouseDown = function(e){ + e.preventDefault(); + this.mouseDown2(e.clientX, e.clientY, e.button); +} + +Whiteboard.prototype.mouseUp2 = function(){ // this.mouseMove(e); // invoke move function for final point //console.debug("mouseup"); this.mouseIsDown = false; - this.currentElementId = null; + this.currentElementId = null; +} +Whiteboard.prototype.mouseUp = function(e){ e.preventDefault(); + this.mouseUp2(); } -Whiteboard.prototype.mouseMove = function(e){ - var xc = ((this.canvasWrapper.scrollLeft() / this.zoom) - this.canvasWidth) + ((e.clientX - this.canvasWrapper.offset().left ) / this.zoom); - var yc = ((this.canvasWrapper.scrollTop() / this.zoom) - this.canvasHeight) + ((e.clientY - this.canvasWrapper.offset().top ) / this.zoom); +Whiteboard.prototype.mouseMove2 = function(clientX, clientY){ + var xc = ((this.canvasWrapper.scrollLeft() / this.zoom) - this.canvasWidth) + ((clientX - this.canvasWrapper.offset().left ) / this.zoom); + var yc = ((this.canvasWrapper.scrollTop() / this.zoom) - this.canvasHeight) + ((clientY - this.canvasWrapper.offset().top ) / this.zoom); //console.debug("mousemove "+this.mouseIsDown+" ("+Math.round(xc)+"x"+Math.round(yc)+")"); // $('#viewport').html("("+Math.round(xc)+"x"+Math.round(yc)+")"); @@ -121,8 +127,8 @@ Whiteboard.prototype.mouseMove = function(e){ if (this.mouseIsDown){ //console.log("we are moving... "+this.mouseMode+" "+e.clientX+"x"+e.clientY+" "+this.canvasWrapper.scrollLeft()+"x"+this.canvasWrapper.scrollTop()); - var x = this.mouseStart.clientX - e.clientX; - var y = this.mouseStart.clientY - e.clientY; + var x = this.mouseStart.clientX - clientX; + var y = this.mouseStart.clientY - clientY; switch (this.mouseMode) { case Whiteboard.mouseMode.CANVAS_MOVE : @@ -151,7 +157,11 @@ Whiteboard.prototype.mouseMove = function(e){ } this.lastXc = xc;this.lastYc = yc; - e.preventDefault(); - } + + } } +Whiteboard.prototype.mouseMove = function(e){ + e.preventDefault(); + this.mouseMove2(e.clientX, e.clientY); +} -- 2.11.4.GIT