]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
SVN_SILENT: removed unnecessary include
[dolphin.git] / src / dolphinview.cpp
index 85bc21c771579384dc0bfc10992d40f12b4dbd64..034b81d3fb4001f401734917542f5a11f358afd2 100644 (file)
@@ -134,8 +134,8 @@ DolphinView::DolphinView(QWidget* parent,
             this, SLOT(clearHoverInformation()));
 
     KDirLister* dirLister = m_viewAccessor.dirLister();
-    connect(dirLister, SIGNAL(redirection(KUrl, KUrl)),
-            this, SIGNAL(redirection(KUrl, KUrl)));
+    connect(dirLister, SIGNAL(redirection(KUrl,KUrl)),
+            this, SLOT(slotRedirection(KUrl,KUrl)));
     connect(dirLister, SIGNAL(completed()),
             this, SLOT(slotDirListerCompleted()));
     connect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
@@ -246,7 +246,7 @@ void DolphinView::setMode(Mode mode)
     emit modeChanged();
 
     updateZoomLevel(oldZoomLevel);
-    if (m_showPreview) {   
+    if (m_showPreview) {
         loadDirectory(viewPropsUrl);
     }
 }
@@ -309,7 +309,8 @@ void DolphinView::invertSelection()
 
 bool DolphinView::hasSelection() const
 {
-    return m_viewAccessor.itemView()->selectionModel()->hasSelection();
+    const QAbstractItemView* view = m_viewAccessor.itemView();
+    return view && view->selectionModel()->hasSelection();
 }
 
 void DolphinView::clearSelection()
@@ -361,6 +362,7 @@ int DolphinView::selectedItemsCount() const
 void DolphinView::setContentsPosition(int x, int y)
 {
     QAbstractItemView* view = m_viewAccessor.itemView();
+    Q_ASSERT(view != 0);
     view->horizontalScrollBar()->setValue(x);
     view->verticalScrollBar()->setValue(y);
 
@@ -369,8 +371,10 @@ void DolphinView::setContentsPosition(int x, int y)
 
 QPoint DolphinView::contentsPosition() const
 {
-    const int x = m_viewAccessor.itemView()->horizontalScrollBar()->value();
-    const int y = m_viewAccessor.itemView()->verticalScrollBar()->value();
+    QAbstractItemView* view = m_viewAccessor.itemView();
+    Q_ASSERT(view != 0);
+    const int x = view->horizontalScrollBar()->value();
+    const int y = view->verticalScrollBar()->value();
     return QPoint(x, y);
 }
 
@@ -624,7 +628,7 @@ void DolphinView::renameSelectedItems()
             return;
         }
         delete dialog;
-        
+
         // the selection would be invalid after renaming the items, so just clear
         // it before
         clearSelection();
@@ -827,20 +831,6 @@ void DolphinView::mouseReleaseEvent(QMouseEvent* event)
     setActive(true);
 }
 
-void DolphinView::wheelEvent(QWheelEvent* event)
-{
-    if (event->modifiers() & Qt::ControlModifier) {
-        const int delta = event->delta();
-        const int level = zoomLevel();
-        if (delta > 0) {
-            setZoomLevel(level + 1);
-        } else if (delta < 0) {
-            setZoomLevel(level - 1);
-        }
-        event->accept();
-    }
-}
-
 bool DolphinView::eventFilter(QObject* watched, QEvent* event)
 {
     switch (event->type()) {
@@ -866,6 +856,24 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         }
         break;
 
+    case QEvent::Wheel:
+        if (watched == m_viewAccessor.itemView()->viewport()) {
+            // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
+            // (the user is probably trying to scroll during a selection in that case)
+            QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
+            if (wheelEvent->modifiers() & Qt::ControlModifier && !(wheelEvent->buttons() & Qt::LeftButton)) {
+                const int delta = wheelEvent->delta();
+                const int level = zoomLevel();
+                if (delta > 0) {
+                    setZoomLevel(level + 1);
+                } else if (delta < 0) {
+                    setZoomLevel(level - 1);
+                }
+                return true;
+            }
+        }
+        break;
+        
     default:
         break;
     }
@@ -1260,6 +1268,7 @@ void DolphinView::applyViewProperties()
 void DolphinView::createView()
 {
     deleteView();
+
     Q_ASSERT(m_viewAccessor.itemView() == 0);
     m_viewAccessor.createView(this, m_controller, m_mode);
 
@@ -1305,9 +1314,14 @@ void DolphinView::deleteView()
         m_topLayout->removeWidget(view);
         view->close();
 
+        // disconnect all signal/slots
         disconnect(view);
         m_controller->disconnect(view);
         view->disconnect();
+        disconnect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
+                   this, SLOT(emitContentsMoved()));
+        disconnect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
+                   this, SLOT(emitContentsMoved()));
 
         m_viewAccessor.deleteView();
     }
@@ -1416,8 +1430,9 @@ void DolphinView::ViewAccessor::deleteView()
     m_iconsView = 0;
     m_detailsView = 0;
 
-    if (m_columnsContainer)
+    if (m_columnsContainer != 0) {
         m_columnsContainer->deleteLater();
+    }
     m_columnsContainer = 0;
 }
 
@@ -1499,4 +1514,10 @@ KDirLister* DolphinView::ViewAccessor::dirLister() const
     return dirModel()->dirLister();
 }
 
+void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
+{
+    emit redirection(oldUrl, newUrl);
+    m_controller->redirectToUrl(newUrl); // #186947
+}
+
 #include "dolphinview.moc"