]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphindetailsview.cpp
fix possible crash when selecting "New Tab" from the tab context menu of an inactive tab
[dolphin.git] / src / dolphindetailsview.cpp
index 2eb631a649bb87ca8aba7d895db156ac54b5fab3..08d03fb0b5effc6a8b6013f70468caa7dd5d43eb 100644 (file)
@@ -47,6 +47,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     QTreeView(parent),
        m_autoResize(true),
     m_controller(controller),
+    m_selectionManager(0),
     m_font(),
     m_decorationSize(),
     m_showElasticBand(false),
@@ -66,9 +67,9 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     setAlternatingRowColors(true);
     setRootIsDecorated(settings->expandableFolders());
     setItemsExpandable(settings->expandableFolders());
+    setEditTriggers(QAbstractItemView::NoEditTriggers);
 
     setMouseTracking(true);
-    viewport()->setAttribute(Qt::WA_Hover);
 
     const ViewProperties props(controller->url());
     setSortIndicatorSection(props.sorting());
@@ -98,12 +99,12 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
         connect(this, SIGNAL(clicked(const QModelIndex&)),
                 controller, SLOT(triggerItem(const QModelIndex&)));
         if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
-            SelectionManager* selManager = new SelectionManager(this);
-            connect(selManager, SIGNAL(selectionChanged()),
+            m_selectionManager = new SelectionManager(this);
+            connect(m_selectionManager, SIGNAL(selectionChanged()),
                     this, SLOT(requestActivation()));
             connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
-                    selManager, SLOT(reset()));
-        }
+                    m_selectionManager, SLOT(reset()));
+         }
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
                 controller, SLOT(triggerItem(const QModelIndex&)));
@@ -134,6 +135,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     updateDecorationSize();
 
     setFocus();
+    viewport()->installEventFilter(this);
 
     connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
             this, SLOT(updateFont()));
@@ -344,18 +346,40 @@ void DolphinDetailsView::resizeEvent(QResizeEvent* event)
 
 void DolphinDetailsView::wheelEvent(QWheelEvent* event)
 {
+    if (m_selectionManager != 0) {
+        m_selectionManager->reset();
+    }
+
     // let Ctrl+wheel events propagate to the DolphinView for icon zooming
     if (event->modifiers() & Qt::ControlModifier) {
         event->ignore();
         return;
     }
+
     QTreeView::wheelEvent(event);
 }
 
 void DolphinDetailsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
 {
     QTreeView::currentChanged(current, previous);
-    selectionModel()->select(current, QItemSelectionModel::ClearAndSelect);
+
+    // Stay consistent with QListView: When changing the current index by key presses,
+    // also change the selection.
+    if (QApplication::mouseButtons() == Qt::NoButton) {
+        selectionModel()->select(current, QItemSelectionModel::ClearAndSelect);
+    }
+}
+
+bool DolphinDetailsView::eventFilter(QObject* watched, QEvent* event)
+{
+    if ((watched == viewport()) && (event->type() == QEvent::Leave)) {
+        // if the mouse is above an item and moved very fast outside the widget,
+        // no viewportEntered() signal might be emitted although the mouse has been moved
+        // above the viewport
+        m_controller->emitViewportEntered();
+    }
+
+    return QTreeView::eventFilter(watched, event);
 }
 
 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
@@ -537,6 +561,10 @@ void DolphinDetailsView::updateDecorationSize()
     m_controller->setZoomInPossible(isZoomInPossible());
     m_controller->setZoomOutPossible(isZoomOutPossible());
 
+    if (m_selectionManager != 0) {
+        m_selectionManager->reset();
+    }
+
     doItemsLayout();
 }