2 * Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 import QtQuick 1.1 // version 1.1 include PinchArea
30 signal sendWbMessage(string sessionId, string xmlContent);
31 signal messageSent(string content);
33 property int canvasWidth : 640;
34 property int canvasHeight: 480;
35 //property string uid : "demo@makneto.org"
38 console.log("II [BoardWidget.qml]: "+msg);
41 console.log("EE [BoardWidget.qml]: "+msg);
44 console.log("WW [BoardWidget.qml]: "+msg);
47 //signal foregroundColorChanged(variant color)
48 signal whiteboardMessageReceived(string data, string contact)
49 property bool whiteboardInitialiyed: false
50 property variant queue: undefined
52 function onWhiteboardMessageReceived(data, contact){
53 if (whiteboardInitialiyed){
54 whiteboardMessageReceived.disconnect(onWhiteboardMessageReceived);
58 if (queue===undefined)
62 obj.contact = contact;
68 //log("whiteboard is not initialized... "+JSON.stringify(queue.length));
79 source: "img/fullscreen.png"
82 AnchorChanges { target: board; anchors.top: board.parent.top; anchors.left: board.parent.left; }
89 source: "img/minimize.png"
92 AnchorChanges { target: board; anchors.right: board.parent.right; anchors.bottom: board.parent.bottom}
98 NumberAnimation{duration: 200}
101 NumberAnimation{duration: 200}
103 Behavior on opacity {
104 NumberAnimation{duration: 200}
107 transitions: Transition {
108 // smoothly reanchor myRect and move into new position
109 AnchorAnimation { duration: 200 }
112 Component.onCompleted: {
113 whiteboardMessageReceived.connect(onWhiteboardMessageReceived);
114 //toolbar.foregroundColorChanged.connect(board.foregroundColorChanged);
119 anchors{bottom: parent.bottom; right: parent.right; top: parent.top}
120 BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
127 anchors{top:parent.top; right: toolbar.left; left: parent.left; bottom: parent.bottom}
130 //anchors.fill: parent
132 Component.onCompleted: {
133 wrapper.width = board.width;
134 wrapper.height = board.height;
142 property variant currentZoom : -1
143 pinch.minimumScale: currentZoom
144 pinch.maximumScale: currentZoom
145 pinch.dragAxis: Pinch.XandYAxis
148 log("onPinchStarted "+pinch.scale);
152 log("onPinchUpdated "+pinch.scale);
156 log("onPinchFinished "+pinch.scale);
162 anchors{fill: parent}
163 settings.pluginsEnabled: false
167 javaScriptWindowObjects: [QtObject {
168 WebView.windowObjectName: "connector"
169 function getUID(){ return board.parent.sessionId; }
171 log("html part of whiteboard is initialized! lets make big stufs...");
172 // html part is loaded, init MaknetoWhiteboard...
173 wbView.evaluateJavaScript ( 'MaknetoWhiteboard.instance.init('+board.canvasWidth+', '+board.canvasHeight+')' );
175 //var zoom = Math.min( wbView.width / (wbView.contentsSize.width *0.3), wbView.height / (wbView.contentsSize.height *0.3) );
176 //wbView.evaluateJavaScript ( '$("#workArea").scrollLeft(640)');
177 wbView.calculateZoom();
179 whiteboardMessageReceived.connect(onWhiteboardMessageReceived);
180 toolbar.foregroundColorChanged.connect(onForegroundColorChanged);
181 messageSent.connect(onMessageSent);
182 whiteboardInitialiyed = true;
183 while (queue !== undefined && queue.length !== 0){
185 var obj = tmp.shift(); // take first element (from array begin)
187 //log("queue message: "+obj.data);
188 onWhiteboardMessageReceived(obj.data, obj.contact);
191 function onForegroundColorChanged(c){
192 //log("onForegroundColorChanged "+c);
193 wbView.evaluateJavaScript ( 'MaknetoWhiteboard.instance.setForegroundColor("'+c+'")' );
195 function onWhiteboardMessageReceived(data, contact){
196 wbView.evaluateJavaScript ( 'MaknetoWhiteboard.instance.processXmlCommand('+JSON.stringify(data)+')' );
197 //log("on whiteboard msg received from "+contact+" "+JSON.stringify(data));
199 function onMessageSent(content){
200 wbView.evaluateJavaScript ( 'MaknetoWhiteboard.instance.messageSent('+JSON.stringify(content)+')' );
202 function sendMessage(xmlMessage){
204 sendWbMessage(board.parent.sessionId, xmlMessage);
209 WebView.windowObjectName: "console"
210 function log(msg) { console.log("II [Whiteboard]: " + msg); }
211 function debug(msg) { console.log("DD [Whiteboard]: " + msg); }
212 function warn(msg) { console.log("WW [Whiteboard]: " + msg); }
213 function error(msg) { console.log("EE [Whiteboard]: " + msg); }
217 function calculateZoom(){
218 var contentWidth = canvasWidth * 3;
219 var contentHeight = canvasHeight * 3;
220 pinchArea.pinch.minimumScale = Math.max( wbView.width / contentWidth, wbView.height / contentHeight );
221 pinchArea.pinch.maximumScale = Math.min( (wbView.width *6) / contentWidth, (wbView.height *6)/ contentHeight );
222 var idealScale = Math.min( wbView.width / canvasWidth, wbView.height / canvasHeight );
223 if (idealScale < pinchArea.pinch.minimumScale)
224 idealScale = pinchArea.pinch.minimumScale;
225 var zoom = pinchArea.currentZoom;
228 if (zoom > pinchArea.pinch.maximumScale)
229 zoom = pinchArea.pinch.maximumScale;
230 if (zoom < pinchArea.pinch.minimumScale)
231 zoom = pinchArea.pinch.minimumScale;
232 log("set zoom "+zoom+" ("+idealScale+") <"+pinchArea.pinch.minimumScale+", "+pinchArea.pinch.maximumScale+">");
233 wbView.evaluateJavaScript ( 'MaknetoWhiteboard.instance.setZoom('+zoom+')' );
237 onContentsSizeChanged: {
238 //log("WebView content size: "+contentsSize.width+"x"+contentsSize.height);
239 //wbView.heuristicZoom(contentsSize.width/2, contentsSize.height/2, 10);
240 // webView.contentsScale
244 //html: "<html><head><script>console.log(\"This is in WebKit!\"); window.connector.qmlCall();</script></head><body><h1>Qt WebKit!</h1></body></html>"
245 url:"qrc:/whiteboard/main.html"
250 wbView.renderingEnabled = false;
251 wbView.renderingEnabled = true;
254 wbView.renderingEnabled = false;
255 wbView.renderingEnabled = true;