]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
Improve the performance of the code part which checks which items are visible. Althou...
[dolphin.git] / src / dolphiniconsview.cpp
index a9659739a99ce3979aaec90124964268ae0e81ac..3cb9b929d59786b66ac070d29b9c8f7c1877e1b2 100644 (file)
 
 #include <QAbstractProxyModel>
 #include <QApplication>
-#include <QPainter>
-#include <QPoint>
 #include <QScrollBar>
 
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     KCategorizedView(parent),
+    m_enableScrollTo(false),
     m_controller(controller),
     m_selectionManager(0),
     m_categoryDrawer(0),
@@ -135,6 +134,19 @@ DolphinIconsView::~DolphinIconsView()
     m_categoryDrawer = 0;
 }
 
+void DolphinIconsView::scrollTo(const QModelIndex& index, ScrollHint hint)
+{
+    // Enable the QListView implementation of scrollTo() only if it has been
+    // triggered by a key press. Otherwise QAbstractItemView wants to scroll to the current
+    // index each time the layout has been changed. This becomes an issue when
+    // previews are loaded and the scrollbar is used: the scrollbar will always
+    // be reset to 0 on each new preview.
+    if (m_enableScrollTo || (state() != QAbstractItemView::NoState)) {
+        KCategorizedView::scrollTo(index, hint);
+        m_enableScrollTo = false;
+    }
+}
+
 void DolphinIconsView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
 {
     KCategorizedView::dataChanged(topLeft, bottomRight);
@@ -167,7 +179,20 @@ void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
 void DolphinIconsView::mousePressEvent(QMouseEvent* event)
 {
     m_controller->requestActivation();
-    if (!indexAt(event->pos()).isValid()) {
+    const QModelIndex index = indexAt(event->pos());
+    if (index.isValid() && (event->button() == Qt::LeftButton)) {
+        // TODO: It should not be necessary to manually set the dragging state, but I could
+        // not reproduce this issue with a Qt-only example yet to find the root cause.
+        // Issue description: start Dolphin, split the view and drag an item from the
+        // inactive view to the active view by a very fast mouse movement. Result:
+        // the item gets selected instead of being dragged...
+        setState(QAbstractItemView::DraggingState);
+    }
+
+    if (!index.isValid()) {
+        if (QApplication::mouseButtons() & Qt::MidButton) {
+            m_controller->replaceUrlByClipboard();
+        }
         const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
         if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
             clearSelection();
@@ -244,6 +269,7 @@ void DolphinIconsView::keyPressEvent(QKeyEvent* event)
 {
     KCategorizedView::keyPressEvent(event);
     m_controller->handleKeyPressEvent(event);
+    m_enableScrollTo = true; // see DolphinIconsView::scrollTo()
 }
 
 void DolphinIconsView::wheelEvent(QWheelEvent* event)