emailuis/nmhswidget/src/nmhswidgettitlerow.cpp
changeset 65 478bc57ad291
parent 54 997a02608b3a
child 75 47d84de1c893
equal deleted inserted replaced
59:16ed8d08d0b1 65:478bc57ad291
    22 #include <hbpushbutton.h>
    22 #include <hbpushbutton.h>
    23 #include <hbcolorscheme.h>
    23 #include <hbcolorscheme.h>
    24 #include <hbevent.h>
    24 #include <hbevent.h>
    25 #include <hbframedrawer.h>
    25 #include <hbframedrawer.h>
    26 #include <hbframeitem.h>
    26 #include <hbframeitem.h>
       
    27 #include <hbtapgesture.h>
       
    28 #include <hbinstantfeedback.h>
    27 #include "nmicons.h"
    29 #include "nmicons.h"
    28 #include "nmhswidgettitlerow.h"
    30 #include "nmhswidgettitlerow.h"
    29 #include "nmhswidgetconsts.h"
    31 #include "nmhswidgetconsts.h"
    30 #include "emailtrace.h"
    32 #include "emailtrace.h"
    31 
    33 
    32 NmHsWidgetTitleRow::NmHsWidgetTitleRow(QGraphicsItem *parent, Qt::WindowFlags flags) :
    34 NmHsWidgetTitleRow::NmHsWidgetTitleRow(QGraphicsItem *parent, Qt::WindowFlags flags) :
    33     HbWidget(parent, flags), 
    35     HbWidget(parent, flags), 
       
    36     mContainer(0),
    34     mMailboxIcon(0), 
    37     mMailboxIcon(0), 
    35     mMailboxInfo(0), 
    38     mMailboxInfo(0), 
    36     mUnreadCountLabel(0),
    39     mUnreadCountLabel(0),
    37     mCollapseExpIconLabel(0), 
    40     mCollapseExpIconLabel(0), 
    38     mAccountName(),
    41     mAccountName(),
    39     mUnreadCount(0),
    42     mUnreadCount(0),
    40     mBackgroundLayoutItem(0)
    43     mBackgroundLayoutItem(0)
    41 {
    44 {
    42     NM_FUNCTION;
    45     NM_FUNCTION;
       
    46     grabGesture(Qt::TapGesture);
    43 }
    47 }
    44 
    48 
    45 /*!
    49 /*!
    46  Destructor
    50  Destructor
    47  */
    51  */
    62 {
    66 {
    63     NM_FUNCTION;
    67     NM_FUNCTION;
    64     
    68     
    65     QPainterPath path;
    69     QPainterPath path;
    66     path.setFillRule(Qt::WindingFill);
    70     path.setFillRule(Qt::WindingFill);
    67     
    71     if (mContainer){
    68     path.addRect(this->geometry());
    72         path.addRect(mContainer->geometry());
       
    73     }
    69     if (mMailboxIcon){
    74     if (mMailboxIcon){
    70         path.addRect(mMailboxIcon->geometry());
    75         path.addRect(mMailboxIcon->geometry());
    71     }    
    76     }    
    72     return path.simplified();
    77     return path.simplified();
    73 }
    78 }
    74 
    79 
       
    80 /*!
       
    81  \fn qreal NmHsWidgetTitleRow::containerHeight()
       
    82 
       
    83  /return qreal defining title row container height in pixels
       
    84  */
       
    85 qreal NmHsWidgetTitleRow::containerHeight()
       
    86 {
       
    87     if (mContainer){
       
    88         return mContainer->preferredHeight();
       
    89     }
       
    90     return 0;
       
    91 }
       
    92 
    75 /*
    93 /*
    76  Setup email row ui
    94  Setup email row ui
    77   Must be called after constructor.
    95   Must be called after constructor.
    78    /return true if loading succeeded, otherwise false. False indicates that object is unusable.
    96    /return true if loading succeeded, otherwise false. False indicates that object is unusable.
    79  */
    97  */
    93  */
   111  */
    94 bool NmHsWidgetTitleRow::loadDocML(HbDocumentLoader &loader)
   112 bool NmHsWidgetTitleRow::loadDocML(HbDocumentLoader &loader)
    95 {
   113 {
    96     NM_FUNCTION;
   114     NM_FUNCTION;
    97     QT_TRY{
   115     QT_TRY{
    98         //Create layout
       
    99         QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
       
   100     
       
   101         layout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
       
   102             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
       
   103         layout->setSpacing(KNmHsWidgetContentsMargin);
       
   104         setLayout(layout); //pass the ownership
       
   105     
       
   106         // find container widget
   116         // find container widget
   107         QGraphicsWidget *container = loader.findWidget(KNmHsWidgetTitleRowContainer);
   117         mContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetTitleRowContainer));
   108         if (!container) {
   118         if (!mContainer) {
   109             NM_ERROR(1,"NmHsWidgetTitleRow::loadDocML Fail @ container");
   119             NM_ERROR(1,"NmHsWidgetTitleRow::loadDocML Fail @ container");
   110             return false;
   120             return false;
   111         }
   121         }
   112         layout->addItem(container);
       
   113     
   122     
   114         //child items possible to update
   123         //child items possible to update
   115         mMailboxIcon = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxIcon));
   124         mMailboxIcon = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxIcon));
   116         mMailboxInfo = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxNameLabel));
   125         mMailboxInfo = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxNameLabel));
   117         mUnreadCountLabel = static_cast<HbLabel*> (loader.findWidget(
   126         mUnreadCountLabel = static_cast<HbLabel*> (loader.findWidget(
   145     HbFrameDrawer* backgroundFrameDrawer = 0;
   154     HbFrameDrawer* backgroundFrameDrawer = 0;
   146     QT_TRY{
   155     QT_TRY{
   147         //pressed background
   156         //pressed background
   148         backgroundFrameDrawer = new HbFrameDrawer("qtg_fr_hsitems_pressed", HbFrameDrawer::NinePieces);
   157         backgroundFrameDrawer = new HbFrameDrawer("qtg_fr_hsitems_pressed", HbFrameDrawer::NinePieces);
   149         mBackgroundLayoutItem = new HbFrameItem( backgroundFrameDrawer );
   158         mBackgroundLayoutItem = new HbFrameItem( backgroundFrameDrawer );
   150         setBackgroundItem( mBackgroundLayoutItem );
   159         mContainer->setBackgroundItem( mBackgroundLayoutItem );
   151 		mBackgroundLayoutItem->hide();
   160 		mBackgroundLayoutItem->hide();
   152         
   161         
   153         //set fonts color
   162         //set fonts color
   154 		setHighlighedFontsColor(false);
   163 		setHighlighedFontsColor(false);
   155 
   164 		
       
   165 		//to get gestures
       
   166 		setGeometry(mContainer->childrenBoundingRect());
       
   167 		
   156         return true;
   168         return true;
   157     }
   169     }
   158     QT_CATCH(...){
   170     QT_CATCH(...){
   159         if(!mBackgroundLayoutItem && backgroundFrameDrawer){
   171         if(!mBackgroundLayoutItem && backgroundFrameDrawer){
   160             delete backgroundFrameDrawer;
   172             delete backgroundFrameDrawer;
   163 
   175 
   164         return false;
   176         return false;
   165     }
   177     }
   166     
   178     
   167 }
   179 }
   168 
       
   169 
   180 
   170 /*!
   181 /*!
   171  Slot for updating account name, calls updateData to update ui.
   182  Slot for updating account name, calls updateData to update ui.
   172  */
   183  */
   173 void NmHsWidgetTitleRow::updateAccountName(const QString& accountName)
   184 void NmHsWidgetTitleRow::updateAccountName(const QString& accountName)
   268     else{
   279     else{
   269         mBackgroundLayoutItem->hide();
   280         mBackgroundLayoutItem->hide();
   270     }
   281     }
   271     }
   282     }
   272 
   283 
   273 /*!
   284 /*
   274  mousePressEvent(QGraphicsSceneMouseEvent *event)
   285  * NmHsWidgetTitleRow::gestureEvent(QGestureEvent *event)
   275  */
   286  */
   276 void NmHsWidgetTitleRow::mousePressEvent(QGraphicsSceneMouseEvent *event)
   287 void NmHsWidgetTitleRow::gestureEvent(QGestureEvent *event)
   277 {
   288 {
   278     NM_FUNCTION;
   289     NM_FUNCTION;
   279 	
   290     
   280 	//to avoid opening email account mistakenly  when tabbing expand/collapse button
   291     if(!event){
   281 	//we dont handle events that are on the top, down or right side of the button
   292         return;
   282     if(event->pos().x() < mUnreadCountLabel->geometry().right())
   293     }    
   283         {
   294     HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   284         setHighlighedFontsColor(true);
   295     if(!gesture){
   285         showHighlight(true);
   296         return;
       
   297     }
       
   298     //to avoid opening email account mistakenly  when tabbing expand/collapse button
       
   299     //we dont handle events that are on the top, down or right side of the button
       
   300     QPointF posFromScene = mapFromScene(event->mapToGraphicsScene(gesture->position()));
       
   301     if(posFromScene.x() < mUnreadCountLabel->geometry().right())
       
   302         {    
       
   303         switch (gesture->state()) {
       
   304             case Qt::GestureStarted:
       
   305                 setHighlighedFontsColor(true);
       
   306                 showHighlight(true);
       
   307             break;
       
   308             case Qt::GestureCanceled:
       
   309                 setHighlighedFontsColor(false);
       
   310                 showHighlight(false);
       
   311             break;
       
   312             case Qt::GestureFinished:
       
   313                 setHighlighedFontsColor(false);
       
   314                 showHighlight(false);
       
   315                 if (gesture->tapStyleHint() == HbTapGesture::Tap) {
       
   316                     HbInstantFeedback::play(HbFeedback::BasicItem);
       
   317                     emit mailboxLaunchTriggered();
       
   318                 }
       
   319             break;
       
   320         default: 
       
   321             break;
   286         }
   322         }
   287 }
   323     }
   288 
       
   289 /*!
       
   290     mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   291 */
       
   292 void NmHsWidgetTitleRow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   293 {
       
   294     NM_FUNCTION;
       
   295 	
       
   296 	//to avoid opening email account mistakenly when tabbing expand/collapse button
       
   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         }
       
   304 }
   324 }
   305 
   325 
   306 /*
   326 /*
   307  * NmHsWidgetTitleRow::event()
   327  * NmHsWidgetTitleRow::event()
   308  */
   328  */