|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "PopupWebChromeItem.h" |
|
20 #include "ChromeWidget.h" |
|
21 #include "WebChromeSnippet.h" |
|
22 |
|
23 namespace GVA { |
|
24 |
|
25 PopupWebChromeItem::PopupWebChromeItem( |
|
26 const QRectF & ownerArea, |
|
27 ChromeWidget * chrome, |
|
28 const QWebElement & element, |
|
29 QGraphicsItem * parent) |
|
30 : WebChromeItem(ownerArea, chrome, element, parent) |
|
31 { |
|
32 } |
|
33 |
|
34 PopupWebChromeItem::~PopupWebChromeItem() |
|
35 {} |
|
36 |
|
37 void PopupWebChromeItem::init(WebChromeSnippet * snippet) |
|
38 { |
|
39 WebChromeItem::init(snippet); |
|
40 |
|
41 // Forward externalMouseEvent signals from context items. |
|
42 QObject::connect( |
|
43 this, |
|
44 SIGNAL(externalMouseEvent(int, const QString &, const QString &)), |
|
45 snippet, |
|
46 SIGNAL(externalMouseEvent(int, const QString &, const QString &))); |
|
47 } |
|
48 |
|
49 bool PopupWebChromeItem::event(QEvent * e) |
|
50 { |
|
51 // Check for external events grabbed by this item. |
|
52 |
|
53 checkForExternalEvent(this, e); |
|
54 |
|
55 switch(e->type()) { |
|
56 case QEvent::Show: |
|
57 scene()->installEventFilter(this); |
|
58 break; |
|
59 case QEvent::Hide: |
|
60 scene()->removeEventFilter(this); |
|
61 break; |
|
62 default: break; |
|
63 } |
|
64 |
|
65 // Let the parent class handle the event. |
|
66 |
|
67 return WebChromeItem::event(e); |
|
68 } |
|
69 |
|
70 bool PopupWebChromeItem::eventFilter(QObject * o, QEvent * e) |
|
71 { |
|
72 // Check for external events NOT grabbed by this item. |
|
73 |
|
74 checkForExternalEvent(o, e); |
|
75 |
|
76 // Don't filter any events. |
|
77 |
|
78 return false; |
|
79 } |
|
80 |
|
81 void PopupWebChromeItem::checkForExternalEvent(QObject * o, QEvent * e) |
|
82 { |
|
83 Q_UNUSED(o); |
|
84 |
|
85 // Ignore all events when this item is not showing. |
|
86 |
|
87 if (!isVisible()) { |
|
88 return; |
|
89 } |
|
90 |
|
91 // Ignore all but a few mouse press events. |
|
92 |
|
93 switch (e->type()) { |
|
94 case QEvent::GraphicsSceneMousePress: |
|
95 case QEvent::GraphicsSceneMouseRelease: |
|
96 case QEvent::GraphicsSceneMouseDoubleClick: |
|
97 case QEvent::GraphicsSceneResize: |
|
98 break; |
|
99 default: |
|
100 return; |
|
101 } |
|
102 |
|
103 // Check where the mouse press event occurred. |
|
104 // If it was outside this item's bounding rectangle, |
|
105 // then tell the world. |
|
106 |
|
107 if(e->type() == QEvent::GraphicsSceneResize) |
|
108 { |
|
109 emitExternalEvent(e); |
|
110 return; |
|
111 } |
|
112 |
|
113 QGraphicsSceneMouseEvent * me = static_cast<QGraphicsSceneMouseEvent*>(e); |
|
114 |
|
115 QPointF eventPosition = me->scenePos(); |
|
116 |
|
117 QRectF itemGeometry = sceneBoundingRect(); |
|
118 |
|
119 if (!itemGeometry.contains(eventPosition)) { |
|
120 emitExternalEvent(e); |
|
121 } |
|
122 } |
|
123 |
|
124 void PopupWebChromeItem::emitExternalEvent(QEvent * e) |
|
125 { |
|
126 QString description; |
|
127 |
|
128 QDebug stream(&description); |
|
129 stream << e; |
|
130 |
|
131 QString name = description; |
|
132 name.truncate(name.indexOf('(')); |
|
133 |
|
134 emit externalMouseEvent(e->type(), name, description.trimmed()); |
|
135 } |
|
136 |
|
137 } // end of namespace GVA |