emailuis/nmailuiwidgets/src/nmattachmentlistitem.cpp
changeset 65 478bc57ad291
parent 59 16ed8d08d0b1
child 66 084b5b1f02a7
equal deleted inserted replaced
59:16ed8d08d0b1 65:478bc57ad291
    17 
    17 
    18 #include "nmailuiwidgetsheaders.h"
    18 #include "nmailuiwidgetsheaders.h"
    19 
    19 
    20 static const QString FILE_PATH_WIDGETML = ":nmattachmentlistitem.widgetml";
    20 static const QString FILE_PATH_WIDGETML = ":nmattachmentlistitem.widgetml";
    21 static const QString FILE_PATH_CSS = ":nmattachmentlistitem.css";
    21 static const QString FILE_PATH_CSS = ":nmattachmentlistitem.css";
       
    22 static const QString LIST_ITEM_BG_FRAME_NORMAL ("qtg_fr_list_normal");
       
    23 static const QString LIST_ITEM_BG_FRAME_PRESSED("qtg_fr_list_pressed");
    22 
    24 
    23 static const int PROGRESSBAR_MIN = 0; 
    25 static const int PROGRESSBAR_MIN = 0; 
    24 static const int PROGRESSBAR_MAX = 100;
    26 static const int PROGRESSBAR_MAX = 100;
    25 static const int PROGRESSBAR_HIDE_COUNTDOWN = 500;
    27 static const int PROGRESSBAR_HIDE_COUNTDOWN = 500;
    26 
    28 
    41  */
    43  */
    42 NmAttachmentListItem::NmAttachmentListItem(QGraphicsItem *parent)
    44 NmAttachmentListItem::NmAttachmentListItem(QGraphicsItem *parent)
    43     : HbWidget( parent ),
    45     : HbWidget( parent ),
    44       mFileNameText(NULL),
    46       mFileNameText(NULL),
    45       mFileSizeText(NULL),
    47       mFileSizeText(NULL),
    46       mProgressBar(NULL)
    48       mProgressBar(NULL),
       
    49       mBackGround(NULL)
    47 {
    50 {
    48     NM_FUNCTION;
    51     NM_FUNCTION;
    49     
    52     
    50     init( );
    53     init( );
    51 	
    54 	
    52     // Informs GestureFramework that NmAttachmentListItem widget is interested 
    55     // Informs GestureFramework that NmAttachmentListItem widget is interested 
    53     // Tap gesture and TapAndHold gesture.
    56     // Tap gesture and TapAndHold gesture.
    54     grabGesture(Qt::TapGesture);
    57     grabGesture(Qt::TapGesture);
       
    58     HbEffect::add("mailAttachmentWidget", "listviewitem_press", "pressed");
       
    59     HbEffect::add("mailAttachmentWidget", "listviewitem_release", "released");
    55 }
    60 }
    56 
    61 
    57 /*!
    62 /*!
    58     Setter for items text color override. This fucntion can be used
    63     Setter for items text color override. This fucntion can be used
    59     if theme background is not used and text needs to be shown in diferent color.
    64     if theme background is not used and text needs to be shown in diferent color.
   183 */
   188 */
   184 void NmAttachmentListItem::constructUi()
   189 void NmAttachmentListItem::constructUi()
   185 {
   190 {
   186     NM_FUNCTION;
   191     NM_FUNCTION;
   187     
   192     
       
   193     //background
       
   194     QScopedPointer<HbFrameItem> backGround(new HbFrameItem(this));
       
   195     backGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
       
   196     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   197     setBackgroundItem(backGround.data());
       
   198     // ownership was transferred to base class
       
   199     mBackGround = backGround.take();
       
   200     
       
   201     
   188     //construct default ui.    
   202     //construct default ui.    
   189     HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML);
   203     HbStyleLoader::registerFilePath(FILE_PATH_WIDGETML);
   190     HbStyleLoader::registerFilePath(FILE_PATH_CSS);
   204     HbStyleLoader::registerFilePath(FILE_PATH_CSS);
   191     
   205     
   192     mFileNameText = new HbTextItem(this); 
   206     
   193     mFileNameText->setObjectName("nmattachmentlistitem_filenametext");
   207     QScopedPointer<HbTextItem> fileNameText(new HbTextItem(this));
   194     HbStyle::setItemName( mFileNameText, "filename" );    
   208     fileNameText->setObjectName("nmattachmentlistitem_filenametext");
   195     mFileNameText->setElideMode(Qt::ElideRight);
   209     HbStyle::setItemName( fileNameText.data(), "filename" );  
   196 
   210     fileNameText->setElideMode(Qt::ElideRight);
   197     mFileSizeText = new HbTextItem(this); 
   211     
   198     mFileSizeText->setObjectName("nmattachmentlistitem_filenamesize");
   212     
   199     HbStyle::setItemName( mFileSizeText, "filesize" );
   213     QScopedPointer<HbTextItem> fileSizeText(new HbTextItem(this));
   200     mFileSizeText->setElideMode(Qt::ElideNone);
   214     fileSizeText->setObjectName("nmattachmentlistitem_filenamesize");
       
   215     HbStyle::setItemName( fileSizeText.data(), "filesize" );
       
   216     fileSizeText->setElideMode(Qt::ElideNone);
       
   217     
       
   218     // ownership transferred to this object
       
   219     mFileSizeText = fileSizeText.take(); 
       
   220     mFileNameText = fileNameText.take();
   201 }
   221 }
   202 
   222 
   203 
   223 
   204 /*!
   224 /*!
   205     Hides the download progress bar
   225     Hides the download progress bar
   218 
   238 
   219 
   239 
   220 /*!
   240 /*!
   221     This function handles gestures
   241     This function handles gestures
   222  */
   242  */
       
   243 
   223 void NmAttachmentListItem::gestureEvent(QGestureEvent *event)
   244 void NmAttachmentListItem::gestureEvent(QGestureEvent *event)
   224 {
   245 {
   225     NM_FUNCTION;
   246     NM_FUNCTION;
   226     
   247     
   227     if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   248     if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   228         switch(tap->tapStyleHint()) {
   249         switch(tap->tapStyleHint()) {
   229         case HbTapGesture::Tap:
   250         case HbTapGesture::Tap: 
   230             {
   251             {
   231                 if (tap->state() == Qt::GestureFinished) {
   252                 Qt::GestureState state = tap->state();
       
   253                 HbInstantFeedback::play(HbFeedback::Basic);
       
   254                 setPressed(true);
       
   255                 if (state == Qt::GestureFinished) {
   232                     emit itemActivated();
   256                     emit itemActivated();
       
   257                     setPressed(false);
       
   258                 }
       
   259                 else if (state == Qt::GestureCanceled) {
       
   260                     setPressed(false);
   233                 }
   261                 }
   234              }
   262              }
   235              break;
   263              break;
   236             
   264             
   237          case HbTapGesture::TapAndHold:
   265          case HbTapGesture::TapAndHold:
   238              {
   266              {
   239                  if (tap->state() == Qt::GestureFinished) {
       
   240                  emit itemLongPressed(event->mapToGraphicsScene(tap->position()));
   267                  emit itemLongPressed(event->mapToGraphicsScene(tap->position()));
   241                  }
   268                  setPressed(false);
   242              }    
   269              }    
   243              break;
   270              break;
   244         }
   271         }
   245     }
   272     }
   246     else {
   273     else {
   247            HbWidget::gestureEvent(event);
   274            HbWidget::gestureEvent(event);
   248     }
   275     }
   249 }
   276 }
   250 
   277 
   251 
   278 /*!
       
   279     Sets the effect of the item when tapping it
       
   280 */
       
   281 void NmAttachmentListItem::setPressed(bool pressed)
       
   282 {
       
   283     if (pressed) {
       
   284         setProperty("state", "pressed");
       
   285         mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_PRESSED);
       
   286         HbEffect::cancel(mBackGround, "released");
       
   287         HbEffect::start(mBackGround, "mailAttachmentWidget", "pressed");
       
   288 
       
   289     }
       
   290     else {
       
   291         setProperty("state", "normal");
       
   292         mBackGround->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME_NORMAL);
       
   293         HbEffect::cancel(mBackGround, "pressed");
       
   294         HbEffect::start(mBackGround, "mailAttachmentWidget", "released");
       
   295     }    
       
   296 }