author | hgs |
Thu, 24 Jun 2010 14:32:18 +0300 | |
changeset 47 | f83bd4ae1fe3 |
parent 44 | c2d07d913565 |
child 48 | 10eaf342f539 |
permissions | -rw-r--r-- |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
44 | 2 |
* Copyright (c) 2009-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 |
*/ |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
#include "nmuiheaders.h" |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
/*! |
44 | 21 |
Constructor. |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
NmMailViewerWK::NmMailViewerWK() |
47 | 24 |
: QGraphicsWebView(), |
25 |
mContent(), |
|
26 |
mParentView(NULL), |
|
27 |
mSuppressRelease(false) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
{ |
47 | 29 |
// Subscribe this widget to tap and pinch gestures. |
30 |
grabGesture(Qt::TapGesture); |
|
44 | 31 |
grabGesture(Qt::PinchGesture); |
47 | 32 |
// Prevent this widget from accepting focus. |
33 |
setFocusPolicy(Qt::NoFocus); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
35 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
/*! |
44 | 37 |
Destructor. |
38 |
*/ |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
NmMailViewerWK::~NmMailViewerWK() |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
{ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
mContent.clear(); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
42 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
/*! |
44 | 45 |
Sets the parent view. |
46 |
*/ |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
47 |
void NmMailViewerWK::setParentView(NmViewerView *parentView) |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
48 |
{ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
49 |
mParentView = parentView; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
51 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
52 |
/*! |
44 | 53 |
Adds content into web view. |
54 |
*/ |
|
43 | 55 |
void NmMailViewerWK::addContent(QString key, QVariant val, NmId partId, bool isFetched) |
56 |
{ |
|
57 |
mContent[key] = NmMailViewerWkContentItem(val, partId, isFetched); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
/*! |
44 | 61 |
Returns resource from added content. |
62 |
*/ |
|
43 | 63 |
QVariant NmMailViewerWK::loadResource(int type, const QUrl &name, NmId &partId, bool &isFetched) |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
{ |
43 | 65 |
NM_FUNCTION; |
66 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
if (type == QTextDocument::ImageResource) { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
QString key = '<' + name.path() + '>'; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
if (!mContent.contains(key)) { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
70 |
key = name.path(); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
71 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
72 |
if (mContent.contains(key)) { |
43 | 73 |
partId = mContent[key].mPartId; |
74 |
isFetched = mContent[key].mIsFetched; |
|
75 |
return mContent[key].mData; |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
76 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
77 |
return 0; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
78 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
79 |
return 0; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
80 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
81 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
/*! |
47 | 83 |
This is the main event handler that processes all incoming events in an |
84 |
appropriate manner. |
|
44 | 85 |
*/ |
47 | 86 |
bool NmMailViewerWK::event(QEvent* event) |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
{ |
44 | 88 |
bool consumed = false; |
89 |
if (event) { |
|
90 |
switch (event->type()) { |
|
91 |
case QEvent::Gesture: |
|
47 | 92 |
// Handle gesture events. |
93 |
gestureEvent(static_cast<QGestureEvent*>(event)); |
|
94 |
consumed = event->isAccepted(); |
|
44 | 95 |
break; |
96 |
case QEvent::GraphicsSceneContextMenu: |
|
47 | 97 |
// Handle context-menu events. |
98 |
// contextMenuEvent() is invoked directly in order to override |
|
99 |
// text selection in QWebPage. |
|
100 |
contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(event)); |
|
101 |
consumed = event->isAccepted(); |
|
44 | 102 |
break; |
103 |
default: |
|
47 | 104 |
// Invoke base class' event handler. |
105 |
consumed = QGraphicsWebView::event(event); |
|
44 | 106 |
break; |
107 |
} |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
108 |
} |
44 | 109 |
return consumed; |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
110 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
111 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
112 |
/*! |
47 | 113 |
Handles context-menu events. |
114 |
*/ |
|
115 |
void NmMailViewerWK::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) |
|
116 |
{ |
|
117 |
if (event) { |
|
118 |
// Suppress context-menu invocations. |
|
119 |
event->accept(); |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
/*! |
|
124 |
Handles gesture events. |
|
44 | 125 |
*/ |
47 | 126 |
void NmMailViewerWK::gestureEvent(QGestureEvent* event) |
127 |
{ |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
128 |
if (event) { |
47 | 129 |
if (QTapGesture* tap = static_cast<QTapGesture*>(event->gesture(Qt::TapGesture))) { |
130 |
switch (tap->state()) { |
|
131 |
case Qt::GestureCanceled: |
|
132 |
// Tap cancellation suppresses the following mouse release. |
|
133 |
mSuppressRelease = true; |
|
134 |
break; |
|
135 |
default: |
|
136 |
// Other states disclose the following mouse release. |
|
137 |
mSuppressRelease = false; |
|
138 |
break; |
|
139 |
} |
|
140 |
event->accept(); |
|
141 |
} |
|
44 | 142 |
if (QPinchGesture* pinch = static_cast<QPinchGesture*>(event->gesture(Qt::PinchGesture))) { |
143 |
// Handle pinch (zoom). |
|
144 |
// At the moment we simply consume the event. |
|
145 |
event->accept(); |
|
146 |
} |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
147 |
} |
47 | 148 |
} |
149 |
||
150 |
/*! |
|
151 |
Handles double-click events. |
|
152 |
*/ |
|
153 |
void NmMailViewerWK::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) |
|
154 |
{ |
|
155 |
if (event) { |
|
156 |
// Handle double clicks (instant zoom). |
|
157 |
// At the moment we simply consume the event. |
|
158 |
event->accept(); |
|
159 |
} |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
160 |
} |
47 | 161 |
|
162 |
/*! |
|
163 |
Handles mouse-move events. |
|
164 |
*/ |
|
165 |
void NmMailViewerWK::mouseMoveEvent(QGraphicsSceneMouseEvent* event) |
|
166 |
{ |
|
167 |
if (event) { |
|
168 |
// Suppress drag selection. |
|
169 |
event->accept(); |
|
170 |
} |
|
171 |
} |
|
172 |
||
173 |
/*! |
|
174 |
Handles mouse-release events. |
|
175 |
*/ |
|
176 |
void NmMailViewerWK::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
|
177 |
{ |
|
178 |
if (event) { |
|
179 |
// Suppress mouse release if the previous tap was cancelled. |
|
180 |
// Otherwise, invoke the base class' event handler. |
|
181 |
if (mSuppressRelease) { |
|
182 |
event->accept(); |
|
183 |
} else { |
|
184 |
QGraphicsWebView::mouseReleaseEvent(event); |
|
185 |
} |
|
186 |
} |
|
187 |
} |