homescreenapp/stateplugins/hsapplibrarystateplugin/src/hslistviewitem.cpp
changeset 86 e4f038c420f7
parent 71 1db7cc813a4e
child 90 3ac3aaebaee5
equal deleted inserted replaced
81:7dd137878ff8 86:e4f038c420f7
    16  */
    16  */
    17 
    17 
    18 #include <hbnamespace.h>
    18 #include <hbnamespace.h>
    19 #include <HbAbstractItemView>
    19 #include <HbAbstractItemView>
    20 #include <HbStyleLoader>
    20 #include <HbStyleLoader>
       
    21 #include <HbTextItem>
       
    22 #include <HbParameterLengthLimiter>
    21 #include <QPainter>
    23 #include <QPainter>
    22 #include <caitemmodel.h>
    24 #include <caitemmodel.h>
    23 #include "hsmenuitemmodel.h"
    25 #include "hsmenuitemmodel.h"
    24 
    26 
    25 #include "hslistviewitem.h"
    27 #include "hslistviewitem.h"
    26 
    28 
    27 
    29 
    28 // TODO: this is only temporary class for show progress bar.
    30 // TODO: this is only temporary class for show progress bar.
    29 // It should be remove when fix from orbit will be in official platfrom.
    31 // It should be remove when fix from orbit will be in official platfrom.
    30 // Remove it from header too.
    32 // Remove it from header too.
       
    33 // It is only about paint method.
    31 
    34 
    32 #ifdef COVERAGE_MEASUREMENT
    35 #ifdef COVERAGE_MEASUREMENT
    33 #pragma CTC SKIP
    36 #pragma CTC SKIP
    34 #endif //COVERAGE_MEASUREMENT
    37 #endif //COVERAGE_MEASUREMENT
    35 void HsProgressBar::paint(QPainter * painter, 
    38 void HsProgressBar::paint(QPainter * painter, 
    59 #ifdef COVERAGE_MEASUREMENT
    62 #ifdef COVERAGE_MEASUREMENT
    60 #pragma CTC ENDSKIP
    63 #pragma CTC ENDSKIP
    61 #endif //COVERAGE_MEASUREMENT
    64 #endif //COVERAGE_MEASUREMENT
    62 
    65 
    63 
    66 
       
    67 void HsProgressBar::setTargetProgressValue(int value) {
       
    68     mTargetValue = value;
       
    69     if (value > progressValue() && value <= maximum()) {
       
    70         if (!mTimerId) {
       
    71             mTimerId = startTimer(10);
       
    72         }
       
    73     } else {
       
    74         setProgressValue(value);
       
    75     }
       
    76 }
       
    77 
       
    78 void HsProgressBar::timerEvent(QTimerEvent *event)
       
    79  {
       
    80      if (mTargetValue == progressValue()) {
       
    81          killTimer(mTimerId);
       
    82          mTimerId = 0;
       
    83      } else {
       
    84          setProgressValue(progressValue()+1);
       
    85      }
       
    86  }
       
    87 
    64 HsListViewItem::HsListViewItem(QGraphicsItem* parent) : 
    88 HsListViewItem::HsListViewItem(QGraphicsItem* parent) : 
    65     HbListViewItem(parent), progress(0), isProgress(false)
    89     HbListViewItem(parent), progress(0), isProgress(false)
    66 {   
    90 {   
    67     setGraphicsSize(LargeIcon);
    91     setGraphicsSize(LargeIcon);
       
    92     setStretchingStyle(StretchLandscape);
    68     if (this == prototype()) {
    93     if (this == prototype()) {
    69         HbStyleLoader::registerFilePath(":/layout/hslistviewitem.css");        
    94         HbStyleLoader::registerFilePath(":/layout/hslistviewitem.css");        
    70     }
    95     }
    71 }
    96 }
    72 
    97 
    84 
   109 
    85     EntryFlags flags = modelIndex().data(
   110     EntryFlags flags = modelIndex().data(
    86         CaItemModel::FlagsRole).value<EntryFlags> ();
   111         CaItemModel::FlagsRole).value<EntryFlags> ();
    87     isProgress = false;
   112     isProgress = false;
    88     if (flags & UninstallEntryFlag) {
   113     if (flags & UninstallEntryFlag) {
       
   114         int progresVal = modelIndex().data(
       
   115                 CaItemModel::UninstalRole).toInt();
    89         isProgress = true;
   116         isProgress = true;
    90         if (!progress) {
   117         if (!progress) {
    91             progress = new HsProgressBar(this);
   118             progress = new HsProgressBar(this);
    92             HbStyle::setItemName(progress, "progress"); 
   119             HbStyle::setItemName(progress, "progress"); 
    93             progress->setRange(0, 100);
   120             progress->setRange(0, 100);
    94             HbEffect::disable(progress);  
   121             HbEffect::disable(progress);  
       
   122             progress->setProgressValue(progresVal);
    95             repolish();
   123             repolish();
       
   124             connect(progress, SIGNAL(valueChanged(int)), SLOT(updatePixmapCache()));
    96         }
   125         }
    97         int progresVal = modelIndex().data(
   126         progress->setTargetProgressValue(progresVal);
    98                 CaItemModel::UninstalRole).toInt();
   127         // TODO, consider moving this logic to model
    99         progress->setProgressValue(progresVal);
   128         foreach (QGraphicsItem * item, this->childItems()) {
       
   129                if (HbStyle::itemName(item) == "text-1") {
       
   130                    HbTextItem* text = (HbTextItem*)item;
       
   131                    text->setText(
       
   132                            HbParameterLengthLimiter("txt_applib_dblist_uninstalling_1")
       
   133                            .arg(text->text()));
       
   134                    break;
       
   135                } 
       
   136            }
   100     } else if (progress) {       
   137     } else if (progress) {       
       
   138         disconnect(progress, SIGNAL(valueChanged()));
   101         delete progress;
   139         delete progress;
   102         progress = 0;
   140         progress = 0;
   103         repolish();
   141         repolish();
   104     }
   142     }
   105     // hide text-2 if we have to 
   143     // hide text-2 if we have to