diff options
| author | Nicolas Fella <[email protected]> | 2023-10-24 23:12:22 +0200 |
|---|---|---|
| committer | Nicolas Fella <[email protected]> | 2023-10-24 23:14:25 +0200 |
| commit | 1826f905d706925456763394de17294bcb6d1c35 (patch) | |
| tree | 6838f9f0a8423cc7b0b86554139299c649f53b42 /src/kitemviews | |
| parent | 8b91acf05b2b41ae68268081d31af18cf66d3bca (diff) | |
| parent | ef59e42c40df5e873a1a1b6c2173d5b55641a783 (diff) | |
Merge branch 'master' into kf6
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.cpp | 5 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistview.cpp | 60 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistview.h | 8 | ||||
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.cpp | 15 | ||||
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.h | 7 |
5 files changed, 77 insertions, 18 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index be7a63e09..5abf1830b 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -539,7 +539,7 @@ void KItemListController::slotChangeCurrentItem(const QString &text, bool search m_selectionManager->beginAnchoredSelection(index); } - m_view->scrollToItem(index); + m_view->scrollToItem(index, KItemListView::ViewItemPosition::Beginning); } } @@ -1299,7 +1299,8 @@ void KItemListController::slotRubberBandChanged() if (widgetRect.intersects(rubberBandRect)) { // Select the full row intersecting with the rubberband rectangle const QRectF selectionRect = widget->selectionRect().translated(widgetRect.topLeft()); - if (selectionRect.intersects(rubberBandRect)) { + const QRectF iconRect = widget->iconRect().translated(widgetRect.topLeft()); + if (selectionRect.intersects(rubberBandRect) || iconRect.intersects(rubberBandRect)) { selectedItems.insert(index); } } diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 659e59f0f..cf1483659 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -537,7 +537,7 @@ bool KItemListView::isElided(int index) const return m_sizeHintResolver->isElided(index); } -void KItemListView::scrollToItem(int index) +void KItemListView::scrollToItem(int index, ViewItemPosition viewItemPosition) { QRectF viewGeometry = geometry(); if (m_headerWidget->isVisible()) { @@ -546,29 +546,65 @@ void KItemListView::scrollToItem(int index) } QRectF currentRect = itemRect(index); - // Fix for Bug 311099 - View the underscore when using Ctrl + PagDown + // 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); - if (!viewGeometry.contains(currentRect)) { - qreal newOffset = scrollOffset(); - if (scrollOrientation() == Qt::Vertical) { + 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 if (currentRect.bottom() > viewGeometry.bottom()) { + } else { newOffset += currentRect.bottom() - viewGeometry.bottom(); } - } else { + 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(); + } + break; + case Nearest: if (currentRect.left() < viewGeometry.left()) { newOffset += currentRect.left() - viewGeometry.left(); - } else if (currentRect.right() > viewGeometry.right()) { + } else { newOffset += currentRect.right() - viewGeometry.right(); } + break; + default: + Q_UNREACHABLE(); } + } - if (newOffset != scrollOffset()) { - Q_EMIT scrollTo(newOffset); - return; - } + if (newOffset != scrollOffset()) { + Q_EMIT scrollTo(newOffset); + return; } Q_EMIT scrollingStopped(); diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h index 7bcaec704..8812eb8cc 100644 --- a/src/kitemviews/kitemlistview.h +++ b/src/kitemviews/kitemlistview.h @@ -59,6 +59,9 @@ class DOLPHIN_EXPORT KItemListView : public QGraphicsWidget Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset NOTIFY itemOffsetChanged) public: + /** The position in the view to which an item should be scrolled to. */ + enum ViewItemPosition { Beginning, Middle, End, Nearest }; + explicit KItemListView(QGraphicsWidget *parent = nullptr); ~KItemListView() override; @@ -251,9 +254,10 @@ public: /** * Scrolls to the item with the index \a index so that the item - * will be fully visible. + * will be fully visible. The item is positioned within the view + * as specified by \a viewItemPosition. */ - void scrollToItem(int index); + void scrollToItem(int index, ViewItemPosition viewItemPosition = ViewItemPosition::Nearest); /** * If several properties of KItemListView are changed synchronously, it is diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index 52df17ad3..e37013f95 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -1205,6 +1205,16 @@ QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, in return m_customizedFontMetrics.elidedText(text, Qt::ElideRight, elidingWidth); } +QString KStandardItemListWidget::escapeString(const QString &text) const +{ + QString escaped(text); + + const QChar returnSymbol(0x21b5); + escaped.replace('\n', returnSymbol); + + return escaped; +} + void KStandardItemListWidget::updateIconsLayoutTextCache() { // +------+ @@ -1227,7 +1237,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache() // Initialize properties for the "text" role. It will be used as anchor // for initializing the position of the other roles. TextInfo *nameTextInfo = m_textInfo.value("text"); - const QString nameText = KStringHandler::preProcessWrap(values["text"].toString()); + const QString nameText = KStringHandler::preProcessWrap(escapeString(values["text"].toString())); nameTextInfo->staticText.setText(nameText); // Calculate the number of lines required for the name and the required width @@ -1348,7 +1358,7 @@ void KStandardItemListWidget::updateCompactLayoutTextCache() qreal y = qRound((widgetHeight - textLinesHeight) / 2); const qreal maxWidth = size().width() - x - option.padding; for (const QByteArray &role : std::as_const(m_sortedVisibleRoles)) { - const QString text = roleText(role, values); + const QString text = escapeString(roleText(role, values)); TextInfo *textInfo = m_textInfo.value(role); textInfo->staticText.setText(text); @@ -1407,6 +1417,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache() const bool isTextRole = (role == "text"); if (isTextRole) { + text = escapeString(text); availableTextWidth -= firstColumnInc - sidePadding(); } diff --git a/src/kitemviews/kstandarditemlistwidget.h b/src/kitemviews/kstandarditemlistwidget.h index 1313179c9..a09f0c7a8 100644 --- a/src/kitemviews/kstandarditemlistwidget.h +++ b/src/kitemviews/kstandarditemlistwidget.h @@ -209,6 +209,13 @@ private: QString elideRightKeepExtension(const QString &text, int elidingWidth) const; /** + * Escapes text for display purposes. + * + * Replaces '\n' with Unicode line break (U+21B5). + */ + QString escapeString(const QString &text) const; + + /** * Closes the role editor and returns the focus back * to the KItemListContainer. */ |
