| 1032 | } |
| 1033 | |
| 1034 | int InstanceView::verticalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const |
| 1035 | { |
| 1036 | const QRect area = viewport()->rect(); |
| 1037 | const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top()); |
| 1038 | const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom()); |
| 1039 | |
| 1040 | int verticalValue = verticalScrollBar()->value(); |
| 1041 | QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing()); |
| 1042 | if (hint == QListView::PositionAtTop || above) |
| 1043 | verticalValue += adjusted.top(); |
| 1044 | else if (hint == QListView::PositionAtBottom || below) |
| 1045 | verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1); |
| 1046 | else if (hint == QListView::PositionAtCenter) |
| 1047 | verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2); |
| 1048 | return verticalValue; |
| 1049 | } |