X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/362817d1834f2ada3ea4552a25fa39bbbb540f8c..c8d8556950005dfd96ebdb41d2f43ad90356367c:/src/kitemviews/kitemlistview.cpp diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index c4c1e3167..5dbc128b5 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -127,7 +127,7 @@ void KItemListView::setScrollOrientation(Qt::Orientation orientation) } } - doLayout(Animation, 0, 0); + doLayout(Animation); onScrollOrientationChanged(orientation, previousOrientation); emit scrollOrientationChanged(orientation, previousOrientation); @@ -159,7 +159,7 @@ void KItemListView::setItemSize(const QSizeF& itemSize) } m_sizeHintResolver->clearCache(); - doLayout(Animation, 0, 0); + doLayout(Animation); onItemSizeChanged(itemSize, previousSize); } @@ -181,9 +181,11 @@ void KItemListView::setScrollOffset(qreal offset) m_layouter->setScrollOffset(offset); m_animation->setScrollOffset(offset); - if (!m_layoutTimer->isActive()) { - doLayout(NoAnimation, 0, 0); - } + + // Don't check whether the m_layoutTimer is active: Changing the + // scroll offset must always trigger a synchronous layout, otherwise + // the smooth-scrolling might get jerky. + doLayout(NoAnimation); onScrollOffsetChanged(offset, previousOffset); } @@ -199,13 +201,19 @@ qreal KItemListView::maximumScrollOffset() const void KItemListView::setItemOffset(qreal offset) { + if (m_layouter->itemOffset() == offset) { + return; + } + m_layouter->setItemOffset(offset); if (m_header) { m_header->setPos(-offset, 0); } - if (!m_layoutTimer->isActive()) { - doLayout(NoAnimation, 0, 0); - } + + // Don't check whether the m_layoutTimer is active: Changing the + // item offset must always trigger a synchronous layout, otherwise + // the smooth-scrolling might get jerky. + doLayout(NoAnimation); } qreal KItemListView::itemOffset() const @@ -241,7 +249,7 @@ void KItemListView::setVisibleRoles(const QList& roles) } updateVisibleRolesSizes(); - doLayout(Animation, 0, 0); + doLayout(Animation); onVisibleRolesChanged(roles, previousRoles); } @@ -330,7 +338,7 @@ void KItemListView::setStyleOption(const KItemListStyleOption& option) } m_sizeHintResolver->clearCache(); - doLayout(Animation, 0, 0); + doLayout(Animation); onStyleOptionChanged(option, previousOption); } @@ -437,9 +445,26 @@ QRectF KItemListView::itemRect(int index) const return m_layouter->itemRect(index); } +QRectF KItemListView::itemContextRect(int index) const +{ + QRectF contextRect; + + const KItemListWidget* widget = m_visibleItems.value(index); + if (widget) { + contextRect = widget->iconRect() | widget->textRect(); + contextRect.translate(itemRect(index).topLeft()); + } + + return contextRect; +} + void KItemListView::scrollToItem(int index) { - const QRectF viewGeometry = geometry(); + QRectF viewGeometry = geometry(); + if (m_header) { + const qreal headerHeight = m_header->size().height(); + viewGeometry.adjust(0, headerHeight, 0, 0); + } const QRectF currentRect = itemRect(index); if (!viewGeometry.contains(currentRect)) { @@ -466,11 +491,6 @@ void KItemListView::scrollToItem(int index) } } -int KItemListView::itemsPerOffset() const -{ - return m_layouter->itemsPerOffset(); -} - void KItemListView::beginTransaction() { ++m_activeTransactions; @@ -489,7 +509,7 @@ void KItemListView::endTransaction() if (m_activeTransactions == 0) { onTransactionEnd(); - doLayout(Animation, 0, 0); + doLayout(Animation); } } @@ -510,10 +530,14 @@ void KItemListView::setHeaderShown(bool show) m_header->setVisibleRolesWidths(headerRolesWidths()); m_header->setZValue(1); - m_useHeaderWidths = false; - connect(m_header, SIGNAL(visibleRoleWidthChanged(QByteArray,qreal,qreal)), this, SLOT(slotVisibleRoleWidthChanged(QByteArray,qreal,qreal))); + connect(m_header, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)), + this, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder))); + connect(m_header, SIGNAL(sortRoleChanged(QByteArray,QByteArray)), + this, SIGNAL(sortRoleChanged(QByteArray,QByteArray))); + + m_useHeaderWidths = false; m_layouter->setHeaderHeight(m_header->size().height()); } else if (!show && m_header) { @@ -754,7 +778,6 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) m_layouter->markAsDirty(); if (m_model->count() == count && maximumScrollOffset() > size().height()) { - kDebug() << "Scrollbar required, skipping layout"; const int scrollBarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent); QSizeF layouterSize = m_layouter->size(); if (scrollOrientation() == Qt::Vertical) { @@ -882,7 +905,7 @@ void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList } } - doLayout(NoAnimation, 0, 0); + doLayout(NoAnimation); } void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges, @@ -919,7 +942,7 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges, // The sort-role has been changed which might result // in modified group headers updateVisibleGroupHeaders(); - doLayout(NoAnimation, 0, 0); + doLayout(NoAnimation); } } } @@ -946,7 +969,7 @@ void KItemListView::slotGroupedSortingChanged(bool current) Q_ASSERT(m_visibleGroups.isEmpty()); } - doLayout(Animation, 0, 0); + doLayout(Animation); } void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) @@ -955,7 +978,7 @@ void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder pr Q_UNUSED(previous); if (m_grouped) { updateVisibleGroupHeaders(); - doLayout(Animation, 0, 0); + doLayout(Animation); } } @@ -965,7 +988,7 @@ void KItemListView::slotSortRoleChanged(const QByteArray& current, const QByteAr Q_UNUSED(previous); if (m_grouped) { updateVisibleGroupHeaders(); - doLayout(Animation, 0, 0); + doLayout(Animation); } } @@ -1039,7 +1062,7 @@ void KItemListView::slotAnimationFinished(QGraphicsWidget* widget, void KItemListView::slotLayoutTimerFinished() { m_layouter->setSize(geometry().size()); - doLayout(Animation, 0, 0); + doLayout(Animation); } void KItemListView::slotRubberBandPosChanged() @@ -1094,7 +1117,7 @@ void KItemListView::slotVisibleRoleWidthChanged(const QByteArray& role, widget->setVisibleRolesSizes(m_stretchedVisibleRolesSizes); } - doLayout(Animation, 0, 0); + doLayout(Animation); } } @@ -1148,7 +1171,9 @@ void KItemListView::triggerAutoScrolling() // the autoscrolling may not get skipped anymore until a new rubberband is created m_skipAutoScrollForRubberBand = false; - setScrollOffset(scrollOffset() + m_autoScrollIncrement); + const qreal maxVisibleOffset = qMax(qreal(0), maximumScrollOffset() - visibleSize); + const qreal newScrollOffset = qMin(scrollOffset() + m_autoScrollIncrement, maxVisibleOffset); + setScrollOffset(newScrollOffset); // Trigger the autoscroll timer which will periodically call // triggerAutoScrolling() @@ -1234,7 +1259,6 @@ KItemListRubberBand* KItemListView::rubberBand() const void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int changedCount) { if (m_layoutTimer->isActive()) { - kDebug() << "Stopping layout timer, synchronous layout requested"; m_layoutTimer->stop(); } @@ -1310,7 +1334,8 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha if (animate && changedCount < 0) { // Items have been deleted, move the created item to the - // imaginary old position. + // imaginary old position. They will get animated to the new position + // later. const QRectF itemRect = m_layouter->itemRect(i - changedCount); if (itemRect.isEmpty()) { const QPointF invisibleOldPos = (scrollOrientation() == Qt::Vertical) @@ -1328,7 +1353,6 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha if (animate) { const bool itemsRemoved = (changedCount < 0); const bool itemsInserted = (changedCount > 0); - if (itemsRemoved && (i >= changedIndex + changedCount + 1)) { // The item is located after the removed items. Animate the moving of the position. m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos); @@ -1364,7 +1388,17 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha widget->setVisible(true); if (widget->size() != itemBounds.size()) { + // Resize the widget for the item to the changed size. if (animate) { + // If a dynamic item size is used then no animation is done in the direction + // of the dynamic size. + if (m_itemSize.width() <= 0) { + // The width is dynamic, apply the new width without animation. + widget->resize(itemBounds.width(), widget->size().height()); + } else if (m_itemSize.height() <= 0) { + // The height is dynamic, apply the new height without animation. + widget->resize(widget->size().width(), itemBounds.height()); + } m_animation->start(widget, KItemListViewAnimation::ResizeAnimation, itemBounds.size()); } else { widget->resize(itemBounds.size());