diff options
| author | Peter Penz <[email protected]> | 2011-11-26 01:05:58 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-11-26 01:16:31 +0100 |
| commit | 362817d1834f2ada3ea4552a25fa39bbbb540f8c (patch) | |
| tree | 706f316224397b44f95516ba857bb8d380a0bb47 /src/kitemviews/kitemlistview.cpp | |
| parent | bf1a8f989e75a50c9a5c839e69573a87ab9ad934 (diff) | |
Folders Panel fixes
The following functionality from Dolphin 1.x has
been ported to the new view-engine:
- Allow expanding/collapsing of items
- Automatically select the current item
- Context menu for items
Related improvements to the view-engine:
- Make the expanding/collapsing interface already accessible
in the base classes KItemModelBase and KItemListView. If
no expanding/collapsing is supported at all by derived models
(which is usually the default case) simply not reimplementing
those 3 methods is sufficient and it does not introduce an
additional complexity like in QAbstractItemModel/QModelIndex.
- Automatically handle the expanding/collapsing in KItemListController.
This also includes the key-handling, which is quite special for
expandable items.
- Don't let KItemListView automatically scroll to the current item
if the current item got changed. The automatic scrolling should
only be done if the current item has been changed by the user.
Hence this functionality has been moved to the KItemListController
which currently only triggers the automatic scrolling if the current
item has been changed by the keyboard (we might extend the usecases
later if required).
Diffstat (limited to 'src/kitemviews/kitemlistview.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistview.cpp | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 389069ce3..c4c1e3167 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -427,11 +427,45 @@ QHash<QByteArray, QSizeF> KItemListView::visibleRolesSizes(const KItemRangeList& return QHash<QByteArray, QSizeF>(); } +bool KItemListView::supportsItemExpanding() const +{ + return false; +} + QRectF KItemListView::itemRect(int index) const { return m_layouter->itemRect(index); } +void KItemListView::scrollToItem(int index) +{ + const QRectF viewGeometry = geometry(); + const QRectF currentRect = itemRect(index); + + if (!viewGeometry.contains(currentRect)) { + qreal newOffset = scrollOffset(); + if (currentRect.top() < viewGeometry.top()) { + Q_ASSERT(scrollOrientation() == Qt::Vertical); + newOffset += currentRect.top() - viewGeometry.top(); + } else if ((currentRect.bottom() > viewGeometry.bottom())) { + Q_ASSERT(scrollOrientation() == Qt::Vertical); + newOffset += currentRect.bottom() - viewGeometry.bottom(); + } else if (currentRect.left() < viewGeometry.left()) { + if (scrollOrientation() == Qt::Horizontal) { + newOffset += currentRect.left() - viewGeometry.left(); + } + } else if ((currentRect.right() > viewGeometry.right())) { + if (scrollOrientation() == Qt::Horizontal) { + newOffset += currentRect.right() - viewGeometry.right(); + } + } + + if (newOffset != scrollOffset()) { + emit scrollTo(newOffset); + } + } +} + int KItemListView::itemsPerOffset() const { return m_layouter->itemsPerOffset(); @@ -950,33 +984,6 @@ void KItemListView::slotCurrentChanged(int current, int previous) Q_ASSERT(!currentWidget->isCurrent()); currentWidget->setCurrent(true); } - - const QRectF viewGeometry = geometry(); - const QRectF currentRect = itemRect(current); - - if (!viewGeometry.contains(currentRect)) { - // Make sure that the new current item is fully visible in the view. - qreal newOffset = scrollOffset(); - if (currentRect.top() < viewGeometry.top()) { - Q_ASSERT(scrollOrientation() == Qt::Vertical); - newOffset += currentRect.top() - viewGeometry.top(); - } else if ((currentRect.bottom() > viewGeometry.bottom())) { - Q_ASSERT(scrollOrientation() == Qt::Vertical); - newOffset += currentRect.bottom() - viewGeometry.bottom(); - } else if (currentRect.left() < viewGeometry.left()) { - if (scrollOrientation() == Qt::Horizontal) { - newOffset += currentRect.left() - viewGeometry.left(); - } - } else if ((currentRect.right() > viewGeometry.right())) { - if (scrollOrientation() == Qt::Horizontal) { - newOffset += currentRect.right() - viewGeometry.right(); - } - } - - if (newOffset != scrollOffset()) { - emit scrollTo(newOffset); - } - } } void KItemListView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous) |
