X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/1826f905d706925456763394de17294bcb6d1c35..b500c27e11acd6a6de4aab507f6df438b6d2f580:/src/kitemviews/kitemlistview.cpp diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index cf1483659..45f5851bf 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -402,6 +402,10 @@ qreal KItemListView::verticalPageStep() const std::optional KItemListView::itemAt(const QPointF &pos) const { + if (headerBoundaries().contains(pos)) { + return std::nullopt; + } + QHashIterator it(m_visibleItems); while (it.hasNext()) { it.next(); @@ -546,64 +550,88 @@ void KItemListView::scrollToItem(int index, ViewItemPosition viewItemPosition) } QRectF currentRect = itemRect(index); + if (layoutDirection() == Qt::RightToLeft && scrollOrientation() == Qt::Horizontal) { + currentRect.moveLeft(m_layouter->size().width() - currentRect.right()); + } + // Fix for Bug 311099 - View the underscore when using Ctrl + PageDown currentRect.adjust(-m_styleOption.horizontalMargin, -m_styleOption.verticalMargin, m_styleOption.horizontalMargin, m_styleOption.verticalMargin); - qreal newOffset = scrollOffset(); - if (scrollOrientation() == Qt::Vertical && (currentRect.top() < viewGeometry.top() || currentRect.bottom() > viewGeometry.bottom())) { - switch (viewItemPosition) { - case Beginning: - newOffset += currentRect.top() - viewGeometry.top(); - break; - case Middle: - newOffset += 0.5 * (currentRect.top() + currentRect.bottom() - (viewGeometry.top() + viewGeometry.bottom())); - break; - case End: - newOffset += currentRect.bottom() - viewGeometry.bottom(); - break; - case Nearest: - if (currentRect.top() < viewGeometry.top()) { - newOffset += currentRect.top() - viewGeometry.top(); - } else { - newOffset += currentRect.bottom() - viewGeometry.bottom(); - } - break; - default: - Q_UNREACHABLE(); - } - } else if (scrollOrientation() == Qt::Horizontal && (currentRect.left() < viewGeometry.left() || currentRect.right() > viewGeometry.right())) { - switch (viewItemPosition) { - case Beginning: - if (layoutDirection() == Qt::RightToLeft) { - newOffset += currentRect.right() - viewGeometry.right(); - } else { - newOffset += currentRect.left() - viewGeometry.left(); - } - break; - case Middle: - newOffset += 0.5 * (currentRect.left() + currentRect.right() - (viewGeometry.left() + viewGeometry.right())); - break; - case End: - if (layoutDirection() == Qt::RightToLeft) { - newOffset += currentRect.left() - viewGeometry.left(); - } else { - newOffset += currentRect.right() - viewGeometry.right(); + qreal offset = 0; + switch (scrollOrientation()) { + case Qt::Vertical: + if (currentRect.top() < viewGeometry.top() || currentRect.bottom() > viewGeometry.bottom()) { + switch (viewItemPosition) { + case Beginning: + offset = currentRect.top() - viewGeometry.top(); + break; + case Middle: + offset = 0.5 * (currentRect.top() + currentRect.bottom() - (viewGeometry.top() + viewGeometry.bottom())); + break; + case End: + offset = currentRect.bottom() - viewGeometry.bottom(); + break; + case Nearest: + if (currentRect.top() < viewGeometry.top()) { + offset = currentRect.top() - viewGeometry.top(); + } + if (currentRect.bottom() > viewGeometry.bottom() + offset) { + offset += currentRect.bottom() - viewGeometry.bottom() - offset; + } + break; + default: + Q_UNREACHABLE(); } - break; - case Nearest: - if (currentRect.left() < viewGeometry.left()) { - newOffset += currentRect.left() - viewGeometry.left(); - } else { - newOffset += currentRect.right() - viewGeometry.right(); + } + break; + case Qt::Horizontal: + if (currentRect.left() < viewGeometry.left() || currentRect.right() > viewGeometry.right()) { + switch (viewItemPosition) { + case Beginning: + if (layoutDirection() == Qt::RightToLeft) { + offset = currentRect.right() - viewGeometry.right(); + } else { + offset = currentRect.left() - viewGeometry.left(); + } + break; + case Middle: + offset = 0.5 * (currentRect.left() + currentRect.right() - (viewGeometry.left() + viewGeometry.right())); + break; + case End: + if (layoutDirection() == Qt::RightToLeft) { + offset = currentRect.left() - viewGeometry.left(); + } else { + offset = currentRect.right() - viewGeometry.right(); + } + break; + case Nearest: + if (layoutDirection() == Qt::RightToLeft) { + if (currentRect.left() < viewGeometry.left()) { + offset = currentRect.left() - viewGeometry.left(); + } + if (currentRect.right() > viewGeometry.right() + offset) { + offset += currentRect.right() - viewGeometry.right() - offset; + } + } else { + if (currentRect.right() > viewGeometry.right()) { + offset = currentRect.right() - viewGeometry.right(); + } + if (currentRect.left() < viewGeometry.left() + offset) { + offset += currentRect.left() - viewGeometry.left() - offset; + } + } + break; + default: + Q_UNREACHABLE(); } - break; - default: - Q_UNREACHABLE(); } + break; + default: + Q_UNREACHABLE(); } - if (newOffset != scrollOffset()) { - Q_EMIT scrollTo(newOffset); + if (!qFuzzyIsNull(offset)) { + Q_EMIT scrollTo(scrollOffset() + offset); return; } @@ -1453,6 +1481,26 @@ void KItemListView::slotSortRoleChanged(const QByteArray ¤t, const QByteAr } } +void KItemListView::slotGroupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) +{ + Q_UNUSED(current) + Q_UNUSED(previous) + if (m_grouped) { + updateVisibleGroupHeaders(); + doLayout(NoAnimation); + } +} + +void KItemListView::slotGroupRoleChanged(const QByteArray ¤t, const QByteArray &previous) +{ + Q_UNUSED(current) + Q_UNUSED(previous) + if (m_grouped) { + updateVisibleGroupHeaders(); + doLayout(NoAnimation); + } +} + void KItemListView::slotCurrentChanged(int current, int previous) { Q_UNUSED(previous) @@ -1715,6 +1763,8 @@ void KItemListView::setModel(KItemModelBase *model) disconnect(m_model, &KItemModelBase::groupedSortingChanged, this, &KItemListView::slotGroupedSortingChanged); disconnect(m_model, &KItemModelBase::sortOrderChanged, this, &KItemListView::slotSortOrderChanged); disconnect(m_model, &KItemModelBase::sortRoleChanged, this, &KItemListView::slotSortRoleChanged); + disconnect(m_model, &KItemModelBase::groupOrderChanged, this, &KItemListView::slotGroupOrderChanged); + disconnect(m_model, &KItemModelBase::groupRoleChanged, this, &KItemListView::slotGroupRoleChanged); m_sizeHintResolver->itemsRemoved(KItemRangeList() << KItemRange(0, m_model->count())); } @@ -2157,7 +2207,7 @@ void KItemListView::updateGroupHeaderForWidget(KItemListWidget *widget) const int groupIndex = groupIndexForItem(index); Q_ASSERT(groupIndex >= 0); groupHeader->setData(groups.at(groupIndex).second); - groupHeader->setRole(model()->sortRole()); + groupHeader->setRole(model()->groupRole()); groupHeader->setStyleOption(m_styleOption); groupHeader->setScrollOrientation(scrollOrientation()); groupHeader->setItemIndex(index);