Skip to content

Commit

Permalink
fix focus movement on dynamic delegates in listView
Browse files Browse the repository at this point in the history
  • Loading branch information
CyAn84 committed Dec 28, 2024
1 parent f8f4d75 commit 867ad8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions client/ui/controllers/focusController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ void FocusController::nextItem(Direction direction)
void FocusController::focusNextListViewItem()
{
qDebug() << "===>> Calling < focusNextListViewItem >...";

m_lvfc->reloadFocusChain();
if (m_lvfc->isLastFocusItemInListView() || m_lvfc->isReturnNeeded()) {
qDebug() << "===>> Last item in [ ListView ] was reached. Going to the NEXT element after [ ListView ]";
dropListView();
nextItem(Direction::Forward);
return;
} else if (m_lvfc->isLastFocusItemInDelegate()) {
qDebug() << "===>> End of delegate elements was reached. Going to the next delegate";
qDebug() << "===>> End of delegate's elements was reached. Going to the next delegate";
m_lvfc->resetFocusChain();
m_lvfc->nextDelegate();
}
Expand All @@ -234,13 +234,14 @@ void FocusController::focusNextListViewItem()
void FocusController::focusPreviousListViewItem()
{
qDebug() << "===>> Calling < focusPreviousListViewItem >...";

m_lvfc->reloadFocusChain();
if (m_lvfc->isFirstFocusItemInListView() || m_lvfc->isReturnNeeded()) {
qDebug() << "===>> First item in [ ListView ] was reached. Going to the PREVIOUS element after [ ListView ]";
dropListView();
nextItem(Direction::Backward);
return;
} else if (m_lvfc->isFirstFocusItemInDelegate()) {
qDebug() << "===>> End of delegate's elements was reached. Going to the previous delegate";
m_lvfc->resetFocusChain();
m_lvfc->previousDelegate();
}
Expand Down
9 changes: 7 additions & 2 deletions client/ui/controllers/listViewFocusController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void ListViewFocusController::focusNextItem()
return;
}

m_focusChain = focusControl::getItemsChain(currentDelegate());
reloadFocusChain();

if (m_focusChain.empty()) {
qWarning() << "No elements found in the delegate. Going to next delegate...";
Expand All @@ -224,7 +224,7 @@ void ListViewFocusController::focusPreviousItem()

if (m_focusChain.empty()) {
qDebug() << "Empty focusChain with current delegate: " << currentDelegate() << "Scanning for elements...";
m_focusChain = focusControl::getItemsChain(currentDelegate());
reloadFocusChain();
}
if (m_focusChain.empty()) {
qWarning() << "No elements found in the delegate. Going to next delegate...";
Expand All @@ -248,6 +248,11 @@ void ListViewFocusController::resetFocusChain()
m_focusedItemIndex = -1;
}

void ListViewFocusController::reloadFocusChain()
{
m_focusChain = focusControl::getItemsChain(currentDelegate());
}

bool ListViewFocusController::isFirstFocusItemInDelegate() const
{
return m_focusedItem && (m_focusedItem == m_focusChain.first());
Expand Down
1 change: 1 addition & 0 deletions client/ui/controllers/listViewFocusController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ListViewFocusController : public QObject
void focusNextItem();
void focusPreviousItem();
void resetFocusChain();
void reloadFocusChain();
bool isFirstFocusItemInListView() const;
bool isFirstFocusItemInDelegate() const;
bool isLastFocusItemInListView() const;
Expand Down

0 comments on commit 867ad8e

Please sign in to comment.