1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: NMailUI web viewer. Inherits from |
15 * |
15 * QGrapohicsWebView and handles gestures, etc. |
16 */ |
16 */ |
17 |
17 |
18 #include "nmuiheaders.h" |
18 #include "nmuiheaders.h" |
19 |
19 |
20 /*! |
20 /*! |
21 Constructor |
21 Constructor. |
22 */ |
22 */ |
23 NmMailViewerWK::NmMailViewerWK() |
23 NmMailViewerWK::NmMailViewerWK() |
24 :QGraphicsWebView() |
24 : QGraphicsWebView(), |
|
25 mContent(), |
|
26 mSuppressRelease(false) |
25 { |
27 { |
|
28 // Subscribe this widget to tap and pinch gestures. |
|
29 grabGesture(Qt::TapGesture); |
|
30 grabGesture(Qt::PinchGesture); |
|
31 // Prevent this widget from accepting focus. |
|
32 setFocusPolicy(Qt::NoFocus); |
26 } |
33 } |
27 |
34 |
28 /*! |
35 /*! |
29 Destructor |
36 Destructor. |
30 */ |
37 */ |
31 NmMailViewerWK::~NmMailViewerWK() |
38 NmMailViewerWK::~NmMailViewerWK() |
32 { |
39 { |
33 mContent.clear(); |
40 mContent.clear(); |
34 } |
41 } |
35 |
42 |
36 /*! |
43 /*! |
37 |
44 Adds content into web view. |
38 */ |
45 */ |
39 void NmMailViewerWK::setParentView(NmViewerView *parentView) |
46 void NmMailViewerWK::addContent(QString key, QVariant val, NmId partId, bool isFetched) |
40 { |
47 { |
41 mParentView = parentView; |
48 mContent[key] = NmMailViewerWkContentItem(val, partId, isFetched); |
42 } |
49 } |
43 |
50 |
44 /*! |
51 /*! |
45 addContent. Function adds content into web view. |
52 Returns resource from added content. |
46 */ |
53 */ |
47 void NmMailViewerWK::addContent(QString key, QVariant val) { |
54 QVariant NmMailViewerWK::loadResource(int type, const QUrl &name, NmId &partId, bool &isFetched) |
48 mContent[key] = val; |
|
49 } |
|
50 |
|
51 /*! |
|
52 loadResource. Function returns resource from added content (added with addContent) |
|
53 */ |
|
54 QVariant NmMailViewerWK::loadResource(int type, const QUrl &name) |
|
55 { |
55 { |
|
56 NM_FUNCTION; |
|
57 |
56 if (type == QTextDocument::ImageResource) { |
58 if (type == QTextDocument::ImageResource) { |
57 QString key = '<' + name.path() + '>'; |
59 QString key = '<' + name.path() + '>'; |
58 if (!mContent.contains(key)) { |
60 if (!mContent.contains(key)) { |
59 key = name.path(); |
61 key = name.path(); |
60 } |
62 } |
61 if (mContent.contains(key)) { |
63 if (mContent.contains(key)) { |
62 return mContent[key]; |
64 partId = mContent[key].mPartId; |
|
65 isFetched = mContent[key].mIsFetched; |
|
66 return mContent[key].mData; |
63 } |
67 } |
64 return 0; |
|
65 } |
68 } |
66 return 0; |
69 return 0; |
67 } |
70 } |
68 |
71 |
69 /*! |
72 /*! |
70 sendMousePressEvent. Function is used to relay mouse event to base class |
73 This is the main event handler that processes all incoming events in an |
71 */ |
74 appropriate manner. |
72 void NmMailViewerWK::sendMousePressEvent(QGraphicsSceneMouseEvent *event) |
75 */ |
|
76 bool NmMailViewerWK::event(QEvent* event) |
73 { |
77 { |
74 if (event){ |
78 bool consumed = false; |
75 QGraphicsWebView::mousePressEvent(event); |
79 if (event) { |
|
80 switch (event->type()) { |
|
81 case QEvent::Gesture: |
|
82 // Handle gesture events. |
|
83 gestureEvent(static_cast<QGestureEvent*>(event)); |
|
84 consumed = event->isAccepted(); |
|
85 break; |
|
86 case QEvent::GraphicsSceneContextMenu: |
|
87 // Handle context-menu events. |
|
88 // contextMenuEvent() is invoked directly in order to override |
|
89 // text selection in QWebPage. |
|
90 contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(event)); |
|
91 consumed = event->isAccepted(); |
|
92 break; |
|
93 default: |
|
94 // Invoke base class' event handler. |
|
95 consumed = QGraphicsWebView::event(event); |
|
96 break; |
|
97 } |
|
98 } |
|
99 return consumed; |
|
100 } |
|
101 |
|
102 /*! |
|
103 Handles context-menu events. |
|
104 */ |
|
105 void NmMailViewerWK::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) |
|
106 { |
|
107 if (event) { |
|
108 // Suppress context-menu invocations. |
|
109 event->accept(); |
76 } |
110 } |
77 } |
111 } |
78 |
112 |
79 /*! |
113 /*! |
80 sendMouseReleaseEvent. Function is used to relay mouse event to base class |
114 Handles gesture events. |
81 */ |
115 */ |
82 void NmMailViewerWK::sendMouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
116 void NmMailViewerWK::gestureEvent(QGestureEvent* event) |
83 { |
117 { |
84 if (event) { |
118 if (event) { |
85 QGraphicsWebView::mouseReleaseEvent(event); |
119 if (QTapGesture* tap = static_cast<QTapGesture*>(event->gesture(Qt::TapGesture))) { |
|
120 switch (tap->state()) { |
|
121 case Qt::GestureCanceled: |
|
122 // Tap cancellation suppresses the following mouse release. |
|
123 mSuppressRelease = true; |
|
124 break; |
|
125 default: |
|
126 // Other states disclose the following mouse release. |
|
127 mSuppressRelease = false; |
|
128 break; |
|
129 } |
|
130 event->accept(); |
|
131 } |
|
132 if (QPinchGesture* pinch = static_cast<QPinchGesture*>(event->gesture(Qt::PinchGesture))) { |
|
133 // Handle pinch (zoom). |
|
134 // At the moment we simply consume the event. |
|
135 event->accept(); |
|
136 } |
86 } |
137 } |
87 } |
138 } |
88 |
139 |
|
140 /*! |
|
141 Handles double-click events. |
|
142 */ |
|
143 void NmMailViewerWK::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) |
|
144 { |
|
145 if (event) { |
|
146 // Handle double clicks (instant zoom). |
|
147 // At the moment we simply consume the event. |
|
148 event->accept(); |
|
149 } |
|
150 } |
89 |
151 |
|
152 /*! |
|
153 Handles mouse-move events. |
|
154 */ |
|
155 void NmMailViewerWK::mouseMoveEvent(QGraphicsSceneMouseEvent* event) |
|
156 { |
|
157 if (event) { |
|
158 // Suppress drag selection. |
|
159 event->accept(); |
|
160 } |
|
161 } |
90 |
162 |
|
163 /*! |
|
164 Handles mouse-release events. |
|
165 */ |
|
166 void NmMailViewerWK::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
|
167 { |
|
168 if (event) { |
|
169 // Suppress mouse release if the previous tap was cancelled. |
|
170 // Otherwise, invoke the base class' event handler. |
|
171 if (mSuppressRelease) { |
|
172 event->accept(); |
|
173 } else { |
|
174 QGraphicsWebView::mouseReleaseEvent(event); |
|
175 } |
|
176 } |
|
177 } |