| 1016 | } |
| 1017 | |
| 1018 | int InstanceView::verticalScrollToValue([[maybe_unused]] const QModelIndex& index, const QRect& rect, QListView::ScrollHint hint) const |
| 1019 | { |
| 1020 | const QRect area = viewport()->rect(); |
| 1021 | const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top()); |
| 1022 | const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom()); |
| 1023 | |
| 1024 | int verticalValue = verticalScrollBar()->value(); |
| 1025 | QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing()); |
| 1026 | if (hint == QListView::PositionAtTop || above) |
| 1027 | verticalValue += adjusted.top(); |
| 1028 | else if (hint == QListView::PositionAtBottom || below) |
| 1029 | verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1); |
| 1030 | else if (hint == QListView::PositionAtCenter) |
| 1031 | verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2); |
| 1032 | return verticalValue; |
| 1033 | } |