Fix tabbing around database widget

Fixes #8352
This commit is contained in:
Jonathan White 2022-08-18 22:18:01 -04:00
parent e5bd5f39fb
commit 79ac8b3c95

View File

@ -559,11 +559,7 @@ void DatabaseWidget::deleteEntries(QList<Entry*> selectedEntries, bool confirm)
void DatabaseWidget::setFocus(Qt::FocusReason reason) void DatabaseWidget::setFocus(Qt::FocusReason reason)
{ {
if (reason == Qt::BacktabFocusReason) { focusNextPrevChild(reason == Qt::TabFocusReason);
m_previewView->setFocus();
} else {
m_groupView->setFocus();
}
} }
void DatabaseWidget::focusOnEntries(bool editIfFocused) void DatabaseWidget::focusOnEntries(bool editIfFocused)
@ -1617,31 +1613,32 @@ void DatabaseWidget::showEvent(QShowEvent* event)
bool DatabaseWidget::focusNextPrevChild(bool next) bool DatabaseWidget::focusNextPrevChild(bool next)
{ {
// [parent] <-> GroupView <-> TagView <-> EntryView <-> EntryPreview <-> [parent] // [parent] <-> GroupView <-> TagView <-> EntryView <-> EntryPreview <-> [parent]
if (next) { QList<QWidget*> sequence = {m_groupView, m_tagView, m_entryView, m_previewView};
if (m_groupView->hasFocus()) { auto widget = qApp->focusWidget();
m_tagView->setFocus();
return true; int idx;
} else if (m_tagView->hasFocus()) { do {
m_entryView->setFocus(); idx = sequence.indexOf(widget);
return true; widget = widget->parentWidget();
} else if (m_entryView->hasFocus()) { } while (idx == -1 && widget);
m_previewView->setFocus();
return true; if (idx == -1) {
} idx = next ? 0 : sequence.size() - 1;
} else { } else {
if (m_previewView->hasFocus()) { idx = next ? idx + 1 : idx - 1;
m_entryView->setFocus();
return true;
} else if (m_entryView->hasFocus()) {
m_tagView->setFocus();
return true;
} else if (m_tagView->hasFocus()) {
m_groupView->setFocus();
return true;
}
} }
// Defer to the parent widget to make a decision // Find the next visible element in the sequence and set the focus
while (idx >= 0 && idx < sequence.size()) {
widget = sequence[idx];
if (widget->isVisible() && widget->height() > 0 && widget->width() > 0) {
widget->setFocus();
return widget;
}
idx = next ? idx + 1 : idx - 1;
}
// Ran out of options, defer to the parent widget
return QStackedWidget::focusNextPrevChild(next); return QStackedWidget::focusNextPrevChild(next);
} }