messagingapp/msgui/unifiedviewer/src/unicontentswidget.cpp
changeset 23 238255e8b033
child 27 e4592d119491
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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 is place holder for message headers and body
       
    15  *
       
    16  */
       
    17 #include "unicontentswidget.h"
       
    18 
       
    19 #include <QGraphicsLinearLayout>
       
    20 #include <hbinputeditorinterface.h>
       
    21 #include <hbinputstandardfilters.h>
       
    22 
       
    23 #include "univiewerfeeder.h"
       
    24 #include "univiewslidewidget.h"
       
    25 #include "convergedmessage.h"
       
    26 #include "debugtraces.h"
       
    27 #include "nativemessageconsts.h"
       
    28 //---------------------------------------------------------------
       
    29 //UniContentsWidget :: UniContentsWidget
       
    30 // @see header file
       
    31 //---------------------------------------------------------------
       
    32 UniContentsWidget::UniContentsWidget(UniViewerFeeder* feeder,QGraphicsItem * parent) :
       
    33     HbWidget(parent), mViewFeeder(feeder), mTotalSlides(1), mCurrentSlide(0), //Not used now
       
    34             mSlideWindow(10), // These need not be class members
       
    35             mInitialLoadCount(2), // These need not be class members
       
    36             mTotalSlidesLoaded(0), mRowCount(0)
       
    37 
       
    38 {
       
    39     QDEBUG_WRITE("UniContentsWidget: Constructor start");
       
    40 
       
    41     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    42     mMainLayout->setSpacing(0);
       
    43     mMainLayout->setContentsMargins(0, 0, 0, 0);
       
    44     
       
    45     if(mViewFeeder->msgType() == KSenduiMtmMmsUidValue)
       
    46     {
       
    47         mMessageType = ConvergedMessage::Mms; 
       
    48     }
       
    49     else if (mViewFeeder->msgType() == KSenduiMtmSmsUidValue)
       
    50     {
       
    51         mMessageType = ConvergedMessage::Sms;
       
    52     }
       
    53     else // Does this hold good.
       
    54     {   
       
    55         mMessageType = ConvergedMessage::None;
       
    56     }
       
    57 
       
    58     // create the mInitailLoadCount number of slides
       
    59     for (int i = 0; i < mInitialLoadCount; i++)
       
    60     {
       
    61         UniViewSlideWidget* slide = new UniViewSlideWidget(feeder, i);
       
    62         addItemToLayout(slide);
       
    63         slide->setInsideLayout(true);
       
    64         mSlides.append(slide);
       
    65         
       
    66         connect(slide,SIGNAL(sendMessage(const QString&)),
       
    67                 this, SIGNAL(sendMessage(const QString&)));
       
    68     }
       
    69 
       
    70     setLayout(mMainLayout);
       
    71 
       
    72     QDEBUG_WRITE("UniContentsWidget: Constructor end");
       
    73 }
       
    74 
       
    75 //---------------------------------------------------------------
       
    76 //UniContentsWidget :: ~UniContentsWidget
       
    77 // @see header file
       
    78 //---------------------------------------------------------------
       
    79 UniContentsWidget::~UniContentsWidget()
       
    80 {
       
    81     for (int a = 0; a < mSlides.count(); a++)
       
    82     {
       
    83         delete mSlides[a];
       
    84     }
       
    85 }
       
    86 
       
    87 //---------------------------------------------------------------
       
    88 //UniContentsWidget ::addItemToLayout
       
    89 // @see header file
       
    90 //---------------------------------------------------------------
       
    91 void UniContentsWidget::addItemToLayout(UniViewSlideWidget* item)
       
    92 {
       
    93     mMainLayout->addItem(item);
       
    94     ++mRowCount;
       
    95 }
       
    96 
       
    97 //---------------------------------------------------------------
       
    98 //UniContentsWidget ::removeItemFromLayout
       
    99 // @see header file
       
   100 //---------------------------------------------------------------
       
   101 void UniContentsWidget::removeItemFromLayout(UniViewSlideWidget* item)
       
   102 {
       
   103     mMainLayout->removeItem(item);
       
   104     mRowCount--;
       
   105 }
       
   106 
       
   107 //---------------------------------------------------------------
       
   108 //UniContentsWidget::clearContent
       
   109 // @see header file
       
   110 //---------------------------------------------------------------
       
   111 void UniContentsWidget::clearContent()
       
   112 {
       
   113     QDEBUG_WRITE("UniContentsWidget::clearContent() start");
       
   114 
       
   115     // Clear the first slide content
       
   116     int slidesToClear;
       
   117     bool returnAfterClear = false;
       
   118     if (mSlides.count() < mSlideWindow)
       
   119     {
       
   120         slidesToClear = mSlides.count();
       
   121         returnAfterClear = true;
       
   122     }
       
   123     else
       
   124     {
       
   125         slidesToClear = mSlideWindow;
       
   126     }
       
   127     for (int i = 0; i < slidesToClear; i++)
       
   128     {
       
   129         mSlides[i]->clearContent();
       
   130         if (mSlides[i]->insideLayout())
       
   131         {
       
   132             this->removeItemFromLayout(mSlides[i]);
       
   133             mSlides[i]->setParent(NULL);
       
   134             mSlides[i]->setParentItem(NULL);
       
   135             mSlides[i]->hide();
       
   136             mSlides[i]->setInsideLayout(false);
       
   137         }
       
   138     }
       
   139 
       
   140     mTotalSlidesLoaded = slidesToClear;
       
   141     if (returnAfterClear)
       
   142         return;
       
   143 
       
   144     // Delete the remaining slides
       
   145     for (int a = slidesToClear; a < mSlides.count(); a++)
       
   146     {
       
   147         mSlides[a]->setParent(NULL);
       
   148         mSlides[a]->setParentItem(NULL);
       
   149         delete mSlides[a];
       
   150         mSlides.removeAt(a);
       
   151         mRowCount--;
       
   152     }
       
   153 
       
   154     QDEBUG_WRITE("UniContentsWidget::clearContent() end");
       
   155 }
       
   156 
       
   157 //---------------------------------------------------------------
       
   158 //UniContentsWidget::populateContent
       
   159 // @see header file
       
   160 //---------------------------------------------------------------
       
   161 void UniContentsWidget::populateContent()
       
   162 {
       
   163     QDEBUG_WRITE("UniContentsWidget::populateContent() start");
       
   164     
       
   165     if ( (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) &&
       
   166          (mViewFeeder->slideCount() > 0) )
       
   167     {
       
   168         mMessageType = ConvergedMessage::Mms; 
       
   169         mTotalSlides = mViewFeeder->slideCount();
       
   170         if (mTotalSlides >= mSlides.count())
       
   171         {
       
   172             mTotalSlidesLoaded = mSlides.count();
       
   173         }
       
   174         else
       
   175         {
       
   176             mTotalSlidesLoaded = mTotalSlides;
       
   177         }
       
   178     }
       
   179     else
       
   180     {
       
   181         mTotalSlidesLoaded = 1;
       
   182         mTotalSlides = 1;
       
   183     }
       
   184 
       
   185     //Populate the mTotalSlidesLoaded
       
   186     for (int i = 0; i < mTotalSlidesLoaded; i++)
       
   187     {
       
   188         if (!mSlides[i]->insideLayout())
       
   189         {
       
   190             mSlides[i]->show();
       
   191             mSlides[i]->setInsideLayout(true);
       
   192             this->addItemToLayout(mSlides[i]);
       
   193         }
       
   194         mSlides[i]->populateContent();
       
   195     }
       
   196 
       
   197     for (int j = mTotalSlidesLoaded; j < mSlides.count(); j++)
       
   198     {
       
   199         if (mSlides[j]->insideLayout())
       
   200         {
       
   201             this->removeItemFromLayout(mSlides[j]);
       
   202             mSlides[j]->setInsideLayout(false);
       
   203             mSlides[j]->hide();
       
   204         }
       
   205     }
       
   206 
       
   207     //Create remaining slides on demand
       
   208 
       
   209     QDEBUG_WRITE("UniContentsWidget::populateContent() end");
       
   210 }
       
   211 
       
   212 //---------------------------------------------------------------
       
   213 //UniContentsWidget::populateNextSlide
       
   214 // @see header file
       
   215 //---------------------------------------------------------------
       
   216 void UniContentsWidget::populateNextSlide()
       
   217 {
       
   218     if (mTotalSlidesLoaded >= mTotalSlides)
       
   219     {
       
   220         return;
       
   221     }
       
   222 
       
   223     UniViewSlideWidget* slide = new UniViewSlideWidget(mViewFeeder,
       
   224         mTotalSlidesLoaded);
       
   225     addItemToLayout(slide);
       
   226     slide->setInsideLayout(true);
       
   227     mSlides.append(slide);
       
   228 
       
   229     slide->populateContent();
       
   230     
       
   231     connect(slide,SIGNAL(sendMessage(const QString&)),
       
   232             this, SIGNAL(sendMessage(const QString&)));
       
   233 
       
   234     mTotalSlidesLoaded++;
       
   235     //TODO to remove the previous slide if the mTotalSlidesLoaded
       
   236     //exceeds the mSlideWindow
       
   237 }
       
   238 
       
   239 // EOF