|
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: Phone UI's Qt view. |
|
15 * |
|
16 */ |
|
17 #include <hbinstance.h> |
|
18 #include <QSignalMapper> |
|
19 #include <hbaction.h> |
|
20 #include <hbtoolbar.h> |
|
21 #include <hbvolumesliderpopup.h> |
|
22 #include <hbnamespace.h> |
|
23 #include <bubblemanager2.h> |
|
24 #include <hblineedit.h> |
|
25 #include <hbmenu.h> |
|
26 |
|
27 #include <xqserviceutil.h> |
|
28 #include <dialpad.h> |
|
29 |
|
30 #include "phoneuiqtview.h" |
|
31 #include "phoneaction.h" |
|
32 |
|
33 PhoneUIQtView::PhoneUIQtView (HbMainWindow &window, QGraphicsItem *parent) : |
|
34 HbView (parent), |
|
35 m_window(window), |
|
36 m_volumeSlider (0), |
|
37 m_expandSignalMapper(0), |
|
38 m_participantListSignalMapper(0), |
|
39 m_volumeCommandId(0) |
|
40 { |
|
41 setTitle(hbTrId("txt_phone_title_telephone")); |
|
42 |
|
43 // call handling widget |
|
44 m_bubbleManager = new BubbleManager (this); |
|
45 |
|
46 setWidget(m_bubbleManager); |
|
47 |
|
48 // Dialpad |
|
49 m_dialpad = new Dialpad(); |
|
50 m_dialpad->setCallButtonEnabled(false); |
|
51 connect(&m_dialpad->editor(),SIGNAL(contentsChanged()), |
|
52 SLOT(onEditorContentChanged())); |
|
53 connect(m_dialpad,SIGNAL(aboutToClose()),this, |
|
54 SLOT(dialpadClosed())); |
|
55 |
|
56 // Set event filter |
|
57 m_window.installEventFilter(this); |
|
58 |
|
59 |
|
60 m_signalMapper = new QSignalMapper (this); |
|
61 connect(m_signalMapper, SIGNAL (mapped (int)), this, SIGNAL (command (int))); |
|
62 connect(&m_window,SIGNAL(orientationChanged(Qt::Orientation)), |
|
63 this,SLOT(handleOrientationChange(Qt::Orientation))); |
|
64 |
|
65 m_menuSignalMapper = new QSignalMapper(this); |
|
66 connect(m_menuSignalMapper, SIGNAL(mapped(int)), this, SIGNAL(command(int))); |
|
67 |
|
68 m_bubbleManager->handleOrientationChange(m_window.orientation()); |
|
69 |
|
70 // changed exit softkey to back button |
|
71 m_backAction = new HbAction(Hb::BackAction,this); |
|
72 connect(m_backAction, SIGNAL(triggered()), this, SLOT(backButtonClicked())); |
|
73 HbAction *action = m_window.softKeyAction(Hb::SecondarySoftKey); |
|
74 m_window.removeSoftKeyAction(Hb::SecondarySoftKey,action); |
|
75 m_window.addSoftKeyAction(Hb::SecondarySoftKey,m_backAction); |
|
76 |
|
77 m_emptyAction = new HbAction(this); |
|
78 |
|
79 createToolBarActions(); |
|
80 } |
|
81 |
|
82 PhoneUIQtView::~PhoneUIQtView () |
|
83 { |
|
84 |
|
85 foreach (HbAction *action, m_toolbarActions ) { |
|
86 delete action; |
|
87 } |
|
88 m_window.removeEventFilter(this); |
|
89 delete m_volumeSlider; |
|
90 delete m_dialpad; |
|
91 } |
|
92 |
|
93 BubbleManagerIF& PhoneUIQtView::bubbleManager() |
|
94 { |
|
95 return *m_bubbleManager; |
|
96 } |
|
97 |
|
98 void PhoneUIQtView::addBubbleCommand ( |
|
99 int bubbleId, |
|
100 const PhoneAction& action ) |
|
101 { |
|
102 HbAction* bubbleAction = new HbAction (); |
|
103 bubbleAction->setText (action.text()); |
|
104 bubbleAction->setIcon (action.icon()); |
|
105 setActionRole(action,*bubbleAction); |
|
106 m_bubbleManager->addAction (bubbleId, bubbleAction); |
|
107 |
|
108 QList<int> bubbles = m_bubbleMap.keys(); |
|
109 bool found(false); |
|
110 |
|
111 for ( int i=0; i<bubbles.size(); ++i ) { |
|
112 if (bubbleId==bubbles[i]){ |
|
113 connect(bubbleAction, SIGNAL (triggered ()), m_bubbleMap.value(bubbleId), SLOT (map ())); |
|
114 m_bubbleMap.value(bubbleId)->setMapping(bubbleAction, action.command()); |
|
115 m_bubbleActionMap.value(bubbleId)->append(bubbleAction); |
|
116 found = true; |
|
117 } |
|
118 } |
|
119 |
|
120 if (!found) { |
|
121 QSignalMapper *mapper = new QSignalMapper(); |
|
122 connect(mapper, SIGNAL (mapped (int)), this, SIGNAL (command (int))); |
|
123 connect(bubbleAction, SIGNAL (triggered ()), mapper, SLOT (map ())); |
|
124 mapper->setMapping (bubbleAction, action.command()); |
|
125 QList<HbAction *> *actionList = new QList<HbAction *>(); |
|
126 actionList->append( bubbleAction ); |
|
127 m_bubbleActionMap.insert(bubbleId,actionList); |
|
128 m_bubbleMap.insert(bubbleId,mapper); |
|
129 } |
|
130 } |
|
131 |
|
132 void PhoneUIQtView::addParticipantListAction( |
|
133 int commandId, |
|
134 const QString& text, |
|
135 const HbIcon& icon) |
|
136 { |
|
137 HbAction* action = new HbAction (); |
|
138 action->setText (text); |
|
139 action->setIcon (icon); |
|
140 m_bubbleManager->addParticipantListAction(action); |
|
141 |
|
142 if (!m_participantListSignalMapper) { |
|
143 m_participantListSignalMapper = new QSignalMapper(); |
|
144 connect(m_participantListSignalMapper, SIGNAL (mapped (int)), this, SIGNAL (command (int))); |
|
145 } |
|
146 |
|
147 connect(action, SIGNAL (triggered ()), m_participantListSignalMapper, SLOT (map ())); |
|
148 m_participantListSignalMapper->setMapping (action, commandId); |
|
149 m_participantListActions.append( action ); |
|
150 } |
|
151 |
|
152 void PhoneUIQtView::clearParticipantListActions() |
|
153 { |
|
154 |
|
155 if (m_participantListSignalMapper) { |
|
156 m_bubbleManager->clearParticipantListActions(); |
|
157 |
|
158 foreach (HbAction *action, m_participantListActions ) { |
|
159 m_participantListSignalMapper->removeMappings(action); |
|
160 delete action; |
|
161 } |
|
162 |
|
163 m_participantListActions.clear(); |
|
164 delete m_participantListSignalMapper; |
|
165 m_participantListSignalMapper = 0; |
|
166 } |
|
167 |
|
168 } |
|
169 |
|
170 void PhoneUIQtView::clearBubbleCommands (int bubbleId) |
|
171 { |
|
172 m_bubbleManager->clearActions (bubbleId); |
|
173 QSignalMapper *mapper = m_bubbleMap.value(bubbleId); |
|
174 |
|
175 if (mapper) { |
|
176 QList<HbAction *> *actions = m_bubbleActionMap.value(bubbleId); |
|
177 |
|
178 foreach (HbAction *action, *actions ) { |
|
179 mapper->removeMappings(action); |
|
180 delete action; |
|
181 } |
|
182 |
|
183 actions->clear(); |
|
184 m_bubbleMap.remove(bubbleId); |
|
185 m_bubbleActionMap.remove(bubbleId); |
|
186 delete mapper; |
|
187 delete actions; |
|
188 } |
|
189 |
|
190 } |
|
191 |
|
192 void PhoneUIQtView::setToolbarActions(const QList<PhoneAction*>& actions) |
|
193 { |
|
194 // clear current toolbar actions |
|
195 for (int i=0;i<toolBar()->actions().count();++i) { |
|
196 m_signalMapper->removeMappings( |
|
197 static_cast<HbAction*>(toolBar()->actions().at(i))); |
|
198 } |
|
199 |
|
200 QList<QAction*> toolBarActions = toolBar()->actions(); |
|
201 |
|
202 if (toolBarActions.size()<actions.size()) { |
|
203 for (int i=toolBarActions.size(); i<actions.size(); ++i) { |
|
204 toolBar()->addAction(m_toolbarActions.at(i)); |
|
205 } |
|
206 } else if (toolBarActions.size()>actions.size()) { |
|
207 for (int i=toolBarActions.size(); 0<i; --i) { |
|
208 if (i>actions.size()) { |
|
209 HbAction* action = static_cast<HbAction*>(toolBarActions.at(i-1)); |
|
210 toolBar()->removeAction(action); |
|
211 } |
|
212 } |
|
213 } |
|
214 |
|
215 for (int i=0; i<toolBar()->actions().size(); ++i) { |
|
216 |
|
217 if (i<actions.count()) { |
|
218 HbAction* action = static_cast<HbAction*>(toolBar()->actions().at(i)); |
|
219 action->setText(actions.at(i)->text()); |
|
220 action->setIcon(actions.at(i)->icon()); |
|
221 action->setDisabled(actions.at(i)->isDisabled()); |
|
222 |
|
223 m_signalMapper->setMapping(action, actions.at(i)->command()); |
|
224 } |
|
225 } |
|
226 |
|
227 if ( m_window.orientation() == Qt::Horizontal ) { |
|
228 toolBar()->setOrientation(Qt::Horizontal); |
|
229 } |
|
230 // update toolbar |
|
231 toolBar()->update(); |
|
232 } |
|
233 |
|
234 void PhoneUIQtView::hideToolbar () |
|
235 { |
|
236 toolBar()->hide (); |
|
237 } |
|
238 |
|
239 void PhoneUIQtView::showToolbar () |
|
240 { |
|
241 setFocus(); |
|
242 toolBar()->show(); |
|
243 } |
|
244 |
|
245 int PhoneUIQtView::volumeSliderValue () |
|
246 { |
|
247 if (m_volumeSlider) { |
|
248 return m_volumeSlider->value (); |
|
249 } else { |
|
250 return -1; |
|
251 } |
|
252 } |
|
253 |
|
254 void PhoneUIQtView::removeVolumeSlider () |
|
255 { |
|
256 if (m_volumeSlider) { |
|
257 if (m_volumeSlider->isVisible()) { |
|
258 m_volumeSlider->hide(); |
|
259 } |
|
260 m_volumeSlider->deleteLater(); |
|
261 m_volumeSlider = 0; |
|
262 } |
|
263 } |
|
264 |
|
265 void PhoneUIQtView::volumeSliderClosed () |
|
266 { |
|
267 removeVolumeSlider(); |
|
268 } |
|
269 |
|
270 void PhoneUIQtView::setVolumeSliderValue ( |
|
271 int value, int commandId, int maxVolumeValue, int minVolumeValue) |
|
272 { |
|
273 m_volumeCommandId = commandId; |
|
274 |
|
275 if (!m_volumeSlider) { |
|
276 m_volumeSlider = new HbVolumeSliderPopup (); |
|
277 m_volumeSlider->setDismissPolicy(HbDialog::TapOutside); |
|
278 m_volumeSlider->setTimeout (10000); // TODO: 10 seconds for now, replace with correct value when spec is ready and says what it is |
|
279 connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(volumeSliderChanged(int))); |
|
280 connect(m_volumeSlider, SIGNAL(aboutToClose()), this, SLOT(volumeSliderClosed())); |
|
281 } |
|
282 |
|
283 |
|
284 if (m_volumeSlider->minimum() != minVolumeValue || |
|
285 m_volumeSlider->maximum() != maxVolumeValue ) { |
|
286 m_volumeSlider->setRange (minVolumeValue, maxVolumeValue); |
|
287 } |
|
288 |
|
289 if (value != m_volumeSlider->value()) |
|
290 m_volumeSlider->setValue (value); |
|
291 |
|
292 if (false == m_volumeSlider->isVisible()) { |
|
293 m_volumeSlider->show(); |
|
294 } |
|
295 } |
|
296 |
|
297 void PhoneUIQtView::volumeSliderChanged(int value) |
|
298 { |
|
299 Q_UNUSED (value); |
|
300 emit command (m_volumeCommandId); |
|
301 } |
|
302 |
|
303 void PhoneUIQtView::setExpandAction(int bubbleId, int commandId) |
|
304 { |
|
305 removeExpandAction(bubbleId); |
|
306 |
|
307 HbAction* action = new HbAction(); |
|
308 m_bubbleManager->setExpandAction(bubbleId, action); |
|
309 |
|
310 if (!m_expandSignalMapper) { |
|
311 m_expandSignalMapper = new QSignalMapper(this); |
|
312 connect(m_expandSignalMapper, SIGNAL (mapped (int)), |
|
313 this, SIGNAL (command (int))); |
|
314 } |
|
315 |
|
316 connect(action, SIGNAL (triggered ()), m_expandSignalMapper, SLOT (map ())); |
|
317 m_expandSignalMapper->setMapping(action, commandId); |
|
318 |
|
319 m_expandActionMap.insert(bubbleId,action); |
|
320 } |
|
321 |
|
322 void PhoneUIQtView::removeExpandAction(int bubbleId) |
|
323 { |
|
324 if (m_expandActionMap.contains(bubbleId)) { |
|
325 m_bubbleManager->setExpandAction(bubbleId, 0); |
|
326 HbAction* action = m_expandActionMap.value(bubbleId); |
|
327 m_expandSignalMapper->removeMappings(action); |
|
328 m_expandActionMap.remove(bubbleId); |
|
329 delete action; |
|
330 } |
|
331 } |
|
332 |
|
333 void PhoneUIQtView::showDialpad() |
|
334 { |
|
335 if (false == m_dialpad->isVisible()) { |
|
336 setDialpadPosition(); |
|
337 m_dialpad->openDialpad(); |
|
338 } |
|
339 } |
|
340 |
|
341 void PhoneUIQtView::hideDialpad() |
|
342 { |
|
343 if (true == m_dialpad->isVisible()) |
|
344 m_dialpad->closeDialpad(); |
|
345 } |
|
346 |
|
347 bool PhoneUIQtView::isDialpadVisible() |
|
348 { |
|
349 return m_dialpad->isVisible(); |
|
350 } |
|
351 |
|
352 QString PhoneUIQtView::dialpadText() |
|
353 { |
|
354 return m_dialpad->editor().text(); |
|
355 } |
|
356 |
|
357 void PhoneUIQtView::clearAndHideDialpad() |
|
358 { |
|
359 m_dialpad->editor().setText(QString("")); |
|
360 hideDialpad(); |
|
361 } |
|
362 |
|
363 void PhoneUIQtView::bringToForeground() |
|
364 { |
|
365 m_window.show(); |
|
366 m_window.raise(); |
|
367 } |
|
368 |
|
369 void PhoneUIQtView::setMenuActions(const QList<PhoneAction*>& actions) |
|
370 { |
|
371 |
|
372 for (int i=menu()->actions().count(); 0<i; --i) { |
|
373 HbAction* action = static_cast<HbAction*>(menu()->actions().at(i-1)); |
|
374 m_menuSignalMapper->removeMappings(action); |
|
375 menu()->removeAction(action); |
|
376 delete action; |
|
377 } |
|
378 |
|
379 for (int i=0; i<actions.count(); ++i) { |
|
380 HbAction* action = new HbAction(); |
|
381 action->setText(actions.at(i)->text()); |
|
382 menu()->addAction(action); |
|
383 connect(action, SIGNAL(triggered()), m_menuSignalMapper, SLOT(map())); |
|
384 m_menuSignalMapper->setMapping(action, actions.at(i)->command()); |
|
385 } |
|
386 |
|
387 } |
|
388 |
|
389 HbMenu &PhoneUIQtView::menuReference() |
|
390 { |
|
391 return *menu(); |
|
392 } |
|
393 |
|
394 void PhoneUIQtView::handleOrientationChange(Qt::Orientation orientation) |
|
395 { |
|
396 if (orientation==Qt::Horizontal) { |
|
397 toolBar()->setOrientation(Qt::Horizontal); |
|
398 } |
|
399 |
|
400 m_bubbleManager->handleOrientationChange(orientation); |
|
401 |
|
402 setDialpadPosition(); |
|
403 } |
|
404 |
|
405 void PhoneUIQtView::backButtonClicked() |
|
406 { |
|
407 XQServiceUtil::toBackground(true); |
|
408 } |
|
409 |
|
410 void PhoneUIQtView::onEditorContentChanged() |
|
411 { |
|
412 m_dialpad->setCallButtonEnabled( |
|
413 m_dialpad->editor().text().length()); |
|
414 } |
|
415 |
|
416 void PhoneUIQtView::dialpadClosed() |
|
417 { |
|
418 emit dialpadIsAboutToClose(); |
|
419 } |
|
420 |
|
421 bool PhoneUIQtView::eventFilter(QObject * /*watched*/, QEvent * event) |
|
422 { |
|
423 if (event->type() == QEvent::KeyPress) { |
|
424 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
425 qDebug() << "PhoneUIQtView::eventFilter: pressed key " << keyEvent->key(); |
|
426 emit keyPressed(keyEvent); |
|
427 return false; |
|
428 } else if (event->type() == QEvent::KeyRelease) { |
|
429 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
430 qDebug() << "PhoneUIQtView::eventFilter: released key " << keyEvent->key(); |
|
431 emit keyReleased(keyEvent); |
|
432 return false; |
|
433 } else { |
|
434 return false; |
|
435 } |
|
436 } |
|
437 |
|
438 void PhoneUIQtView::setDialpadPosition() |
|
439 { |
|
440 QRectF screenRect = m_window.layoutRect(); |
|
441 |
|
442 if (m_window.orientation() == Qt::Horizontal) { |
|
443 // dialpad takes half of the screen |
|
444 m_dialpad->setPos(QPointF(screenRect.width()/2, |
|
445 this->scenePos().y())); |
|
446 m_dialpad->setPreferredSize(screenRect.width()/2, |
|
447 (screenRect.height()-scenePos().y())); |
|
448 } else { |
|
449 // dialpad takes 65% of the screen height |
|
450 qreal screenHeight = screenRect.height(); |
|
451 m_dialpad->setPos(QPointF(0, |
|
452 screenHeight/2.25)); |
|
453 m_dialpad->setPreferredSize(screenRect.width(), |
|
454 screenHeight-screenHeight/2.25); |
|
455 } |
|
456 } |
|
457 |
|
458 void PhoneUIQtView::setActionRole(const PhoneAction& pa, HbAction& action) |
|
459 { |
|
460 if (pa.actionRole()==PhoneAction::Accept) { |
|
461 action.setSoftKeyRole(QAction::PositiveSoftKey); |
|
462 } else if (pa.actionRole()==PhoneAction::Decline) { |
|
463 action.setSoftKeyRole(QAction::NegativeSoftKey); |
|
464 } |
|
465 } |
|
466 |
|
467 void PhoneUIQtView::createToolBarActions() |
|
468 { |
|
469 for (int i=0;i<4;++i) { |
|
470 HbAction* action = new HbAction(); |
|
471 connect(action, SIGNAL(triggered()), m_signalMapper, SLOT(map())); |
|
472 m_toolbarActions.append(action); |
|
473 } |
|
474 } |
|
475 |
|
476 void PhoneUIQtView::shutdownPhoneApp() |
|
477 { |
|
478 qDebug() << "PhoneUIQtView::shutdownPhoneApp "; |
|
479 QCoreApplication::quit(); |
|
480 } |
|
481 |
|
482 void PhoneUIQtView::setBackButtonVisible(bool visible) |
|
483 { |
|
484 HbAction *oldAction = m_window.softKeyAction(Hb::SecondarySoftKey); |
|
485 m_window.removeSoftKeyAction(Hb::SecondarySoftKey, oldAction); |
|
486 if (visible) { |
|
487 m_window.addSoftKeyAction(Hb::SecondarySoftKey, m_backAction); |
|
488 } |
|
489 else { |
|
490 m_window.addSoftKeyAction(Hb::SecondarySoftKey, m_emptyAction); |
|
491 } |
|
492 } |
|
493 |