author | hgs |
Tue, 29 Jun 2010 17:12:28 +0300 | |
changeset 48 | 10eaf342f539 |
parent 47 | f83bd4ae1fe3 |
child 57 | ae34e1715e21 |
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 |
* |
|
48 | 14 |
* Description: NMailUI web viewer. Inherits from |
15 |
* QGrapohicsWebView and handles gestures, etc. |
|
44 | 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 |
mSuppressRelease(false) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
{ |
47 | 28 |
// Subscribe this widget to tap and pinch gestures. |
29 |
grabGesture(Qt::TapGesture); |
|
44 | 30 |
grabGesture(Qt::PinchGesture); |
47 | 31 |
// Prevent this widget from accepting focus. |
32 |
setFocusPolicy(Qt::NoFocus); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
33 |
} |
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 |
/*! |
44 | 36 |
Destructor. |
37 |
*/ |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
NmMailViewerWK::~NmMailViewerWK() |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
{ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
mContent.clear(); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
} |
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 |
/*! |
44 | 44 |
Adds content into web view. |
45 |
*/ |
|
43 | 46 |
void NmMailViewerWK::addContent(QString key, QVariant val, NmId partId, bool isFetched) |
47 |
{ |
|
48 |
mContent[key] = NmMailViewerWkContentItem(val, partId, isFetched); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
49 |
} |
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 |
/*! |
44 | 52 |
Returns resource from added content. |
53 |
*/ |
|
43 | 54 |
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
|
55 |
{ |
43 | 56 |
NM_FUNCTION; |
57 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
if (type == QTextDocument::ImageResource) { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
QString key = '<' + name.path() + '>'; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
if (!mContent.contains(key)) { |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
61 |
key = name.path(); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
63 |
if (mContent.contains(key)) { |
43 | 64 |
partId = mContent[key].mPartId; |
65 |
isFetched = mContent[key].mIsFetched; |
|
66 |
return mContent[key].mData; |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
return 0; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
70 |
} |
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 |
/*! |
47 | 73 |
This is the main event handler that processes all incoming events in an |
74 |
appropriate manner. |
|
44 | 75 |
*/ |
47 | 76 |
bool NmMailViewerWK::event(QEvent* event) |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
77 |
{ |
44 | 78 |
bool consumed = false; |
79 |
if (event) { |
|
80 |
switch (event->type()) { |
|
81 |
case QEvent::Gesture: |
|
47 | 82 |
// Handle gesture events. |
83 |
gestureEvent(static_cast<QGestureEvent*>(event)); |
|
84 |
consumed = event->isAccepted(); |
|
44 | 85 |
break; |
86 |
case QEvent::GraphicsSceneContextMenu: |
|
47 | 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(); |
|
44 | 92 |
break; |
93 |
default: |
|
47 | 94 |
// Invoke base class' event handler. |
95 |
consumed = QGraphicsWebView::event(event); |
|
44 | 96 |
break; |
97 |
} |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
98 |
} |
44 | 99 |
return consumed; |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
100 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
101 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
102 |
/*! |
47 | 103 |
Handles context-menu events. |
104 |
*/ |
|
105 |
void NmMailViewerWK::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) |
|
106 |
{ |
|
107 |
if (event) { |
|
108 |
// Suppress context-menu invocations. |
|
109 |
event->accept(); |
|
110 |
} |
|
111 |
} |
|
112 |
||
113 |
/*! |
|
114 |
Handles gesture events. |
|
44 | 115 |
*/ |
47 | 116 |
void NmMailViewerWK::gestureEvent(QGestureEvent* event) |
117 |
{ |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
118 |
if (event) { |
47 | 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 |
} |
|
44 | 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 |
} |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
137 |
} |
47 | 138 |
} |
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 |
} |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
150 |
} |
47 | 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 |
} |
|
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 |
} |