X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b3ac8d783bd2df15014b848657fbe601e7575f38..a6b4348ddbc8fdf64ddb2c454e7fa2179e82c61b:/src/kitemviews/kitemlistview.cpp diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index f906b7a13..42c5e25c2 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -8,12 +8,16 @@ #include "kitemlistview.h" +#ifndef QT_NO_ACCESSIBILITY +#include "accessibility/kitemlistcontaineraccessible.h" +#include "accessibility/kitemlistdelegateaccessible.h" +#include "accessibility/kitemlistviewaccessible.h" +#endif #include "dolphindebug.h" #include "kitemlistcontainer.h" #include "kitemlistcontroller.h" #include "kitemlistheader.h" #include "kitemlistselectionmanager.h" -#include "kitemlistviewaccessible.h" #include "kstandarditemlistwidget.h" #include "private/kitemlistheaderwidget.h" @@ -21,6 +25,8 @@ #include "private/kitemlistsizehintresolver.h" #include "private/kitemlistviewlayouter.h" +#include + #include #include #include @@ -550,6 +556,10 @@ 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); @@ -735,6 +745,7 @@ void KItemListView::editRole(int index, const QByteArray &role) } m_editingRole = true; + m_controller->selectionManager()->setCurrentItem(index); widget->setEditedRole(role); connect(widget, &KItemListWidget::roleEditingCanceled, this, &KItemListView::slotRoleEditingCanceled); @@ -1368,9 +1379,20 @@ void KItemListView::slotItemsMoved(const KItemRange &itemRange, const QList const int firstVisibleMovedIndex = qMax(firstVisibleIndex(), itemRange.index); const int lastVisibleMovedIndex = qMin(lastVisibleIndex(), itemRange.index + itemRange.count - 1); + /// Represents an item that was moved while being edited. + struct MovedEditedItem { + int movedToIndex; + QByteArray editedRole; + }; + std::optional movedEditedItem; for (int index = firstVisibleMovedIndex; index <= lastVisibleMovedIndex; ++index) { KItemListWidget *widget = m_visibleItems.value(index); if (widget) { + if (m_editingRole && !widget->editedRole().isEmpty()) { + movedEditedItem = {movedToIndexes[index - itemRange.index], widget->editedRole()}; + disconnectRoleEditingSignals(index); + m_editingRole = false; + } updateWidgetProperties(widget, index); initializeItemListWidget(widget); } @@ -1378,6 +1400,10 @@ void KItemListView::slotItemsMoved(const KItemRange &itemRange, const QList doLayout(NoAnimation); updateSiblingsInformation(); + + if (movedEditedItem) { + editRole(movedEditedItem->movedToIndex, movedEditedItem->editedRole); + } } void KItemListView::slotItemsChanged(const KItemRangeList &itemRanges, const QSet &roles) @@ -1411,13 +1437,7 @@ void KItemListView::slotItemsChanged(const KItemRangeList &itemRanges, const QSe updateVisibleGroupHeaders(); doLayout(NoAnimation); } - - QAccessibleTableModelChangeEvent ev(this, QAccessibleTableModelChangeEvent::DataChanged); - ev.setFirstRow(itemRange.index); - ev.setLastRow(itemRange.index + itemRange.count); - QAccessible::updateAccessibility(&ev); } - doLayout(NoAnimation); } @@ -1479,8 +1499,6 @@ void KItemListView::slotSortRoleChanged(const QByteArray ¤t, const QByteAr void KItemListView::slotCurrentChanged(int current, int previous) { - Q_UNUSED(previous) - // In SingleSelection mode (e.g., in the Places Panel), the current item is // always the selected item. It is not necessary to highlight the current item then. if (m_controller->selectionBehavior() != KItemListController::SingleSelection) { @@ -1494,23 +1512,39 @@ void KItemListView::slotCurrentChanged(int current, int previous) currentWidget->setCurrent(true); } } - - QAccessibleEvent ev(this, QAccessible::Focus); - ev.setChild(current); - QAccessible::updateAccessibility(&ev); +#ifndef QT_NO_ACCESSIBILITY + if (current != previous && QAccessible::isActive()) { + static_cast(QAccessible::queryAccessibleInterface(this))->announceCurrentItem(); + } +#endif } void KItemListView::slotSelectionChanged(const KItemSet ¤t, const KItemSet &previous) { - Q_UNUSED(previous) - QHashIterator it(m_visibleItems); while (it.hasNext()) { it.next(); const int index = it.key(); KItemListWidget *widget = it.value(); - widget->setSelected(current.contains(index)); + const bool isSelected(current.contains(index)); + widget->setSelected(isSelected); + +#ifndef QT_NO_ACCESSIBILITY + if (!QAccessible::isActive()) { + continue; + } + // Let the screen reader announce "selected" or "not selected" for the active item. + const bool wasSelected(previous.contains(index)); + if (isSelected != wasSelected) { + QAccessibleEvent accessibleSelectionChangedEvent(this, QAccessible::SelectionAdd); + accessibleSelectionChangedEvent.setChild(index); + QAccessible::updateAccessibility(&accessibleSelectionChangedEvent); + } } +#else + } + Q_UNUSED(previous) +#endif } void KItemListView::slotAnimationFinished(QGraphicsWidget *widget, KItemListViewAnimation::AnimationType type) @@ -1563,10 +1597,10 @@ void KItemListView::slotRubberBandActivationChanged(bool active) curve.addCubicBezierSegment(QPointF(0.4, 0.0), QPointF(1.0, 1.0), QPointF(1.0, 1.0)); animation->setEasingCurve(curve); - connect(animation, &QVariantAnimation::valueChanged, this, [=](const QVariant &) { + connect(animation, &QVariantAnimation::valueChanged, this, [=, this](const QVariant &) { update(); }); - connect(animation, &QVariantAnimation::finished, this, [=]() { + connect(animation, &QVariantAnimation::finished, this, [=, this]() { m_rubberBandAnimations.removeAll(animation); delete animation; });