fix focus move on list views with header and-or footer

This commit is contained in:
Cyril Anisimov 2024-10-25 03:42:22 +02:00
parent 42645a98f8
commit 3d7209ee7a
2 changed files with 51 additions and 9 deletions

View file

@ -142,7 +142,7 @@ void ListViewFocusController::nextDelegate()
{ {
switch(m_currentSection) { switch(m_currentSection) {
case Section::Default: { case Section::Default: {
if(m_header) { if(hasHeader()) {
m_currentSection = Section::Header; m_currentSection = Section::Header;
viewToBegin(); viewToBegin();
break; break;
@ -160,7 +160,7 @@ void ListViewFocusController::nextDelegate()
if (m_delegateIndex < (size() - 1)) { if (m_delegateIndex < (size() - 1)) {
m_delegateIndex++; m_delegateIndex++;
break; break;
} else if (m_footer) { } else if (hasFooter()) {
m_currentSection = Section::Footer; m_currentSection = Section::Footer;
viewToEnd(); viewToEnd();
break; break;
@ -182,7 +182,7 @@ void ListViewFocusController::previousDelegate()
{ {
switch(m_currentSection) { switch(m_currentSection) {
case Section::Default: { case Section::Default: {
if(m_footer) { if(hasFooter()) {
m_currentSection = Section::Footer; m_currentSection = Section::Footer;
break; break;
} }
@ -200,7 +200,7 @@ void ListViewFocusController::previousDelegate()
if (m_delegateIndex > 0) { if (m_delegateIndex > 0) {
m_delegateIndex--; m_delegateIndex--;
break; break;
} else if (m_header) { } else if (hasHeader()) {
m_currentSection = Section::Header; m_currentSection = Section::Header;
break; break;
} }
@ -331,15 +331,54 @@ bool ListViewFocusController::isLastFocusItemInDelegate()
bool ListViewFocusController::isFirstFocusItemInListView() bool ListViewFocusController::isFirstFocusItemInListView()
{ {
return (m_delegateIndex == 0) && isFirstFocusItemInDelegate(); switch (m_currentSection) {
case Section::Footer: {
return isFirstFocusItemInDelegate() && !hasHeader() && (size() == 0);
}
case Section::Delegate: {
return isFirstFocusItemInDelegate() && (m_delegateIndex == 0) && !hasHeader();
}
case Section::Header: {
isFirstFocusItemInDelegate();
}
case Section::Default: {
return true;
}
default:
qWarning() << "Wrong section";
return true;
}
}
bool ListViewFocusController::hasHeader()
{
return m_header && !getItemsChain(m_header).isEmpty();
}
bool ListViewFocusController::hasFooter()
{
return m_footer && !getItemsChain(m_footer).isEmpty();
} }
bool ListViewFocusController::isLastFocusItemInListView() bool ListViewFocusController::isLastFocusItemInListView()
{ {
bool isLastSection = (m_footer && m_currentSection == Section::Footer) switch (m_currentSection) {
|| (!m_footer && (m_currentSection == Section::Delegate) && (m_delegateIndex == size() - 1)) case Section::Default: {
|| (m_header && (m_currentSection == Section::Header) && (size() <= 0) && !m_footer); return !hasHeader() && (size() == 0) && !hasFooter();
return isLastSection && isLastFocusItemInDelegate(); }
case Section::Header: {
return isLastFocusItemInDelegate() && (size() == 0) && !hasFooter();
}
case Section::Delegate: {
return isLastFocusItemInDelegate() && (m_delegateIndex == size() - 1) && !hasFooter();
}
case Section::Footer: {
return isLastFocusItemInDelegate();
}
default:
qWarning() << "Wrong section";
return true;
}
} }
bool ListViewFocusController::isReturnNeeded() bool ListViewFocusController::isReturnNeeded()

View file

@ -59,6 +59,9 @@ private:
QQuickItem* currentDelegate(); QQuickItem* currentDelegate();
QQuickItem* focusedItem(); QQuickItem* focusedItem();
bool hasHeader();
bool hasFooter();
QQuickItem* m_listView; QQuickItem* m_listView;
QList<QObject*> m_focusChain; QList<QObject*> m_focusChain;
Section m_currentSection; Section m_currentSection;