emailuis/nmhswidget/src/nmhswidgettitlerow.cpp
changeset 47 f83bd4ae1fe3
parent 43 99bcbff212ad
child 49 00c7ae862740
--- a/emailuis/nmhswidget/src/nmhswidgettitlerow.cpp	Fri Jun 11 16:42:02 2010 +0300
+++ b/emailuis/nmhswidget/src/nmhswidgettitlerow.cpp	Thu Jun 24 14:32:18 2010 +0300
@@ -22,6 +22,8 @@
 #include <HbPushButton>
 #include <HbColorScheme>
 #include <HbEvent>
+#include <hbframedrawer.h>
+#include <hbframeitem.h>
 #include "nmicons.h"
 #include "nmhswidgettitlerow.h"
 #include "nmhswidgetconsts.h"
@@ -34,7 +36,8 @@
     mUnreadCountLabel(0),
     mCollapseExpIconLabel(0), 
     mAccountName(),
-    mUnreadCount(0)
+    mUnreadCount(0),
+    mBackgroundLayoutItem(0)
 {
     NM_FUNCTION;
 }
@@ -44,9 +47,46 @@
  */
 NmHsWidgetTitleRow::~NmHsWidgetTitleRow()
 {
+    NM_FUNCTION; 
+}
+
+/*!
+ \fn QPainterPath NmHsWidgetTitleRow::shape()
+
+ Called by home screen fw to check widget boundaries, needed to draw
+ outside widget boundingRect.
+ /return QPainterPath path describing actual boundaries of widget 
+  including child items
+ */
+QPainterPath NmHsWidgetTitleRow::shape() const
+{
     NM_FUNCTION;
+    
+    QPainterPath path;
+    path.setFillRule(Qt::WindingFill);
+    
+    path.addRect(this->geometry());
+    if (mMailboxIcon){
+        path.addRect(mMailboxIcon->geometry());
+    }    
+    return path.simplified();
 }
 
+/*
+ Setup email row ui
+  Must be called after constructor.
+   /return true if loading succeeded, otherwise false. False indicates that object is unusable.
+ */
+bool NmHsWidgetTitleRow::setupUI()
+    {
+    NM_FUNCTION;
+
+    if(!loadDocML() || !setupGraphics()){
+        return false;
+    }
+    return true;
+    }
+
 /*!
  Loads layout data and child items from docml file. Must be called after constructor.
  /return true if loading succeeded, otherwise false. False indicates that object is unusable
@@ -92,13 +132,10 @@
             NM_ERROR(1,"NmHsWidgetTitleRow::loadDocML Fail @ icons & labels");
             return false;
         }
-    
-        //Expand collapse button
+		
+		//Expand collapse button
         connect(mCollapseExpIconLabel, SIGNAL(clicked()), this, SIGNAL(expandCollapseButtonPressed()));
-        
-        //set fonts color
-        setFontsColor(false);
-
+		
         return true;
     }
     QT_CATCH(...){
@@ -106,6 +143,39 @@
     }
 }
 
+/*
+ Setup graphics that cannot be loaded from docml.
+  /return true if loading succeeded, otherwise false. False indicates that object is unusable.
+ */
+bool NmHsWidgetTitleRow::setupGraphics()
+    {
+    NM_FUNCTION;
+    
+    HbFrameDrawer* backgroundFrameDrawer = 0;
+    QT_TRY{
+        //pressed background
+        backgroundFrameDrawer = new HbFrameDrawer("qtg_fr_hsitems_pressed", HbFrameDrawer::NinePieces);
+        mBackgroundLayoutItem = new HbFrameItem( backgroundFrameDrawer );
+        setBackgroundItem( mBackgroundLayoutItem );
+		mBackgroundLayoutItem->hide();
+        
+        //set fonts color
+		setHighlighedFontsColor(false);
+
+        return true;
+    }
+    QT_CATCH(...){
+        if(!mBackgroundLayoutItem && backgroundFrameDrawer){
+            delete backgroundFrameDrawer;
+            backgroundFrameDrawer = NULL;
+        }
+
+        return false;
+    }
+    
+    }
+
+
 /*!
  Slot for updating account name, calls updateData to update ui.
  */
@@ -173,9 +243,9 @@
 
 /*!
     sets fonts color.
-    param bool pressed indicates if row is pressed down or not
+    /param bool pressed indicates if row is pressed down or not
 */
-void NmHsWidgetTitleRow::setFontsColor( bool pressed )
+void NmHsWidgetTitleRow::setHighlighedFontsColor( bool pressed )
     {
     NM_FUNCTION;
     QColor newFontColor;
@@ -191,6 +261,21 @@
     mUnreadCountLabel->setTextColor(newFontColor);
     }
 
+/*!
+    change background pressed state
+    /param bool show if true then shown, false hide
+*/
+void NmHsWidgetTitleRow::showHighlight( bool show )
+    {
+    NM_FUNCTION;;
+    
+    if(show){
+        mBackgroundLayoutItem->show();
+    }
+    else{
+        mBackgroundLayoutItem->hide();
+    }
+    }
 
 /*!
  mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -198,8 +283,14 @@
 void NmHsWidgetTitleRow::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
     NM_FUNCTION;
-    Q_UNUSED(event); 
-    setFontsColor(true);
+	
+	//to avoid opening email account mistakenly  when tabbing expand/collapse button
+	//we dont handle events that are on the top, down or right side of the button
+    if(event->pos().x() < mUnreadCountLabel->geometry().right())
+        {
+        setHighlighedFontsColor(true);
+        showHighlight(true);
+        }
 }
 
 /*!
@@ -208,9 +299,15 @@
 void NmHsWidgetTitleRow::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
     NM_FUNCTION;
-    Q_UNUSED(event);
-    setFontsColor(false);
-    emit mailboxLaunchTriggered();
+	
+	//to avoid opening email account mistakenly when tabbing expand/collapse button
+	//we dont handle events that are on the top, down or right side of the button
+    if(event->pos().x() < mUnreadCountLabel->geometry().right())
+        {
+        setHighlighedFontsColor(false);
+        showHighlight(false);
+        emit mailboxLaunchTriggered();
+        }
 }
 
 /*
@@ -221,7 +318,7 @@
     NM_FUNCTION;
     QEvent::Type eventType = event->type();
     if( eventType == HbEvent::ThemeChanged ){
-        setFontsColor(false);
+        setHighlighedFontsColor(false);
         return true;
     }
     return HbWidget::event(event);