|
1 |
|
2 /* |
|
3 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * |
|
6 * This program is free software: you can redistribute it and/or modify |
|
7 * it under the terms of the GNU Lesser General Public License as published by |
|
8 * the Free Software Foundation, version 2.1 of the License. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU Lesser General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Lesser General Public License |
|
16 * along with this program. If not, |
|
17 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
18 * |
|
19 * Description: |
|
20 * This class extends WebChromeContainerSnippet class to hold the |
|
21 * content view toolbar buttons. Showing/Hiding of the sub-chrome snippets in response to |
|
22 * the button selection is not entirely done here as we have a hybrid html-native design. |
|
23 * MostVisited: Show/Hide is handled in handleMVButton. |
|
24 * Menu: Show is handled in Javascript. Hide is handled here. |
|
25 * Zoom: Show/Hide is handled here. Zoom action buttons |
|
26 * Note: Most Visited is native while Menu and Zoom are html based. All three of them need to |
|
27 * be dismissed if the user taps anywhere else on the screen. Since mv is native, it handles |
|
28 * all mouse events and dismisses itself. Zoom/Menu are created as PopupChromeItem which receives |
|
29 * the mouse events in its event filter and emits a signal if the user taps anywhere on the screen |
|
30 * other than itself. This signal is handled here. |
|
31 * Sub-chromes are hidden after a specified timeout if there is no user interaction with the |
|
32 * particular chrome. This class listens to the mouse events of the sub-chromes and |
|
33 * their children to manage this. |
|
34 * |
|
35 */ |
|
36 |
|
37 #include "ContentToolbarSnippet.h" |
|
38 #include "ContentToolbarChromeItem.h" |
|
39 #include "mostvisitedsnippet.h" |
|
40 #include "ViewStack.h" |
|
41 #include "webpagecontroller.h" |
|
42 #include "ExternalEventCharm.h" |
|
43 |
|
44 #include <QDebug> |
|
45 |
|
46 |
|
47 namespace GVA { |
|
48 |
|
49 |
|
50 ContentToolbarSnippet::ContentToolbarSnippet(const QString& elementId, ChromeWidget * chrome, const QWebElement & element) |
|
51 : ToolbarSnippet(elementId, chrome, element), |
|
52 m_middleSnippet(NULL), |
|
53 m_subChromeSnippet(NULL) |
|
54 { |
|
55 |
|
56 m_type = TOOLBAR_WEB_VIEW; |
|
57 m_subChromeInactiveTimer = new QTimer(this); |
|
58 connect(m_subChromeInactiveTimer, SIGNAL(timeout()), this, SLOT(onInactivityTimer())); |
|
59 |
|
60 } |
|
61 |
|
62 ContentToolbarSnippet::~ContentToolbarSnippet() |
|
63 { |
|
64 delete m_subChromeInactiveTimer; |
|
65 } |
|
66 |
|
67 ContentToolbarSnippet * ContentToolbarSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element) |
|
68 { |
|
69 ContentToolbarSnippet * that = new ContentToolbarSnippet( elementId, chrome, element ); |
|
70 that->setChromeWidget( new ContentToolbarChromeItem( that ) ); |
|
71 return that; |
|
72 } |
|
73 |
|
74 void ContentToolbarSnippet::updateSize(QSize size) { |
|
75 //qDebug() << "ContentToolbarSnippet::updateSize" << size.width() ; |
|
76 setWidth(size.width()); |
|
77 ToolbarSnippet::updateSize(size); |
|
78 |
|
79 } |
|
80 |
|
81 void ContentToolbarSnippet::updateOwnerArea() { |
|
82 |
|
83 |
|
84 //qDebug() << "ContentToolbarSnippet::updateOwnerArea" << m_chrome->width() ; |
|
85 setWidth(m_chrome->layout()->size().width()); |
|
86 ToolbarSnippet::updateOwnerArea(); |
|
87 |
|
88 //qDebug() << "------------Relayout "<< elementId() << hidesContent(); |
|
89 // If hidesContent is true, it means that the snippet is tied to the chrome's layout. Hence, we |
|
90 // should invalidate and activate the layout here so that the layout and recalculate all |
|
91 // edges (we don't want to wait for the asynchronous layout request to be handled as |
|
92 // that would cause the this snippet to be painted in incorrect position before the layoutRequest |
|
93 // is handled |
|
94 if (hidesContent() ) { |
|
95 chrome()->layout()->layout()->invalidate(); |
|
96 chrome()->layout()->layout()->activate(); |
|
97 } |
|
98 } |
|
99 |
|
100 void ContentToolbarSnippet::setWidth(int width ){ |
|
101 |
|
102 QGraphicsLinearLayout* l = layout(); |
|
103 |
|
104 // We are using the width of the first element as the first and last elements are the same width |
|
105 if (l && l->itemAt(0)) { |
|
106 |
|
107 qreal snippetWidth = width -(2 * l->itemAt(0)->geometry().width()); |
|
108 m_middleSnippet->setLayoutWidth(snippetWidth, true); |
|
109 |
|
110 } |
|
111 |
|
112 } |
|
113 |
|
114 void ContentToolbarSnippet::childAdded(ChromeSnippet* child) { |
|
115 |
|
116 addActionInfo(child->elementId()); |
|
117 } |
|
118 |
|
119 void ContentToolbarSnippet::addActionInfo(QString id) { |
|
120 |
|
121 ToolbarActions_t* t = new ToolbarActions_t(); |
|
122 if (id == "BackButtonSnippet" ) { |
|
123 t->actionId = CONTENT_VIEW_ACTION_BACK; |
|
124 t->actionName = CONTENT_TOTOLBAR_BACK; |
|
125 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png"; |
|
126 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_disabled.png"; |
|
127 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png"; |
|
128 } |
|
129 else if (id == "ZoomButtonSnippet" ) { |
|
130 t->actionId = CONTENT_VIEW_ACTION_ZOOM; |
|
131 t->actionName = CONTENT_TOTOLBAR_ZOOM; |
|
132 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom.png"; |
|
133 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom_disabled.png"; |
|
134 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom_pressed.png"; |
|
135 } |
|
136 else if (id == "MenuButtonSnippet" ) { |
|
137 t->actionId = CONTENT_VIEW_ACTION_MENU; |
|
138 t->actionName = CONTENT_TOTOLBAR_MENU; |
|
139 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_menu.png"; |
|
140 t->disabledImg = ""; |
|
141 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_menu_pressed.png"; |
|
142 } |
|
143 else if (id == "MostVisitedButtonSnippet" ) { |
|
144 t->actionId = CONTENT_VIEW_ACTION_MOSTVISITED; |
|
145 t->actionName = CONTENT_TOTOLBAR_MOSTVISITED; |
|
146 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_mostvisited.png"; |
|
147 t->disabledImg = ""; |
|
148 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_mostvisited_pressed.png"; |
|
149 } |
|
150 else if (id == "ToggleTBButtonSnippet" ) { |
|
151 t->actionId = CONTENT_VIEW_ACTION_TOGGLETB; |
|
152 t->actionName = CONTENT_TOTOLBAR_TOGGLETB; |
|
153 t->normalImg = TOOLBAR_FULL_TB_TOGGLE_ICON; |
|
154 t->disabledImg = ""; |
|
155 t->activeImg = TOOLBAR_FULL_TB_SELECTED_TOGGLE_ICON; |
|
156 } |
|
157 t->id = id; |
|
158 m_actionInfo.append(t); |
|
159 } |
|
160 |
|
161 void ContentToolbarSnippet::addChild(ChromeSnippet* child) { |
|
162 |
|
163 WebChromeContainerSnippet * s = dynamic_cast<WebChromeContainerSnippet* >(child); |
|
164 if (s) { |
|
165 connect(child, SIGNAL(childAdded(ChromeSnippet*)), this, SLOT(childAdded(ChromeSnippet*))); |
|
166 m_middleSnippet = s; |
|
167 // Set the snippet width |
|
168 setWidth(m_chrome->layout()->size().width()); |
|
169 } |
|
170 else { |
|
171 addActionInfo(child->elementId()); |
|
172 } |
|
173 |
|
174 WebChromeContainerSnippet::addChild(child); |
|
175 |
|
176 } |
|
177 |
|
178 void ContentToolbarSnippet::onChromeComplete() { |
|
179 |
|
180 ChromeItem * item = static_cast<ChromeItem* >(widget()); |
|
181 manageChildren(item); |
|
182 |
|
183 // Connect back to initialLayoutCompleted signal |
|
184 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_BACK); |
|
185 connect(WebPageController::getSingleton(), SIGNAL(initialLayoutCompleted()), button->widget(), SLOT(onHidden())); |
|
186 connect(WebPageController::getSingleton(), SIGNAL(loadFinished(bool)), button->widget(), SLOT(onHidden())); |
|
187 |
|
188 connect(m_chrome, SIGNAL(aspectChanged(int)) , this, SLOT(onAspectChanged())); |
|
189 |
|
190 } |
|
191 |
|
192 void ContentToolbarSnippet::manageChildren(ChromeItem * it) { |
|
193 |
|
194 |
|
195 /*! |
|
196 * Content toolbar needs to listen to mouse events of each of the toolbar |
|
197 * buttons as well as the snippets that pop-up on selecting these |
|
198 * buttons. Some of these buttons are not direct children of content toolbar |
|
199 * but placed within another container. Also, the pop-ups are not directly |
|
200 * linked to content toolbar. Here, all these snippets are determined to connect to the |
|
201 * widget's mosueEvent signal |
|
202 */ |
|
203 QList<QGraphicsItem *> items = it->childItems(); |
|
204 //qDebug() << " ------------------- Num of children " << items.count(); |
|
205 for (int i = 0; i < items.count() ; i++) { |
|
206 |
|
207 // Can't use qobject_cast since QGraphicsWdiget is not a QObject |
|
208 ChromeItem * item = dynamic_cast<ChromeItem* >(items.at(i)); |
|
209 if (item ) { |
|
210 |
|
211 WebChromeContainerSnippet * s = dynamic_cast<WebChromeContainerSnippet* >(item->snippet()); |
|
212 // If it is a container, need to connect to it's child items, so recurse |
|
213 if (s ) { |
|
214 manageChildren(item); |
|
215 } |
|
216 else { // Individual item |
|
217 //qDebug() << "Item: " << item->snippet()->elementId(); |
|
218 ContentToolbarChromeItem * w = static_cast<ContentToolbarChromeItem*>(widget()); |
|
219 if (w->autoHideToolbar()) { |
|
220 // Connect to the snippet's mouse event to cancel auto-timeout |
|
221 connect(item, SIGNAL(mouseEvent(QEvent::Type)), w, SLOT(onSnippetMouseEvent(QEvent::Type))); |
|
222 } |
|
223 |
|
224 setAction(item->snippet()); |
|
225 manageLink(item); |
|
226 } |
|
227 } |
|
228 } |
|
229 |
|
230 } |
|
231 |
|
232 void ContentToolbarSnippet::manageLink(ChromeItem * item) { |
|
233 |
|
234 // If it has a linked snippet, connect to it's mouse event and also |
|
235 // to it's children's mouse events |
|
236 ChromeSnippet * link = item->snippet()->linkedSnippet(); |
|
237 if (link) { |
|
238 ChromeItem* it = dynamic_cast <ChromeItem * > (link->widget()); |
|
239 if (it ) { |
|
240 // Connect to linked snippet's mouse events to control the sub-chrome |
|
241 connect(it, SIGNAL(mouseEvent(QEvent::Type)), this, SLOT(onSnippetMouseEvent(QEvent::Type))); |
|
242 |
|
243 // Save the linked children to be used later for hiding |
|
244 ContentToolbarChromeItem * w = static_cast<ContentToolbarChromeItem*>(widget()); |
|
245 w->addLinkedChild(link); |
|
246 |
|
247 // In case it has children, connect to their mouse events as well |
|
248 QList<QGraphicsItem *> childItems = it->childItems(); |
|
249 int count = childItems.count(); |
|
250 |
|
251 // If the linked snippet has children that are widgets themselves, listen to their |
|
252 // mouse events as well. |
|
253 for (int i = 0; i < count ; i++) { |
|
254 ChromeItem * child = dynamic_cast<ChromeItem* >(childItems.at(i)); |
|
255 |
|
256 // To control sub-chrome timer |
|
257 connect(child, SIGNAL(mouseEvent(QEvent::Type)), this, SLOT(onSnippetMouseEvent(QEvent::Type))); |
|
258 } |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 |
|
264 void ContentToolbarSnippet::setAction(ChromeSnippet * s) { |
|
265 |
|
266 //qDebug() << "setAction: " << s->elementId(); |
|
267 ToolbarSnippet::setAction(s); |
|
268 ActionButtonSnippet * button = static_cast<ActionButtonSnippet*> (s); |
|
269 |
|
270 // Set selected on press to false here so that we can control when to |
|
271 // change action button icon state |
|
272 button->setActiveOnPress(false); |
|
273 button->getDefaultAction()->setCheckable(true); |
|
274 |
|
275 ChromeItem * item = static_cast<ChromeItem*>(s->widget()); |
|
276 connect(item, SIGNAL(mouseEvent( QEvent::Type )), this, SLOT(onMouseEvent(QEvent::Type))); |
|
277 |
|
278 int index = getIndex(s); |
|
279 |
|
280 if (index != -1) { |
|
281 QAction * action = button->getDefaultAction(); |
|
282 ToolbarActions_t * t = m_actionInfo.at(index); |
|
283 |
|
284 switch (t->actionId) { |
|
285 |
|
286 case CONTENT_VIEW_ACTION_ZOOM: |
|
287 addZoomButton(action, button); |
|
288 break; |
|
289 case CONTENT_VIEW_ACTION_MENU: |
|
290 addMenuButton(action, button); |
|
291 break; |
|
292 case CONTENT_VIEW_ACTION_MOSTVISITED: |
|
293 addMostVisitedButton(action, button); |
|
294 break; |
|
295 case CONTENT_VIEW_ACTION_TOGGLETB: |
|
296 addToggleTBButton(action, button); |
|
297 break; |
|
298 default: |
|
299 break; |
|
300 } |
|
301 } |
|
302 |
|
303 } |
|
304 |
|
305 void ContentToolbarSnippet::addZoomButton(QAction * action, ActionButtonSnippet* button) { |
|
306 |
|
307 assert(action); |
|
308 assert(button); |
|
309 connect(action, SIGNAL(triggered()), this, SLOT(handleZoomButton())); |
|
310 |
|
311 |
|
312 // Connect to hide and show signals of the linked snippet |
|
313 connectHideShowSignals(button); |
|
314 connect( button->linkedSnippet(), SIGNAL(externalMouseEvent(QEvent *, const QString , const QString )), this, SLOT(onExternalMouse(QEvent *, const QString , const QString))); |
|
315 |
|
316 |
|
317 } |
|
318 |
|
319 void ContentToolbarSnippet::addMenuButton(QAction * action, ActionButtonSnippet* button) { |
|
320 |
|
321 assert(action); |
|
322 assert(button); |
|
323 |
|
324 connect(action, SIGNAL(triggered()), this, SLOT(handleMenuButton())); |
|
325 |
|
326 // Connect to hide and show signals of the linked snippet |
|
327 connectHideShowSignals(button); |
|
328 connect( button->linkedSnippet(), SIGNAL(externalMouseEvent(QEvent *, const QString , const QString )), this, SLOT(onExternalMouse(QEvent *, const QString , const QString))); |
|
329 |
|
330 } |
|
331 |
|
332 void ContentToolbarSnippet::addMostVisitedButton(QAction * action, ActionButtonSnippet* button) { |
|
333 |
|
334 assert(action); |
|
335 assert(button); |
|
336 |
|
337 connect(action, SIGNAL(triggered()), this, SLOT(handleMVButton())); |
|
338 |
|
339 // Connect to hide and show signals of the linked snippet |
|
340 connectHideShowSignals(button); |
|
341 } |
|
342 |
|
343 void ContentToolbarSnippet::addToggleTBButton(QAction * action, ActionButtonSnippet* button) { |
|
344 |
|
345 assert(action); |
|
346 assert(button); |
|
347 |
|
348 connect(action, SIGNAL(triggered()), this, SLOT(handleToggleTBButton())); |
|
349 } |
|
350 |
|
351 |
|
352 void ContentToolbarSnippet::handleZoomButton() { |
|
353 |
|
354 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_ZOOM); |
|
355 ChromeSnippet * zoomSnippet = button->linkedSnippet(); |
|
356 |
|
357 |
|
358 if (zoomSnippet->isVisible() ) { |
|
359 zoomSnippet->hide(); |
|
360 } |
|
361 else { |
|
362 hideOtherPopups(button->elementId()); |
|
363 zoomSnippet->show(); |
|
364 |
|
365 // Show the action buttons. We can get the snippets by their id or do this to show them. |
|
366 ChromeItem* it = dynamic_cast <ChromeItem * > (zoomSnippet->widget()); |
|
367 QList<QGraphicsItem *> childItems = it->childItems(); |
|
368 int count = childItems.count(); |
|
369 |
|
370 for (int i = 0; i < count ; i++) { |
|
371 ChromeItem * child = dynamic_cast<ChromeItem* >(childItems.at(i)); |
|
372 child->snippet()->show(); |
|
373 |
|
374 } |
|
375 } |
|
376 |
|
377 } |
|
378 |
|
379 void ContentToolbarSnippet::handleMenuButton() { |
|
380 |
|
381 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_MENU); |
|
382 ChromeSnippet * menuSnippet = button->linkedSnippet(); |
|
383 |
|
384 if (!menuSnippet->isVisible() ) { |
|
385 |
|
386 emit menuButtonSelected(); |
|
387 hideOtherPopups(button->elementId()); |
|
388 |
|
389 } |
|
390 else { |
|
391 menuSnippet->hide(); |
|
392 } |
|
393 |
|
394 } |
|
395 |
|
396 void ContentToolbarSnippet::handleMVButton() { |
|
397 |
|
398 //qDebug() << "ContentToolbarSnippet::handleMVButton() "; |
|
399 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_MOSTVISITED); |
|
400 hideOtherPopups(button->elementId()); |
|
401 button->linkedSnippet()->toggleVisibility(); |
|
402 } |
|
403 |
|
404 void ContentToolbarSnippet::handleToggleTBButton() { |
|
405 ContentToolbarChromeItem * w = static_cast<ContentToolbarChromeItem*>(widget()); |
|
406 w->toggleMiddleSnippet(); |
|
407 } |
|
408 |
|
409 |
|
410 void ContentToolbarSnippet::hideOtherPopups(QString id) { |
|
411 |
|
412 |
|
413 for (int i = 0; i < m_actionInfo.size() ; i++ ) { |
|
414 |
|
415 ToolbarActions_t * t = m_actionInfo.at(i); |
|
416 if (t->id != id ) { |
|
417 ActionButtonSnippet * buttonSnippet = static_cast<ActionButtonSnippet*> ( m_chrome->getSnippet(t->id)); |
|
418 ChromeSnippet * linkedSnippet = buttonSnippet->linkedSnippet(); |
|
419 |
|
420 // If there is another sub-chrome visible, hide it |
|
421 if (linkedSnippet ) { |
|
422 if ( linkedSnippet->isVisible()) { |
|
423 linkedSnippet->hide(); |
|
424 } |
|
425 else { |
|
426 // When the user selects the menu button, menu is displayed after certain timeout |
|
427 // and it is possible that the user can select another button. So cancel it if the |
|
428 // button is 'checked' if we get another action trigger |
|
429 |
|
430 //qDebug() << "ContentToolbarSnippet::hideOtherPopups: " << id << "Button: " << t->id << buttonSnippet->isChecked(); |
|
431 |
|
432 if ( (buttonSnippet->elementId() == "MenuButtonSnippet" ) && (buttonSnippet->isChecked() )) { |
|
433 emit menuButtonCanceled(); |
|
434 buttonSnippet->updateButtonState(false); |
|
435 } |
|
436 } |
|
437 } |
|
438 } |
|
439 |
|
440 } |
|
441 |
|
442 |
|
443 } |
|
444 |
|
445 void ContentToolbarSnippet::connectHideShowSignals(ActionButtonSnippet * button) { |
|
446 |
|
447 // Connect to hide and show signals of the linked snippet |
|
448 ChromeSnippet * snippet = button->linkedSnippet(); |
|
449 ActionButton * actionButton = static_cast<ActionButton*>(button->widget()); |
|
450 connect(snippet, SIGNAL(hidden()), actionButton, SLOT(onHidden())); |
|
451 connect(snippet, SIGNAL(shown()), actionButton, SLOT(onShown())); |
|
452 |
|
453 connect(snippet, SIGNAL(hidden()), this, SLOT(onHidden())); |
|
454 connect(snippet, SIGNAL(shown()), this, SLOT(onShown())); |
|
455 |
|
456 } |
|
457 |
|
458 void ContentToolbarSnippet::onAspectChanged( ) { |
|
459 |
|
460 // Hide any pop-up that is visible |
|
461 hideOtherPopups(QString()); |
|
462 } |
|
463 |
|
464 void ContentToolbarSnippet::onSnippetMouseEvent( QEvent::Type type) { |
|
465 |
|
466 //qDebug() << "ContentToolbarSnippet::onSnippetMouseEvent : Type" << type; |
|
467 if (type == QEvent::GraphicsSceneMousePress || type == QEvent::MouseButtonPress ) { |
|
468 resetTimer(false); |
|
469 } |
|
470 else if (type == QEvent::GraphicsSceneMouseRelease || type == QEvent::MouseButtonRelease ) { |
|
471 resetTimer(); |
|
472 } |
|
473 } |
|
474 |
|
475 void ContentToolbarSnippet::onMouseEvent( QEvent::Type type) { |
|
476 |
|
477 ActionButton* button = static_cast<ActionButton*> ( sender()); |
|
478 ActionButtonSnippet * buttonSnippet = static_cast<ActionButtonSnippet*>( button->snippet()); |
|
479 ChromeSnippet * linkedSnippet = buttonSnippet->linkedSnippet(); |
|
480 //qDebug() << "ContentToolbarSnippet::onMouseEvent : Button : " << buttonSnippet->elementId() << " type: " << type ; |
|
481 |
|
482 // Set the action button state to active so that we can show a selected image before the |
|
483 // action is acted upon |
|
484 if ( (button->defaultAction()->isEnabled() && type == QEvent::GraphicsSceneMousePress ) || |
|
485 (button->defaultAction()->isEnabled() && type == QEvent::GraphicsSceneMouseDoubleClick )) { |
|
486 |
|
487 // Set active flag if there is no linked snippet (the button acts as toggle if it |
|
488 // has a linked snippet. If there is linked snippet, set active flag if the linked snippet |
|
489 // is not visible |
|
490 if (!linkedSnippet || (linkedSnippet && (!linkedSnippet->isVisible() ))) { |
|
491 buttonSnippet->setActive(true); |
|
492 } |
|
493 } |
|
494 } |
|
495 |
|
496 void ContentToolbarSnippet::onHidden() { |
|
497 |
|
498 ChromeSnippet * snippet = static_cast<ChromeSnippet *> (sender()); |
|
499 //qDebug() << "ContentToolbarSnippet::onHidden" << snippet->elementId(); |
|
500 if (snippet == m_subChromeSnippet ) { |
|
501 |
|
502 //qDebug() << "ContentToolbarSnippet::onHidden hide shown snippet" << snippet->elementId(); |
|
503 resetTimer(false); |
|
504 m_subChromeSnippet = NULL; |
|
505 } |
|
506 |
|
507 } |
|
508 |
|
509 void ContentToolbarSnippet::onShown() { |
|
510 |
|
511 // If one sub-chrome is being displayed when another is requested to be launched by the user, to avoid |
|
512 //depending on the order of receiving hidden and shown signals for each of those, we save the snippet |
|
513 // being shown and then later when hidden signal is received, the sender is compared to the |
|
514 // snippet for which we started the timer so that the timer is started and stopped for the |
|
515 // correct snippet. If 'shown' signal for the second is received before hidden for the second, the timer |
|
516 // is stopped and restarted and the sub-chrome snippet is set to the new one. When 'hidden' is received |
|
517 // for the first, it is ignored as it doesn't match our saved snippet value. |
|
518 m_subChromeSnippet = static_cast<ChromeSnippet *> (sender()); |
|
519 //qDebug() << "ContentToolbarSnippet::onShown" << m_subChromeSnippet->elementId(); |
|
520 |
|
521 resetTimer(); |
|
522 |
|
523 } |
|
524 |
|
525 |
|
526 void ContentToolbarSnippet::onInactivityTimer() { |
|
527 |
|
528 //qDebug() << "ContentToolbarSnippet::onInactivityTimer" << m_subChromeSnippet->elementId(); |
|
529 if (m_subChromeSnippet->elementId() == "MostVisitedViewId" ) { |
|
530 MostVisitedSnippet * mv = static_cast<MostVisitedSnippet *>(m_subChromeSnippet); |
|
531 mv->close(); |
|
532 // Stop the timer here as there is animation to complete before hide is received |
|
533 resetTimer(false); |
|
534 m_subChromeSnippet = NULL; |
|
535 } |
|
536 else { |
|
537 |
|
538 // Hide the snippet. onHidden slot will be called when the snippet is hidden |
|
539 // and there we will stop the timer and reset m_subChromeSnippet |
|
540 m_subChromeSnippet->hide(); |
|
541 } |
|
542 } |
|
543 |
|
544 |
|
545 void ContentToolbarSnippet::resetTimer(bool start) { |
|
546 |
|
547 int duration = TOOLBAR_POPUP_INACTIVITY_DURATION; |
|
548 if (m_subChromeInactiveTimer->isActive() ) { |
|
549 //qDebug() << " Stop timer for " << m_subChromeSnippet->elementId(); |
|
550 m_subChromeInactiveTimer->stop(); |
|
551 } |
|
552 |
|
553 if (start) { |
|
554 if (m_subChromeSnippet->elementId() == "ZoomBarId" ) { |
|
555 duration = TOOLBAR_ZOOMBAR_INACTIVITY_DURATION; |
|
556 } |
|
557 //qDebug() << " Start timer for " << m_subChromeSnippet->elementId(); |
|
558 m_subChromeInactiveTimer->start(duration); |
|
559 } |
|
560 |
|
561 } |
|
562 void ContentToolbarSnippet::onExternalMouse( QEvent * ev , |
|
563 const QString & name, |
|
564 const QString & description) { |
|
565 |
|
566 Q_UNUSED(description); |
|
567 ChromeSnippet * snippet = static_cast<ChromeSnippet *> (sender()); |
|
568 QGraphicsSceneMouseEvent * me = static_cast<QGraphicsSceneMouseEvent*>(ev); |
|
569 ChromeSnippet * linkedButton = getLinkedButton(snippet); |
|
570 |
|
571 // For sub-chromes like zoom and menu, we get mouse events anywhere on the |
|
572 // screen including the ones on the corresponding button on the toolbar. Hide |
|
573 // the sub-chrome only if the mouse press is anywhere other than the |
|
574 // corresponding button |
|
575 if (linkedButton ) { |
|
576 ChromeItem * item = static_cast<ChromeItem* >(linkedButton->widget()); |
|
577 if (item && item->sceneBoundingRect().contains(me->scenePos() )) { |
|
578 return; |
|
579 } |
|
580 } |
|
581 |
|
582 if (name == ExternalEventCharm::s_mouseClick) { |
|
583 snippet->hide(); |
|
584 } |
|
585 |
|
586 |
|
587 } |
|
588 |
|
589 |
|
590 void ContentToolbarSnippet::handleToolbarStateChange(ContentToolbarState state){ |
|
591 |
|
592 |
|
593 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_TOGGLETB); |
|
594 |
|
595 // set the appopriate icons based on the state |
|
596 |
|
597 if (state != CONTENT_TOOLBAR_STATE_INVALID ) { |
|
598 if (state == CONTENT_TOOLBAR_STATE_PARTIAL ) { |
|
599 button->setIcon(TOOLBAR_PARTIAL_TB_TOGGLE_ICON); |
|
600 button->setActiveIcon(TOOLBAR_PARTIAL_TB_SELECTED_TOGGLE_ICON); |
|
601 } |
|
602 else if (state == CONTENT_TOOLBAR_STATE_FULL ) { |
|
603 button->setIcon(TOOLBAR_FULL_TB_TOGGLE_ICON); |
|
604 button->setActiveIcon(TOOLBAR_FULL_TB_SELECTED_TOGGLE_ICON); |
|
605 |
|
606 } |
|
607 // Also reset the button state if the change in state was triggered by toggle-button selection |
|
608 button->updateButtonState(false); |
|
609 |
|
610 } |
|
611 } |
|
612 |
|
613 ChromeSnippet* ContentToolbarSnippet::getLinkedButton(ChromeSnippet * snippet ) { |
|
614 |
|
615 ChromeSnippet * linkedButton = NULL; |
|
616 for (int i = 0; i < m_actionInfo.size() ; i++ ) { |
|
617 ToolbarActions_t * t = m_actionInfo.at(i); |
|
618 ChromeSnippet * s = getActionButtonSnippet (t->actionId) ; |
|
619 if (s->linkedSnippet() && s->linkedSnippet()->elementId() == snippet->elementId() ) { |
|
620 linkedButton = s; |
|
621 break; |
|
622 } |
|
623 |
|
624 } |
|
625 return linkedButton; |
|
626 |
|
627 |
|
628 } |
|
629 |
|
630 } // end of namespace GVA |
|
631 |
|
632 |