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.
21 import "./components/styles/default" as DefaultStyles
23 import org.makneto 0.1 as Makneto
33 signal sendMessage(string sessionId, string text)
34 signal changeChatState(string sessionId, int state)
36 property variant inputPopupComponent : Qt.createComponent("InputPopup.qml");
37 property variant messageItemComponent : Qt.createComponent("MessageItem.qml");
38 property variant popup: undefined
39 property bool typingState: false
42 console.log("II [ChatWidget.qml]: "+msg);
45 console.log("EE [ChatWidget.qml]: "+msg);
48 console.log("WW [ChatWidget.qml]: "+msg);
50 function textMessageReceived(text, contact){
51 //log("message received from "+contact+": "+text);
52 history.addMessage(true, contact, new Date(), text);
54 function chatStateChanged(chatState, contact){
55 // status message like "karry typing..."
57 if (chatState == Makneto.Session.ChatStateGone)
59 if (chatState == Makneto.Session.ChatStateComposing)
60 msg = contact+" typing..."
62 statusMessage.text = msg;
65 function sendMessagePriv(message){
66 message = message.trim();
67 if (message.length===0)
69 //log("sending message... "+message);
70 sendMessage(sessionScene.sessionId, message);
71 history.addMessage(false, "you", new Date(), message);
75 typingTimer.restart();
81 changeChatState(sessionScene.sessionId, b? Makneto.Session.ChatStateComposing: Makneto.Session.ChatStateActive)
86 interval: 3000; running: false; repeat: false
92 Component.onCompleted: {
98 BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
99 anchors{ bottom: editor.top; right: parent.right; left: parent.left; top: parent.top; margins: 4}
102 // Create a flickable to view a large view.
108 contentHeight: content.height
109 contentWidth: content.width
111 function addMessage(incoming, sender, time, message) {
112 var item = messageItemComponent.createObject(content);
113 item.incoming = incoming;
114 item.sender = sender;
116 item.message = message;
118 item.y = content.height;
119 content.height += item.height;
122 function updatePosition(){
123 contentWrapper.height = Math.max(content.height, history.height);
124 history.contentY = contentWrapper.height - history.height;
126 onHeightChanged: {updatePosition();}
130 width: historyWrapper.width
135 width: historyWrapper.width
137 anchors.bottom: contentWrapper.bottom
145 anchors{horizontalCenter: parent.horizontalCenter; bottom: parent.bottom; leftMargin:6}
152 //BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
153 //height: Math.max( parent.height * 0.2, messageTextArea.minimumHeight)
154 height: 2 * messageTextArea.minimumHeight
155 anchors{ bottom: parent.bottom; right: parent.right; left: parent.left; margins: 4}
159 anchors{top: parent.top; right: parent.right; bottom: parent.bottom}
162 BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
166 inputMethod.flipped = !inputMethod.flipped;
167 messageTextArea.focus = !inputMethod.flipped;
172 source: "img/keyboard.png"
181 property bool flipped: false
182 property int angle: 180
183 property int yAxis: 0
184 property int xAxis: 1
186 anchors{top: parent.top; left: parent.left; bottom: parent.bottom; right: flipButton.left; rightMargin: 4}
188 transform: Rotation {
189 id: rotation; origin.x: inputMethod.width / 2; origin.y: inputMethod.height / 2
190 axis.x: inputMethod.xAxis; axis.y: inputMethod.yAxis; axis.z: 0
194 name: "back"; when: inputMethod.flipped
195 PropertyChanges { target: rotation; angle: inputMethod.angle }
198 transitions: Transition {
200 NumberAnimation { target: rotation; properties: "angle"; duration: 500 }
201 SequentialAnimation {
202 NumberAnimation { target: inputMethod; property: "scale"; to: 0.75; duration: 250 }
203 NumberAnimation { target: inputMethod; property: "scale"; to: 1.0; duration: 250 }
211 //anchors.margins: 10
214 if (event.key == Qt.Key_Return && !(event.modifiers & Qt.ShiftModifier)){
215 var message = messageTextArea.text.trim();
216 messageTextArea.text = "";
217 sendMessagePriv(message);
218 //items[0].component.state = "detail"
231 BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
235 if (popup === undefined || popup === null){
236 if(inputPopupComponent.status != Component.Ready){
237 error("Component "+inputPopupComponent.url+" is not ready!");
238 error(inputPopupComponent.errorString());
242 popup = inputPopupComponent.createObject(main);
244 error("error creating popup");
245 error(inputPopupComponent.errorString());
249 popup.destroyOnHide = false;
250 popup.popupFromX = main.width * .9;
251 popup.popupFromY = main.height * .2;
252 popup.finalWidth = main.width * .8;
253 popup.finalHeight = editor.height * 3;
254 popup.state = "visible";
256 popup.enterText.connect(sendMessagePriv);
257 popup.typing.connect(typing);
265 source: "img/chat.svg"
266 anchors{horizontalCenter: parent.horizontalCenter; top: parent.top; bottom: parent.bottom}