15 * along with this program. If not, |
16 * along with this program. If not, |
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
17 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
17 * |
18 * |
18 * Description: |
19 * Description: |
19 * This class extends WebChromeContainerSnippet class to hold the |
20 * This class extends WebChromeContainerSnippet class to hold the |
20 * content view toolbar buttons |
21 * content view toolbar buttons. Showing/Hiding of the sub-chrome snippets in response to |
21 * Note: 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. |
22 * the button selection is not entirely done here as we have a |
|
23 * a hybrid html-native design. |
|
24 * MostVisited: Show/Hide is handled in handleMVButton. |
23 * MostVisited: Show/Hide is handled in handleMVButton. |
25 * Menu: Show is handled in Javascript. Hide is handled here. |
24 * Menu: Show is handled in Javascript. Hide is handled here. |
26 * Zoom: Show/Hide is handled here |
25 * Zoom: Show/Hide is handled here. Zoom action buttons |
27 * Note: Most Visited is native while Menu and Zoom are html based. All three of them need to |
26 * Note: Most Visited is native while Menu and Zoom are html based. All three of them need to |
28 * be dismissed if the user taps anywhere else on the screen. Since mv is native, it handles |
27 * be dismissed if the user taps anywhere else on the screen. Since mv is native, it handles |
29 * all mouse events and dismisses itself. Zoom/Menu are created as PopupChromeItem which receives |
28 * all mouse events and dismisses itself. Zoom/Menu are created as PopupChromeItem which receives |
30 * the mouse events in its event filter and emits a signal if the user taps anywhere on the screen |
29 * the mouse events in its event filter and emits a signal if the user taps anywhere on the screen |
31 * other than itself. This signal is handled here. |
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. |
32 * |
34 * |
33 */ |
35 */ |
34 |
36 |
35 #include "ContentToolbarSnippet.h" |
37 #include "ContentToolbarSnippet.h" |
36 #include "ContentToolbarChromeItem.h" |
38 #include "ContentToolbarChromeItem.h" |
37 #include "mostvisitedsnippet.h" |
39 #include "mostvisitedsnippet.h" |
38 #include "Toolbar.h" |
|
39 #include "ViewStack.h" |
40 #include "ViewStack.h" |
40 #include "webpagecontroller.h" |
41 #include "webpagecontroller.h" |
|
42 #include "ExternalEventCharm.h" |
41 |
43 |
42 #include <QDebug> |
44 #include <QDebug> |
43 |
45 |
44 |
46 |
45 namespace GVA { |
47 namespace GVA { |
46 |
48 |
47 |
49 |
48 ContentToolbarSnippet::ContentToolbarSnippet(const QString& elementId, ChromeWidget * chrome, const QRectF& ownerArea, const QWebElement & element, QGraphicsWidget * widget) |
50 ContentToolbarSnippet::ContentToolbarSnippet(const QString& elementId, ChromeWidget * chrome, const QWebElement & element) |
49 : ToolbarSnippet(elementId, chrome, ownerArea, element, widget), |
51 : ToolbarSnippet(elementId, chrome, element), |
50 m_middleSnippet(NULL), |
52 m_middleSnippet(NULL), |
51 m_subChromeSnippet(NULL) |
53 m_subChromeSnippet(NULL) |
52 { |
54 { |
53 |
55 |
54 m_type = TOOLBAR_WEB_VIEW; |
56 m_type = TOOLBAR_WEB_VIEW; |
60 ContentToolbarSnippet::~ContentToolbarSnippet() |
62 ContentToolbarSnippet::~ContentToolbarSnippet() |
61 { |
63 { |
62 delete m_subChromeInactiveTimer; |
64 delete m_subChromeInactiveTimer; |
63 } |
65 } |
64 |
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 |
65 void ContentToolbarSnippet::updateSize(QSize size) { |
74 void ContentToolbarSnippet::updateSize(QSize size) { |
66 //qDebug() << "ContentToolbarSnippet::updateSize" << size.width() ; |
75 //qDebug() << "ContentToolbarSnippet::updateSize" << size.width() ; |
67 setWidth(size.width()); |
76 setWidth(size.width()); |
68 ToolbarSnippet::updateSize(size); |
77 ToolbarSnippet::updateSize(size); |
69 |
78 |
70 } |
79 } |
71 |
80 |
72 void ContentToolbarSnippet::updateOwnerArea() { |
81 void ContentToolbarSnippet::updateOwnerArea() { |
73 |
82 |
74 |
83 |
75 //qDebug() << "ContentToolbarSnippet::updateOwnerArea" << m_chrome->width() ; |
84 //qDebug() << "ContentToolbarSnippet::updateOwnerArea" << m_chrome->width() ; |
76 setWidth(m_chrome->width()); |
85 setWidth(m_chrome->layout()->size().width()); |
77 ToolbarSnippet::updateOwnerArea(); |
86 ToolbarSnippet::updateOwnerArea(); |
78 |
87 |
79 //qDebug() << "------------Relayout "<< elementId() << hidesContent(); |
88 //qDebug() << "------------Relayout "<< elementId() << hidesContent(); |
80 // If hidesContent is true, it means that the snippet is tied to the chrome's layout. Hence, we |
89 // If hidesContent is true, it means that the snippet is tied to the chrome's layout. Hence, we |
81 // should invalidate and activate the layout here so that the layout and recalculate all |
90 // should invalidate and activate the layout here so that the layout and recalculate all |
82 // edges (we don't want to wait for the asynchronous layout request to be handled as |
91 // edges (we don't want to wait for the asynchronous layout request to be handled as |
83 // that would cause the this snippet to be painted in incorrect position before the layoutRequest |
92 // that would cause the this snippet to be painted in incorrect position before the layoutRequest |
84 // is handled |
93 // is handled |
85 if (hidesContent() ) { |
94 if (hidesContent() ) { |
86 chrome()->layout()->invalidate(); |
95 chrome()->layout()->layout()->invalidate(); |
87 chrome()->layout()->activate(); |
96 chrome()->layout()->layout()->activate(); |
88 } |
97 } |
89 } |
98 } |
90 |
99 |
91 void ContentToolbarSnippet::setWidth(int width ){ |
100 void ContentToolbarSnippet::setWidth(int width ){ |
92 |
101 |
111 |
120 |
112 ToolbarActions_t* t = new ToolbarActions_t(); |
121 ToolbarActions_t* t = new ToolbarActions_t(); |
113 if (id == "BackButtonSnippet" ) { |
122 if (id == "BackButtonSnippet" ) { |
114 t->actionId = CONTENT_VIEW_ACTION_BACK; |
123 t->actionId = CONTENT_VIEW_ACTION_BACK; |
115 t->actionName = CONTENT_TOTOLBAR_BACK; |
124 t->actionName = CONTENT_TOTOLBAR_BACK; |
116 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png"; |
125 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png"; |
117 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_disabled.png"; |
126 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_disabled.png"; |
118 t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png"; |
127 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png"; |
119 } |
128 } |
120 else if (id == "ZoomButtonSnippet" ) { |
129 else if (id == "ZoomButtonSnippet" ) { |
121 t->actionId = CONTENT_VIEW_ACTION_ZOOM; |
130 t->actionId = CONTENT_VIEW_ACTION_ZOOM; |
122 t->actionName = CONTENT_TOTOLBAR_ZOOM; |
131 t->actionName = CONTENT_TOTOLBAR_ZOOM; |
123 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom.png"; |
132 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom.png"; |
124 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom_disabled.png"; |
133 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom_disabled.png"; |
125 t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom_pressed.png"; |
134 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_zoom_pressed.png"; |
126 } |
135 } |
127 else if (id == "MenuButtonSnippet" ) { |
136 else if (id == "MenuButtonSnippet" ) { |
128 t->actionId = CONTENT_VIEW_ACTION_MENU; |
137 t->actionId = CONTENT_VIEW_ACTION_MENU; |
129 t->actionName = CONTENT_TOTOLBAR_MENU; |
138 t->actionName = CONTENT_TOTOLBAR_MENU; |
130 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_menu.png"; |
139 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_menu.png"; |
131 t->disabledImg = ""; |
140 t->disabledImg = ""; |
132 t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_menu_pressed.png"; |
141 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_menu_pressed.png"; |
133 } |
142 } |
134 else if (id == "MostVisitedButtonSnippet" ) { |
143 else if (id == "MostVisitedButtonSnippet" ) { |
135 t->actionId = CONTENT_VIEW_ACTION_MOSTVISITED; |
144 t->actionId = CONTENT_VIEW_ACTION_MOSTVISITED; |
136 t->actionName = CONTENT_TOTOLBAR_MOSTVISITED; |
145 t->actionName = CONTENT_TOTOLBAR_MOSTVISITED; |
137 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_mostvisited.png"; |
146 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_mostvisited.png"; |
138 t->disabledImg = ""; |
147 t->disabledImg = ""; |
139 t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_mostvisited_pressed.png"; |
148 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_mostvisited_pressed.png"; |
140 } |
149 } |
141 else if (id == "ToggleTBButtonSnippet" ) { |
150 else if (id == "ToggleTBButtonSnippet" ) { |
142 t->actionId = CONTENT_VIEW_ACTION_TOGGLETB; |
151 t->actionId = CONTENT_VIEW_ACTION_TOGGLETB; |
143 t->actionName = CONTENT_TOTOLBAR_TOGGLETB; |
152 t->actionName = CONTENT_TOTOLBAR_TOGGLETB; |
144 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_toggleTB.png"; |
153 t->normalImg = TOOLBAR_FULL_TB_TOGGLE_ICON; |
145 t->disabledImg = ""; |
154 t->disabledImg = ""; |
146 t->selectedImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_toggleTB_pressed.png"; |
155 t->activeImg = TOOLBAR_FULL_TB_SELECTED_TOGGLE_ICON; |
147 } |
156 } |
148 t->id = id; |
157 t->id = id; |
149 m_actionInfo.append(t); |
158 m_actionInfo.append(t); |
150 } |
159 } |
151 |
160 |
172 manageChildren(item); |
181 manageChildren(item); |
173 |
182 |
174 // Connect back to initialLayoutCompleted signal |
183 // Connect back to initialLayoutCompleted signal |
175 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_BACK); |
184 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_BACK); |
176 connect(WebPageController::getSingleton(), SIGNAL(initialLayoutCompleted()), button->widget(), SLOT(onHidden())); |
185 connect(WebPageController::getSingleton(), SIGNAL(initialLayoutCompleted()), button->widget(), SLOT(onHidden())); |
|
186 connect(WebPageController::getSingleton(), SIGNAL(loadFinished(bool)), button->widget(), SLOT(onHidden())); |
177 |
187 |
178 connect(m_chrome, SIGNAL(aspectChanged(int)) , this, SLOT(onAspectChanged())); |
188 connect(m_chrome, SIGNAL(aspectChanged(int)) , this, SLOT(onAspectChanged())); |
179 |
189 |
180 } |
190 } |
181 |
191 |
189 * but placed within another container. Also, the pop-ups are not directly |
199 * but placed within another container. Also, the pop-ups are not directly |
190 * linked to content toolbar. Here, all these snippets are determined to connect to the |
200 * linked to content toolbar. Here, all these snippets are determined to connect to the |
191 * widget's mosueEvent signal |
201 * widget's mosueEvent signal |
192 */ |
202 */ |
193 QList<QGraphicsItem *> items = it->childItems(); |
203 QList<QGraphicsItem *> items = it->childItems(); |
194 ContentToolbarChromeItem * w = static_cast<ContentToolbarChromeItem*>(widget()); |
|
195 //qDebug() << " ------------------- Num of children " << items.count(); |
204 //qDebug() << " ------------------- Num of children " << items.count(); |
196 for (int i = 0; i < items.count() ; i++) { |
205 for (int i = 0; i < items.count() ; i++) { |
197 |
206 |
198 // Can't use qobject_cast since QGraphicsWdiget is not a QObject |
207 // Can't use qobject_cast since QGraphicsWdiget is not a QObject |
199 ChromeItem * item = dynamic_cast<ChromeItem* >(items.at(i)); |
208 ChromeItem * item = dynamic_cast<ChromeItem* >(items.at(i)); |
203 // If it is a container, need to connect to it's child items, so recurse |
212 // If it is a container, need to connect to it's child items, so recurse |
204 if (s ) { |
213 if (s ) { |
205 manageChildren(item); |
214 manageChildren(item); |
206 } |
215 } |
207 else { // Individual item |
216 else { // Individual item |
208 //qDebug() << "Item: " << item->snippet()->elementId(); |
217 //qDebug() << "Item: " << item->snippet()->elementId(); |
209 if (w->autoHideToolbar()) { |
218 ContentToolbarChromeItem * w = static_cast<ContentToolbarChromeItem*>(widget()); |
210 connect(item, SIGNAL(mouseEvent(QEvent::Type)), w, SLOT(onSnippetMouseEvent(QEvent::Type))); |
219 if (w->autoHideToolbar()) { |
211 } |
220 // Connect to the snippet's mouse event to cancel auto-timeout |
212 // Connect to the mouse event to show selected image on key press |
221 connect(item, SIGNAL(mouseEvent(QEvent::Type)), w, SLOT(onSnippetMouseEvent(QEvent::Type))); |
213 //connect(item, SIGNAL(mouseEvent( QEvent::Type )), this, SLOT(onMouseEvent(QEvent::Type))); |
|
214 setAction(item->snippet()); |
|
215 |
|
216 |
|
217 ChromeSnippet * link = item->snippet()->linkedSnippet(); |
|
218 |
|
219 if (link) { |
|
220 ChromeItem* it = dynamic_cast <ChromeItem * > (link->widget()); |
|
221 if (it ) { |
|
222 connect(it, SIGNAL(mouseEvent(QEvent::Type)), this, SLOT(onSnippetMouseEvent(QEvent::Type))); |
|
223 // Save the linked children to be used later for hiding |
|
224 w->addLinkedChild(link); |
|
225 |
|
226 // In case it has more children, recurse |
|
227 manageChildren(it); |
|
228 } |
|
229 } |
222 } |
|
223 |
|
224 setAction(item->snippet()); |
|
225 manageLink(item); |
230 } |
226 } |
231 } |
227 } |
232 } |
228 } |
233 |
229 |
234 } |
230 } |
235 |
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 |
236 |
263 |
237 void ContentToolbarSnippet::setAction(ChromeSnippet * s) { |
264 void ContentToolbarSnippet::setAction(ChromeSnippet * s) { |
238 |
265 |
239 //qDebug() << "setAction: " << s->elementId(); |
266 //qDebug() << "setAction: " << s->elementId(); |
240 ToolbarSnippet::setAction(s); |
267 ToolbarSnippet::setAction(s); |
241 ActionButtonSnippet * button = static_cast<ActionButtonSnippet*> (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 |
242 int index = getIndex(s); |
278 int index = getIndex(s); |
243 |
279 |
244 if (index != -1) { |
280 if (index != -1) { |
245 QAction * action = button->getDefaultAction(); |
281 QAction * action = button->getDefaultAction(); |
246 ToolbarActions_t * t = m_actionInfo.at(index); |
282 ToolbarActions_t * t = m_actionInfo.at(index); |
273 connect(action, SIGNAL(triggered()), this, SLOT(handleZoomButton())); |
309 connect(action, SIGNAL(triggered()), this, SLOT(handleZoomButton())); |
274 |
310 |
275 |
311 |
276 // Connect to hide and show signals of the linked snippet |
312 // Connect to hide and show signals of the linked snippet |
277 connectHideShowSignals(button); |
313 connectHideShowSignals(button); |
278 connect( button->linkedSnippet(), SIGNAL(externalMouseEvent(int, const QString , const QString )), this, SLOT(onExternalMouse(int, const QString , const QString))); |
314 connect( button->linkedSnippet(), SIGNAL(externalMouseEvent(QEvent *, const QString , const QString )), this, SLOT(onExternalMouse(QEvent *, const QString , const QString))); |
|
315 |
279 |
316 |
280 } |
317 } |
281 |
318 |
282 void ContentToolbarSnippet::addMenuButton(QAction * action, ActionButtonSnippet* button) { |
319 void ContentToolbarSnippet::addMenuButton(QAction * action, ActionButtonSnippet* button) { |
283 |
320 |
286 |
323 |
287 connect(action, SIGNAL(triggered()), this, SLOT(handleMenuButton())); |
324 connect(action, SIGNAL(triggered()), this, SLOT(handleMenuButton())); |
288 |
325 |
289 // Connect to hide and show signals of the linked snippet |
326 // Connect to hide and show signals of the linked snippet |
290 connectHideShowSignals(button); |
327 connectHideShowSignals(button); |
291 connect( button->linkedSnippet(), SIGNAL(externalMouseEvent(int, const QString , const QString )), this, SLOT(onExternalMouse(int, const QString , const QString))); |
328 connect( button->linkedSnippet(), SIGNAL(externalMouseEvent(QEvent *, const QString , const QString )), this, SLOT(onExternalMouse(QEvent *, const QString , const QString))); |
292 |
329 |
293 } |
330 } |
294 |
331 |
295 void ContentToolbarSnippet::addMostVisitedButton(QAction * action, ActionButtonSnippet* button) { |
332 void ContentToolbarSnippet::addMostVisitedButton(QAction * action, ActionButtonSnippet* button) { |
296 |
333 |
315 void ContentToolbarSnippet::handleZoomButton() { |
352 void ContentToolbarSnippet::handleZoomButton() { |
316 |
353 |
317 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_ZOOM); |
354 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_ZOOM); |
318 ChromeSnippet * zoomSnippet = button->linkedSnippet(); |
355 ChromeSnippet * zoomSnippet = button->linkedSnippet(); |
319 |
356 |
320 //qDebug() << "ContentToolbarSnippet::handleZoomButton() : Show flag: " << zoomSnippet->getDontShowFlag() << "Checked " << button->isChecked(); |
357 |
321 |
358 if (zoomSnippet->isVisible() ) { |
322 // Zoom bar is dismissed if the user taps anywhere on the screen. We get externalMouseEvent |
359 zoomSnippet->hide(); |
323 // if the user presses the button also. In addition to that the action is triggered and the |
|
324 // handler is called. In this case, we don't need to do anything, so we use the DontShowFlag |
|
325 // to determine if there is any action needed. |
|
326 if (zoomSnippet->getDontShowFlag() ){ |
|
327 // Set selected state to false as it gets enabled in ActionButton mousePressEvent handling |
|
328 button->setLatched(false); |
|
329 zoomSnippet->setDontShowFlag(false); |
|
330 } |
360 } |
331 else { |
361 else { |
332 hideOtherPopups(button->elementId()); |
362 hideOtherPopups(button->elementId()); |
333 zoomSnippet->show(); |
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 } |
334 } |
375 } |
335 |
376 |
336 } |
377 } |
337 |
378 |
338 void ContentToolbarSnippet::handleMenuButton() { |
379 void ContentToolbarSnippet::handleMenuButton() { |
339 |
380 |
340 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_MENU); |
381 ActionButtonSnippet * button = getActionButtonSnippet(CONTENT_VIEW_ACTION_MENU); |
341 ChromeSnippet * menuSnippet = button->linkedSnippet(); |
382 ChromeSnippet * menuSnippet = button->linkedSnippet(); |
342 |
383 |
343 //qDebug() << "ContentToolbarSnippet::handleMenuButton() : Show flag: " << button->linkedSnippet()->getDontShowFlag() << "Checked: " << button->isChecked(); |
384 if (!menuSnippet->isVisible() ) { |
344 if (menuSnippet ) { |
385 |
345 //qDebug() << "ContentToolbarSnippet::handleMenuButton() : Dont show flag " << menuSnippet->getDontShowFlag(); |
386 emit menuButtonSelected(); |
346 if (menuSnippet->getDontShowFlag() ){ |
387 hideOtherPopups(button->elementId()); |
347 // Set selected state to false as it gets enabled in ActionButton mousePressEvent handling |
388 |
348 button->setLatched(false); |
389 } |
349 menuSnippet->setDontShowFlag(false); |
390 else { |
350 } |
391 menuSnippet->hide(); |
351 else { |
|
352 // Hide other pop-ups if any. Showing the menu is handled in |
|
353 // javascript |
|
354 emit menuButtonSelected(); |
|
355 hideOtherPopups(button->elementId()); |
|
356 } |
|
357 } |
392 } |
358 |
393 |
359 } |
394 } |
360 |
395 |
361 void ContentToolbarSnippet::handleMVButton() { |
396 void ContentToolbarSnippet::handleMVButton() { |
443 void ContentToolbarSnippet::onMouseEvent( QEvent::Type type) { |
475 void ContentToolbarSnippet::onMouseEvent( QEvent::Type type) { |
444 |
476 |
445 ActionButton* button = static_cast<ActionButton*> ( sender()); |
477 ActionButton* button = static_cast<ActionButton*> ( sender()); |
446 ActionButtonSnippet * buttonSnippet = static_cast<ActionButtonSnippet*>( button->snippet()); |
478 ActionButtonSnippet * buttonSnippet = static_cast<ActionButtonSnippet*>( button->snippet()); |
447 ChromeSnippet * linkedSnippet = buttonSnippet->linkedSnippet(); |
479 ChromeSnippet * linkedSnippet = buttonSnippet->linkedSnippet(); |
448 //qDebug() << "ContentToolbarSnippet::onMouseEvent : Button : " << buttonSnippet->elementId() << " type: " << type << "Is Enabled " << button->defaultAction()->isEnabled(); |
480 //qDebug() << "ContentToolbarSnippet::onMouseEvent : Button : " << buttonSnippet->elementId() << " type: " << type ; |
449 |
481 |
450 // Set the action button state to active so that we can show a selected image before the |
482 // Set the action button state to active so that we can show a selected image before the |
451 // action is acted upon |
483 // action is acted upon |
452 if (button->defaultAction()->isEnabled() && type == QEvent::GraphicsSceneMousePress ) { |
484 if ( (button->defaultAction()->isEnabled() && type == QEvent::GraphicsSceneMousePress ) || |
|
485 (button->defaultAction()->isEnabled() && type == QEvent::GraphicsSceneMouseDoubleClick )) { |
453 |
486 |
454 // Set active flag if there is no linked snippet (the button acts as toggle if it |
487 // Set active flag if there is no linked snippet (the button acts as toggle if it |
455 // has a linked snippet. If there is linked snippet, set active flag if the linked snippet |
488 // has a linked snippet. If there is linked snippet, set active flag if the linked snippet |
456 // is not visible and dont show flag is false |
489 // is not visible |
457 if (!linkedSnippet || (linkedSnippet && (!linkedSnippet->isVisible() && !linkedSnippet->getDontShowFlag()))){ |
490 if (!linkedSnippet || (linkedSnippet && (!linkedSnippet->isVisible() ))) { |
458 buttonSnippet->setActive(true); |
491 buttonSnippet->setActive(true); |
459 } |
492 } |
460 } |
493 } |
461 } |
494 } |
462 |
495 |
524 //qDebug() << " Start timer for " << m_subChromeSnippet->elementId(); |
557 //qDebug() << " Start timer for " << m_subChromeSnippet->elementId(); |
525 m_subChromeInactiveTimer->start(duration); |
558 m_subChromeInactiveTimer->start(duration); |
526 } |
559 } |
527 |
560 |
528 } |
561 } |
529 void ContentToolbarSnippet::onExternalMouse( int type, |
562 void ContentToolbarSnippet::onExternalMouse( QEvent * ev , |
530 const QString & name, |
563 const QString & name, |
531 const QString & description) { |
564 const QString & description) { |
532 |
565 |
533 Q_UNUSED(type); |
|
534 Q_UNUSED(description); |
566 Q_UNUSED(description); |
535 ChromeSnippet * snippet = static_cast<ChromeSnippet *> (sender()); |
567 ChromeSnippet * snippet = static_cast<ChromeSnippet *> (sender()); |
536 //qDebug() << "ContentToolbarSnippet::onExternalMouse" << snippet->elementId() << name; |
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 } |
537 |
581 |
538 if (name == "QGraphicsSceneMousePressEvent" || name == "QGraphicsSceneResizeEvent" ) { |
582 if (name == ExternalEventCharm::s_mouseClick) { |
539 snippet->hide(); |
583 snippet->hide(); |
540 snippet->setDontShowFlag(true); |
|
541 QTimer::singleShot(500, snippet, SLOT(disableDontShowFlag())); |
|
542 } |
584 } |
543 |
585 |
544 |
586 |
545 } |
587 } |
546 |
588 |
547 |
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 |
548 } // end of namespace GVA |
630 } // end of namespace GVA |
549 |
631 |
550 |
632 |