emailuis/nmhswidget/src/nmhswidgettitlerow.cpp
changeset 54 997a02608b3a
parent 30 759dc5235cdb
child 65 478bc57ad291
equal deleted inserted replaced
53:bf7eb7911fc5 54:997a02608b3a
    13  *
    13  *
    14  * Description: 
    14  * Description: 
    15  *
    15  *
    16  */
    16  */
    17 
    17 
       
    18 #include <qgraphicslinearlayout.h>
    18 #include <QtGui>
    19 #include <QtGui>
    19 #include <QGraphicsLinearLayout>
       
    20 #include <hbdocumentloader.h>
    20 #include <hbdocumentloader.h>
    21 #include <hblabel.h>
    21 #include <hblabel.h>
    22 #include <HbPushButton>
    22 #include <hbpushbutton.h>
    23 #include <HbColorScheme>
    23 #include <hbcolorscheme.h>
    24 #include <HbEvent>
    24 #include <hbevent.h>
       
    25 #include <hbframedrawer.h>
       
    26 #include <hbframeitem.h>
    25 #include "nmicons.h"
    27 #include "nmicons.h"
    26 #include "nmhswidgettitlerow.h"
    28 #include "nmhswidgettitlerow.h"
    27 #include "nmhswidgetconsts.h"
    29 #include "nmhswidgetconsts.h"
    28 #include "emailtrace.h"
    30 #include "emailtrace.h"
    29 
    31 
    32     mMailboxIcon(0), 
    34     mMailboxIcon(0), 
    33     mMailboxInfo(0), 
    35     mMailboxInfo(0), 
    34     mUnreadCountLabel(0),
    36     mUnreadCountLabel(0),
    35     mCollapseExpIconLabel(0), 
    37     mCollapseExpIconLabel(0), 
    36     mAccountName(),
    38     mAccountName(),
    37     mUnreadCount(0)
    39     mUnreadCount(0),
       
    40     mBackgroundLayoutItem(0)
    38 {
    41 {
    39     NM_FUNCTION;
    42     NM_FUNCTION;
    40 }
    43 }
    41 
    44 
    42 /*!
    45 /*!
    43  Destructor
    46  Destructor
    44  */
    47  */
    45 NmHsWidgetTitleRow::~NmHsWidgetTitleRow()
    48 NmHsWidgetTitleRow::~NmHsWidgetTitleRow()
    46 {
    49 {
    47     NM_FUNCTION;
    50     NM_FUNCTION; 
    48 }
    51 }
       
    52 
       
    53 /*!
       
    54  \fn QPainterPath NmHsWidgetTitleRow::shape()
       
    55 
       
    56  Called by home screen fw to check widget boundaries, needed to draw
       
    57  outside widget boundingRect.
       
    58  /return QPainterPath path describing actual boundaries of widget 
       
    59   including child items
       
    60  */
       
    61 QPainterPath NmHsWidgetTitleRow::shape() const
       
    62 {
       
    63     NM_FUNCTION;
       
    64     
       
    65     QPainterPath path;
       
    66     path.setFillRule(Qt::WindingFill);
       
    67     
       
    68     path.addRect(this->geometry());
       
    69     if (mMailboxIcon){
       
    70         path.addRect(mMailboxIcon->geometry());
       
    71     }    
       
    72     return path.simplified();
       
    73 }
       
    74 
       
    75 /*
       
    76  Setup email row ui
       
    77   Must be called after constructor.
       
    78    /return true if loading succeeded, otherwise false. False indicates that object is unusable.
       
    79  */
       
    80 bool NmHsWidgetTitleRow::setupUI(HbDocumentLoader &loader)
       
    81     {
       
    82     NM_FUNCTION;
       
    83 
       
    84     if(!loadDocML(loader) || !setupGraphics()){
       
    85         return false;
       
    86     }
       
    87     return true;
       
    88     }
    49 
    89 
    50 /*!
    90 /*!
    51  Loads layout data and child items from docml file. Must be called after constructor.
    91  Loads layout data and child items from docml file. Must be called after constructor.
    52  /return true if loading succeeded, otherwise false. False indicates that object is unusable
    92  /return true if loading succeeded, otherwise false. False indicates that object is unusable
    53  */
    93  */
    54 bool NmHsWidgetTitleRow::loadDocML()
    94 bool NmHsWidgetTitleRow::loadDocML(HbDocumentLoader &loader)
    55 {
    95 {
    56     NM_FUNCTION;
    96     NM_FUNCTION;
    57     QT_TRY{
    97     QT_TRY{
    58         // Use document loader to load the contents
       
    59         HbDocumentLoader loader;
       
    60         bool ok(false);
       
    61         loader.load(KNmHsWidgetTitleRowDocML, &ok);
       
    62         if (!ok) {
       
    63             NM_ERROR(1,"NmHsWidgetTitleRow::loadDocML Fail @ loader");
       
    64             return false; //failure
       
    65         }
       
    66     
       
    67         //Create layout
    98         //Create layout
    68         QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
    99         QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
    69     
   100     
    70         layout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
   101         layout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
    71             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
   102             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
    90     
   121     
    91         if (!mMailboxIcon || !mMailboxInfo || !mUnreadCountLabel || !mCollapseExpIconLabel) {
   122         if (!mMailboxIcon || !mMailboxInfo || !mUnreadCountLabel || !mCollapseExpIconLabel) {
    92             NM_ERROR(1,"NmHsWidgetTitleRow::loadDocML Fail @ icons & labels");
   123             NM_ERROR(1,"NmHsWidgetTitleRow::loadDocML Fail @ icons & labels");
    93             return false;
   124             return false;
    94         }
   125         }
    95     
   126 		
    96         //Expand collapse button
   127 		//Expand collapse button
    97         connect(mCollapseExpIconLabel, SIGNAL(clicked()), this, SIGNAL(expandCollapseButtonPressed()));
   128         connect(mCollapseExpIconLabel, SIGNAL(clicked()), this, SIGNAL(expandCollapseButtonPressed()));
       
   129 		
       
   130         return true;
       
   131     }
       
   132     QT_CATCH(...){
       
   133         return false;
       
   134     }
       
   135 }
       
   136 
       
   137 /*
       
   138  Setup graphics that cannot be loaded from docml.
       
   139   /return true if loading succeeded, otherwise false. False indicates that object is unusable.
       
   140  */
       
   141 bool NmHsWidgetTitleRow::setupGraphics()
       
   142 {
       
   143     NM_FUNCTION;
       
   144     
       
   145     HbFrameDrawer* backgroundFrameDrawer = 0;
       
   146     QT_TRY{
       
   147         //pressed background
       
   148         backgroundFrameDrawer = new HbFrameDrawer("qtg_fr_hsitems_pressed", HbFrameDrawer::NinePieces);
       
   149         mBackgroundLayoutItem = new HbFrameItem( backgroundFrameDrawer );
       
   150         setBackgroundItem( mBackgroundLayoutItem );
       
   151 		mBackgroundLayoutItem->hide();
    98         
   152         
    99         //set fonts color
   153         //set fonts color
   100         setFontsColor(false);
   154 		setHighlighedFontsColor(false);
   101 
   155 
   102         return true;
   156         return true;
   103     }
   157     }
   104     QT_CATCH(...){
   158     QT_CATCH(...){
       
   159         if(!mBackgroundLayoutItem && backgroundFrameDrawer){
       
   160             delete backgroundFrameDrawer;
       
   161             backgroundFrameDrawer = NULL;
       
   162         }
       
   163 
   105         return false;
   164         return false;
   106     }
   165     }
   107 }
   166     
       
   167 }
       
   168 
   108 
   169 
   109 /*!
   170 /*!
   110  Slot for updating account name, calls updateData to update ui.
   171  Slot for updating account name, calls updateData to update ui.
   111  */
   172  */
   112 void NmHsWidgetTitleRow::updateAccountName(const QString& accountName)
   173 void NmHsWidgetTitleRow::updateAccountName(const QString& accountName)
   159 {
   220 {
   160     NM_FUNCTION;
   221     NM_FUNCTION;
   161     mMailboxInfo->setPlainText(mAccountName);
   222     mMailboxInfo->setPlainText(mAccountName);
   162     //If unread count is -1, hide the unread count label completely.
   223     //If unread count is -1, hide the unread count label completely.
   163     //This indicates that there are no mails at all (or the initial sync is not done)
   224     //This indicates that there are no mails at all (or the initial sync is not done)
   164     if (mUnreadCount != -1) {
   225     if (mUnreadCount >= 0) {
   165         QString unreadCount(hbTrId("txt_mail_widget_list_l1").arg(mUnreadCount));
   226         QString unreadCount(hbTrId("txt_mail_widget_list_l1").arg(mUnreadCount));
   166         mUnreadCountLabel->setPlainText(unreadCount);
   227         mUnreadCountLabel->setPlainText(unreadCount);
   167         mUnreadCountLabel->setVisible(true);
   228         QFontMetrics fm(mUnreadCountLabel->font());
       
   229         qreal textWidth = fm.width(unreadCount);
       
   230         mUnreadCountLabel->setMaximumWidth(textWidth);
   168     }
   231     }
   169     else {
   232     else {
   170         mUnreadCountLabel->setVisible(false);
   233         mUnreadCountLabel->setMaximumWidth(0);
   171     }
   234     }
   172 }
   235 }
   173 
   236 
   174 /*!
   237 /*!
   175     sets fonts color.
   238     sets fonts color.
   176     param bool pressed indicates if row is pressed down or not
   239     /param bool pressed indicates if row is pressed down or not
   177 */
   240 */
   178 void NmHsWidgetTitleRow::setFontsColor( bool pressed )
   241 void NmHsWidgetTitleRow::setHighlighedFontsColor( bool pressed )
   179     {
   242     {
   180     NM_FUNCTION;
   243     NM_FUNCTION;
   181     QColor newFontColor;
   244     QColor newFontColor;
   182     
   245     
   183     if(pressed){
   246     if(pressed){
   189  
   252  
   190     mMailboxInfo->setTextColor(newFontColor);
   253     mMailboxInfo->setTextColor(newFontColor);
   191     mUnreadCountLabel->setTextColor(newFontColor);
   254     mUnreadCountLabel->setTextColor(newFontColor);
   192     }
   255     }
   193 
   256 
       
   257 /*!
       
   258     change background pressed state
       
   259     /param bool show if true then shown, false hide
       
   260 */
       
   261 void NmHsWidgetTitleRow::showHighlight( bool show )
       
   262     {
       
   263     NM_FUNCTION;;
       
   264     
       
   265     if(show){
       
   266         mBackgroundLayoutItem->show();
       
   267     }
       
   268     else{
       
   269         mBackgroundLayoutItem->hide();
       
   270     }
       
   271     }
   194 
   272 
   195 /*!
   273 /*!
   196  mousePressEvent(QGraphicsSceneMouseEvent *event)
   274  mousePressEvent(QGraphicsSceneMouseEvent *event)
   197  */
   275  */
   198 void NmHsWidgetTitleRow::mousePressEvent(QGraphicsSceneMouseEvent *event)
   276 void NmHsWidgetTitleRow::mousePressEvent(QGraphicsSceneMouseEvent *event)
   199 {
   277 {
   200     NM_FUNCTION;
   278     NM_FUNCTION;
   201     Q_UNUSED(event); 
   279 	
   202     setFontsColor(true);
   280 	//to avoid opening email account mistakenly  when tabbing expand/collapse button
       
   281 	//we dont handle events that are on the top, down or right side of the button
       
   282     if(event->pos().x() < mUnreadCountLabel->geometry().right())
       
   283         {
       
   284         setHighlighedFontsColor(true);
       
   285         showHighlight(true);
       
   286         }
   203 }
   287 }
   204 
   288 
   205 /*!
   289 /*!
   206     mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   290     mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   207 */
   291 */
   208 void NmHsWidgetTitleRow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   292 void NmHsWidgetTitleRow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   209 {
   293 {
   210     NM_FUNCTION;
   294     NM_FUNCTION;
   211     Q_UNUSED(event);
   295 	
   212     setFontsColor(false);
   296 	//to avoid opening email account mistakenly when tabbing expand/collapse button
   213     emit mailboxLaunchTriggered();
   297 	//we dont handle events that are on the top, down or right side of the button
       
   298     if(event->pos().x() < mUnreadCountLabel->geometry().right())
       
   299         {
       
   300         setHighlighedFontsColor(false);
       
   301         showHighlight(false);
       
   302         emit mailboxLaunchTriggered();
       
   303         }
   214 }
   304 }
   215 
   305 
   216 /*
   306 /*
   217  * NmHsWidgetTitleRow::event()
   307  * NmHsWidgetTitleRow::event()
   218  */
   308  */
   219 bool NmHsWidgetTitleRow::event( QEvent *event )
   309 bool NmHsWidgetTitleRow::event( QEvent *event )
   220 {
   310 {
   221     NM_FUNCTION;
   311     NM_FUNCTION;
   222     QEvent::Type eventType = event->type();
   312     QEvent::Type eventType = event->type();
   223     if( eventType == HbEvent::ThemeChanged ){
   313     if( eventType == HbEvent::ThemeChanged ){
   224         setFontsColor(false);
   314         setHighlighedFontsColor(false);
   225         return true;
   315         return true;
   226     }
   316     }
   227     return HbWidget::event(event);
   317     return HbWidget::event(event);
   228 }
   318 }