+ if (!view()->hasFocus() && QApplication::focusWidget() && QApplication::focusWidget()->isVisible()
+ && !static_cast<QWidget *>(m_parent->object())->isAncestorOf(QApplication::focusWidget())) {
+ // Something else than this view has focus, so we do not announce anything.
+ m_lastAnnouncedIndex = -1; // Reset this to -1 so we properly move focus to the current item the next time this method is called.
+ return;
+ }
+
+ /// Announce the current item (or the view if there is no current item).
+ const int currentIndex = view()->m_controller->selectionManager()->currentItem();
+ if (currentIndex < 0) {
+ // The current index is invalid! There might be no items in the list. Instead the list itself is announced.
+ m_shouldAnnounceLocation = true;
+ QAccessibleEvent announceEmptyViewPlaceholderMessageEvent(this, QAccessible::Focus);
+ QAccessible::updateAccessibility(&announceEmptyViewPlaceholderMessageEvent);
+ } else if (currentIndex != m_lastAnnouncedIndex) {
+ QAccessibleEvent announceNewlyFocusedItemEvent(this, QAccessible::Focus);
+ announceNewlyFocusedItemEvent.setChild(currentIndex);
+ QAccessible::updateAccessibility(&announceNewlyFocusedItemEvent);
+ } else {
+ QAccessibleEvent announceCurrentItemNameChangeEvent(this, QAccessible::NameChanged);
+ announceCurrentItemNameChangeEvent.setChild(currentIndex);
+ QAccessible::updateAccessibility(&announceCurrentItemNameChangeEvent);
+ QAccessibleEvent announceCurrentItemDescriptionChangeEvent(this, QAccessible::DescriptionChanged);
+ announceCurrentItemDescriptionChangeEvent.setChild(currentIndex);
+ QAccessible::updateAccessibility(&announceCurrentItemDescriptionChangeEvent);
+ }
+ m_lastAnnouncedIndex = currentIndex;
+
+ /// Announce the location if we are not just moving within the same location.
+ if (m_shouldAnnounceLocation) {
+ m_shouldAnnounceLocation = false;
+
+ QAccessibleEvent announceAccessibleDescriptionEvent1(this, QAccessible::NameChanged);
+ QAccessible::updateAccessibility(&announceAccessibleDescriptionEvent1);
+ QAccessibleEvent announceAccessibleDescriptionEvent(this, QAccessible::DescriptionChanged);
+ QAccessible::updateAccessibility(&announceAccessibleDescriptionEvent);
+ }