messagingapp/msgui/unifiedviewer/src/univiewerheadercontainer.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 48 4f501b74aeb1
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    22 #include <HbGroupBox>
    22 #include <HbGroupBox>
    23 #include <HbFrameItem>
    23 #include <HbFrameItem>
    24 
    24 
    25 // USER INCLUDES
    25 // USER INCLUDES
    26 #include "univieweraddresscontainer.h"
    26 #include "univieweraddresscontainer.h"
    27 #include "univiewerattachmentcontainer.h"
       
    28 #include "univiewerdetailswidget.h"
    27 #include "univiewerdetailswidget.h"
    29 #include "univiewerfeeder.h"
    28 #include "univiewerfeeder.h"
       
    29 #include "univiewerattachmentwidget.h"
    30 
    30 
    31 #include "nativemessageconsts.h"
    31 #include "nativemessageconsts.h"
    32 
    32 
    33 // LOCALIZATION
    33 // LOCALIZATION
    34 #define LOC_SEND_FAILED hbTrId("txt_messaging_formlabel_sending_failed")
    34 #define LOC_SEND_FAILED hbTrId("txt_messaging_formlabel_sending_failed")
    35 
    35 
    36 // LOCAL CONSTANTS
    36 // LOCAL CONSTANTS
    37 const QString ADDR_LIST_SEPARATOR(", ");
    37 const QString ADDR_LIST_SEPARATOR(", ");
    38 const QString BG_FRAME_GRAPHICS("qtg_fr_form_heading");
    38 const QString BG_FRAME_GRAPHICS("qtg_fr_form_heading");
       
    39 const QString DIVIDER_FRAME("qtg_graf_divider_h_thin");
    39 
    40 
    40 //---------------------------------------------------------------
    41 //---------------------------------------------------------------
    41 // UniViewerHeaderContainer :: UniViewerHeaderContainer
    42 // UniViewerHeaderContainer :: UniViewerHeaderContainer
    42 // @see header file
    43 // @see header file
    43 //---------------------------------------------------------------
    44 //---------------------------------------------------------------
    44 UniViewerHeaderContainer::UniViewerHeaderContainer(UniViewerFeeder* feeder, QGraphicsItem *parent) :
    45 UniViewerHeaderContainer::UniViewerHeaderContainer(UniViewerFeeder* feeder, QGraphicsItem *parent) :
    45     HbWidget(parent), mViewFeeder(feeder), mViewerDetails(0), mHeaderGroupBox(0),
    46     HbWidget(parent), mViewFeeder(feeder), mViewerDetails(0), mHeaderGroupBox(0), mSeparator(0),
    46         mAddressContainer(0), mAttachmentContainer(0)
    47         mAddressContainer(0)
    47 {
    48 {
    48     HbFrameItem *bgItem = new HbFrameItem(BG_FRAME_GRAPHICS, HbFrameDrawer::NinePieces, this);
    49     this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    49     this->setBackgroundItem(bgItem);
    50 
    50 
    51     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
    51     QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
    52     mMainLayout->setSpacing(0);
    52     mainLayout->setSpacing(0);
    53     mMainLayout->setContentsMargins(0, 0, 0, 0);
    53     mainLayout->setContentsMargins(0, 0, 0, 0);
       
    54 
    54 
    55     // Address Group box
    55     // Address Group box
    56     mHeaderGroupBox = new HbGroupBox(this);
    56     mHeaderGroupBox = new HbGroupBox(this);
       
    57     connect(mHeaderGroupBox, SIGNAL(toggled(bool)), this, SLOT(addressBoxToggled(bool)));
    57 
    58 
    58     // Address container
    59     // Address container
    59     mAddressContainer = new UniViewerAddressContainer(mHeaderGroupBox);
    60     mAddressContainer = new UniViewerAddressContainer(this);
       
    61     connect(mAddressContainer,SIGNAL(sendMessage(const QString&,const QString&)),
       
    62             this, SIGNAL(sendMessage(const QString&,const QString&)));
    60 
    63 
    61     mHeaderGroupBox->setContentWidget(mAddressContainer);
    64     mHeaderGroupBox->setContentWidget(mAddressContainer);
       
    65 
       
    66     // Separator
       
    67     mSeparator = new HbFrameItem(DIVIDER_FRAME, HbFrameDrawer::OnePiece, this);
       
    68     mSeparator->setMinimumHeight(2.0);
       
    69     mSeparator->frameDrawer().fillWholeRect();
       
    70     mSeparator->hide();
    62 
    71 
    63     // Viewer Details widget
    72     // Viewer Details widget
    64     mViewerDetails = new UniViewerDetailsWidget(this);
    73     mViewerDetails = new UniViewerDetailsWidget(this);
    65 
    74 
    66     // Attachment Container
    75     // This widget is created to apply background for header & details.
    67     mAttachmentContainer = new UniViewerAttachmentContainer(this);
    76     HbWidget *headerContainer = new HbWidget(this);
       
    77 
       
    78     QGraphicsLinearLayout *headerLayout = new QGraphicsLinearLayout(Qt::Vertical, headerContainer);
       
    79     headerLayout->setSpacing(0);
       
    80     headerLayout->setContentsMargins(0, 0, 0, 0);
       
    81 
       
    82     HbFrameItem *bgItem = new HbFrameItem(BG_FRAME_GRAPHICS, HbFrameDrawer::NinePieces, this);
       
    83     headerContainer->setBackgroundItem(bgItem, -2.0);
    68 
    84 
    69     //Add address group box and insert into layout
    85     //Add address group box and insert into layout
    70     mainLayout->addItem(mHeaderGroupBox);
    86     headerLayout->addItem(mHeaderGroupBox);
    71     mainLayout->addItem(mViewerDetails);
    87     headerLayout->addItem(mSeparator);
    72     mainLayout->addItem(mAttachmentContainer);
    88     headerLayout->addItem(mViewerDetails);
    73 
    89 
    74     this->setLayout(mainLayout);
    90     headerContainer->setLayout(headerLayout);
       
    91 
       
    92     mMainLayout->addItem(headerContainer);
       
    93 
       
    94     this->setLayout(mMainLayout);
    75 }
    95 }
    76 
    96 
    77 //---------------------------------------------------------------
    97 //---------------------------------------------------------------
    78 // UniViewerHeaderContainer :: ~UniViewerHeaderContainer
    98 // UniViewerHeaderContainer :: ~UniViewerHeaderContainer
    79 // @see header file
    99 // @see header file
   107     populateAttachments();
   127     populateAttachments();
   108 
   128 
   109     // Expand address group box for outgoing messages.
   129     // Expand address group box for outgoing messages.
   110     if (mViewFeeder->isIncoming()) {
   130     if (mViewFeeder->isIncoming()) {
   111         mHeaderGroupBox->setCollapsed(true);
   131         mHeaderGroupBox->setCollapsed(true);
       
   132         addressBoxToggled(true);
   112     }
   133     }
   113     else {
   134     else {
   114         mHeaderGroupBox->setCollapsed(false);
   135         mHeaderGroupBox->setCollapsed(false);
       
   136         addressBoxToggled(false);
   115     }
   137     }
   116 }
   138 }
   117 
   139 
   118 //---------------------------------------------------------------
   140 //---------------------------------------------------------------
   119 // UniViewerHeaderContainer :: clearContent
   141 // UniViewerHeaderContainer :: clearContent
   122 void UniViewerHeaderContainer::clearContent()
   144 void UniViewerHeaderContainer::clearContent()
   123 {
   145 {
   124     if (mViewerDetails) {
   146     if (mViewerDetails) {
   125         mViewerDetails->clearContent();
   147         mViewerDetails->clearContent();
   126     }
   148     }
   127     if (mAddressContainer) {
   149 
   128         mAddressContainer->clearContent();
   150     // Clear the attachments.
   129     }
   151     for (int i = 0; i < mUniViewerAttachmentstList.count(); ++i) {
   130     if (mAttachmentContainer) {
   152         mMainLayout->removeItem(mUniViewerAttachmentstList[i]);
   131         mAttachmentContainer->clearContent();
   153         mUniViewerAttachmentstList[i]->setParent(NULL);
   132     }
   154         delete mUniViewerAttachmentstList[i];
       
   155         mUniViewerAttachmentstList[i] = NULL;
       
   156     }
       
   157     mUniViewerAttachmentstList.clear();
       
   158 
       
   159     resize(rect().width(), -1);
   133 }
   160 }
   134 
   161 
   135 //---------------------------------------------------------------
   162 //---------------------------------------------------------------
   136 // UniViewerHeaderContainer :: populateSubject
   163 // UniViewerHeaderContainer :: populateSubject
   137 // @see header file
   164 // @see header file
   163 void UniViewerHeaderContainer::populateAttachments()
   190 void UniViewerHeaderContainer::populateAttachments()
   164 {
   191 {
   165     UniMessageInfoList attachList = mViewFeeder->attachmentsList();
   192     UniMessageInfoList attachList = mViewFeeder->attachmentsList();
   166     for (int a = 0; a < attachList.count(); ++a) {
   193     for (int a = 0; a < attachList.count(); ++a) {
   167         UniMessageInfo* info = attachList.at(a);
   194         UniMessageInfo* info = attachList.at(a);
   168         mAttachmentContainer->addAttachmentWidget(info->mimetype(), info->path());
   195         UniViewerAttachmentWidget *attachmentWidget = new UniViewerAttachmentWidget(this);
       
   196         mUniViewerAttachmentstList.append(attachmentWidget);
       
   197         attachmentWidget->populate(info);
   169         delete info;
   198         delete info;
       
   199         mMainLayout->addItem(attachmentWidget);
   170     }
   200     }
   171 }
   201 }
   172 
   202 
   173 //---------------------------------------------------------------
   203 //---------------------------------------------------------------
   174 // UniViewerHeaderContainer :: populateAttachments
   204 // UniViewerHeaderContainer :: populateAttachments
   182 
   212 
   183     // From field is added ONLY for incoming messages.
   213     // From field is added ONLY for incoming messages.
   184     if (mViewFeeder->isIncoming()) {
   214     if (mViewFeeder->isIncoming()) {
   185         mAddressContainer->setFromField(from, alias);
   215         mAddressContainer->setFromField(from, alias);
   186     }
   216     }
   187     // TO field is added ONLY for outgoing messages.
   217     // For outgoing SMS messages add TO field.
   188     else if (!toList.isEmpty()) {
   218     else if (mViewFeeder->msgType() == KSenduiMtmSmsUidValue && !toList.isEmpty()) {
   189         mAddressContainer->setToField(toList);
   219         mAddressContainer->setToField(toList);
   190     }
   220     }
   191 
   221 
   192     // CC field is added ONLY for MMS messages.
   222     // For MMS messages add TO, CC, BCC fields irrespective of incoming/outgoing.
   193     if (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) {
   223     if (mViewFeeder->msgType() == KSenduiMtmMmsUidValue) {
       
   224         if (!toList.isEmpty()) {
       
   225             mAddressContainer->setToField(toList);
       
   226         }
   194         ConvergedMessageAddressList ccList = mViewFeeder->ccAddressList();
   227         ConvergedMessageAddressList ccList = mViewFeeder->ccAddressList();
   195         if (!ccList.isEmpty()) {
   228         if (!ccList.isEmpty()) {
   196             mAddressContainer->setCcField(ccList);
   229             mAddressContainer->setCcField(ccList);
   197         }
   230         }
   198     }
   231         ConvergedMessageAddressList bccList = mViewFeeder->bccAddressList();
   199 
   232         if (!bccList.isEmpty()) {
   200     mAddressContainer->insertDivider();
   233             mAddressContainer->setBccField(bccList);
       
   234         }
       
   235     }
       
   236 
   201 }
   237 }
   202 //---------------------------------------------------------------
   238 //---------------------------------------------------------------
   203 // UniViewerHeaderContainer :: setAddrGroupBoxHeading
   239 // UniViewerHeaderContainer :: setAddrGroupBoxHeading
   204 // @see header file
   240 // @see header file
   205 //---------------------------------------------------------------
   241 //---------------------------------------------------------------
   235         address.append(ADDR_LIST_SEPARATOR);
   271         address.append(ADDR_LIST_SEPARATOR);
   236     }
   272     }
   237     address.chop(ADDR_LIST_SEPARATOR.size());
   273     address.chop(ADDR_LIST_SEPARATOR.size());
   238     return address;
   274     return address;
   239 }
   275 }
       
   276 
       
   277 //---------------------------------------------------------------
       
   278 // UniViewerHeaderContainer :: addressBoxToggled
       
   279 // @see header file
       
   280 //---------------------------------------------------------------
       
   281 void UniViewerHeaderContainer::addressBoxToggled(bool state)
       
   282 {
       
   283     (state) ? mSeparator->hide() : mSeparator->show();
       
   284 }
       
   285 
       
   286 // EOF