homescreenapp/stateplugins/hsapplibrarystateplugin/src/hslistviewitem.cpp
changeset 90 3ac3aaebaee5
parent 86 e4f038c420f7
child 97 66b5fe3c07fd
equal deleted inserted replaced
86:e4f038c420f7 90:3ac3aaebaee5
    33 // It is only about paint method.
    33 // It is only about paint method.
    34 
    34 
    35 #ifdef COVERAGE_MEASUREMENT
    35 #ifdef COVERAGE_MEASUREMENT
    36 #pragma CTC SKIP
    36 #pragma CTC SKIP
    37 #endif //COVERAGE_MEASUREMENT
    37 #endif //COVERAGE_MEASUREMENT
    38 void HsProgressBar::paint(QPainter * painter, 
    38 void HsProgressBar::paint(QPainter * painter,
    39         const QStyleOptionGraphicsItem * option, 
    39         const QStyleOptionGraphicsItem * option,
    40         QWidget * widget)
    40         QWidget * widget)
    41 {
    41 {
    42     Q_UNUSED(widget)
    42     Q_UNUSED(widget)
    43     QStyleOptionGraphicsItem pixmapOption(*option);
    43     QStyleOptionGraphicsItem pixmapOption(*option);
    44     foreach (QGraphicsItem *child, childItems()) {
    44     foreach (QGraphicsItem *child, childItems()) {
    45         painter->save();            
    45         painter->save();
    46         painter->translate(child->pos());
    46         painter->translate(child->pos());
    47         pixmapOption.exposedRect = child->boundingRect();
    47         pixmapOption.exposedRect = child->boundingRect();
    48         child->paint(painter, &pixmapOption, 0);
    48         child->paint(painter, &pixmapOption, 0);
    49         
    49 
    50         foreach (QGraphicsItem *child2, child->childItems()) {
    50         foreach (QGraphicsItem *grandChild, child->childItems()) {
    51             if (child2->isVisible()) {
    51             if (grandChild->isVisible()) {
    52                 painter->save();            
    52                 painter->save();
    53                 painter->translate(child2->pos());
    53                 painter->translate(grandChild->pos());
    54                 pixmapOption.exposedRect = child2->boundingRect();
    54                 pixmapOption.exposedRect = grandChild->boundingRect();
    55                 child2->paint(painter, &pixmapOption, 0);
    55                 grandChild->paint(painter, &pixmapOption);
    56                 painter->restore(); 
    56                 painter->restore();
    57             }
    57             }
    58         }
    58         }
    59         painter->restore();
    59         painter->restore();
    60     }
    60     }
    61 }    
    61 }
    62 #ifdef COVERAGE_MEASUREMENT
    62 #ifdef COVERAGE_MEASUREMENT
    63 #pragma CTC ENDSKIP
    63 #pragma CTC ENDSKIP
    64 #endif //COVERAGE_MEASUREMENT
    64 #endif //COVERAGE_MEASUREMENT
    65 
    65 
    66 
    66 void HsProgressBar::setTargetProgressValue(int value)
    67 void HsProgressBar::setTargetProgressValue(int value) {
    67 {
    68     mTargetValue = value;
    68     mTargetValue = value;
    69     if (value > progressValue() && value <= maximum()) {
    69     if (value > progressValue() && value <= maximum()) {
    70         if (!mTimerId) {
    70         if (!mTimerId) {
    71             mTimerId = startTimer(10);
    71             mTimerId = startTimer(10);
    72         }
    72         }
    74         setProgressValue(value);
    74         setProgressValue(value);
    75     }
    75     }
    76 }
    76 }
    77 
    77 
    78 void HsProgressBar::timerEvent(QTimerEvent *event)
    78 void HsProgressBar::timerEvent(QTimerEvent *event)
    79  {
    79 {
    80      if (mTargetValue == progressValue()) {
    80     Q_UNUSED(event);
    81          killTimer(mTimerId);
    81     if (mTargetValue == progressValue()) {
    82          mTimerId = 0;
    82         killTimer(mTimerId);
    83      } else {
    83         mTimerId = 0;
    84          setProgressValue(progressValue()+1);
    84     } else {
    85      }
    85         setProgressValue(progressValue()+1);
       
    86     }
    86  }
    87  }
    87 
    88 
    88 HsListViewItem::HsListViewItem(QGraphicsItem* parent) : 
    89 HsListViewItem::HsListViewItem(QGraphicsItem* parent) :
    89     HbListViewItem(parent), progress(0), isProgress(false)
    90     HbListViewItem(parent), progress(0), isProgress(false)
    90 {   
    91 {
    91     setGraphicsSize(LargeIcon);
    92     setGraphicsSize(LargeIcon);
    92     setStretchingStyle(StretchLandscape);
    93     setStretchingStyle(StretchLandscape);
    93     if (this == prototype()) {
    94     if (this == prototype()) {
    94         HbStyleLoader::registerFilePath(":/layout/hslistviewitem.css");        
    95         HbStyleLoader::registerFilePath(":/layout/hslistviewitem.css");
    95     }
    96     }
    96 }
    97 }
    97 
    98 
    98 HsListViewItem::~HsListViewItem()
    99 HsListViewItem::~HsListViewItem()
    99 {
   100 {
   114         int progresVal = modelIndex().data(
   115         int progresVal = modelIndex().data(
   115                 CaItemModel::UninstalRole).toInt();
   116                 CaItemModel::UninstalRole).toInt();
   116         isProgress = true;
   117         isProgress = true;
   117         if (!progress) {
   118         if (!progress) {
   118             progress = new HsProgressBar(this);
   119             progress = new HsProgressBar(this);
   119             HbStyle::setItemName(progress, "progress"); 
   120             HbStyle::setItemName(progress, "progress");
   120             progress->setRange(0, 100);
   121             progress->setRange(0, 100);
   121             HbEffect::disable(progress);  
   122             HbEffect::disable(progress);
   122             progress->setProgressValue(progresVal);
   123             progress->setProgressValue(progresVal);
   123             repolish();
   124             repolish();
   124             connect(progress, SIGNAL(valueChanged(int)), SLOT(updatePixmapCache()));
   125             connect(progress, SIGNAL(valueChanged(int)), SLOT(updatePixmapCache()));
   125         }
   126         }
   126         progress->setTargetProgressValue(progresVal);
   127         progress->setTargetProgressValue(progresVal);
   130                    HbTextItem* text = (HbTextItem*)item;
   131                    HbTextItem* text = (HbTextItem*)item;
   131                    text->setText(
   132                    text->setText(
   132                            HbParameterLengthLimiter("txt_applib_dblist_uninstalling_1")
   133                            HbParameterLengthLimiter("txt_applib_dblist_uninstalling_1")
   133                            .arg(text->text()));
   134                            .arg(text->text()));
   134                    break;
   135                    break;
   135                } 
   136                }
   136            }
   137            }
   137     } else if (progress) {       
   138     } else if (progress) {
   138         disconnect(progress, SIGNAL(valueChanged()));
   139         disconnect(progress, SIGNAL(valueChanged()));
   139         delete progress;
   140         delete progress;
   140         progress = 0;
   141         progress = 0;
   141         repolish();
   142         repolish();
   142     }
   143     }
   143     // hide text-2 if we have to 
   144     // hide text-2 if we have to
   144     foreach (QGraphicsItem * item, this->childItems()) {
   145     foreach (QGraphicsItem * item, this->childItems()) {
   145         if (HbStyle::itemName(item) == "text-2") {
   146         if (HbStyle::itemName(item) == "text-2") {
   146             item->setVisible(!isProgress);            
   147             item->setVisible(!isProgress);
   147             break;
   148             break;
   148         } 
   149         }
   149     }
   150     }
   150 }
   151 }
   151 
   152 
   152 HbAbstractViewItem*  HsListViewItem::createItem()
   153 HbAbstractViewItem*  HsListViewItem::createItem()
   153 {
   154 {
   154     return new HsListViewItem(*this);
   155     return new HsListViewItem(*this);
   155 }
   156 }
   156 
   157 
   157 
   158 
   158 void HsListViewItem::polish(HbStyleParameters& params)
   159 void HsListViewItem::polish(HbStyleParameters& params)
   159 {       
   160 {
   160     if (isProgress) {
   161     if (isProgress) {
   161         HbStyleLoader::registerFilePath(":/layout/hslistviewitem.widgetml");
   162         HbStyleLoader::registerFilePath(":/layout/hslistviewitem.widgetml");
   162     }
   163     }
   163     HbListViewItem::setProperty("progress", isProgress);
   164     HbListViewItem::setProperty("progress", isProgress);
   164     HbListViewItem::polish(params);   
   165     HbListViewItem::polish(params);
   165     if (isProgress) {
   166     if (isProgress) {
   166         HbStyleLoader::unregisterFilePath(":/layout/hslistviewitem.widgetml");
   167         HbStyleLoader::unregisterFilePath(":/layout/hslistviewitem.widgetml");
   167     }
   168     }
   168 }
   169 }
   169 
   170