src/gui/itemviews/qabstractitemview.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
--- a/src/gui/itemviews/qabstractitemview.cpp	Mon Jun 21 22:38:13 2010 +0100
+++ b/src/gui/itemviews/qabstractitemview.cpp	Thu Jul 22 16:41:55 2010 +0100
@@ -104,8 +104,10 @@
         horizontalScrollMode(QAbstractItemView::ScrollPerItem),
         currentIndexSet(false),
         wrapItemText(false),
-        delayedPendingLayout(false)
+        delayedPendingLayout(true),
+        moveCursorUpdatedView(false)
 {
+    keyboardInputTime.invalidate();
 }
 
 QAbstractItemViewPrivate::~QAbstractItemViewPrivate()
@@ -131,8 +133,6 @@
 
     viewport->setBackgroundRole(QPalette::Base);
 
-    doDelayedItemsLayout();
-
     q->setAttribute(Qt::WA_InputMethodEnabled);
 
 #ifdef QT_SOFTKEYS_ENABLED
@@ -679,7 +679,11 @@
         connect(d->model, SIGNAL(modelReset()), this, SLOT(reset()));
         connect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged()));
     }
-    setSelectionModel(new QItemSelectionModel(d->model, this));
+
+    QItemSelectionModel *selection_model = new QItemSelectionModel(d->model, this);
+    connect(d->model, SIGNAL(destroyed()), selection_model, SLOT(deleteLater()));
+    setSelectionModel(selection_model);
+
     reset(); // kill editors, set new root and do layout
 }
 
@@ -1785,7 +1789,10 @@
         emit clicked(index);
         if (edited)
             return;
-        if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this))
+        QStyleOptionViewItemV4 option = d->viewOptionsV4();
+        if (d->pressedAlreadySelected)
+            option.state |= QStyle::State_Selected;
+        if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this))
             emit activated(index);
     }
 }
@@ -2090,7 +2097,7 @@
         bool autoScroll = d->autoScroll;
         d->autoScroll = false;
         QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); // first visible index
-        if (index.isValid() && d->isIndexEnabled(index))
+        if (index.isValid() && d->isIndexEnabled(index) && event->reason() != Qt::MouseFocusReason)
             selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
         d->autoScroll = autoScroll;
     }
@@ -2210,6 +2217,7 @@
 #endif
 
     QPersistentModelIndex newCurrent;
+    d->moveCursorUpdatedView = false;
     switch (event->key()) {
     case Qt::Key_Down:
         newCurrent = moveCursor(MoveDown, event->modifiers());
@@ -2266,6 +2274,7 @@
                 QRect rect(d->pressedPosition - d->offset(), QSize(1, 1));
                 setSelection(rect, command);
             }
+            event->accept();
             return;
         }
     }
@@ -2297,6 +2306,8 @@
     case Qt::Key_Escape:
     case Qt::Key_Shift:
     case Qt::Key_Control:
+    case Qt::Key_Delete:
+    case Qt::Key_Backspace:
         event->ignore();
         break;
     case Qt::Key_Space:
@@ -2361,6 +2372,8 @@
         }
         break; }
     }
+    if (d->moveCursorUpdatedView)
+        event->accept();
 }
 
 /*!
@@ -2837,16 +2850,16 @@
 
     QModelIndex start = currentIndex().isValid() ? currentIndex()
                         : d->model->index(0, 0, d->root);
-    QTime now(QTime::currentTime());
     bool skipRow = false;
-    if (search.isEmpty()
-        || (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) {
+    bool keyboardTimeWasValid = d->keyboardInputTime.isValid();
+    qint64 keyboardInputTimeElapsed = d->keyboardInputTime.restart();
+    if (search.isEmpty() || !keyboardTimeWasValid
+        || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
         d->keyboardInput = search;
         skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0)
     } else {
         d->keyboardInput += search;
     }
-    d->keyboardInputTime = now;
 
     // special case for searches with same key like 'aaaaa'
     bool sameKey = false;