add setDelegateIndex method to listViewFocusController

This commit is contained in:
Cyril Anisimov 2024-12-09 01:32:11 +01:00
parent f331c11f51
commit 3cc70790bd
2 changed files with 10 additions and 3 deletions

View file

@ -141,6 +141,12 @@ int ListViewFocusController::currentIndex() const
return m_delegateIndex;
}
void ListViewFocusController::setDelegateIndex(int index)
{
m_delegateIndex = index;
m_listView->setProperty("currentIndex", index);
}
void ListViewFocusController::nextDelegate()
{
const auto sectionName = m_currentSectionString[static_cast<int>(m_currentSection)];
@ -164,7 +170,7 @@ void ListViewFocusController::nextDelegate()
}
case Section::Delegate:
if (m_delegateIndex < (size() - 1)) {
m_delegateIndex++;
setDelegateIndex(m_delegateIndex + 1);
viewAtCurrentIndex();
break;
} else if (hasFooter()) {
@ -199,14 +205,14 @@ void ListViewFocusController::previousDelegate()
case Section::Footer: {
if (size() > 0) {
m_currentSection = Section::Delegate;
m_delegateIndex = size() - 1;
setDelegateIndex(size() - 1);
break;
}
[[fallthrough]];
}
case Section::Delegate: {
if (m_delegateIndex > 0) {
m_delegateIndex--;
setDelegateIndex(m_delegateIndex - 1);
break;
} else if (hasHeader()) {
m_currentSection = Section::Header;

View file

@ -52,6 +52,7 @@ private:
int size() const;
int currentIndex() const;
void setDelegateIndex(int index);
void viewAtCurrentIndex() const;
QQuickItem* itemAtIndex(const int index) const;
QQuickItem* currentDelegate() const;