author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 13:35:48 +0300 | |
changeset 34 | 84197e66a4bd |
parent 31 | ebfee66fde93 |
child 43 | 35b64624a9e7 |
permissions | -rw-r--r-- |
31 | 1 |
/* |
2 |
* Copyright (c) 2009 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: This widget displays the body of the viewer |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include "univiewerbodywidget.h" |
|
19 |
||
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
20 |
// SYSTEM INCLUDES |
31 | 21 |
#include <QFile> |
22 |
#include <HbTextItem> |
|
23 |
#include <HbMainWindow> |
|
24 |
||
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
25 |
// USER INCLUDES |
31 | 26 |
#include "univiewertextitem.h" |
27 |
#include "univiewerpixmapwidget.h" |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
28 |
#include "univieweraudiowidget.h" |
31 | 29 |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
30 |
// LOCAL CONSTANTS |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
31 |
const QString IMAGE_MIMETYPE("image"); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
32 |
const QString AUDIO_MIMETYPE("audio"); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
33 |
const QString VIDEO_MIMETYPE("video"); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
34 |
const QString TEXT_MIMETYPE("text"); |
31 | 35 |
|
36 |
//--------------------------------------------------------------- |
|
37 |
//UniViewerBodyWidget::UniViewerBodyWidget |
|
38 |
// @see header file |
|
39 |
//--------------------------------------------------------------- |
|
40 |
UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : |
|
41 |
HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0), |
|
42 |
mPixmapItem(0), mAudioItem(0) |
|
43 |
{ |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
44 |
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
31 | 45 |
} |
46 |
||
47 |
//--------------------------------------------------------------- |
|
48 |
//UniViewerBodyWidget::~UniViewerBodyWidget |
|
49 |
// @see header file |
|
50 |
//--------------------------------------------------------------- |
|
51 |
UniViewerBodyWidget::~UniViewerBodyWidget() |
|
52 |
{ |
|
53 |
} |
|
54 |
||
55 |
//--------------------------------------------------------------- |
|
56 |
//UniViewerBodyWidget::setImage |
|
57 |
// @see header file |
|
58 |
//--------------------------------------------------------------- |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
59 |
void UniViewerBodyWidget::setPixmap(const QString &mimeType, const QString &pixmapFile) |
31 | 60 |
{ |
61 |
setHasPixmap(true); |
|
62 |
//create image item instance |
|
63 |
if (!mPixmapItem) { |
|
64 |
mPixmapItem = new UniViewerPixmapWidget(this); |
|
65 |
HbStyle::setItemName(mPixmapItem, "pixmap"); |
|
66 |
} |
|
67 |
mPixmapItem->hide(); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
68 |
mPixmapItem->populate(mimeType, pixmapFile); |
31 | 69 |
|
70 |
this->repolish(); |
|
71 |
} |
|
72 |
||
73 |
//--------------------------------------------------------------- |
|
74 |
//UniViewerBodyWidget::setAudio |
|
75 |
// @see header file |
|
76 |
//--------------------------------------------------------------- |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
77 |
void UniViewerBodyWidget::setAudio(const QString &mimeType, const QString &audiofile) |
31 | 78 |
{ |
79 |
if (!mAudioItem) { |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
80 |
mAudioItem = new UniViewerAudioWidget(this); |
31 | 81 |
HbStyle::setItemName(mAudioItem, "audioItem"); |
82 |
} |
|
83 |
mAudioItem->hide(); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
84 |
mAudioItem->populate(mimeType, audiofile); |
31 | 85 |
|
86 |
this->repolish(); |
|
87 |
} |
|
88 |
||
89 |
//--------------------------------------------------------------- |
|
90 |
//UniViewerBodyWidget::setVideo |
|
91 |
// @see header file |
|
92 |
//--------------------------------------------------------------- |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
93 |
void UniViewerBodyWidget::setVideo(const QString &mimeType, const QString &videofile) |
31 | 94 |
{ |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
95 |
Q_UNUSED(mimeType) |
31 | 96 |
Q_UNUSED(videofile) |
97 |
} |
|
98 |
||
99 |
//--------------------------------------------------------------- |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
100 |
//UniViewerBodyWidget::setText |
31 | 101 |
// @see header file |
102 |
//--------------------------------------------------------------- |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
103 |
void UniViewerBodyWidget::setText(QString text) |
31 | 104 |
{ |
105 |
setHasText(true); |
|
106 |
||
107 |
if (!mTextItem) { |
|
108 |
mTextItem = new UniViewerTextItem(this); |
|
109 |
HbStyle::setItemName(mTextItem, "textItem"); |
|
110 |
connect(mTextItem, SIGNAL(sendMessage(const QString&)), this, |
|
111 |
SIGNAL(sendMessage(const QString&))); |
|
112 |
} |
|
113 |
mTextItem->hide(); |
|
114 |
text.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
|
115 |
text.replace('\r', QChar::LineSeparator); |
|
116 |
mTextItem->setText(text); |
|
117 |
this->repolish(); |
|
118 |
} |
|
119 |
||
120 |
//--------------------------------------------------------------- |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
121 |
// UniViewerBodyWidget::setSlideCounter |
31 | 122 |
// @see header file |
123 |
//--------------------------------------------------------------- |
|
124 |
void UniViewerBodyWidget::setSlideCounter(QString &slideCounter) |
|
125 |
{ |
|
126 |
if (!mSlideCounter) { |
|
127 |
mSlideCounter = new HbTextItem(this); |
|
128 |
HbStyle::setItemName(mSlideCounter, "slideCounter"); |
|
129 |
} |
|
130 |
||
131 |
mSlideCounter->hide(); |
|
132 |
mSlideCounter->setText(slideCounter); |
|
133 |
this->repolish(); |
|
134 |
} |
|
135 |
||
136 |
//--------------------------------------------------------------- |
|
137 |
// UniViewerBodyWidget::setHasText |
|
138 |
// @see header file |
|
139 |
//--------------------------------------------------------------- |
|
140 |
void UniViewerBodyWidget::setHasText(bool text) |
|
141 |
{ |
|
142 |
mHasText = text; |
|
143 |
} |
|
144 |
||
145 |
//--------------------------------------------------------------- |
|
146 |
// UniViewerBodyWidget::hasText |
|
147 |
// @see header file |
|
148 |
//--------------------------------------------------------------- |
|
149 |
bool UniViewerBodyWidget::hasText() |
|
150 |
{ |
|
151 |
return mHasText; |
|
152 |
} |
|
153 |
||
154 |
//--------------------------------------------------------------- |
|
155 |
// UniViewerBodyWidget::setHasPixmap |
|
156 |
// @see header file |
|
157 |
//--------------------------------------------------------------- |
|
158 |
void UniViewerBodyWidget::setHasPixmap(bool pixmap) |
|
159 |
{ |
|
160 |
mHasPixmap = pixmap; |
|
161 |
} |
|
162 |
||
163 |
//--------------------------------------------------------------- |
|
164 |
// UniViewerBodyWidget::hasPixmap |
|
165 |
// @see header file |
|
166 |
//--------------------------------------------------------------- |
|
167 |
bool UniViewerBodyWidget::hasPixmap() |
|
168 |
{ |
|
169 |
return mHasPixmap; |
|
170 |
} |
|
171 |
||
172 |
//--------------------------------------------------------------- |
|
173 |
// UniViewerBodyWidget::setSlideContents |
|
174 |
// @see header file |
|
175 |
//--------------------------------------------------------------- |
|
176 |
void UniViewerBodyWidget::setSlideContents(UniMessageInfoList objList, QString slideString) |
|
177 |
{ |
|
178 |
if (!slideString.isEmpty()) { |
|
179 |
setSlideCounter(slideString); |
|
180 |
} |
|
181 |
||
182 |
int count = objList.count(); |
|
183 |
for (int a = 0; a < count; ++a) { |
|
184 |
UniMessageInfo* info = objList.at(a); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
185 |
QString mimeType = info->mimetype(); |
31 | 186 |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
187 |
if (mimeType.contains(TEXT_MIMETYPE)) { |
31 | 188 |
QFile file(info->path()); |
189 |
if (file.open(QIODevice::ReadOnly)) { |
|
190 |
QString textContent(file.readAll()); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
191 |
setText(textContent); |
31 | 192 |
} |
193 |
} |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
194 |
else if (mimeType.contains(VIDEO_MIMETYPE)) { |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
195 |
setVideo(mimeType, info->path()); |
31 | 196 |
} |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
197 |
else if (mimeType.contains(AUDIO_MIMETYPE)) { |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
198 |
setAudio(mimeType, info->path()); |
31 | 199 |
} |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
200 |
else if (mimeType.contains(IMAGE_MIMETYPE)) { |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
201 |
setPixmap(mimeType, info->path()); |
31 | 202 |
} |
203 |
||
204 |
delete info; |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
//--------------------------------------------------------------- |
|
209 |
//UniViewerBodyWidget :: clearContent |
|
210 |
// @see header file |
|
211 |
//--------------------------------------------------------------- |
|
212 |
void UniViewerBodyWidget::clearContent() |
|
213 |
{ |
|
214 |
// delete the temp items(pixmap) & clear permanent items(text) |
|
215 |
if (mPixmapItem) { |
|
216 |
mPixmapItem->setParent(NULL); |
|
217 |
delete mPixmapItem; |
|
218 |
mPixmapItem = NULL; |
|
219 |
} |
|
220 |
||
221 |
if (mAudioItem) { |
|
222 |
mAudioItem->setParent(NULL); |
|
223 |
delete mAudioItem; |
|
224 |
mAudioItem = NULL; |
|
225 |
} |
|
226 |
||
227 |
if (mTextItem) { |
|
228 |
mTextItem->setParent(NULL); |
|
229 |
delete mTextItem; |
|
230 |
mTextItem = NULL; |
|
231 |
} |
|
232 |
||
233 |
setHasText(false); |
|
234 |
setHasPixmap(false); |
|
235 |
repolish(); |
|
236 |
} |
|
237 |
||
238 |
//--------------------------------------------------------------- |
|
239 |
//UniViewerBodyWidget::sizeHint |
|
240 |
// @see header file |
|
241 |
//--------------------------------------------------------------- |
|
242 |
QSizeF UniViewerBodyWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const |
|
243 |
{ |
|
244 |
QSizeF szHint = HbWidget::sizeHint(which, constraint); |
|
245 |
||
246 |
HbMainWindow *mainWindow = this->mainWindow(); |
|
247 |
if (!mainWindow) { |
|
248 |
return szHint; |
|
249 |
} |
|
250 |
||
251 |
qreal screenWidth = 0.0; |
|
252 |
qreal screenHeight = 0.0; |
|
253 |
qreal leftMargin = 0.0; |
|
254 |
qreal rightMargin = 0.0; |
|
255 |
qreal chromeHeight = 0.0; |
|
256 |
qreal toolbarHeight = 0.0; |
|
257 |
qreal iconSize = 0.0; |
|
258 |
qreal spacing = 0.0; |
|
259 |
qreal unitSize = HbDeviceProfile::profile(mPixmapItem).unitValue(); |
|
260 |
style()->parameter("hb-param-screen-width", screenWidth); |
|
261 |
style()->parameter("hb-param-screen-height", screenHeight); |
|
262 |
style()->parameter("hb-param-margin-gene-left", leftMargin); |
|
263 |
style()->parameter("hb-param-margin-gene-right", rightMargin); |
|
264 |
style()->parameter("hb-param-widget-chrome-height", chromeHeight); |
|
265 |
style()->parameter("hb-param-widget-toolbar-height", toolbarHeight); |
|
266 |
style()->parameter("hb-param-graphic-size-primary-large", iconSize); |
|
267 |
style()->parameter("hb-param-margin-gene-middle-vertical", spacing); |
|
268 |
||
269 |
qreal maxWidth = 0.0; |
|
270 |
qreal maxHeight = 0.0; |
|
271 |
||
272 |
// Calculate max height & max width. |
|
273 |
if (mainWindow->orientation() == Qt::Horizontal) { |
|
274 |
qreal temp; |
|
275 |
temp = screenWidth; |
|
276 |
screenWidth = screenHeight; |
|
277 |
screenHeight = temp; |
|
278 |
||
279 |
if (mPixmapItem && mHasText) { |
|
280 |
maxWidth = (screenWidth / 2) - leftMargin - unitSize; |
|
281 |
} |
|
282 |
else { |
|
283 |
maxWidth = screenWidth - leftMargin - rightMargin; |
|
284 |
} |
|
285 |
maxHeight = screenHeight - chromeHeight - toolbarHeight; |
|
286 |
||
287 |
if (mAudioItem) { |
|
288 |
mAudioItem->setStretched(true); |
|
289 |
} |
|
290 |
} |
|
291 |
else if (mainWindow->orientation() == Qt::Vertical) { |
|
292 |
maxWidth = screenWidth - leftMargin - rightMargin; |
|
293 |
maxHeight = screenHeight - chromeHeight - toolbarHeight; |
|
294 |
||
295 |
if (mAudioItem) { |
|
296 |
mAudioItem->setStretched(false); |
|
297 |
} |
|
298 |
} |
|
299 |
||
300 |
// Slide Counter |
|
301 |
QSizeF slideCounterSize(0, 0); |
|
302 |
if (mSlideCounter) { |
|
303 |
slideCounterSize = mSlideCounter->effectiveSizeHint(which, constraint); |
|
304 |
mSlideCounter->show(); |
|
305 |
} |
|
306 |
// Audio Item |
|
307 |
QSizeF audioSize(0, 0); |
|
308 |
if (mAudioItem) { |
|
309 |
audioSize = mAudioItem->effectiveSizeHint(which, constraint); |
|
310 |
mAudioItem->show(); |
|
311 |
} |
|
312 |
||
313 |
// Text Item |
|
314 |
QSizeF textSize(0, 0); |
|
315 |
if (mTextItem) { |
|
316 |
textSize = mTextItem->effectiveSizeHint(which, constraint); |
|
317 |
mTextItem->show(); |
|
318 |
} |
|
319 |
||
320 |
// Pixmap Item |
|
321 |
QSizeF pixmapSize(0, 0); |
|
322 |
if (mPixmapItem) { |
|
323 |
qreal imageWidth = mPixmapItem->icon().defaultSize().width(); |
|
324 |
qreal imageHeight = mPixmapItem->icon().defaultSize().height(); |
|
325 |
||
326 |
qreal widthToSet = 0.0; |
|
327 |
qreal heightToSet = 0.0; |
|
328 |
||
329 |
if (imageWidth < iconSize) { |
|
330 |
widthToSet = iconSize; |
|
331 |
heightToSet = iconSize; |
|
332 |
} |
|
333 |
else if (imageWidth <= maxWidth) { |
|
334 |
// resize not needed |
|
335 |
widthToSet = imageWidth; |
|
336 |
heightToSet = qMin(imageHeight, maxHeight); |
|
337 |
} |
|
338 |
else { |
|
339 |
// resize needed, keep aspect-ratio and resize |
|
340 |
widthToSet = maxWidth; |
|
341 |
heightToSet = maxWidth * (imageHeight / imageWidth); |
|
342 |
heightToSet = qMin(heightToSet, maxHeight); |
|
343 |
||
344 |
} |
|
345 |
if (heightToSet == maxHeight) { |
|
346 |
widthToSet = heightToSet * (imageWidth / imageHeight); |
|
347 |
} |
|
348 |
||
349 |
pixmapSize.setHeight(heightToSet); |
|
350 |
pixmapSize.setWidth(widthToSet); |
|
351 |
mPixmapItem->setPreferredSize(pixmapSize); |
|
352 |
mPixmapItem->show(); |
|
353 |
} |
|
354 |
||
355 |
// Calculate the size hint to be returned. |
|
356 |
szHint.setHeight(0); |
|
357 |
||
358 |
if (!slideCounterSize.isNull()) { |
|
359 |
szHint.rheight() += (slideCounterSize.height() + spacing); |
|
360 |
} |
|
361 |
if (!audioSize.isNull()) { |
|
362 |
szHint.rheight() += (audioSize.height() + spacing); |
|
363 |
} |
|
364 |
||
365 |
if (mainWindow->orientation() == Qt::Horizontal) { |
|
366 |
qreal remainingHeight = qMax(pixmapSize.height(), textSize.height()); |
|
367 |
if (remainingHeight > 0.0) { |
|
368 |
szHint.rheight() += (remainingHeight + spacing); |
|
369 |
} |
|
370 |
} |
|
371 |
else if (mainWindow->orientation() == Qt::Vertical) { |
|
372 |
if (!pixmapSize.isNull()) { |
|
373 |
szHint.rheight() += (pixmapSize.height() + spacing); |
|
374 |
} |
|
375 |
if (!textSize.isNull()) { |
|
376 |
szHint.rheight() += (textSize.height() + spacing); |
|
377 |
} |
|
378 |
} |
|
379 |
szHint.rheight() = qMax(maxHeight, szHint.height()); |
|
380 |
||
381 |
return szHint; |
|
382 |
} |
|
383 |
||
384 |
// EOF |