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". |
37 mHeader(NULL), |
37 mHeader(NULL), |
38 mMessageBodyType(NmPlainText), |
38 mMessageBodyType(NmPlainText), |
39 mEditorWidget(NULL), |
39 mEditorWidget(NULL), |
40 mScrollArea(NULL), |
40 mScrollArea(NULL), |
41 mScrollAreaContents(NULL), |
41 mScrollAreaContents(NULL), |
42 mApplication(application) |
42 mApplication(application), |
|
43 mNeedForWidthAdjustment(false) |
43 { |
44 { |
44 NM_FUNCTION; |
45 NM_FUNCTION; |
45 |
46 |
46 // Construct container for the header widgets |
47 // Construct container for the header widgets |
47 mHeader = new NmEditorHeader(this, documentLoader); |
48 mHeader = new NmEditorHeader(this, application, documentLoader); |
48 |
49 |
49 // Get pointer to body text area handling widget |
50 // Get pointer to body text area handling widget |
50 mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY)); |
51 mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY)); |
51 |
52 |
|
53 // Enable the emoticons. |
|
54 mEditorWidget->setSmileysEnabled(true); |
|
55 |
52 // Set body editor to use NmEditorTextDocument |
56 // Set body editor to use NmEditorTextDocument |
53 NmEditorTextDocument *textDocument = new NmEditorTextDocument(manager); |
57 NmEditorTextDocument *textDocument = new NmEditorTextDocument(manager); |
54 mEditorWidget->setDocument(textDocument); |
58 mEditorWidget->setDocument(textDocument); |
55 textDocument->setParent(mEditorWidget); // ownership changes |
59 textDocument->setParent(mEditorWidget); // ownership changes |
56 |
60 |
57 mScrollArea = qobject_cast<NmBaseViewScrollArea *> |
61 mScrollArea = qobject_cast<NmBaseViewScrollArea *> |
58 (documentLoader->findWidget(NMUI_EDITOR_SCROLL_AREA)); |
62 (documentLoader->findWidget(NMUI_EDITOR_SCROLL_AREA)); |
|
63 |
59 mScrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal); |
64 mScrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal); |
60 |
65 mScrollArea->setClampingStyle(HbScrollArea::BounceBackClamping); |
|
66 |
61 // Enable style picker menu item. |
67 // Enable style picker menu item. |
62 mEditorWidget->setFormatDialog(new HbFormatDialog()); |
68 mEditorWidget->setFormatDialog(new HbFormatDialog()); |
63 |
69 |
64 mScrollAreaContents = |
70 mScrollAreaContents = |
65 qobject_cast<HbWidget *>(documentLoader->findWidget(NMUI_EDITOR_SCROLL_AREA_CONTENTS)); |
71 qobject_cast<HbWidget *>(documentLoader->findWidget(NMUI_EDITOR_SCROLL_AREA_CONTENTS)); |
66 |
72 |
67 // Create signal slot connections |
73 // Create signal slot connections |
68 createConnections(); |
74 createConnections(); |
|
75 |
|
76 // The following line is necessary in terms of being able to add emoticons |
|
77 // (smileys) to an empty document (mail content). Otherwise the private |
|
78 // pointer of the QTextDocument which the smiley engine has is NULL and |
|
79 // inserting a smiley will lead to an error. |
|
80 mEditorWidget->setPlainText(""); |
69 } |
81 } |
70 |
82 |
71 /*! |
83 /*! |
72 Destructor |
84 Destructor |
73 */ |
85 */ |
85 NmUiEditorStartMode &editorStartMode) |
97 NmUiEditorStartMode &editorStartMode) |
86 { |
98 { |
87 NM_FUNCTION; |
99 NM_FUNCTION; |
88 |
100 |
89 QString bodyContent; |
101 QString bodyContent; |
|
102 QTextCursor cursor(mEditorWidget->document()); |
90 |
103 |
91 // Create the "reply" header (also for forward message) |
104 // Create the "reply" header (also for forward message) |
92 if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll || |
105 if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll || |
93 editorStartMode==NmUiEditorForward) { |
106 editorStartMode==NmUiEditorForward) { |
|
107 bodyContent.append(QString("<style type=\"text/css\">* { color: black; }</style>")); |
94 bodyContent.append(NmUtilities::createReplyHeader(originalMessage.envelope())); |
108 bodyContent.append(NmUtilities::createReplyHeader(originalMessage.envelope())); |
95 } |
109 } |
96 |
110 |
97 // Check which part is present. Html or plain text part. We use the original message parts. |
111 // Check which part is present. Html or plain text part. We use the original message parts. |
98 const NmMessagePart *htmlPart = originalMessage.htmlBodyPart(); |
112 const NmMessagePart *htmlPart = originalMessage.htmlBodyPart(); |
101 if (htmlPart) { |
115 if (htmlPart) { |
102 bodyContent.append(htmlPart->textContent()); |
116 bodyContent.append(htmlPart->textContent()); |
103 if(editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll ) { |
117 if(editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll ) { |
104 removeEmbeddedImages(bodyContent); |
118 removeEmbeddedImages(bodyContent); |
105 } |
119 } |
106 emit setHtml(bodyContent); |
120 cursor.insertHtml(bodyContent); |
107 mMessageBodyType = NmHTMLText; |
121 mMessageBodyType = NmHTMLText; |
108 } |
122 } |
109 else if (plainPart) { |
123 else if (plainPart) { |
110 // Plain text part was present, set it to HbTextEdit |
124 // Plain text part was present, set it to HbTextEdit |
111 bodyContent.append(plainPart->textContent()); |
125 bodyContent.append(plainPart->textContent()); |
112 emit setPlainText(bodyContent); |
126 cursor.insertText(bodyContent); |
113 mMessageBodyType = NmPlainText; |
127 mMessageBodyType = NmPlainText; |
114 } |
128 |
|
129 // Next we set text color for black for all current content |
|
130 QTextCharFormat blackForeground; |
|
131 blackForeground = cursor.charFormat(); |
|
132 blackForeground.setForeground(Qt::black); |
|
133 cursor.select(QTextCursor::Document); |
|
134 cursor.mergeCharFormat(blackForeground); |
|
135 } |
|
136 // Update of the body width is done when next contentChanged signal comes from the body. |
|
137 mNeedForWidthAdjustment = true; |
|
138 cursor.clearSelection(); |
|
139 cursor.setPosition(0); |
|
140 cursor.insertHtml(QString("<html><body><br><br></body></html>")); |
115 } |
141 } |
116 |
142 |
117 /*! |
143 /*! |
118 This method creates all needed signal-slot connections |
144 This method creates all needed signal-slot connections |
119 */ |
145 */ |
150 SLOT(ensureCursorVisibility()), Qt::QueuedConnection); |
176 SLOT(ensureCursorVisibility()), Qt::QueuedConnection); |
151 |
177 |
152 // listen to the parent's (NmEditorView) size changes which happen eg. when VKB is opened/closed |
178 // listen to the parent's (NmEditorView) size changes which happen eg. when VKB is opened/closed |
153 connect(parent(), SIGNAL(sizeChanged()), this, SLOT(ensureCursorVisibility()), |
179 connect(parent(), SIGNAL(sizeChanged()), this, SLOT(ensureCursorVisibility()), |
154 Qt::QueuedConnection); |
180 Qt::QueuedConnection); |
|
181 |
|
182 // Listen scroll posion change signals for header reposition. |
|
183 connect(mScrollArea, SIGNAL(scrollPositionChanged(QPointF)), |
|
184 mHeader, SLOT(repositHeader(QPointF))); |
|
185 |
|
186 // Listen content change signal for body widget width adjustment. |
|
187 connect(mEditorWidget->document(), SIGNAL(contentsChanged()), this, |
|
188 SLOT(setEditorContentWidth()), Qt::QueuedConnection); |
155 } |
189 } |
156 |
190 |
157 /*! |
191 /*! |
158 Return pointer to the email body text edit widget |
192 Return pointer to the email body text edit widget |
159 */ |
193 */ |
204 qreal bodyAreaMinSize = screenHeight - chromeHeight - topMargin - headerHeight; |
238 qreal bodyAreaMinSize = screenHeight - chromeHeight - topMargin - headerHeight; |
205 |
239 |
206 qreal bodyAreaSize = fmax(bodyAreaMinSize, documentHeightAndMargins); |
240 qreal bodyAreaSize = fmax(bodyAreaMinSize, documentHeightAndMargins); |
207 |
241 |
208 mScrollAreaContents->setPreferredHeight(topMargin + headerHeight + bodyAreaSize); |
242 mScrollAreaContents->setPreferredHeight(topMargin + headerHeight + bodyAreaSize); |
|
243 } |
|
244 |
|
245 /*! |
|
246 This slot is used to set width for the body field. |
|
247 For some reason HbTextEdit does not set it's width, so we need to se it here. |
|
248 This slot can be removed if HbTextEdit is fixed. |
|
249 */ |
|
250 void NmEditorContent::setEditorContentWidth() |
|
251 { |
|
252 NM_FUNCTION; |
|
253 |
|
254 if (mNeedForWidthAdjustment) { |
|
255 mNeedForWidthAdjustment = false; |
|
256 mScrollAreaContents->setPreferredWidth(mEditorWidget->document()->idealWidth()); |
|
257 } |
209 } |
258 } |
210 |
259 |
211 /*! |
260 /*! |
212 This slot is called when the cursor visibility has to be ensured ie. the scroll position is |
261 This slot is called when the cursor visibility has to be ensured ie. the scroll position is |
213 adjusted so that the cursor can be seen. |
262 adjusted so that the cursor can be seen. |