emailuis/nmhswidget/src/nmhswidgettitlerow.cpp
changeset 23 2dc6caa42ec3
parent 18 578830873419
child 30 759dc5235cdb
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    14  * Description: 
    14  * Description: 
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <QDebug>
    18 #include <QDebug>
       
    19 #include <QtGui>
    19 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsLinearLayout>
    20 #include <hbdocumentloader.h>
    21 #include <hbdocumentloader.h>
    21 #include <hblabel.h>
    22 #include <hblabel.h>
       
    23 #include <HbPushButton>
    22 #include "nmicons.h"
    24 #include "nmicons.h"
    23 #include "nmhswidgettitlerow.h"
    25 #include "nmhswidgettitlerow.h"
    24 #include "nmhswidgetconsts.h"
    26 #include "nmhswidgetconsts.h"
    25 
    27 
    26 NmHsWidgetTitleRow::NmHsWidgetTitleRow(QGraphicsItem *parent, Qt::WindowFlags flags)
    28 NmHsWidgetTitleRow::NmHsWidgetTitleRow(QGraphicsItem *parent, Qt::WindowFlags flags) :
    27     : HbWidget(parent, flags),
    29     HbWidget(parent, flags), 
    28       mMailboxIcon(0),
    30     mMailboxIcon(0), 
    29       mMailboxInfo(0),
    31     mMailboxInfo(0), 
    30       mAccountName(0),
    32     mUnreadCountLabel(0),
    31       mUnreadCount(0)
    33     mCollapseExpIconLabel(0), 
       
    34     mAccountName(0), 
       
    35     mUnreadCount(0)
    32 {
    36 {
    33     qDebug() << "NmHsWidgetTitleRow::NmHsWidgetTitleRow IN -->>";
    37     qDebug() << "NmHsWidgetTitleRow::NmHsWidgetTitleRow IN -->>";
    34     
    38 
    35     loadDocML();
       
    36     
       
    37     qDebug() << "NmHsWidgetTitleRow::NmHsWidgetTitleRow OUT <<--";
    39     qDebug() << "NmHsWidgetTitleRow::NmHsWidgetTitleRow OUT <<--";
    38 }
    40 }
    39 
    41 
    40 /*!
    42 /*!
    41     Destructor
    43  Destructor
    42 */
    44  */
    43 NmHsWidgetTitleRow::~NmHsWidgetTitleRow()
    45 NmHsWidgetTitleRow::~NmHsWidgetTitleRow()
    44 {
    46 {
    45     qDebug() << "NmHsWidgetTitleRow::~NmHsWidgetTitleRow IN -->>";
    47     qDebug() << "NmHsWidgetTitleRow::~NmHsWidgetTitleRow IN -->>";
    46 
    48 
    47     qDebug() << "NmHsWidgetTitleRow::~NmHsWidgetTitleRow OUT <<--";
    49     qDebug() << "NmHsWidgetTitleRow::~NmHsWidgetTitleRow OUT <<--";
    48 }
    50 }
       
    51 
       
    52 /*!
       
    53  Loads layout data and child items from docml file. Must be called after constructor.
       
    54  /return true if loading succeeded, otherwise false. False indicates that object is unusable
       
    55  */
       
    56 bool NmHsWidgetTitleRow::loadDocML()
       
    57 {
       
    58     QT_TRY{
       
    59         qDebug() << "NmHsWidgetTitleRow::loadDocML IN -->>";
    49     
    60     
    50 /*!
    61         // Use document loader to load the contents
    51     Loads layout data and child items from docml file
    62         HbDocumentLoader loader;
    52 */
    63         bool ok(false);
    53 void NmHsWidgetTitleRow::loadDocML()
    64         loader.load(KNmHsWidgetTitleRowDocML, &ok);
    54 {
    65         if (!ok) {
    55     qDebug() << "NmHsWidgetTitleRow::loadDocML IN -->>";
    66             qDebug() << "NmHsWidgetTitleRow::loadDocML Fail @ loader -->>";
       
    67             return false; //failure
       
    68         }
    56     
    69     
    57     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
    70         //Create layout
    58     layout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
    71         QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
       
    72     
       
    73         layout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
    59             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
    74             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
    60     layout->setSpacing(KNmHsWidgetContentsMargin);    
    75         layout->setSpacing(KNmHsWidgetContentsMargin);
       
    76         setLayout(layout); //pass the ownership
    61     
    77     
    62     // Use document loader to load the contents
    78         // find container widget
    63     HbDocumentLoader loader;
    79         QGraphicsWidget *container = loader.findWidget(KNmHsWidgetTitleRowContainer);
    64     bool ok = false;
    80         if (!container) {
    65     loader.load( KNmHsWidgetTitleRowDocML, &ok);
    81             qDebug() << "NmHsWidgetTitleRow::loadDocML Fail @ container -->>";
    66     Q_ASSERT_X(ok, "nmhswidget", "invalid title docml file");
    82             return false;
       
    83         }
       
    84         layout->addItem(container);
    67     
    85     
    68     // find container widget
    86         //child items possible to update
    69     QGraphicsWidget *container = loader.findWidget(KNmHsWidgetTitleRowContainer);
    87         mMailboxIcon = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxIcon));
    70     Q_ASSERT_X((container != 0), "nmhswidget", "container not found!");
    88         mMailboxInfo = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxNameLabel));
    71     layout->addItem(container);
    89         mUnreadCountLabel = static_cast<HbLabel*> (loader.findWidget(
       
    90             KNmHsWidgetTitleRowUnreadCountLabel));
       
    91         mCollapseExpIconLabel = static_cast<HbPushButton*> (loader.findWidget(
       
    92             KNmHsWidgetTitleRowCollapseExpandIconLabel));
    72     
    93     
    73     //child items possible to update
    94         if (!mMailboxIcon || !mMailboxInfo || !mUnreadCountLabel || !mCollapseExpIconLabel) {
    74     mMailboxIcon = static_cast<HbLabel*>(loader.findWidget(KNmHsWidgetTitleRowMailboxIcon));
    95             qDebug() << "NmHsWidgetTitleRow::loadDocML Fail @ icons & labels -->>";
    75     mMailboxIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconDefaultMailbox));
    96             return false;
    76     mMailboxInfo = static_cast<HbLabel*>(loader.findWidget(KNmHsWidgetTitleRowMailboxNameLabel));
    97         }
    77 
       
    78     setLayout(layout);
       
    79     
    98     
    80     qDebug() << "NmHsWidgetTitleRow::loadDocML OUT <<--";
    99         //Expand collapse button
       
   100         connect(mCollapseExpIconLabel, SIGNAL(clicked()), this, SIGNAL(expandCollapseButtonPressed()));
       
   101     
       
   102         qDebug() << "NmHsWidgetTitleRow::loadDocML OUT <<--";
       
   103         return true;
       
   104     }
       
   105     QT_CATCH(...){
       
   106         return false;
       
   107     }
    81 }
   108 }
    82 
   109 
    83 /*!
   110 /*!
    84     Slot for updating account name, calls updateData to update ui.
   111  Slot for updating account name, calls updateData to update ui.
    85 */
   112  */
    86 void NmHsWidgetTitleRow::updateAccountName(const QString& accountName )
   113 void NmHsWidgetTitleRow::updateAccountName(const QString& accountName)
    87     {
   114 {
       
   115     qDebug() << "NmHsWidgetTitleRow::updateAccountName IN -->>";
    88     mAccountName = accountName;
   116     mAccountName = accountName;
    89     updateData();
   117     updateData();
    90     }
   118     qDebug() << "NmHsWidgetTitleRow::updateAccountName OUT <<--";
       
   119 }
    91 
   120 
    92 /*!
   121 /*!
    93     Slot for updating unread count, calls updateData to update ui.
   122  Set account icon name
    94 */
   123  */
    95 void NmHsWidgetTitleRow::updateUnreadCount(const int& unreadCount )
   124 void NmHsWidgetTitleRow::setAccountIcon(const QString& accountIconName)
    96     {
   125 {
       
   126     qDebug() << "NmHsWidgetTitleRow::setAccountIcon -- accountIconName" << accountIconName;
       
   127     mMailboxIcon->setIcon(accountIconName);
       
   128     qDebug() << "NmHsWidgetTitleRow::setAccountIcon OUT <<--";
       
   129 }
       
   130 
       
   131 /*!
       
   132  Slot for updating unread count, calls updateData to update ui.
       
   133  */
       
   134 void NmHsWidgetTitleRow::updateUnreadCount(const int& unreadCount)
       
   135 {
       
   136     qDebug() << "NmHsWidgetTitleRow::updateUnreadCount IN -->>";
    97     mUnreadCount = unreadCount;
   137     mUnreadCount = unreadCount;
    98     updateData();
   138     updateData();
    99     }
   139     qDebug() << "NmHsWidgetTitleRow::updateUnreadCount OUT <<--";
       
   140 }
   100 
   141 
   101 /*!
   142 /*!
   102     Update the data displayed in the UI
   143  Update the data displayed in the UI
   103 */
   144  */
   104 void NmHsWidgetTitleRow::updateData()
   145 void NmHsWidgetTitleRow::updateData()
   105     {
   146 {
   106     //TODO: Sprint 3: use localization for displaying data
   147     qDebug() << "NmHsWidgetTitleRow::updateData() IN -->>";
   107     QString info = mAccountName;
   148     mMailboxInfo->setPlainText(mAccountName);
   108     info.append(" (");
   149     //If unread count is -1, hide the unread count label completely.
   109     info.append( QString::number(mUnreadCount));
   150     //This indicates that there are no mails at all (or the initial sync is not done)
   110     info.append(")");
   151     if (mUnreadCount != -1) {
   111     mMailboxInfo->setPlainText(info);
   152         QString unreadCount(hbTrId("txt_mail_widget_list_l1").arg(mUnreadCount));
       
   153         mUnreadCountLabel->setPlainText(unreadCount);
       
   154         mUnreadCountLabel->setVisible(true);
   112     }
   155     }
       
   156     else {
       
   157         mUnreadCountLabel->setVisible(false);
       
   158     }
       
   159     qDebug() << "NmHsWidgetTitleRow::updateData() OUT <<--";
       
   160 }
       
   161 
       
   162 /*!
       
   163  mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   164  */
       
   165 void NmHsWidgetTitleRow::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   166 {
       
   167     qDebug() << "NmHsWidgetTitleRow::mousePressEvent() IN -->>";
       
   168     Q_UNUSED(event); 
       
   169 	emit mailboxLaunchTriggered();
       
   170     qDebug() << "NmHsWidgetTitleRow::mousePressEvent() OUT <<--";
       
   171 }