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
31 color: main.useSyspal? syspal.window :"black"
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: {
96 SystemPalette{ id: syspal }
100 BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
101 anchors{ bottom: editor.top; right: parent.right; left: parent.left; top: parent.top; margins: 4}
104 // Create a flickable to view a large view.
110 contentHeight: content.height
111 contentWidth: content.width
113 function addMessage(incoming, sender, time, message) {
114 var item = messageItemComponent.createObject(content);
115 item.incoming = incoming;
116 item.sender = sender;
118 item.message = message;
120 item.y = content.height;
121 content.height += item.height;
124 function updatePosition(){
125 contentWrapper.height = Math.max(content.height, history.height);
126 history.contentY = contentWrapper.height - history.height;
128 onHeightChanged: {updatePosition();}
132 width: historyWrapper.width
137 width: historyWrapper.width
139 anchors.bottom: contentWrapper.bottom
146 color: main.useSyspal? syspal.windowText :"gray"
148 anchors{horizontalCenter: parent.horizontalCenter; bottom: parent.bottom; leftMargin:6}
155 //BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
156 //height: Math.max( parent.height * 0.2, messageTextArea.minimumHeight)
157 height: 2 * messageTextArea.minimumHeight
158 anchors{ bottom: parent.bottom; right: parent.right; left: parent.left; margins: 4}
162 anchors{top: parent.top; right: parent.right; bottom: parent.bottom}
165 BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
169 inputMethod.flipped = !inputMethod.flipped;
170 messageTextArea.focus = !inputMethod.flipped;
175 source: "img/keyboard.png"
182 state: main.useSyspal? syspal.window :"back"
184 property bool flipped: false
185 property int angle: 180
186 property int yAxis: 0
187 property int xAxis: 1
189 anchors{top: parent.top; left: parent.left; bottom: parent.bottom; right: flipButton.left; rightMargin: 4}
191 transform: Rotation {
192 id: rotation; origin.x: inputMethod.width / 2; origin.y: inputMethod.height / 2
193 axis.x: inputMethod.xAxis; axis.y: inputMethod.yAxis; axis.z: 0
197 name: "back"; when: inputMethod.flipped
198 PropertyChanges { target: rotation; angle: inputMethod.angle }
201 transitions: Transition {
203 NumberAnimation { target: rotation; properties: "angle"; duration: 500 }
204 SequentialAnimation {
205 NumberAnimation { target: inputMethod; property: "scale"; to: 0.75; duration: 250 }
206 NumberAnimation { target: inputMethod; property: "scale"; to: 1.0; duration: 250 }
214 //anchors.margins: 10
217 if (event.key == Qt.Key_Return && !(event.modifiers & Qt.ShiftModifier)){
218 var message = messageTextArea.text.trim();
219 messageTextArea.text = "";
220 sendMessagePriv(message);
221 //items[0].component.state = "detail"
234 BorderImage { source: "img/lineedit.sci"; anchors.fill: parent }
238 if (popup === undefined || popup === null){
239 if(inputPopupComponent.status != Component.Ready){
240 error("Component "+inputPopupComponent.url+" is not ready!");
241 error(inputPopupComponent.errorString());
245 popup = inputPopupComponent.createObject(main);
247 error("error creating popup");
248 error(inputPopupComponent.errorString());
252 popup.destroyOnHide = false;
253 popup.popupFromX = main.width * .9;
254 popup.popupFromY = main.height * .2;
255 popup.finalWidth = main.width * .8;
256 popup.finalHeight = editor.height * 3;
257 popup.state = "visible";
259 popup.enterText.connect(sendMessagePriv);
260 popup.typing.connect(typing);
268 source: "img/chat.svg"
269 anchors{horizontalCenter: parent.horizontalCenter; top: parent.top; bottom: parent.bottom}