messagingapp/msgui/unifiedviewer/src/univiewerbodywidget.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 47 5b14749788d7
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
    18 #include "univiewerbodywidget.h"
    18 #include "univiewerbodywidget.h"
    19 
    19 
    20 #include <QFile>
    20 #include <QFile>
    21 #include <QFileInfo>
    21 #include <QFileInfo>
    22 #include <QPixmap>
    22 #include <QPixmap>
    23 #include <QGraphicsLayout>
       
    24 #include <QSignalMapper>
    23 #include <QSignalMapper>
    25 
    24 
    26 #include <HbTextItem>
    25 #include <HbTextItem>
    27 #include <HbIconItem>
       
    28 #include <HbPushButton>
    26 #include <HbPushButton>
    29 #include <HbAction>
       
    30 #include <HbMenu>
    27 #include <HbMenu>
    31 #include <HbMainWindow>
    28 #include <HbMainWindow>
    32 #include <HbInstance>
       
    33 #include <HbGesture>
       
    34 #include <HbGestureSceneFilter>
       
    35 
    29 
    36 #include <xqaiwrequest.h>
    30 #include <xqaiwrequest.h>
    37 #include <xqrequestinfo.h>
    31 #include <xqrequestinfo.h>
    38 #include <xqappmgr.h>
    32 #include <xqappmgr.h>
    39 
    33 
    40 #include "univiewertextitem.h"
    34 #include "univiewertextitem.h"
       
    35 #include "univiewerpixmapwidget.h"
    41 #include "msgmediautil.h"
    36 #include "msgmediautil.h"
    42 // LOCAL CONSTANTS
    37 // LOCAL CONSTANTS
    43 const QString AUDIO_ICON("qtg_mono_audio");
    38 const QString AUDIO_ICON("qtg_mono_audio");
    44 
    39 
    45 // Localization
    40 // Localization
    46 #define LOC_TITLE   hbTrId("txt_messaging_title_messaging")
    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")
    47 
    44 
    48 //---------------------------------------------------------------
    45 //---------------------------------------------------------------
    49 //UniViewerBodyWidget::UniViewerBodyWidget
    46 //UniViewerBodyWidget::UniViewerBodyWidget
    50 // @see header file
    47 // @see header file
    51 //---------------------------------------------------------------
    48 //---------------------------------------------------------------
    52 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) :
    49 UniViewerBodyWidget::UniViewerBodyWidget(QGraphicsItem *parent) :
    53     HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0),
    50     HbWidget(parent), mHasText(false), mHasPixmap(false), mTextItem(0), mSlideCounter(0),
    54         mIconItem(0), mAudioItem(0)
    51         mPixmapItem(0), mAudioItem(0)
    55 {
    52 {
    56     //Gesture filter for the image
    53     this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
    57     gestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this);
       
    58     gestureFilter->setLongpressAnimation(true);
       
    59     HbGesture *gesture = new HbGesture(HbGesture::longpress, 20);
       
    60     gestureFilter->addGesture(gesture);
       
    61     connect(gesture, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF)));
       
    62     // Signal mapper for opening media files
    54     // Signal mapper for opening media files
    63     mSignalMapper = new QSignalMapper(this);
    55     mSignalMapper = new QSignalMapper(this);
    64     connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &)));
    56     connect(mSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(openMedia(const QString &)));
    65 }
    57 }
    66 
    58 
    74 
    66 
    75 //---------------------------------------------------------------
    67 //---------------------------------------------------------------
    76 //UniViewerBodyWidget::setImage
    68 //UniViewerBodyWidget::setImage
    77 // @see header file
    69 // @see header file
    78 //---------------------------------------------------------------
    70 //---------------------------------------------------------------
    79 void UniViewerBodyWidget::setImage(QString imagefile)
    71 void UniViewerBodyWidget::setPixmap(QString pixmapFile)
    80 {
    72 {
    81     setHasPixmap(true);
    73     setHasPixmap(true);
    82     //create image item instance
    74     //create image item instance
    83     if (!mIconItem) {
    75     if (!mPixmapItem) {
    84         mIconItem = new HbIconItem(this);
    76         mPixmapItem = new UniViewerPixmapWidget(this);
    85         HbStyle::setItemName(mIconItem, "pixmap");
    77         HbStyle::setItemName(mPixmapItem, "pixmap");
    86     }
    78         connect(mPixmapItem, SIGNAL(shortTap(QString)), this, SLOT(openMedia(QString)));
    87 
    79     }
    88     QPixmap pixmap(imagefile);
    80 
    89     mIconItem->setIcon(HbIcon(pixmap));
    81     mPixmapItem->hide();
    90 
    82     mPixmapItem->setPixmap(pixmapFile);
    91     // TODO
       
    92     // Implementation for short tap action is unclear
       
    93     // Connect to signal mapper
       
    94 
    83 
    95     this->repolish();
    84     this->repolish();
    96 }
    85 }
    97 
    86 
    98 //---------------------------------------------------------------
    87 //---------------------------------------------------------------
   103 {
    92 {
   104     if (!mAudioItem) {
    93     if (!mAudioItem) {
   105         mAudioItem = new HbPushButton(this);
    94         mAudioItem = new HbPushButton(this);
   106         HbStyle::setItemName(mAudioItem, "audioItem");
    95         HbStyle::setItemName(mAudioItem, "audioItem");
   107     }
    96     }
       
    97     mAudioItem->hide();
   108     QFileInfo fileInfo(audiofile);
    98     QFileInfo fileInfo(audiofile);
   109     mAudioItem->setIcon(HbIcon(AUDIO_ICON));
    99     mAudioItem->setIcon(HbIcon(AUDIO_ICON));
   110     mAudioItem->setText(fileInfo.baseName());
   100     mAudioItem->setText(fileInfo.baseName());
   111     MsgMediaUtil mediaUtil;
   101     MsgMediaUtil mediaUtil;
   112     mAudioItem->setAdditionalText(mediaUtil.mediaDuration(audiofile));
   102     mAudioItem->setAdditionalText(mediaUtil.mediaDuration(audiofile));
   140         mTextItem = new UniViewerTextItem(this);
   130         mTextItem = new UniViewerTextItem(this);
   141         HbStyle::setItemName(mTextItem, "textItem");
   131         HbStyle::setItemName(mTextItem, "textItem");
   142         connect(mTextItem, SIGNAL(sendMessage(const QString&)), this,
   132         connect(mTextItem, SIGNAL(sendMessage(const QString&)), this,
   143             SIGNAL(sendMessage(const QString&)));
   133             SIGNAL(sendMessage(const QString&)));
   144     }
   134     }
       
   135     mTextItem->hide();
   145     text.replace(QChar::ParagraphSeparator, QChar::LineSeparator);
   136     text.replace(QChar::ParagraphSeparator, QChar::LineSeparator);
   146     text.replace('\r', QChar::LineSeparator);
   137     text.replace('\r', QChar::LineSeparator);
   147     mTextItem->setText(text);
   138     mTextItem->setText(text);
   148     this->repolish();
   139     this->repolish();
   149 }
   140 }
   157     if (!mSlideCounter) {
   148     if (!mSlideCounter) {
   158         mSlideCounter = new HbTextItem(this);
   149         mSlideCounter = new HbTextItem(this);
   159         HbStyle::setItemName(mSlideCounter, "slideCounter");
   150         HbStyle::setItemName(mSlideCounter, "slideCounter");
   160     }
   151     }
   161 
   152 
       
   153     mSlideCounter->hide();
   162     mSlideCounter->setText(slideCounter);
   154     mSlideCounter->setText(slideCounter);
   163     this->repolish();
   155     this->repolish();
   164 }
   156 }
   165 
   157 
   166 //---------------------------------------------------------------
   158 //---------------------------------------------------------------
   214         UniMessageInfo* info = objList.at(a);
   206         UniMessageInfo* info = objList.at(a);
   215         QString type = info->mimetype();
   207         QString type = info->mimetype();
   216 
   208 
   217         if (type.contains("text")) {
   209         if (type.contains("text")) {
   218             QFile file(info->path());
   210             QFile file(info->path());
   219             if (file.open(QIODevice::ReadOnly))
   211             if (file.open(QIODevice::ReadOnly)) {
   220 			{
   212                 QString textContent(file.readAll());
   221 			QString textContent(file.readAll());
   213                 setTextContent(textContent);
   222             setTextContent(textContent);
   214             }
   223 			}
       
   224             
       
   225         }
   215         }
   226         else if (type.contains("video")) {
   216         else if (type.contains("video")) {
   227             setVideo(info->path());
   217             setVideo(info->path());
   228         }
   218         }
   229         else if (type.contains("audio")) {
   219         else if (type.contains("audio")) {
   230             setAudio(info->path());
   220             setAudio(info->path());
   231         }
   221         }
   232         else if (type.contains("image")) {
   222         else if (type.contains("image")) {
   233             setImage(info->path());
   223             setPixmap(info->path());
   234         }
   224         }
   235 
   225 
   236         delete info;
   226         delete info;
   237     }
   227     }
   238 }
   228 }
   242 // @see header file
   232 // @see header file
   243 //---------------------------------------------------------------
   233 //---------------------------------------------------------------
   244 void UniViewerBodyWidget::clearContent()
   234 void UniViewerBodyWidget::clearContent()
   245 {
   235 {
   246     // delete the temp items(pixmap) & clear permanent items(text)
   236     // delete the temp items(pixmap) & clear permanent items(text)
   247     if (mIconItem) {
   237     if (mPixmapItem) {
   248         mIconItem->setParent(NULL);
   238         mPixmapItem->setParent(NULL);
   249         delete mIconItem;
   239         delete mPixmapItem;
   250         mIconItem = NULL;
   240         mPixmapItem = NULL;
   251     }
   241     }
   252 
   242 
   253     if (mAudioItem) {
   243     if (mAudioItem) {
   254         mAudioItem->setParent(NULL);
   244         mAudioItem->setParent(NULL);
   255         delete mAudioItem;
   245         delete mAudioItem;
   266     setHasPixmap(false);
   256     setHasPixmap(false);
   267     repolish();
   257     repolish();
   268 }
   258 }
   269 
   259 
   270 //---------------------------------------------------------------
   260 //---------------------------------------------------------------
   271 //UniViewerBodyWidget::resizeEvent
   261 //UniViewerBodyWidget::sizeHint
   272 // @see header file
   262 // @see header file
   273 //---------------------------------------------------------------
   263 //---------------------------------------------------------------
   274 void UniViewerBodyWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
   264 QSizeF UniViewerBodyWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
   275 {
   265 {
   276     Q_UNUSED(event)
   266     QSizeF szHint = HbWidget::sizeHint(which, constraint);
   277 
   267 
   278     HbMainWindow *mainWindow = this->mainWindow();
   268     HbMainWindow *mainWindow = this->mainWindow();
   279     if (mainWindow) {
   269     if (!mainWindow) {
   280         qreal screenWidth = 0.0;
   270         return szHint;
   281         qreal screenHeight = 0.0;
   271     }
   282         qreal leftMargin = 0.0;
   272 
   283         qreal rightMargin = 0.0;
   273     qreal screenWidth = 0.0;
   284         qreal chromeHeight = 0.0;
   274     qreal screenHeight = 0.0;
   285         qreal toolbarHeight = 0.0;
   275     qreal leftMargin = 0.0;
   286         qreal iconSize = 0.0;
   276     qreal rightMargin = 0.0;
   287         qreal unitSize = HbDeviceProfile::profile(mIconItem).unitValue();
   277     qreal chromeHeight = 0.0;
   288         style()->parameter("hb-param-screen-width", screenWidth);
   278     qreal toolbarHeight = 0.0;
   289         style()->parameter("hb-param-screen-height", screenHeight);
   279     qreal iconSize = 0.0;
   290         style()->parameter("hb-param-margin-gene-left", leftMargin);
   280     qreal spacing = 0.0;
   291         style()->parameter("hb-param-margin-gene-right", rightMargin);
   281     qreal unitSize = HbDeviceProfile::profile(mPixmapItem).unitValue();
   292         style()->parameter("hb-param-widget-chrome-height", chromeHeight);
   282     style()->parameter("hb-param-screen-width", screenWidth);
   293         style()->parameter("hb-param-widget-toolbar-height", toolbarHeight);
   283     style()->parameter("hb-param-screen-height", screenHeight);
   294         style()->parameter("hb-param-graphic-size-primary-large", iconSize);
   284     style()->parameter("hb-param-margin-gene-left", leftMargin);
   295 
   285     style()->parameter("hb-param-margin-gene-right", rightMargin);
   296         qreal maxWidth = 0.0;
   286     style()->parameter("hb-param-widget-chrome-height", chromeHeight);
   297         qreal maxHeight = 0.0;
   287     style()->parameter("hb-param-widget-toolbar-height", toolbarHeight);
   298 
   288     style()->parameter("hb-param-graphic-size-primary-large", iconSize);
   299         if (mainWindow->orientation() == Qt::Horizontal) {
   289     style()->parameter("hb-param-margin-gene-middle-vertical", spacing);
   300             qreal temp;
   290 
   301             temp = screenWidth;
   291     qreal maxWidth = 0.0;
   302             screenWidth = screenHeight;
   292     qreal maxHeight = 0.0;
   303             screenHeight = temp;
   293 
   304             if (mIconItem) {
   294     // Calculate max height & max width.
   305                 if (mHasText) {
   295     if (mainWindow->orientation() == Qt::Horizontal) {
   306                     maxWidth = (screenWidth / 2) - leftMargin - unitSize;
   296         qreal temp;
   307                 }
   297         temp = screenWidth;
   308                 else {
   298         screenWidth = screenHeight;
   309                     maxWidth = screenWidth - leftMargin - rightMargin;
   299         screenHeight = temp;
   310                 }
   300 
   311                 maxHeight = screenHeight - chromeHeight - toolbarHeight;
   301         if (mPixmapItem && mHasText) {
   312             }
   302             maxWidth = (screenWidth / 2) - leftMargin - unitSize;
   313             if (mAudioItem) {
   303         }
   314                 mAudioItem->setStretched(true);
   304         else {
   315             }
   305             maxWidth = screenWidth - leftMargin - rightMargin;
   316         }
   306         }
   317         else if (mainWindow->orientation() == Qt::Vertical) {
   307         maxHeight = screenHeight - chromeHeight - toolbarHeight;
   318             if (mIconItem) {
   308 
   319                 maxWidth = screenWidth - leftMargin - rightMargin;
   309         if (mAudioItem) {
   320                 maxHeight = screenHeight - chromeHeight - toolbarHeight;
   310             mAudioItem->setStretched(true);
   321             }
   311         }
   322             if (mAudioItem) {
   312     }
   323                 mAudioItem->setStretched(false);
   313     else if (mainWindow->orientation() == Qt::Vertical) {
   324             }
   314         maxWidth = screenWidth - leftMargin - rightMargin;
   325         }
   315         maxHeight = screenHeight - chromeHeight - toolbarHeight;
   326 
   316 
   327         if (mIconItem) {
   317         if (mAudioItem) {
   328             qreal imageWidth = mIconItem->icon().defaultSize().width();
   318             mAudioItem->setStretched(false);
   329             qreal imageHeight = mIconItem->icon().defaultSize().height();
   319         }
   330 
   320     }
   331             qreal widthToSet = 0.0;
   321 
   332             qreal heightToSet = 0.0;
   322     // Slide Counter
   333 
   323     QSizeF slideCounterSize(0, 0);
   334             if (imageWidth < iconSize) {
   324     if (mSlideCounter) {
   335                 widthToSet = iconSize;
   325         slideCounterSize = mSlideCounter->effectiveSizeHint(which, constraint);
   336                 heightToSet = iconSize;
   326         mSlideCounter->show();
   337             }
   327     }
   338             else if (imageWidth <= maxWidth) {
   328     // Audio Item
   339                 // resize not needed
   329     QSizeF audioSize(0, 0);
   340                 widthToSet = imageWidth;
   330     if (mAudioItem) {
   341                 heightToSet = qMin(imageHeight, maxHeight);
   331         audioSize = mAudioItem->effectiveSizeHint(which, constraint);
   342             }
   332         mAudioItem->show();
   343             else {
   333     }
   344                 // resize needed, keep aspect-ratio and resize
   334 
   345                 widthToSet = maxWidth;
   335     // Text Item
   346                 heightToSet = maxWidth * (imageHeight / imageWidth);
   336     QSizeF textSize(0, 0);
   347                 heightToSet = qMin(heightToSet, maxHeight);
   337     if (mTextItem) {
   348 
   338         textSize = mTextItem->effectiveSizeHint(which, constraint);
   349             }
   339         mTextItem->show();
   350             if (heightToSet == maxHeight) {
   340     }
   351                 widthToSet = heightToSet * (imageWidth / imageHeight);
   341 
   352             }
   342     // Pixmap Item
   353 
   343     QSizeF pixmapSize(0, 0);
   354             mIconItem->setPreferredWidth(widthToSet);
   344     if (mPixmapItem) {
   355             mIconItem->setPreferredHeight(heightToSet);
   345         qreal imageWidth = mPixmapItem->icon().defaultSize().width();
   356         }
   346         qreal imageHeight = mPixmapItem->icon().defaultSize().height();
   357     }
   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;
   358 }
   404 }
   359 
   405 
   360 //---------------------------------------------------------------
   406 //---------------------------------------------------------------
   361 //UniViewerBodyWidget::longPressed
   407 //UniViewerBodyWidget::longPressed
   362 // @see header file
   408 // @see header file
   363 //---------------------------------------------------------------
   409 //---------------------------------------------------------------
   364 void UniViewerBodyWidget::longPressed(QPointF position)
   410 void UniViewerBodyWidget::longPressed(QPointF position)
   365 {
   411 {
   366 
   412 
   367     HbMenu* menu = new HbMenu;
   413     HbMenu* menu = new HbMenu;
   368     menu->addAction(tr("Open"), this, SLOT(openMedia()));
   414     menu->setAttribute(Qt::WA_DeleteOnClose);
   369     menu->addAction(tr("View details"), this, SLOT(viewDetails()));
   415     menu->addAction(LOC_OPEN, this, SLOT(openMedia()));
   370     menu->exec(position);
   416     menu->addAction(LOC_SAVE, this, SLOT(saveMedia()));
   371     delete menu;
   417     menu->setPreferredPos(position);
       
   418     menu->show();
   372 }
   419 }
   373 
   420 
   374 //---------------------------------------------------------------
   421 //---------------------------------------------------------------
   375 //UniViewerBodyWidget::openMedia
   422 //UniViewerBodyWidget::openMedia
   376 // @see header file
   423 // @see header file
   435     sf.close();
   482     sf.close();
   436     delete request;
   483     delete request;
   437 }
   484 }
   438 
   485 
   439 //---------------------------------------------------------------
   486 //---------------------------------------------------------------
   440 //UniViewerBodyWidget::viewDetails
   487 //UniViewerBodyWidget::saveMedia
   441 // @see header file
   488 // @see header file
   442 //---------------------------------------------------------------
   489 //---------------------------------------------------------------
   443 void UniViewerBodyWidget::viewDetails()
   490 void UniViewerBodyWidget::saveMedia()
   444 {
   491 {
   445     //open details view.
       
   446 }
   492 }
   447 
   493 
   448 //---------------------------------------------------------------
   494 //---------------------------------------------------------------
   449 // UniViewerBodyWidget :: handleOk
   495 // UniViewerBodyWidget :: handleOk
   450 // @see header file
   496 // @see header file