From c206ea53ebac0436bad0c00c1e340f23efb3aa16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Fri, 2 Oct 2009 16:15:56 +0300 Subject: Filedialog impossible to use with keypad navigation QFileDialog contains own internal derived classes for line edit and list view. Unfortunately, these classes do not handle keypad navigation correctly - they just accept the navigation key events, causing the navigation to halt. Added support for QFileDialogListView, QFileDialogTreeView and private filedialog class QFileDialogPrivate to handle and possibly ignore keypad navigaion key events. Additionally, added support to keypad navigation to ignore empty widgets. This allows keypad navigation not to go invisible when empty widgets are tried to be navigated into. Task-number: QT-643 Reviewed-by: Alessandro Portale --- src/gui/dialogs/qfiledialog.cpp | 22 +++++++++++++++++++++- src/gui/kernel/qwidget.cpp | 10 +++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 297c900..eb5fed0 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -3022,6 +3022,12 @@ bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) { case Qt::Key_Escape: q->hide(); return true; +#ifdef QT_KEYPAD_NAVIGATION + case Qt::Key_Down: + case Qt::Key_Up: + return (QApplication::navigationMode() != Qt::NavigationModeKeypadTabOrder + && QApplication::navigationMode() != Qt::NavigationModeKeypadDirectional); +#endif default: break; } @@ -3142,7 +3148,17 @@ void QFileDialogListView::keyPressEvent(QKeyEvent *e) if (!d_ptr->itemViewKeyboardEvent(e)) { QListView::keyPressEvent(e); } +#ifdef QT_KEYPAD_NAVIGATION + if ((QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder + || QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) + && !hasEditFocus()) { + e->ignore(); + } else { + e->accept(); + } +#else e->accept(); +#endif } QFileDialogTreeView::QFileDialogTreeView(QWidget *parent) : QTreeView(parent) @@ -3189,7 +3205,11 @@ void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) { int key = e->key(); QLineEdit::keyPressEvent(e); - if (key != Qt::Key_Escape) + if (key != Qt::Key_Escape +#ifdef QT_KEYPAD_NAVIGATION + && QApplication::navigationMode() == Qt::NavigationModeNone +#endif + ) e->accept(); if (hideOnEsc && (key == Qt::Key_Escape || key == Qt::Key_Return || key == Qt::Key_Enter)) { e->accept(); diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 0b75b06..3cfbb09 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11444,11 +11444,15 @@ QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction) QWidget *targetWidget = 0; int shortestDistance = INT_MAX; foreach(QWidget *targetCandidate, QApplication::allWidgets()) { - - if (targetCandidate->focusProxy()) //skip if focus proxy set - continue; const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint())); + + // For focus proxies, the child widget handling the focus can have keypad navigation focus, + // but the owner of the proxy cannot. + // Additionally, empty widgets should be ignored. + if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty()) + continue; + if ( targetCandidate != sourceWidget && targetCandidate->focusPolicy() & Qt::TabFocus && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top()) -- cgit v0.12