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 |
/* |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
* |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
* Description: Message editor contents widget |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
* |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
*/ |
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 |
// Layout |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
static const char *NMUI_EDITOR_BODY = "BodyTextEdit"; |
47 | 22 |
static const char *NMUI_EDITOR_SCROLL_AREA = "scrollArea"; |
23 |
static const char *NMUI_EDITOR_SCROLL_AREA_CONTENTS = "scrollAreaContents"; |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
|
47 | 25 |
// Regular expression for selecting img tags with "cid" in the mail. |
26 |
static const char *NMUI_EDITOR_REMOVE_EMBD_IMAGES_REG = |
|
27 |
"(<img (src\\s*=\\s*)(.{0,1}cid)([^<]+)(>\\s*|/>\\s*|></img>\\s*))"; |
|
28 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
30 |
Constructor |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
*/ |
47 | 32 |
NmEditorContent::NmEditorContent(QObject *parent, |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
33 |
HbDocumentLoader *documentLoader, |
47 | 34 |
QNetworkAccessManager &manager, |
35 |
NmApplication &application) : |
|
36 |
QObject(parent), |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
37 |
mHeaderWidget(NULL), |
47 | 38 |
mMessageBodyType(NmPlainText), |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
mEditorWidget(NULL), |
47 | 40 |
mScrollArea(NULL), |
41 |
mScrollAreaContents(NULL), |
|
42 |
mApplication(application) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
{ |
43 | 44 |
NM_FUNCTION; |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
|
47 | 46 |
// Construct container for the header widgets |
47 |
mHeaderWidget = new NmEditorHeader(this, documentLoader); |
|
18
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 |
// Get pointer to body text area handling widget |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY)); |
43 | 51 |
|
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
52 |
// Set body editor to use NmEditorTextDocument |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
53 |
NmEditorTextDocument *textDocument = new NmEditorTextDocument(manager); |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
54 |
mEditorWidget->setDocument(textDocument); |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
55 |
textDocument->setParent(mEditorWidget); // ownership changes |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
56 |
|
47 | 57 |
mScrollArea = qobject_cast<NmBaseViewScrollArea *> |
58 |
(documentLoader->findObject(NMUI_EDITOR_SCROLL_AREA)); |
|
23
2dc6caa42ec3
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
59 |
|
2dc6caa42ec3
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
60 |
// Enable style picker menu item. |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
61 |
mEditorWidget->setFormatDialog(new HbFormatDialog()); |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
|
47 | 63 |
mScrollAreaContents = |
64 |
qobject_cast<HbWidget *>(documentLoader->findWidget(NMUI_EDITOR_SCROLL_AREA_CONTENTS)); |
|
65 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
// Create signal slot connections |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
createConnections(); |
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 |
|
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 |
Destructor |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
72 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
73 |
NmEditorContent::~NmEditorContent() |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
74 |
{ |
43 | 75 |
NM_FUNCTION; |
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 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
78 |
/*! |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
79 |
Fill message data into header and body fileds. If reply envelopw is |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
80 |
present, reply header is generated and set to editor. Reply |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
81 |
envelope ownership is not transferred here. |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
*/ |
47 | 83 |
void NmEditorContent::setMessageData(const NmMessage &originalMessage, |
84 |
NmUiEditorStartMode &editorStartMode) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
85 |
{ |
43 | 86 |
NM_FUNCTION; |
44 | 87 |
|
88 |
QString bodyContent; |
|
89 |
||
47 | 90 |
// Create the "reply" header (also for forward message) |
91 |
if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll || |
|
92 |
editorStartMode==NmUiEditorForward) { |
|
93 |
bodyContent.append(NmUtilities::createReplyHeader(originalMessage.envelope())); |
|
44 | 94 |
} |
95 |
||
43 | 96 |
// Check which part is present. Html or plain text part. We use the original message parts. |
97 |
const NmMessagePart *htmlPart = originalMessage.htmlBodyPart(); |
|
98 |
const NmMessagePart *plainPart = originalMessage.plainTextBodyPart(); |
|
44 | 99 |
|
47 | 100 |
if (htmlPart) { |
44 | 101 |
bodyContent.append(htmlPart->textContent()); |
47 | 102 |
if(editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll ) { |
103 |
removeEmbeddedImages(bodyContent); |
|
104 |
} |
|
44 | 105 |
emit setHtml(bodyContent); |
47 | 106 |
mMessageBodyType = NmHTMLText; |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
107 |
} |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
108 |
else if (plainPart) { |
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
109 |
// Plain text part was present, set it to HbTextEdit |
44 | 110 |
bodyContent.append(plainPart->textContent()); |
111 |
emit setPlainText(bodyContent); |
|
47 | 112 |
mMessageBodyType = NmPlainText; |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
113 |
} |
20
ecc8def7944a
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
114 |
} |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
115 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
116 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
117 |
This method creates all needed signal-slot connections |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
118 |
*/ |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
119 |
void NmEditorContent::createConnections() |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
120 |
{ |
43 | 121 |
NM_FUNCTION; |
122 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
123 |
// Signal for setting HbTextEdit widgets html content |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
124 |
connect(this, SIGNAL(setHtml(QString)), |
44 | 125 |
mEditorWidget, SLOT(setHtml(QString)), Qt::QueuedConnection); |
47 | 126 |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
127 |
// Signal for setting HbTextEdit widgets plain text content |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
128 |
connect(this, SIGNAL(setPlainText(QString)), |
44 | 129 |
mEditorWidget, SLOT(setPlainText(QString)), Qt::QueuedConnection); |
47 | 130 |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
131 |
// Inform text edit widget that header height has been changed |
47 | 132 |
connect(mHeaderWidget, SIGNAL(headerHeightChanged(int)), this, SLOT(setEditorContentHeight()), |
133 |
Qt::QueuedConnection); |
|
134 |
||
135 |
// we are interested in the document's height changes |
|
136 |
connect(mEditorWidget->document()->documentLayout(), SIGNAL(documentSizeChanged(QSizeF)), this, |
|
137 |
SLOT(setEditorContentHeight()), Qt::QueuedConnection); |
|
138 |
||
139 |
// We need to update the scroll position according the editor cursor position |
|
140 |
connect(mEditorWidget, SIGNAL(cursorPositionChanged(int, int)), this, |
|
141 |
SLOT(setScrollPosition(int, int)), Qt::QueuedConnection); |
|
142 |
||
143 |
// We need to know the scroll area's current position for calculating the new position in |
|
144 |
// setScrollPosition |
|
145 |
connect(mScrollArea, SIGNAL(scrollPositionChanged(QPointF)), this, |
|
146 |
SLOT(updateScrollPosition(QPointF)), Qt::QueuedConnection); |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
147 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
148 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
149 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
150 |
Return pointer to the email body text edit widget |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
151 |
*/ |
47 | 152 |
NmEditorTextEdit *NmEditorContent::editor() const |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
153 |
{ |
43 | 154 |
NM_FUNCTION; |
155 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
156 |
return mEditorWidget; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
157 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
158 |
|
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
159 |
/*! |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
160 |
Return pointer to the header widget |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
161 |
*/ |
47 | 162 |
NmEditorHeader *NmEditorContent::header() const |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
163 |
{ |
43 | 164 |
NM_FUNCTION; |
165 |
||
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
166 |
return mHeaderWidget; |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
167 |
} |
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
168 |
|
47 | 169 |
/*! |
170 |
This slot is called when header widget height has been changed. Function performs |
|
171 |
the repositioning of the body field and resizing of the editor and content area. |
|
172 |
*/ |
|
173 |
void NmEditorContent::setEditorContentHeight() |
|
174 |
{ |
|
175 |
NM_FUNCTION; |
|
176 |
||
177 |
qreal topMargin = 0; |
|
178 |
HbStyle().parameter("hb-param-margin-gene-top", topMargin); |
|
179 |
||
180 |
// header height |
|
181 |
qreal headerHeight = mHeaderWidget->headerHeight(); |
|
182 |
||
183 |
// body area editor's document height with margins added |
|
184 |
qreal documentHeightAndMargins = mEditorWidget->document()->size().height() + |
|
185 |
(mEditorWidget->document()->documentMargin() * 2); |
|
186 |
||
187 |
// get the chrome height |
|
188 |
qreal chromeHeight = 0; |
|
189 |
HbStyle().parameter("hb-param-widget-chrome-height", chromeHeight); |
|
190 |
||
191 |
qreal toolbarHeight = 0; |
|
192 |
HbStyle().parameter("hb-param-widget-toolbar-height", toolbarHeight); |
|
193 |
||
194 |
// screen height |
|
195 |
qreal screenHeight = mApplication.screenSize().height(); |
|
196 |
||
197 |
// set min size for the body area so that at least the screen area is always filled |
|
198 |
qreal bodyAreaMinSize = screenHeight - chromeHeight - topMargin - headerHeight; |
|
199 |
||
200 |
qreal bodyAreaSize = fmax(bodyAreaMinSize, documentHeightAndMargins); |
|
201 |
||
202 |
mScrollAreaContents->setPreferredHeight(topMargin + headerHeight + bodyAreaSize); |
|
203 |
} |
|
204 |
||
205 |
/*! |
|
206 |
This slot is called when cursor position is changed in body area using |
|
207 |
'pointing stick' or keyboard. Function will update the scroll position |
|
208 |
of the content so that cursor does not go outside of the screen or |
|
209 |
behind the virtual keyboard. |
|
210 |
*/ |
|
211 |
void NmEditorContent::setScrollPosition(int oldPos, int newPos) |
|
212 |
{ |
|
213 |
NM_FUNCTION; |
|
214 |
||
215 |
Q_UNUSED(oldPos); |
|
216 |
||
217 |
qreal chromeHeight = 0; |
|
218 |
HbStyle().parameter("hb-param-widget-chrome-height", chromeHeight); |
|
219 |
||
220 |
const QSizeF screenReso = mApplication.screenSize(); |
|
221 |
qreal maxHeight = screenReso.height() - chromeHeight; |
|
222 |
||
223 |
// Get cursor position coordinates |
|
224 |
QRectF cursorPosPix = mEditorWidget->rectForPosition(newPos); |
|
225 |
||
226 |
// Calculate the screen top and bottom boundaries, this means the part of the |
|
227 |
// background scroll area which is currently visible. |
|
228 |
qreal visibleRectTopBoundary; |
|
229 |
qreal visibleRectBottomBoundary; |
|
230 |
||
231 |
qreal headerHeight = mHeaderWidget->headerHeight(); |
|
232 |
||
233 |
if (mScrollPosition.y() < headerHeight) { |
|
234 |
// Header is completely or partially visible |
|
235 |
visibleRectTopBoundary = headerHeight - mScrollPosition.y(); |
|
236 |
visibleRectBottomBoundary = maxHeight - visibleRectTopBoundary; |
|
237 |
} |
|
238 |
else { |
|
239 |
// Header is not visible |
|
240 |
visibleRectTopBoundary = mScrollPosition.y() - headerHeight; |
|
241 |
visibleRectBottomBoundary = visibleRectTopBoundary + maxHeight; |
|
242 |
} |
|
243 |
||
244 |
// Do scrolling if cursor is out of the screen boundaries |
|
245 |
if (cursorPosPix.y() > visibleRectBottomBoundary) { |
|
246 |
// Do scroll forward |
|
247 |
mScrollArea->scrollContentsTo(QPointF(0, cursorPosPix.y() - maxHeight + headerHeight)); |
|
248 |
} |
|
249 |
else if (cursorPosPix.y() + headerHeight < mScrollPosition.y()) { |
|
250 |
// Do scroll backward |
|
251 |
mScrollArea->scrollContentsTo(QPointF(0, cursorPosPix.y() + headerHeight)); |
|
252 |
} |
|
253 |
} |
|
254 |
||
255 |
/*! |
|
256 |
This slot is called when background scroll areas scroll position has been shanged. |
|
257 |
*/ |
|
258 |
void NmEditorContent::updateScrollPosition(const QPointF &newPosition) |
|
259 |
{ |
|
260 |
NM_FUNCTION; |
|
261 |
||
262 |
mScrollPosition = newPosition; |
|
263 |
} |
|
264 |
||
265 |
/*! |
|
266 |
Removes embedded images from the message body |
|
267 |
*/ |
|
268 |
void NmEditorContent::removeEmbeddedImages(QString &bodyContent) |
|
269 |
{ |
|
270 |
NM_FUNCTION; |
|
271 |
||
272 |
QRegExp regExp(NMUI_EDITOR_REMOVE_EMBD_IMAGES_REG, Qt::CaseInsensitive); |
|
273 |
bodyContent.remove(regExp); |
|
274 |
} |