|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "msgeditorwidget.h" |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <HbStyle> |
|
22 #include <HbPushButton> |
|
23 #include <qgraphicsscene.h> |
|
24 #include "debugtraces.h" |
|
25 |
|
26 // LOCAL CONSTANTS |
|
27 const QString PLUGINPATH("conversationviewplugin.dll"); |
|
28 |
|
29 const QString SMS_SERVICE("messaging.mserver.sms"); |
|
30 const QString SEND_BUTTON(QObject::tr("Send")); |
|
31 |
|
32 const QString SEND_ICON(":/icons/qtg_mono_send.png"); |
|
33 |
|
34 QGraphicsItem* FOCUSITEM = 0; |
|
35 |
|
36 //--------------------------------------------------------------- |
|
37 // MsgEditorWidget::MsgEditorWidget |
|
38 // @see header |
|
39 //--------------------------------------------------------------- |
|
40 MsgEditorWidget::MsgEditorWidget(QGraphicsItem *parent) : |
|
41 HbWidget(parent), mServiceId(SMS_SERVICE), mMsgEditor(NULL), |
|
42 mSendButton(NULL) |
|
43 { |
|
44 int baseId = style()->registerPlugin(PLUGINPATH); |
|
45 |
|
46 #ifdef _DEBUG_TRACES_ |
|
47 qDebug() << "MsgEditorWidget BASE ID --->" << baseId; |
|
48 #endif |
|
49 |
|
50 setPluginBaseId(baseId); |
|
51 |
|
52 // Initialize the widget. |
|
53 init(); |
|
54 } |
|
55 |
|
56 //--------------------------------------------------------------- |
|
57 // MsgEditorWidget::init |
|
58 // @see header |
|
59 //--------------------------------------------------------------- |
|
60 void MsgEditorWidget::init() |
|
61 { |
|
62 // Create mandatory element of mesh layout. |
|
63 mMsgEditor = new MsgEditor(this); |
|
64 mMsgEditor->setMaxRows(5); // NOTE: Don't remove this line. |
|
65 HbStyle::setItemName(mMsgEditor, "msgEditor"); |
|
66 |
|
67 mSendButton = new HbPushButton(this); |
|
68 HbStyle::setItemName(mSendButton, "sendButton"); |
|
69 mSendButton->setIcon(HbIcon(SEND_ICON)); |
|
70 mSendButton->setEnabled(false); |
|
71 FOCUSITEM = mSendButton; |
|
72 |
|
73 connect(mSendButton, SIGNAL(clicked()),this, SLOT(onClicked())); |
|
74 connect(mMsgEditor, SIGNAL(replyStarted()),this, SIGNAL(replyStarted())); |
|
75 connect(mMsgEditor, SIGNAL(textChanged(QString)),this,SLOT(onTextChanged(QString))); |
|
76 |
|
77 } |
|
78 |
|
79 //--------------------------------------------------------------- |
|
80 // MsgEditorWidget::~MsgEditorWidget |
|
81 // @see header |
|
82 //--------------------------------------------------------------- |
|
83 MsgEditorWidget::~MsgEditorWidget() |
|
84 { |
|
85 style()->unregisterPlugin(PLUGINPATH); |
|
86 } |
|
87 |
|
88 //--------------------------------------------------------------- |
|
89 // MsgEditorWidget::serviceId |
|
90 // @see header |
|
91 //--------------------------------------------------------------- |
|
92 const QString& MsgEditorWidget::serviceId() |
|
93 { |
|
94 return mServiceId; |
|
95 } |
|
96 |
|
97 //--------------------------------------------------------------- |
|
98 // MsgEditorWidget::content |
|
99 // @see header |
|
100 //--------------------------------------------------------------- |
|
101 QString MsgEditorWidget::content() const |
|
102 { |
|
103 return mMsgEditor->text(); |
|
104 } |
|
105 |
|
106 //--------------------------------------------------------------- |
|
107 // MsgEditorWidget::setContent |
|
108 // @see header |
|
109 //--------------------------------------------------------------- |
|
110 void MsgEditorWidget::setContent(const QString &text) |
|
111 { |
|
112 mMsgEditor->setText(text); |
|
113 } |
|
114 |
|
115 //--------------------------------------------------------------- |
|
116 // MsgEditorWidget::clear |
|
117 // @see header |
|
118 //--------------------------------------------------------------- |
|
119 void MsgEditorWidget::clear() |
|
120 { |
|
121 mMsgEditor->setText(QString()); |
|
122 mMsgEditor->setCursorVisibility(Hb::TextCursorHidden); |
|
123 } |
|
124 |
|
125 //--------------------------------------------------------------- |
|
126 // MsgEditorWidget::clear |
|
127 // @see header |
|
128 //--------------------------------------------------------------- |
|
129 void MsgEditorWidget::onTextChanged(const QString& str) |
|
130 { |
|
131 if(str.length() > 0 ) |
|
132 { |
|
133 if(!mSendButton->isEnabled()) |
|
134 { |
|
135 mSendButton->setFocusProxy(mMsgEditor); |
|
136 mSendButton->setEnabled(true); |
|
137 } |
|
138 } |
|
139 else |
|
140 { |
|
141 if(mSendButton->isEnabled()) |
|
142 { |
|
143 mSendButton->setFocusProxy(0); |
|
144 mSendButton->setEnabled(false); |
|
145 } |
|
146 } |
|
147 } |
|
148 |
|
149 //--------------------------------------------------------------- |
|
150 // MsgEditor::onClicked |
|
151 // @see header |
|
152 //--------------------------------------------------------------- |
|
153 void MsgEditorWidget::onClicked() |
|
154 { |
|
155 mSendButton->setFocusProxy(0); |
|
156 mMsgEditor->setFocusProxy(mSendButton); |
|
157 |
|
158 this->scene()->clearFocus(); |
|
159 this->scene()->setFocusItem(mSendButton); |
|
160 |
|
161 mMsgEditor->setFocusProxy(0); |
|
162 |
|
163 mMsgEditor->setCursorVisibility(Hb::TextCursorHidden); |
|
164 |
|
165 emit sendMessage(); |
|
166 } |
|
167 |
|
168 |
|
169 //--------------------------------------------------------------- |
|
170 // MsgEditor::MsgEditor |
|
171 // @see header |
|
172 //--------------------------------------------------------------- |
|
173 MsgEditor::MsgEditor(QGraphicsItem *parent) |
|
174 :HbLineEdit(parent) |
|
175 { |
|
176 |
|
177 } |
|
178 |
|
179 //--------------------------------------------------------------- |
|
180 // MsgEditor::focusInEvent |
|
181 // @see header |
|
182 //--------------------------------------------------------------- |
|
183 void MsgEditor::focusInEvent(QFocusEvent *event) |
|
184 { |
|
185 if(event->reason() == Qt::MouseFocusReason) |
|
186 { |
|
187 HbLineEdit::focusInEvent(event); |
|
188 FOCUSITEM->setFocusProxy(this); |
|
189 setCursorVisibility(Hb::TextCursorVisible); |
|
190 emit replyStarted(); |
|
191 } |
|
192 else |
|
193 { |
|
194 setCursorVisibility(Hb::TextCursorHidden); |
|
195 } |
|
196 } |
|
197 |
|
198 //--------------------------------------------------------------- |
|
199 // MsgEditor::focusOutEvent |
|
200 // @see header |
|
201 //--------------------------------------------------------------- |
|
202 void MsgEditor::focusOutEvent(QFocusEvent * event) |
|
203 { |
|
204 FOCUSITEM->setFocusProxy(0); |
|
205 setCursorVisibility(Hb::TextCursorHidden); |
|
206 HbLineEdit::focusOutEvent(event); |
|
207 } |
|
208 |
|
209 // EOF |