src/hbwidgets/itemviews/hbgridview.cpp
changeset 6 c3690ec91ef8
parent 2 06ff229162e9
child 23 e6ad4ef83b23
child 34 ed14f46c0e55
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    47  
    47  
    48  Scrolling can be set to either a \link Qt::Horizontal \endlink or \link Qt::Vertical \endlink direction.
    48  Scrolling can be set to either a \link Qt::Horizontal \endlink or \link Qt::Vertical \endlink direction.
    49  Items are arranged according to the scroll direction i.e Qt::Horizontal lays out items 
    49  Items are arranged according to the scroll direction i.e Qt::Horizontal lays out items 
    50  horizontally and Qt::Vertical lays out items vertically.
    50  horizontally and Qt::Vertical lays out items vertically.
    51 
    51 
    52  By default the HbScrollArea::ClampingStyle used is BounceBackClamping, the HbScrollArea::ScrollingStyle is PanOrFlick,
    52  By default the HbScrollArea::ClampingStyle used is BounceBackClamping, the HbScrollArea::ScrollingStyle is PanWithFollowOn,
    53  scrollbars are invisible and recycling and inertia are disabled.
    53  scrollbars are invisible and recycling and inertia are disabled.
    54 
    54 
    55  The following code snippet demonstrates the use of HbGridView
    55  The following code snippet demonstrates the use of HbGridView
    56  \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,21}
    56  \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,21}
    57  */
    57 */
    58 
    58 
    59 /*!
    59 /*!
    60  GridView recycling is in proto state.
    60  GridView recycling is in proto state.
    61  */
    61 */
    62 
    62 
    63 /*!    
    63 /*!    
    64   See also  HbAbstractItemView,HbAbstractViewitem,HbGridViewItem,HbScrollArea
    64   See also  HbAbstractItemView,HbAbstractViewitem,HbGridViewItem,HbScrollArea
    65  */
    65 */
    66 
    66 
    67 /*!
    67 /*!
    68  \fn void HbGridView::setUniformItemSizes(bool enabled) is public from HbAbstractItemView but for HbGridView
    68  \fn void HbGridView::setUniformItemSizes(bool enabled) is public from HbAbstractItemView but for HbGridView
    69  Calling this method make no sense - in grid case it is reimplemented and do not change
    69  Calling this method make no sense - in grid case it is reimplemented and do not change
    70  anything (items are always same size).
    70  anything (items are always same size).
    71 */
    71 */
    72 
    72 
    73 /*!
    73 /*!
    74  Constructs a new HbGridView with \a parent.
    74  Constructs a new HbGridView with \a parent.
    75  */
    75 */
    76 HbGridView::HbGridView(QGraphicsItem *parent) :
    76 HbGridView::HbGridView(QGraphicsItem *parent) :
    77     HbAbstractItemView(*new HbGridViewPrivate(), new HbGridItemContainer(), new HbModelIterator(), parent)
    77     HbAbstractItemView(*new HbGridViewPrivate(), new HbGridItemContainer(), new HbModelIterator(), parent)
    78 {
    78 {
    79     Q_D( HbGridView );
    79     Q_D( HbGridView );
    80     d->q_ptr = this;
    80     d->q_ptr = this;
    82 }
    82 }
    83 
    83 
    84 /*!
    84 /*!
    85     Constructs a grid view with a private class object \a dd, 
    85     Constructs a grid view with a private class object \a dd, 
    86     \a container and \a parent.
    86     \a container and \a parent.
    87  */
    87 */
    88 HbGridView::HbGridView(HbGridViewPrivate &dd, HbAbstractItemContainer *container, QGraphicsItem *parent) :
    88 HbGridView::HbGridView(HbGridViewPrivate &dd, HbAbstractItemContainer *container, QGraphicsItem *parent) :
    89     HbAbstractItemView(dd, container, new HbModelIterator(), parent)
    89     HbAbstractItemView(dd, container, new HbModelIterator(), parent)
    90 {
    90 {
    91     Q_D( HbGridView );
    91     Q_D( HbGridView );
    92     d->q_ptr = this;
    92     d->q_ptr = this;
   102 
   102 
   103 /*!
   103 /*!
   104     Returns the total number of rows in the view.
   104     Returns the total number of rows in the view.
   105 
   105 
   106     \sa setRowCount()
   106     \sa setRowCount()
   107  */
   107 */
   108 int HbGridView::rowCount() const
   108 int HbGridView::rowCount() const
   109 {
   109 {
   110     Q_D(const HbGridView);
   110     Q_D(const HbGridView);
   111     return d->itemContainer()->rowCount();
   111     return d->itemContainer()->rowCount();
   112 }
   112 }
   113 
   113 
   114 /*!
   114 /*!
   115     Sets the total number of rows to \a rowCount.
   115     Sets the total number of rows to \a rowCount.
   116 
   116 
   117     \sa HbGridView::rowCount()
   117     \sa HbGridView::rowCount()
   118  */
   118 */
   119 void HbGridView::setRowCount(int rowCount)
   119 void HbGridView::setRowCount(int rowCount)
   120 {
   120 {
   121     Q_D(HbGridView);
   121     Q_D(HbGridView);
   122 
   122 
   123     d->mVisibleIndex = d->indexInTheCenter();
   123     d->mVisibleIndex = d->indexInTheCenter();
   129 
   129 
   130 /*!
   130 /*!
   131     Returns the total number of columns in the view.
   131     Returns the total number of columns in the view.
   132 
   132 
   133     \sa setColumnCount()
   133     \sa setColumnCount()
   134  */
   134 */
   135 int HbGridView::columnCount() const
   135 int HbGridView::columnCount() const
   136 {
   136 {
   137     Q_D(const HbGridView);
   137     Q_D(const HbGridView);
   138     return d->itemContainer()->columnCount();
   138     return d->itemContainer()->columnCount();
   139 }
   139 }
   140 
   140 
   141 /*!
   141 /*!
   142     Sets the total number of columns to \a columnCount.
   142     Sets the total number of columns to \a columnCount.
   143 
   143 
   144     \sa columnCount()
   144     \sa columnCount()
   145  */
   145 */
   146 void HbGridView::setColumnCount(int columnCount)
   146 void HbGridView::setColumnCount(int columnCount)
   147 {
   147 {
   148     Q_D(HbGridView);
   148     Q_D(HbGridView);
   149 
   149 
   150     d->mVisibleIndex = d->indexInTheCenter();
   150     d->mVisibleIndex = d->indexInTheCenter();
   157 
   157 
   158 /*!
   158 /*!
   159     Returns true if icons are currently displayed in GridView.
   159     Returns true if icons are currently displayed in GridView.
   160  
   160  
   161     \sa setIconVisible()
   161     \sa setIconVisible()
       
   162 */
       
   163 bool HbGridView::iconVisible() const
       
   164 {
       
   165     Q_D(const HbGridView);
       
   166     return d->mIconVisible;
       
   167 }
       
   168 
       
   169 /*!
       
   170     Set visibility of icons in grid view to \a visible. All view items are updated.
       
   171 
       
   172     By default icons are visible.
       
   173 
       
   174     \sa iconVisible()
       
   175 */
       
   176 void HbGridView::setIconVisible(bool visible)
       
   177 {
       
   178     Q_D(HbGridView);
       
   179     d->setIconVisible(visible);
       
   180 }
       
   181 
       
   182 /*!
       
   183     Returns visibility of text in grid view.
       
   184 
       
   185     \sa setTextVisible()
       
   186 */
       
   187 bool HbGridView::textVisible() const
       
   188 {
       
   189     Q_D(const HbGridView);
       
   190     return d->mTextVisible;
       
   191 }
       
   192 
       
   193 /*!
       
   194     Sets visibility of text in grid view to \a visible. All view items are updated.
       
   195 
       
   196     By default text is visible.
       
   197 
       
   198     \sa HbGridView::textVisible()
       
   199 */
       
   200 void HbGridView::setTextVisible(bool visible)
       
   201 {
       
   202     Q_D(HbGridView);
       
   203     d->setTextVisible(visible);
       
   204 }
       
   205 
       
   206 
       
   207 /*!
       
   208     Returns true if the HbGridView will automatically swap the row and column counts in orientation change.
       
   209 
       
   210     \sa HbGridView::setSwapDimensionsOnOrientationChange()
   162  */
   211  */
   163 bool HbGridView::iconVisible() const
   212 bool HbGridView::swapDimensionsOnOrientationChange() const
   164 {
   213 {
   165     Q_D(const HbGridView);
   214     Q_D(const HbGridView);
   166     return d->mIconVisible;
   215     return d->mSwapDimensionsOnOrientationChange;
   167 }
   216 }
   168 
   217 
   169 /*!
   218 /*!
   170     Set visibility of icons in grid view to \a visible. All view items are updated.
   219     Sets automatic row and column count swapping in orientatation change to \a swap. 
   171 
   220 
   172     By default icons are visible.
   221     By default the row and column counts are swapped in orientation change. 
   173 
   222 
   174     \sa iconVisible()
   223     \sa HbGridView::swapDimensionsOnOrientationChange()
   175  */
   224  */
   176 void HbGridView::setIconVisible(bool visible)
   225 
   177 {
   226 void HbGridView::setSwapDimensionsOnOrientationChange(bool swap)
   178     Q_D(HbGridView);
   227 {
   179     d->setIconVisible(visible);
   228     Q_D(HbGridView);
   180 }
   229     d->mSwapDimensionsOnOrientationChange = swap;
   181 
   230 }
   182 /*!
   231 
   183     Returns visibility of text in grid view.
       
   184 
       
   185     \sa setTextVisible()
       
   186  */
       
   187 bool HbGridView::textVisible() const
       
   188 {
       
   189     Q_D(const HbGridView);
       
   190     return d->mTextVisible;
       
   191 }
       
   192 
       
   193 /*!
       
   194     Sets visibility of text in grid view to \a visible. All view items are updated.
       
   195 
       
   196     By default text is visible.
       
   197 
       
   198     \sa HbGridView::textVisible()
       
   199  */
       
   200 void HbGridView::setTextVisible(bool visible)
       
   201 {
       
   202     Q_D(HbGridView);
       
   203     d->setTextVisible(visible);
       
   204 }
       
   205 
   232 
   206 /*!
   233 /*!
   207     Returns item at \a row and \a column.
   234     Returns item at \a row and \a column.
   208  */
   235 */
   209 HbAbstractViewItem *HbGridView::itemAt(int row, int column) const
   236 HbAbstractViewItem *HbGridView::itemAt(int row, int column) const
   210 {
   237 {
   211     Q_D(const HbGridView);
   238     Q_D(const HbGridView);
   212    if (     row >= 0
   239    if (     row >= 0
   213        &&   column >= 0
   240        &&   column >= 0
   219    return 0;
   246    return 0;
   220 }
   247 }
   221 
   248 
   222 /*!
   249 /*!
   223  \reimp
   250  \reimp
   224  */
   251 */
   225 void HbGridView::scrollTo(const QModelIndex &index, ScrollHint hint)
   252 void HbGridView::scrollTo(const QModelIndex &index, ScrollHint hint)
   226 {
   253 {
   227     Q_D(HbGridView);
   254     Q_D(HbGridView);
   228     // always use container, event if recycling is off and all items are 
   255     // always use container, event if recycling is off and all items are 
   229     // in container, but still aditional action is needed -
   256     // in container, but still additional action is needed -
   230     // container::scrollTo is responsible for procesing all
   257     // container::scrollTo is responsible for procesing all
   231     // posponed events (DelayedLayoutRequest)
   258     // posponed events (DelayedLayoutRequest)
   232     if (    d->mModelIterator->model()
   259     if (    d->mModelIterator->model()
   233         &&  index.model() == d->mModelIterator->model()) {
   260         &&  index.model() == d->mModelIterator->model()) {
   234         d->itemContainer()->scrollTo(index, hint);
   261         d->itemContainer()->scrollTo(index, hint);
   246     event->accept();
   273     event->accept();
   247 }
   274 }
   248 
   275 
   249 /*!
   276 /*!
   250     \reimp
   277     \reimp
   251  */
   278 */
   252 void HbGridView::orientationAboutToBeChanged()
   279 void HbGridView::orientationAboutToBeChanged()
   253 {
   280 {
   254     Q_D(HbGridView);
   281     Q_D(HbGridView);
   255     d->mVisibleIndex = d->indexInTheCenter();
   282     d->mVisibleIndex = d->indexInTheCenter();
   256 }
   283 }
   257 
   284 
   258 /*!
   285 /*!
   259     \reimp
   286     \reimp
   260  */
   287 */
   261 void HbGridView::orientationChanged(Qt::Orientation newOrientation)
   288 void HbGridView::orientationChanged(Qt::Orientation newOrientation)
   262 {
   289 {
   263     Q_D(HbGridView);
   290     Q_D(HbGridView);
   264     d->mContainer->setPos(0,0);
   291     d->mContainer->setPos(0,0);
   265     d->itemContainer()->orientationChanged(newOrientation);
   292     if (d->mSwapDimensionsOnOrientationChange) {
   266 
   293         d->itemContainer()->orientationChanged(newOrientation);
   267     // abstract part is enought - container update buffer
   294     }
       
   295 
       
   296     // abstract part is enough - container update buffer
   268     HbAbstractItemView::scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
   297     HbAbstractItemView::scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
   269 
   298 
   270     d->mVisibleIndex = QModelIndex();
   299     d->mVisibleIndex = QModelIndex();
   271 }
   300 }
   272 
   301 
   359     }
   388     }
   360 }
   389 }
   361 
   390 
   362 /*!
   391 /*!
   363     This slot is connected to scrollDirectionsChanged signal emitted from HbScrollArea.
   392     This slot is connected to scrollDirectionsChanged signal emitted from HbScrollArea.
   364  */
   393 */
   365 void HbGridView::scrollDirectionChanged(Qt::Orientations scrollDirection)
   394 void HbGridView::scrollDirectionChanged(Qt::Orientations scrollDirection)
   366 {
   395 {
   367     Q_D(HbGridView);
   396     Q_D(HbGridView);
   368     // scroll direction changed, calculations need to be done on old value
   397     // scroll direction changed, calculations need to be done on old value
   369     d->mVisibleIndex = d->indexInTheCenter((d->mScrollDirections == Qt::Vertical) 
   398     d->mVisibleIndex = d->indexInTheCenter((d->mScrollDirections == Qt::Vertical) 
   370         ? Qt::Horizontal : Qt::Vertical);
   399         ? Qt::Horizontal : Qt::Vertical);
   371     d->mContainer->setPos(0,0);
   400     d->mContainer->setPos(0,0);
   372     d->itemContainer()->scrollDirectionChanged(scrollDirection);
   401     d->itemContainer()->scrollDirectionChanged(scrollDirection);
   373 
   402 
   374     // abstract part is enought - container update buffer
   403     // abstract part is enough - container update buffer
   375     HbAbstractItemView::scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
   404     HbAbstractItemView::scrollTo(d->mVisibleIndex, HbAbstractItemView::PositionAtCenter);
   376 
   405 
   377     d->mVisibleIndex = QModelIndex();
   406     d->mVisibleIndex = QModelIndex();
   378 }
   407 }
   379 
   408