src/hbwidgets/itemviews/hbradiobuttonlist.cpp
changeset 7 923ff622b8b9
parent 5 627c4a0fd0e7
child 23 e6ad4ef83b23
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    35 
    35 
    36 //TODO: consider moving these two to proper place (widget params?)
    36 //TODO: consider moving these two to proper place (widget params?)
    37 const int HB_RADIOBUTTONLIST_ITEM_ACTIVATION_TIMER = 150;
    37 const int HB_RADIOBUTTONLIST_ITEM_ACTIVATION_TIMER = 150;
    38 const int HB_RADIOBUTTONLIST_PREVIEW_TIMER = 500;
    38 const int HB_RADIOBUTTONLIST_PREVIEW_TIMER = 500;
    39 
    39 
    40 const int HB_RADIOBUTTONLIST_MINIMUM_ITEM_COUNT_IN_SIZE_HINT = 4;
       
    41 
       
    42 /*!
    40 /*!
    43     \class HbRadioButtonList
    41     \class HbRadioButtonList
    44     \brief HbRadioButtonList provides a widget for a string list with radio buttons
    42     \brief HbRadioButtonList provides a widget for a string list with radio buttons
    45     @alpha
    43     @alpha
    46     @hbwidgets
    44     @hbwidgets
   128 
   126 
   129     QModelIndex mCurrentIndex; //Note that this is not the same as d->mHitItem
   127     QModelIndex mCurrentIndex; //Note that this is not the same as d->mHitItem
   130     HbRadioButtonList::PreviewMode mPreviewMode;
   128     HbRadioButtonList::PreviewMode mPreviewMode;
   131     bool mPreviewGoingOn;
   129     bool mPreviewGoingOn;
   132     bool mStartUp;
   130     bool mStartUp;
   133     qreal mHeight;
       
   134 };
   131 };
   135 
   132 
   136 HbRadioButtonListPrivate::HbRadioButtonListPrivate() :
   133 HbRadioButtonListPrivate::HbRadioButtonListPrivate() :
   137     HbListViewPrivate(),
   134     HbListViewPrivate(),
   138     mPreviewMode(HbRadioButtonList::NoPreview),
   135     mPreviewMode(HbRadioButtonList::NoPreview),
   139     mPreviewGoingOn(false),
   136     mPreviewGoingOn(false),
   140     mStartUp(true),
   137     mStartUp(true)
   141     mHeight(0)
       
   142 {     
   138 {     
   143 }
   139 }
   144 
   140 
   145 HbRadioButtonListPrivate::~HbRadioButtonListPrivate() 
   141 HbRadioButtonListPrivate::~HbRadioButtonListPrivate() 
   146 {
   142 {
   171     q->setSelectionMode(q->HbAbstractItemView::SingleSelection);
   167     q->setSelectionMode(q->HbAbstractItemView::SingleSelection);
   172     q->setSelected(selected);   
   168     q->setSelected(selected);   
   173     q->setPreviewMode(previewMode);
   169     q->setPreviewMode(previewMode);
   174     q->setLongPressEnabled(false);
   170     q->setLongPressEnabled(false);
   175     q->setUniformItemSizes(true);
   171     q->setUniformItemSizes(true);
   176     calculateItemHeight();
       
   177 }
       
   178 
       
   179 void HbRadioButtonListPrivate::calculateItemHeight()
       
   180 {
       
   181     Q_Q(HbRadioButtonList);
       
   182     if (!q->items().isEmpty()) {
       
   183         //Let's create a temporary item and take the height for the size hint
       
   184         HbAbstractViewItem *tempItem = q->itemPrototypes().first()->createItem();
       
   185         tempItem->setModelIndex(mModelIterator->nextIndex(QModelIndex()));
       
   186 
       
   187         qreal oldHeight = mHeight;
       
   188         mHeight = tempItem->effectiveSizeHint(Qt::PreferredSize).height();
       
   189 
       
   190         delete tempItem;
       
   191 
       
   192         if (mHeight != oldHeight) {
       
   193             q->updateGeometry();
       
   194         }
       
   195     }
       
   196 }
   172 }
   197 
   173 
   198 void HbRadioButtonListPrivate::emitStartPreview(int row)
   174 void HbRadioButtonListPrivate::emitStartPreview(int row)
   199 {
   175 {
   200     Q_Q(HbRadioButtonList);
   176     Q_Q(HbRadioButtonList);
   250 {
   226 {
   251     Q_D(HbRadioButtonList);
   227     Q_D(HbRadioButtonList);
   252     QStringListModel *stringListModel = qobject_cast<QStringListModel *>(d->mModelIterator->model());
   228     QStringListModel *stringListModel = qobject_cast<QStringListModel *>(d->mModelIterator->model());
   253     if (stringListModel) {
   229     if (stringListModel) {
   254         stringListModel->setStringList(list);
   230         stringListModel->setStringList(list);
   255         //Calculate the item height only if needed
       
   256         if(d->mHeight==0){
       
   257             d->calculateItemHeight();
       
   258         }
       
   259         updateGeometry();
   231         updateGeometry();
   260     } else {
   232     } else {
   261         //TODO: set the item here using the base model class
   233         //TODO: set the item here using the base model class
   262         //or document that this is not in use with own models
   234         //or document that this is not in use with own models
   263     }
   235     }
   408 /*!
   380 /*!
   409     \reimp
   381     \reimp
   410 */
   382 */
   411 QSizeF HbRadioButtonList::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
   383 QSizeF HbRadioButtonList::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
   412 {
   384 {
   413     Q_D(const HbRadioButtonList);
   385     return HbListView::sizeHint(which, constraint);
   414     if (which == Qt::PreferredSize) {
       
   415         QSizeF defaultSize = HbListView::sizeHint(which,constraint);
       
   416         qreal minHeight = (d->mHeight) * HB_RADIOBUTTONLIST_MINIMUM_ITEM_COUNT_IN_SIZE_HINT;
       
   417         defaultSize.setHeight(qMax(defaultSize.height(), minHeight));
       
   418         
       
   419         qreal height = (d->mHeight) * (d->mModelIterator->indexCount());
       
   420         if( height <= defaultSize.height()) {
       
   421             return QSizeF(defaultSize.width(), height);
       
   422         } else {
       
   423             return defaultSize;
       
   424         } 
       
   425     } else {
       
   426         return HbListView::sizeHint(which, constraint);
       
   427     }
       
   428 }
   386 }
   429 
   387 
   430 /*!
   388 /*!
   431     \reimp
   389     \reimp
   432 */
   390 */
   433 void HbRadioButtonList::rowsInserted(const QModelIndex &parent, int start, int end)
   391 void HbRadioButtonList::rowsInserted(const QModelIndex &parent, int start, int end)
   434 {
   392 {
   435     Q_D(HbRadioButtonList);
       
   436     HbListView::rowsInserted(parent,start,end);
   393     HbListView::rowsInserted(parent,start,end);
   437     //Calculate the item height only if needed
       
   438     if(d->mHeight==0){
       
   439         d->calculateItemHeight();
       
   440     }
       
   441     updateGeometry();
       
   442 }
   394 }
   443 
   395 
   444 /*!
   396 /*!
   445     \reimp
   397     \reimp
   446 */
   398 */
   447 void HbRadioButtonList::rowsRemoved(const QModelIndex &parent, int start, int end)
   399 void HbRadioButtonList::rowsRemoved(const QModelIndex &parent, int start, int end)
   448 {
   400 {
   449     HbListView::rowsRemoved(parent,start,end);
   401     HbListView::rowsRemoved(parent,start,end);
   450     updateGeometry();
       
   451 }
   402 }
   452 
   403 
   453 /*!
   404 /*!
   454     \reimp
   405     \reimp
   455 */
   406 */
   456 void HbRadioButtonList::reset()
   407 void HbRadioButtonList::reset()
   457 {
   408 {
   458     HbListView::reset();
   409     HbListView::reset();
   459     updateGeometry();
       
   460 }
   410 }
   461 #include "moc_hbradiobuttonlist.cpp"
   411 #include "moc_hbradiobuttonlist.cpp"
   462 
   412