| 993 | } |
| 994 | |
| 995 | int InstanceView::verticalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const |
| 996 | { |
| 997 | const QRect area = viewport()->rect(); |
| 998 | const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top()); |
| 999 | const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom()); |
| 1000 | |
| 1001 | int verticalValue = verticalScrollBar()->value(); |
| 1002 | QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing()); |
| 1003 | if (hint == QListView::PositionAtTop || above) |
| 1004 | verticalValue += adjusted.top(); |
| 1005 | else if (hint == QListView::PositionAtBottom || below) |
| 1006 | verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1); |
| 1007 | else if (hint == QListView::PositionAtCenter) |
| 1008 | verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2); |
| 1009 | return verticalValue; |
| 1010 | } |