|
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 |
|
20 #include <QFile> |
|
21 #include <QFileInfo> |
|
22 #include <QPixmap> |
|
23 #include <QSignalMapper> |
|
24 |
|
25 #include <HbTextItem> |
|
26 #include <HbPushButton> |
|
27 #include <HbMenu> |
|
28 #include <HbMainWindow> |
|
29 |
|
30 #include <xqaiwrequest.h> |
|
31 #include <xqrequestinfo.h> |
|
32 #include <xqappmgr.h> |
|
33 |
|
34 #include "univiewertextitem.h" |
|
35 #include "univiewerpixmapwidget.h" |
|
36 #include "msgmediautil.h" |
|
37 // LOCAL CONSTANTS |
|
38 const QString AUDIO_ICON("qtg_mono_audio"); |
|
39 |
|
40 // Localization |
|
41 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
|
42 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
43 #define LOC_SAVE hbTrId("txt_common_menu_save") |
|
44 |
|
45 //--------------------------------------------------------------- |
|
46 //UniViewerBodyWidget::UniViewerBodyWidget |
|
47 // @see header file |
|
48 //--------------------------------------------------------------- |
|
49 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) : |
|
50 HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0), |
|
51 mPixmapItem(0), mAudioItem(0) |
|
52 { |
|
53 this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); |
|
54 // Signal mapper for opening media files |
|
55 mSignalMapper = new QSignalMapper(this); |
|
56 connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &))); |
|
57 } |
|
58 |
|
59 //--------------------------------------------------------------- |
|
60 //UniViewerBodyWidget::~UniViewerBodyWidget |
|
61 // @see header file |
|
62 //--------------------------------------------------------------- |
|
63 UniViewerBodyWidget::~UniViewerBodyWidget() |
|
64 { |
|
65 } |
|
66 |
|
67 //--------------------------------------------------------------- |
|
68 //UniViewerBodyWidget::setImage |
|
69 // @see header file |
|
70 //--------------------------------------------------------------- |
|
71 void UniViewerBodyWidget::setPixmap(QString pixmapFile) |
|
72 { |
|
73 setHasPixmap(true); |
|
74 //create image item instance |
|
75 if (!mPixmapItem) { |
|
76 mPixmapItem = new UniViewerPixmapWidget(this); |
|
77 HbStyle::setItemName(mPixmapItem, "pixmap"); |
|
78 connect(mPixmapItem, SIGNAL(shortTap(QString)), this, SLOT(openMedia(QString))); |
|
79 } |
|
80 |
|
81 mPixmapItem->hide(); |
|
82 mPixmapItem->setPixmap(pixmapFile); |
|
83 |
|
84 this->repolish(); |
|
85 } |
|
86 |
|
87 //--------------------------------------------------------------- |
|
88 //UniViewerBodyWidget::setAudio |
|
89 // @see header file |
|
90 //--------------------------------------------------------------- |
|
91 void UniViewerBodyWidget::setAudio(QString audiofile) |
|
92 { |
|
93 if (!mAudioItem) { |
|
94 mAudioItem = new HbPushButton(this); |
|
95 HbStyle::setItemName(mAudioItem, "audioItem"); |
|
96 } |
|
97 mAudioItem->hide(); |
|
98 QFileInfo fileInfo(audiofile); |
|
99 mAudioItem->setIcon(HbIcon(AUDIO_ICON)); |
|
100 mAudioItem->setText(fileInfo.baseName()); |
|
101 MsgMediaUtil mediaUtil; |
|
102 mAudioItem->setAdditionalText(mediaUtil.mediaDuration(audiofile)); |
|
103 mAudioItem->setTextAlignment(Qt::AlignLeft); |
|
104 |
|
105 // Connect to signal mapper with file name |
|
106 mSignalMapper->setMapping(mAudioItem, audiofile); |
|
107 connect(mAudioItem, SIGNAL(clicked()), mSignalMapper, SLOT(map())); |
|
108 |
|
109 this->repolish(); |
|
110 } |
|
111 |
|
112 //--------------------------------------------------------------- |
|
113 //UniViewerBodyWidget::setVideo |
|
114 // @see header file |
|
115 //--------------------------------------------------------------- |
|
116 void UniViewerBodyWidget::setVideo(QString videofile) |
|
117 { |
|
118 Q_UNUSED(videofile) |
|
119 } |
|
120 |
|
121 //--------------------------------------------------------------- |
|
122 //UniViewerBodyWidget::setTextContent |
|
123 // @see header file |
|
124 //--------------------------------------------------------------- |
|
125 void UniViewerBodyWidget::setTextContent(QString text) |
|
126 { |
|
127 setHasText(true); |
|
128 |
|
129 if (!mTextItem) { |
|
130 mTextItem = new UniViewerTextItem(this); |
|
131 HbStyle::setItemName(mTextItem, "textItem"); |
|
132 connect(mTextItem, SIGNAL(sendMessage(const QString&)), this, |
|
133 SIGNAL(sendMessage(const QString&))); |
|
134 } |
|
135 mTextItem->hide(); |
|
136 text.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
|
137 text.replace('\r', QChar::LineSeparator); |
|
138 mTextItem->setText(text); |
|
139 this->repolish(); |
|
140 } |
|
141 |
|
142 //--------------------------------------------------------------- |
|
143 //UniViewerBodyWidget::setTextContent |
|
144 // @see header file |
|
145 //--------------------------------------------------------------- |
|
146 void UniViewerBodyWidget::setSlideCounter(QString &slideCounter) |
|
147 { |
|
148 if (!mSlideCounter) { |
|
149 mSlideCounter = new HbTextItem(this); |
|
150 HbStyle::setItemName(mSlideCounter, "slideCounter"); |
|
151 } |
|
152 |
|
153 mSlideCounter->hide(); |
|
154 mSlideCounter->setText(slideCounter); |
|
155 this->repolish(); |
|
156 } |
|
157 |
|
158 //--------------------------------------------------------------- |
|
159 // UniViewerBodyWidget::setHasText |
|
160 // @see header file |
|
161 //--------------------------------------------------------------- |
|
162 void UniViewerBodyWidget::setHasText(bool text) |
|
163 { |
|
164 mHasText = text; |
|
165 } |
|
166 |
|
167 //--------------------------------------------------------------- |
|
168 // UniViewerBodyWidget::hasText |
|
169 // @see header file |
|
170 //--------------------------------------------------------------- |
|
171 bool UniViewerBodyWidget::hasText() |
|
172 { |
|
173 return mHasText; |
|
174 } |
|
175 |
|
176 //--------------------------------------------------------------- |
|
177 // UniViewerBodyWidget::setHasPixmap |
|
178 // @see header file |
|
179 //--------------------------------------------------------------- |
|
180 void UniViewerBodyWidget::setHasPixmap(bool pixmap) |
|
181 { |
|
182 mHasPixmap = pixmap; |
|
183 } |
|
184 |
|
185 //--------------------------------------------------------------- |
|
186 // UniViewerBodyWidget::hasPixmap |
|
187 // @see header file |
|
188 //--------------------------------------------------------------- |
|
189 bool UniViewerBodyWidget::hasPixmap() |
|
190 { |
|
191 return mHasPixmap; |
|
192 } |
|
193 |
|
194 //--------------------------------------------------------------- |
|
195 // UniViewerBodyWidget::setSlideContents |
|
196 // @see header file |
|
197 //--------------------------------------------------------------- |
|
198 void UniViewerBodyWidget::setSlideContents(UniMessageInfoList objList, QString slideString) |
|
199 { |
|
200 if (!slideString.isEmpty()) { |
|
201 setSlideCounter(slideString); |
|
202 } |
|
203 |
|
204 int count = objList.count(); |
|
205 for (int a = 0; a < count; ++a) { |
|
206 UniMessageInfo* info = objList.at(a); |
|
207 QString type = info->mimetype(); |
|
208 |
|
209 if (type.contains("text")) { |
|
210 QFile file(info->path()); |
|
211 if (file.open(QIODevice::ReadOnly)) { |
|
212 QString textContent(file.readAll()); |
|
213 setTextContent(textContent); |
|
214 } |
|
215 } |
|
216 else if (type.contains("video")) { |
|
217 setVideo(info->path()); |
|
218 } |
|
219 else if (type.contains("audio")) { |
|
220 setAudio(info->path()); |
|
221 } |
|
222 else if (type.contains("image")) { |
|
223 setPixmap(info->path()); |
|
224 } |
|
225 |
|
226 delete info; |
|
227 } |
|
228 } |
|
229 |
|
230 //--------------------------------------------------------------- |
|
231 //UniViewerBodyWidget :: clearContent |
|
232 // @see header file |
|
233 //--------------------------------------------------------------- |
|
234 void UniViewerBodyWidget::clearContent() |
|
235 { |
|
236 // delete the temp items(pixmap) & clear permanent items(text) |
|
237 if (mPixmapItem) { |
|
238 mPixmapItem->setParent(NULL); |
|
239 delete mPixmapItem; |
|
240 mPixmapItem = NULL; |
|
241 } |
|
242 |
|
243 if (mAudioItem) { |
|
244 mAudioItem->setParent(NULL); |
|
245 delete mAudioItem; |
|
246 mAudioItem = NULL; |
|
247 } |
|
248 |
|
249 if (mTextItem) { |
|
250 mTextItem->setParent(NULL); |
|
251 delete mTextItem; |
|
252 mTextItem = NULL; |
|
253 } |
|
254 |
|
255 setHasText(false); |
|
256 setHasPixmap(false); |
|
257 repolish(); |
|
258 } |
|
259 |
|
260 //--------------------------------------------------------------- |
|
261 //UniViewerBodyWidget::sizeHint |
|
262 // @see header file |
|
263 //--------------------------------------------------------------- |
|
264 QSizeF UniViewerBodyWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const |
|
265 { |
|
266 QSizeF szHint = HbWidget::sizeHint(which, constraint); |
|
267 |
|
268 HbMainWindow *mainWindow = this->mainWindow(); |
|
269 if (!mainWindow) { |
|
270 return szHint; |
|
271 } |
|
272 |
|
273 qreal screenWidth = 0.0; |
|
274 qreal screenHeight = 0.0; |
|
275 qreal leftMargin = 0.0; |
|
276 qreal rightMargin = 0.0; |
|
277 qreal chromeHeight = 0.0; |
|
278 qreal toolbarHeight = 0.0; |
|
279 qreal iconSize = 0.0; |
|
280 qreal spacing = 0.0; |
|
281 qreal unitSize = HbDeviceProfile::profile(mPixmapItem).unitValue(); |
|
282 style()->parameter("hb-param-screen-width", screenWidth); |
|
283 style()->parameter("hb-param-screen-height", screenHeight); |
|
284 style()->parameter("hb-param-margin-gene-left", leftMargin); |
|
285 style()->parameter("hb-param-margin-gene-right", rightMargin); |
|
286 style()->parameter("hb-param-widget-chrome-height", chromeHeight); |
|
287 style()->parameter("hb-param-widget-toolbar-height", toolbarHeight); |
|
288 style()->parameter("hb-param-graphic-size-primary-large", iconSize); |
|
289 style()->parameter("hb-param-margin-gene-middle-vertical", spacing); |
|
290 |
|
291 qreal maxWidth = 0.0; |
|
292 qreal maxHeight = 0.0; |
|
293 |
|
294 // Calculate max height & max width. |
|
295 if (mainWindow->orientation() == Qt::Horizontal) { |
|
296 qreal temp; |
|
297 temp = screenWidth; |
|
298 screenWidth = screenHeight; |
|
299 screenHeight = temp; |
|
300 |
|
301 if (mPixmapItem && mHasText) { |
|
302 maxWidth = (screenWidth / 2) - leftMargin - unitSize; |
|
303 } |
|
304 else { |
|
305 maxWidth = screenWidth - leftMargin - rightMargin; |
|
306 } |
|
307 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
|
308 |
|
309 if (mAudioItem) { |
|
310 mAudioItem->setStretched(true); |
|
311 } |
|
312 } |
|
313 else if (mainWindow->orientation() == Qt::Vertical) { |
|
314 maxWidth = screenWidth - leftMargin - rightMargin; |
|
315 maxHeight = screenHeight - chromeHeight - toolbarHeight; |
|
316 |
|
317 if (mAudioItem) { |
|
318 mAudioItem->setStretched(false); |
|
319 } |
|
320 } |
|
321 |
|
322 // Slide Counter |
|
323 QSizeF slideCounterSize(0, 0); |
|
324 if (mSlideCounter) { |
|
325 slideCounterSize = mSlideCounter->effectiveSizeHint(which, constraint); |
|
326 mSlideCounter->show(); |
|
327 } |
|
328 // Audio Item |
|
329 QSizeF audioSize(0, 0); |
|
330 if (mAudioItem) { |
|
331 audioSize = mAudioItem->effectiveSizeHint(which, constraint); |
|
332 mAudioItem->show(); |
|
333 } |
|
334 |
|
335 // Text Item |
|
336 QSizeF textSize(0, 0); |
|
337 if (mTextItem) { |
|
338 textSize = mTextItem->effectiveSizeHint(which, constraint); |
|
339 mTextItem->show(); |
|
340 } |
|
341 |
|
342 // Pixmap Item |
|
343 QSizeF pixmapSize(0, 0); |
|
344 if (mPixmapItem) { |
|
345 qreal imageWidth = mPixmapItem->icon().defaultSize().width(); |
|
346 qreal imageHeight = mPixmapItem->icon().defaultSize().height(); |
|
347 |
|
348 qreal widthToSet = 0.0; |
|
349 qreal heightToSet = 0.0; |
|
350 |
|
351 if (imageWidth < iconSize) { |
|
352 widthToSet = iconSize; |
|
353 heightToSet = iconSize; |
|
354 } |
|
355 else if (imageWidth <= maxWidth) { |
|
356 // resize not needed |
|
357 widthToSet = imageWidth; |
|
358 heightToSet = qMin(imageHeight, maxHeight); |
|
359 } |
|
360 else { |
|
361 // resize needed, keep aspect-ratio and resize |
|
362 widthToSet = maxWidth; |
|
363 heightToSet = maxWidth * (imageHeight / imageWidth); |
|
364 heightToSet = qMin(heightToSet, maxHeight); |
|
365 |
|
366 } |
|
367 if (heightToSet == maxHeight) { |
|
368 widthToSet = heightToSet * (imageWidth / imageHeight); |
|
369 } |
|
370 |
|
371 pixmapSize.setHeight(heightToSet); |
|
372 pixmapSize.setWidth(widthToSet); |
|
373 mPixmapItem->setPreferredSize(pixmapSize); |
|
374 mPixmapItem->show(); |
|
375 } |
|
376 |
|
377 // Calculate the size hint to be returned. |
|
378 szHint.setHeight(0); |
|
379 |
|
380 if (!slideCounterSize.isNull()) { |
|
381 szHint.rheight() += (slideCounterSize.height() + spacing); |
|
382 } |
|
383 if (!audioSize.isNull()) { |
|
384 szHint.rheight() += (audioSize.height() + spacing); |
|
385 } |
|
386 |
|
387 if (mainWindow->orientation() == Qt::Horizontal) { |
|
388 qreal remainingHeight = qMax(pixmapSize.height(), textSize.height()); |
|
389 if (remainingHeight > 0.0) { |
|
390 szHint.rheight() += (remainingHeight + spacing); |
|
391 } |
|
392 } |
|
393 else if (mainWindow->orientation() == Qt::Vertical) { |
|
394 if (!pixmapSize.isNull()) { |
|
395 szHint.rheight() += (pixmapSize.height() + spacing); |
|
396 } |
|
397 if (!textSize.isNull()) { |
|
398 szHint.rheight() += (textSize.height() + spacing); |
|
399 } |
|
400 } |
|
401 szHint.rheight() = qMax(maxHeight, szHint.height()); |
|
402 |
|
403 return szHint; |
|
404 } |
|
405 |
|
406 //--------------------------------------------------------------- |
|
407 //UniViewerBodyWidget::longPressed |
|
408 // @see header file |
|
409 //--------------------------------------------------------------- |
|
410 void UniViewerBodyWidget::longPressed(QPointF position) |
|
411 { |
|
412 |
|
413 HbMenu* menu = new HbMenu; |
|
414 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
415 menu->addAction(LOC_OPEN, this, SLOT(openMedia())); |
|
416 menu->addAction(LOC_SAVE, this, SLOT(saveMedia())); |
|
417 menu->setPreferredPos(position); |
|
418 menu->show(); |
|
419 } |
|
420 |
|
421 //--------------------------------------------------------------- |
|
422 //UniViewerBodyWidget::openMedia |
|
423 // @see header file |
|
424 //--------------------------------------------------------------- |
|
425 void UniViewerBodyWidget::openMedia() |
|
426 { |
|
427 } |
|
428 |
|
429 //--------------------------------------------------------------- |
|
430 //UniViewerBodyWidget::openMedia |
|
431 // @see header file |
|
432 //--------------------------------------------------------------- |
|
433 void UniViewerBodyWidget::openMedia(const QString& fileName) |
|
434 { |
|
435 XQSharableFile sf; |
|
436 XQAiwRequest* request = 0; |
|
437 |
|
438 if (!sf.open(fileName)) { |
|
439 return; |
|
440 } |
|
441 |
|
442 // Get handlers |
|
443 XQApplicationManager appManager; |
|
444 QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf); |
|
445 if (fileHandlers.count() > 0) { |
|
446 XQAiwInterfaceDescriptor d = fileHandlers.first(); |
|
447 request = appManager.create(sf, d); |
|
448 |
|
449 if (!request) { |
|
450 sf.close(); |
|
451 return; |
|
452 } |
|
453 } |
|
454 else { |
|
455 sf.close(); |
|
456 return; |
|
457 } |
|
458 |
|
459 // Result handlers |
|
460 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
461 connect(request, SIGNAL(requestError(const QVariant&)), this, |
|
462 SLOT(handleError(const QVariant&))); |
|
463 |
|
464 request->setEmbedded(true); |
|
465 request->setSynchronous(true); |
|
466 |
|
467 // Fill args |
|
468 QList<QVariant> args; |
|
469 args << qVariantFromValue(sf); |
|
470 request->setArguments(args); |
|
471 |
|
472 // Fill headers |
|
473 QString key("WindowTitle"); |
|
474 QVariant value(QString(LOC_TITLE)); |
|
475 XQRequestInfo info; |
|
476 info.setInfo(key, value); |
|
477 request->setInfo(info); |
|
478 |
|
479 request->send(); |
|
480 |
|
481 // Cleanup |
|
482 sf.close(); |
|
483 delete request; |
|
484 } |
|
485 |
|
486 //--------------------------------------------------------------- |
|
487 //UniViewerBodyWidget::saveMedia |
|
488 // @see header file |
|
489 //--------------------------------------------------------------- |
|
490 void UniViewerBodyWidget::saveMedia() |
|
491 { |
|
492 } |
|
493 |
|
494 //--------------------------------------------------------------- |
|
495 // UniViewerBodyWidget :: handleOk |
|
496 // @see header file |
|
497 //--------------------------------------------------------------- |
|
498 void UniViewerBodyWidget::handleOk(const QVariant& result) |
|
499 { |
|
500 Q_UNUSED(result) |
|
501 } |
|
502 |
|
503 //--------------------------------------------------------------- |
|
504 // UniViewerBodyWidget :: handleError |
|
505 // @see header file |
|
506 //--------------------------------------------------------------- |
|
507 void UniViewerBodyWidget::handleError(int errorCode, const QString& errorMessage) |
|
508 { |
|
509 Q_UNUSED(errorMessage) |
|
510 Q_UNUSED(errorCode) |
|
511 } |
|
512 // EOF |