src/gui/itemviews/qabstractitemview.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 29 b72c6db6890b
--- a/src/gui/itemviews/qabstractitemview.cpp	Fri Apr 16 15:50:13 2010 +0300
+++ b/src/gui/itemviews/qabstractitemview.cpp	Mon May 03 13:17:34 2010 +0300
@@ -2119,6 +2119,11 @@
     Q_D(QAbstractItemView);
     QAbstractScrollArea::focusOutEvent(event);
     d->viewport->update();
+
+#ifdef QT_SOFTKEYS_ENABLED
+    if(!hasEditFocus())
+        removeAction(d->doneSoftKey);
+#endif
 }
 
 /*!
@@ -2144,7 +2149,12 @@
             if (!hasEditFocus()) {
                 setEditFocus(true);
 #ifdef QT_SOFTKEYS_ENABLED
-                addAction(d->doneSoftKey);
+                // If we can't keypad navigate to any direction, there is no sense to add
+                // "Done" softkey, since it basically does nothing when there is
+                // only one widget in screen
+                if(QWidgetPrivate::canKeypadNavigate(Qt::Horizontal)
+                        || QWidgetPrivate::canKeypadNavigate(Qt::Vertical))
+                    addAction(d->doneSoftKey);
 #endif
                 return;
             }
@@ -2160,6 +2170,26 @@
             event->ignore();
         }
         return;
+    case Qt::Key_Down:
+    case Qt::Key_Up:
+        // Let's ignore vertical navigation events, only if there is no other widget
+        // what can take the focus in vertical direction. This means widget can handle navigation events
+        // even the widget don't have edit focus, and there is no other widget in requested direction.
+        if(QApplication::keypadNavigationEnabled() && !hasEditFocus()
+                && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
+            event->ignore();
+            return;
+        }
+        break;
+    case Qt::Key_Left:
+    case Qt::Key_Right:
+        // Similar logic as in up and down events
+        if(QApplication::keypadNavigationEnabled() && !hasEditFocus()
+                && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this))) {
+            event->ignore();
+            return;
+        }
+        break;
     default:
         if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
             event->ignore();
@@ -2245,7 +2275,7 @@
     case Qt::Key_Down:
     case Qt::Key_Up:
 #ifdef QT_KEYPAD_NAVIGATION
-        if (QApplication::keypadNavigationEnabled()) {
+        if (QApplication::keypadNavigationEnabled() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
             event->accept(); // don't change focus
             break;
         }
@@ -2253,8 +2283,10 @@
     case Qt::Key_Left:
     case Qt::Key_Right:
 #ifdef QT_KEYPAD_NAVIGATION
-        if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
-            event->accept(); // don't change horizontal focus in directional mode
+        if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
+                && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal)
+                || (QWidgetPrivate::inTabWidget(this) && d->model->columnCount(d->root) > 1))) {
+            event->accept(); // don't change focus
             break;
         }
 #endif // QT_KEYPAD_NAVIGATION
@@ -2536,6 +2568,7 @@
     QStyleOptionViewItemV4 option = d->viewOptionsV4();
     QList<QEditorInfo>::iterator it = d->editors.begin();
     QWidgetList editorsToRelease;
+    QWidgetList editorsToHide;
     while (it != d->editors.end()) {
         QModelIndex index = it->index;
         QWidget *editor = it->editor;
@@ -2547,7 +2580,7 @@
                 if (delegate)
                     delegate->updateEditorGeometry(editor, option, index);
             } else {
-                editor->hide();
+                editorsToHide << editor;
             }
             ++it;
         } else {
@@ -2556,8 +2589,11 @@
         }
     }
 
-    //we release the editor outside of the loop because it might change the focus and try
+    //we hide and release the editor outside of the loop because it might change the focus and try
     //to change the d->editors list.
+    for (int i = 0; i < editorsToHide.count(); ++i) {
+        editorsToHide.at(i)->hide();
+    }
     for (int i = 0; i < editorsToRelease.count(); ++i) {
         d->releaseEditor(editorsToRelease.at(i));
     }
@@ -3014,6 +3050,7 @@
     if (!d->isIndexValid(index))
         return;
     if (QWidget *oldWidget = indexWidget(index)) {
+        d->persistent.remove(oldWidget);
         d->removeEditor(oldWidget);
         oldWidget->deleteLater();
     }