221 } else { |
221 } else { |
222 HbScrollAreaPrivate::setContentPosition(value, orientation, animate); |
222 HbScrollAreaPrivate::setContentPosition(value, orientation, animate); |
223 } |
223 } |
224 } |
224 } |
225 |
225 |
226 QModelIndex HbGridViewPrivate::indexInTheCenter(Qt::Orientations scrollDirection) const |
226 QModelIndex HbGridViewPrivate::firstFullyVisibleIndex() const |
227 { |
227 { |
228 Q_Q(const HbGridView); |
228 QModelIndex first, last; |
229 QModelIndex centerViewModelIndex; // nearest to center of the screen |
229 mContainer->firstAndLastVisibleModelIndex(first, last, true); |
230 if (!mContainer->items().isEmpty()) { |
230 return first; |
231 qreal centerPos; |
231 } |
232 HbGridItemContainer *container = itemContainer(); |
|
233 if (scrollDirection == Qt::Vertical) { |
|
234 // calculating row: |
|
235 centerPos = -container->pos().y() + q->boundingRect().height() / 2 |
|
236 // take rather item that is just above of view center instead of bottom one |
|
237 - container->viewLayout()->effectiveSizeHint(Qt::MinimumSize).height() / 2; |
|
238 // calculate item row |
|
239 centerPos /= container->viewLayout()->effectiveSizeHint(Qt::MinimumSize).height(); |
|
240 //calculate item index |
|
241 centerPos *= itemContainer()->columnCount(); |
|
242 // go to center column |
|
243 centerPos += itemContainer()->columnCount() / 2; |
|
244 } else { |
|
245 // calculating row: |
|
246 centerPos = -container->pos().x() + q->boundingRect().width() / 2 |
|
247 // take rather item that is just on the left of view center instead of right one |
|
248 - container->viewLayout()->effectiveSizeHint(Qt::MinimumSize).width() / 2; |
|
249 // calculate buffer row |
|
250 centerPos /= container->viewLayout()->effectiveSizeHint(Qt::MinimumSize).width(); |
|
251 //calculate item index |
|
252 centerPos *= itemContainer()->rowCount(); |
|
253 // go to center row |
|
254 centerPos += itemContainer()->rowCount() / 2; |
|
255 } |
|
256 int centerIndex = qRound(centerPos); |
|
257 if (centerIndex >= container->items().size()) { |
|
258 centerIndex = container->items().size() / 2; |
|
259 } |
|
260 centerViewModelIndex = container->items().at(centerIndex)->modelIndex(); |
|
261 } |
|
262 return centerViewModelIndex; |
|
263 } |
|