3
|
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);
|
12
|
341 |
//Connect to handle external events of back press
|
|
342 |
connect( button->linkedSnippet(), SIGNAL(externalMouseEvent(QEvent *, const QString , const QString )), this, SLOT(onExternalMouse(QEvent *, const QString , const QString)));
|
3
|
343 |
}
|
|
344 |
|
|
345 |
void ContentToolbarSnippet::addToggleTBButton(QAction * action, ActionButtonSnippet* button) {
|
|
346 |
|
|
347 |
assert(action);
|
|
348 |
assert(button);
|
|
349 |
|
|
350 |
connect(action, SIGNAL(triggered()), this, SLOT(handleToggleTBButton()));
|
|
351 |
}
|
|
352 |
|
|
353 |
|
|
354 |
void ContentToolbarSnippet::handleZoomButton() {
|
|
355 |
|
|
356 |
ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_ZOOM);
|
|
357 |
ChromeSnippet * zoomSnippet = button->linkedSnippet();
|
|
358 |
|
|
359 |
|
|
360 |
if (zoomSnippet->isVisible() ) {
|
|
361 |
zoomSnippet->hide();
|
|
362 |
}
|
|
363 |
else {
|
|
364 |
hideOtherPopups(button->elementId());
|
|
365 |
zoomSnippet->show();
|
|
366 |
|
|
367 |
// Show the action buttons. We can get the snippets by their id or do this to show them.
|
|
368 |
ChromeItem* it = dynamic_cast <ChromeItem * > (zoomSnippet->widget());
|
|
369 |
QList<QGraphicsItem *> childItems = it->childItems();
|
|
370 |
int count = childItems.count();
|
|
371 |
|
|
372 |
for (int i = 0; i < count ; i++) {
|
|
373 |
ChromeItem * child = dynamic_cast<ChromeItem* >(childItems.at(i));
|
|
374 |
child->snippet()->show();
|
|
375 |
|
|
376 |
}
|
|
377 |
}
|
|
378 |
|
|
379 |
}
|
|
380 |
|
|
381 |
void ContentToolbarSnippet::handleMenuButton() {
|
|
382 |
|
|
383 |
ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_MENU);
|
|
384 |
ChromeSnippet * menuSnippet = button->linkedSnippet();
|
|
385 |
|
|
386 |
if (!menuSnippet->isVisible() ) {
|
|
387 |
|
|
388 |
emit menuButtonSelected();
|
|
389 |
hideOtherPopups(button->elementId());
|
|
390 |
|
|
391 |
}
|
|
392 |
else {
|
|
393 |
menuSnippet->hide();
|
|
394 |
}
|
|
395 |
|
|
396 |
}
|
|
397 |
|
|
398 |
void ContentToolbarSnippet::handleMVButton() {
|
|
399 |
|
|
400 |
//qDebug() << "ContentToolbarSnippet::handleMVButton() ";
|
|
401 |
ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_MOSTVISITED);
|
|
402 |
hideOtherPopups(button->elementId());
|
|
403 |
button->linkedSnippet()->toggleVisibility();
|
|
404 |
}
|
|
405 |
|
|
406 |
void ContentToolbarSnippet::handleToggleTBButton() {
|
|
407 |
ContentToolbarChromeItem * w = static_cast<ContentToolbarChromeItem*>(widget());
|
|
408 |
w->toggleMiddleSnippet();
|
|
409 |
}
|
|
410 |
|
|
411 |
|
|
412 |
void ContentToolbarSnippet::hideOtherPopups(QString id) {
|
|
413 |
|
|
414 |
|
|
415 |
for (int i = 0; i < m_actionInfo.size() ; i++ ) {
|
|
416 |
|
|
417 |
ToolbarActions_t * t = m_actionInfo.at(i);
|
|
418 |
if (t->id != id ) {
|
|
419 |
ActionButtonSnippet * buttonSnippet = static_cast<ActionButtonSnippet*> ( m_chrome->getSnippet(t->id));
|
|
420 |
ChromeSnippet * linkedSnippet = buttonSnippet->linkedSnippet();
|
|
421 |
|
|
422 |
// If there is another sub-chrome visible, hide it
|
|
423 |
if (linkedSnippet ) {
|
|
424 |
if ( linkedSnippet->isVisible()) {
|
|
425 |
linkedSnippet->hide();
|
|
426 |
}
|
|
427 |
else {
|
|
428 |
// When the user selects the menu button, menu is displayed after certain timeout
|
|
429 |
// and it is possible that the user can select another button. So cancel it if the
|
|
430 |
// button is 'checked' if we get another action trigger
|
|
431 |
|
|
432 |
//qDebug() << "ContentToolbarSnippet::hideOtherPopups: " << id << "Button: " << t->id << buttonSnippet->isChecked();
|
|
433 |
|
|
434 |
if ( (buttonSnippet->elementId() == "MenuButtonSnippet" ) && (buttonSnippet->isChecked() )) {
|
|
435 |
emit menuButtonCanceled();
|
|
436 |
buttonSnippet->updateButtonState(false);
|
|
437 |
}
|
|
438 |
}
|
|
439 |
}
|
|
440 |
}
|
|
441 |
|
|
442 |
}
|
|
443 |
|
|
444 |
|
|
445 |
}
|
|
446 |
|
|
447 |
void ContentToolbarSnippet::connectHideShowSignals(ActionButtonSnippet * button) {
|
|
448 |
|
|
449 |
// Connect to hide and show signals of the linked snippet
|
|
450 |
ChromeSnippet * snippet = button->linkedSnippet();
|
|
451 |
ActionButton * actionButton = static_cast<ActionButton*>(button->widget());
|
|
452 |
connect(snippet, SIGNAL(hidden()), actionButton, SLOT(onHidden()));
|
|
453 |
connect(snippet, SIGNAL(shown()), actionButton, SLOT(onShown()));
|
|
454 |
|
|
455 |
connect(snippet, SIGNAL(hidden()), this, SLOT(onHidden()));
|
|
456 |
connect(snippet, SIGNAL(shown()), this, SLOT(onShown()));
|
|
457 |
|
|
458 |
}
|
|
459 |
|
|
460 |
void ContentToolbarSnippet::onAspectChanged( ) {
|
|
461 |
|
12
|
462 |
updateOwnerArea();
|
3
|
463 |
// Hide any pop-up that is visible
|
|
464 |
hideOtherPopups(QString());
|
|
465 |
}
|
|
466 |
|
|
467 |
void ContentToolbarSnippet::onSnippetMouseEvent( QEvent::Type type) {
|
|
468 |
|
|
469 |
//qDebug() << "ContentToolbarSnippet::onSnippetMouseEvent : Type" << type;
|
|
470 |
if (type == QEvent::GraphicsSceneMousePress || type == QEvent::MouseButtonPress ) {
|
|
471 |
resetTimer(false);
|
|
472 |
}
|
|
473 |
else if (type == QEvent::GraphicsSceneMouseRelease || type == QEvent::MouseButtonRelease ) {
|
|
474 |
resetTimer();
|
|
475 |
}
|
|
476 |
}
|
|
477 |
|
|
478 |
void ContentToolbarSnippet::onMouseEvent( QEvent::Type type) {
|
|
479 |
|
|
480 |
ActionButton* button = static_cast<ActionButton*> ( sender());
|
|
481 |
ActionButtonSnippet * buttonSnippet = static_cast<ActionButtonSnippet*>( button->snippet());
|
|
482 |
ChromeSnippet * linkedSnippet = buttonSnippet->linkedSnippet();
|
|
483 |
//qDebug() << "ContentToolbarSnippet::onMouseEvent : Button : " << buttonSnippet->elementId() << " type: " << type ;
|
|
484 |
|
|
485 |
// Set the action button state to active so that we can show a selected image before the
|
|
486 |
// action is acted upon
|
|
487 |
if ( (button->defaultAction()->isEnabled() && type == QEvent::GraphicsSceneMousePress ) ||
|
|
488 |
(button->defaultAction()->isEnabled() && type == QEvent::GraphicsSceneMouseDoubleClick )) {
|
|
489 |
|
|
490 |
// Set active flag if there is no linked snippet (the button acts as toggle if it
|
|
491 |
// has a linked snippet. If there is linked snippet, set active flag if the linked snippet
|
|
492 |
// is not visible
|
|
493 |
if (!linkedSnippet || (linkedSnippet && (!linkedSnippet->isVisible() ))) {
|
|
494 |
buttonSnippet->setActive(true);
|
|
495 |
}
|
|
496 |
}
|
|
497 |
}
|
|
498 |
|
|
499 |
void ContentToolbarSnippet::onHidden() {
|
|
500 |
|
|
501 |
ChromeSnippet * snippet = static_cast<ChromeSnippet *> (sender());
|
|
502 |
//qDebug() << "ContentToolbarSnippet::onHidden" << snippet->elementId();
|
|
503 |
if (snippet == m_subChromeSnippet ) {
|
|
504 |
|
|
505 |
//qDebug() << "ContentToolbarSnippet::onHidden hide shown snippet" << snippet->elementId();
|
|
506 |
resetTimer(false);
|
|
507 |
m_subChromeSnippet = NULL;
|
|
508 |
}
|
|
509 |
|
|
510 |
}
|
|
511 |
|
|
512 |
void ContentToolbarSnippet::onShown() {
|
|
513 |
|
|
514 |
// If one sub-chrome is being displayed when another is requested to be launched by the user, to avoid
|
|
515 |
//depending on the order of receiving hidden and shown signals for each of those, we save the snippet
|
|
516 |
// being shown and then later when hidden signal is received, the sender is compared to the
|
|
517 |
// snippet for which we started the timer so that the timer is started and stopped for the
|
|
518 |
// correct snippet. If 'shown' signal for the second is received before hidden for the second, the timer
|
|
519 |
// is stopped and restarted and the sub-chrome snippet is set to the new one. When 'hidden' is received
|
|
520 |
// for the first, it is ignored as it doesn't match our saved snippet value.
|
|
521 |
m_subChromeSnippet = static_cast<ChromeSnippet *> (sender());
|
|
522 |
//qDebug() << "ContentToolbarSnippet::onShown" << m_subChromeSnippet->elementId();
|
|
523 |
|
|
524 |
resetTimer();
|
|
525 |
|
|
526 |
}
|
|
527 |
|
|
528 |
|
|
529 |
void ContentToolbarSnippet::onInactivityTimer() {
|
|
530 |
|
|
531 |
//qDebug() << "ContentToolbarSnippet::onInactivityTimer" << m_subChromeSnippet->elementId();
|
|
532 |
if (m_subChromeSnippet->elementId() == "MostVisitedViewId" ) {
|
|
533 |
MostVisitedSnippet * mv = static_cast<MostVisitedSnippet *>(m_subChromeSnippet);
|
|
534 |
mv->close();
|
|
535 |
// Stop the timer here as there is animation to complete before hide is received
|
|
536 |
resetTimer(false);
|
|
537 |
m_subChromeSnippet = NULL;
|
|
538 |
}
|
|
539 |
else {
|
|
540 |
|
|
541 |
// Hide the snippet. onHidden slot will be called when the snippet is hidden
|
|
542 |
// and there we will stop the timer and reset m_subChromeSnippet
|
|
543 |
m_subChromeSnippet->hide();
|
|
544 |
}
|
|
545 |
}
|
|
546 |
|
|
547 |
|
|
548 |
void ContentToolbarSnippet::resetTimer(bool start) {
|
|
549 |
|
|
550 |
int duration = TOOLBAR_POPUP_INACTIVITY_DURATION;
|
|
551 |
if (m_subChromeInactiveTimer->isActive() ) {
|
|
552 |
//qDebug() << " Stop timer for " << m_subChromeSnippet->elementId();
|
|
553 |
m_subChromeInactiveTimer->stop();
|
|
554 |
}
|
|
555 |
|
|
556 |
if (start) {
|
|
557 |
if (m_subChromeSnippet->elementId() == "ZoomBarId" ) {
|
|
558 |
duration = TOOLBAR_ZOOMBAR_INACTIVITY_DURATION;
|
|
559 |
}
|
|
560 |
//qDebug() << " Start timer for " << m_subChromeSnippet->elementId();
|
|
561 |
m_subChromeInactiveTimer->start(duration);
|
|
562 |
}
|
|
563 |
|
|
564 |
}
|
|
565 |
void ContentToolbarSnippet::onExternalMouse( QEvent * ev ,
|
|
566 |
const QString & name,
|
|
567 |
const QString & description) {
|
|
568 |
|
|
569 |
Q_UNUSED(description);
|
|
570 |
ChromeSnippet * snippet = static_cast<ChromeSnippet *> (sender());
|
|
571 |
QGraphicsSceneMouseEvent * me = static_cast<QGraphicsSceneMouseEvent*>(ev);
|
|
572 |
ChromeSnippet * linkedButton = getLinkedButton(snippet);
|
|
573 |
|
|
574 |
// For sub-chromes like zoom and menu, we get mouse events anywhere on the
|
|
575 |
// screen including the ones on the corresponding button on the toolbar. Hide
|
|
576 |
// the sub-chrome only if the mouse press is anywhere other than the
|
|
577 |
// corresponding button
|
|
578 |
if (linkedButton ) {
|
|
579 |
ChromeItem * item = static_cast<ChromeItem* >(linkedButton->widget());
|
|
580 |
if (item && item->sceneBoundingRect().contains(me->scenePos() )) {
|
|
581 |
return;
|
|
582 |
}
|
|
583 |
}
|
|
584 |
|
|
585 |
if (name == ExternalEventCharm::s_mouseClick) {
|
|
586 |
snippet->hide();
|
|
587 |
}
|
|
588 |
|
|
589 |
|
|
590 |
}
|
|
591 |
|
|
592 |
|
|
593 |
void ContentToolbarSnippet::handleToolbarStateChange(ContentToolbarState state){
|
|
594 |
|
|
595 |
|
|
596 |
ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_TOGGLETB);
|
|
597 |
|
|
598 |
// set the appopriate icons based on the state
|
|
599 |
|
|
600 |
if (state != CONTENT_TOOLBAR_STATE_INVALID ) {
|
|
601 |
if (state == CONTENT_TOOLBAR_STATE_PARTIAL ) {
|
|
602 |
button->setIcon(TOOLBAR_PARTIAL_TB_TOGGLE_ICON);
|
|
603 |
button->setActiveIcon(TOOLBAR_PARTIAL_TB_SELECTED_TOGGLE_ICON);
|
|
604 |
}
|
|
605 |
else if (state == CONTENT_TOOLBAR_STATE_FULL ) {
|
|
606 |
button->setIcon(TOOLBAR_FULL_TB_TOGGLE_ICON);
|
|
607 |
button->setActiveIcon(TOOLBAR_FULL_TB_SELECTED_TOGGLE_ICON);
|
|
608 |
|
|
609 |
}
|
|
610 |
// Also reset the button state if the change in state was triggered by toggle-button selection
|
|
611 |
button->updateButtonState(false);
|
|
612 |
|
|
613 |
}
|
|
614 |
}
|
|
615 |
|
|
616 |
ChromeSnippet* ContentToolbarSnippet::getLinkedButton(ChromeSnippet * snippet ) {
|
|
617 |
|
|
618 |
ChromeSnippet * linkedButton = NULL;
|
|
619 |
for (int i = 0; i < m_actionInfo.size() ; i++ ) {
|
|
620 |
ToolbarActions_t * t = m_actionInfo.at(i);
|
|
621 |
ChromeSnippet * s = getActionButtonSnippet (t->actionId) ;
|
|
622 |
if (s->linkedSnippet() && s->linkedSnippet()->elementId() == snippet->elementId() ) {
|
|
623 |
linkedButton = s;
|
|
624 |
break;
|
|
625 |
}
|
|
626 |
|
|
627 |
}
|
|
628 |
return linkedButton;
|
|
629 |
|
|
630 |
|
|
631 |
}
|
|
632 |
|
|
633 |
} // end of namespace GVA
|
|
634 |
|
|
635 |
|