]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Move the changing of the cursor-shape from the extensions-factory and the selection...
authorPeter Penz <peter.penz19@gmail.com>
Fri, 8 Oct 2010 19:10:53 +0000 (19:10 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 8 Oct 2010 19:10:53 +0000 (19:10 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1183934

src/views/selectionmanager.cpp
src/views/selectionmanager.h
src/views/selectiontoggle.cpp
src/views/selectiontoggle.h
src/views/viewextensionsfactory.cpp
src/views/viewextensionsfactory.h

index 7353e5a39e940968cda76f50520ec39707519a92..c06d827bddbd69c1acccee90e1956c19a5b00d07 100644 (file)
@@ -38,7 +38,8 @@ SelectionManager::SelectionManager(QAbstractItemView* parent) :
     QObject(parent),
     m_view(parent),
     m_toggle(0),
-    m_connected(false)
+    m_connected(false),
+    m_appliedPointingHandCursor(false)
 {
     connect(parent, SIGNAL(entered(const QModelIndex&)),
             this, SLOT(slotEntered(const QModelIndex&)));
@@ -49,6 +50,7 @@ SelectionManager::SelectionManager(QAbstractItemView* parent) :
     m_toggle->hide();
     connect(m_toggle, SIGNAL(clicked(bool)),
             this, SLOT(setItemSelected(bool)));
+    m_toggle->installEventFilter(this);
 
     m_view->viewport()->installEventFilter(this);
 }
@@ -59,14 +61,45 @@ SelectionManager::~SelectionManager()
 
 bool SelectionManager::eventFilter(QObject* watched, QEvent* event)
 {
-    Q_ASSERT(watched == m_view->viewport());
-    if (event->type() == QEvent::MouseButtonPress) {
-        // Set the toggle invisible, if a mouse button has been pressed
-        // outside the toggle boundaries. This e.g. assures, that the toggle
-        // gets invisible during dragging items.
-        const QRect toggleBounds(m_toggle->mapToGlobal(QPoint(0, 0)), m_toggle->size());
-        m_toggle->setVisible(toggleBounds.contains(QCursor::pos()));
+    if (watched == m_view->viewport()) {
+        switch (event->type()) {
+        case QEvent::Leave:
+            m_toggle->hide();
+            break;
+
+        case QEvent::MouseButtonPress: {
+            // Set the toggle invisible, if a mouse button has been pressed
+            // outside the toggle boundaries. This e.g. assures, that the toggle
+            // gets invisible during dragging items.
+            const QRect toggleBounds(m_toggle->mapToGlobal(QPoint(0, 0)), m_toggle->size());
+            m_toggle->setVisible(toggleBounds.contains(QCursor::pos()));
+            break;
+        }
+
+        default:
+            break;
+        }
+    } else if (watched == m_toggle) {
+        switch (event->type()) {
+        case QEvent::Hide:
+            // If the toggle button gets hidden, the cursor is not above the item
+            // anymore and the shape must get restored
+            restoreCursor();
+            break;
+
+        case QEvent::Enter:
+            QApplication::changeOverrideCursor(Qt::ArrowCursor);
+            break;
+
+        case QEvent::Leave:
+            QApplication::changeOverrideCursor(Qt::PointingHandCursor);
+            break;
+
+        default:
+            break;
+        }
     }
+
     return QObject::eventFilter(watched, event);
 }
 
@@ -82,6 +115,8 @@ void SelectionManager::slotEntered(const QModelIndex& index)
                             (index.column() == DolphinModel::Name) &&
                             (QApplication::mouseButtons() == Qt::NoButton);
     if (showToggle) {
+        applyPointingHandCursor();
+
         m_toggle->setUrl(urlForIndex(index));
 
         if (!m_connected) {
@@ -198,4 +233,21 @@ const QModelIndex SelectionManager::indexForUrl(const KUrl& url) const
     return proxyModel->mapFromSource(dirIndex);
 }
 
+
+void SelectionManager::applyPointingHandCursor()
+{
+    if (!m_appliedPointingHandCursor) {
+        QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
+        m_appliedPointingHandCursor = true;
+    }
+}
+
+void SelectionManager::restoreCursor()
+{
+    if (m_appliedPointingHandCursor) {
+        QApplication::restoreOverrideCursor();
+        m_appliedPointingHandCursor = false;
+    }
+}
+
 #include "selectionmanager.moc"
index 85145a50b95e8ac0e051b3f7cf59de6b073254ec..9cab4f3a97f60f925ab35ac97340765a88c703da 100644 (file)
@@ -65,11 +65,14 @@ private slots:
 private:
     KUrl urlForIndex(const QModelIndex& index) const;
     const QModelIndex indexForUrl(const KUrl& url) const;
+    void applyPointingHandCursor();
+    void restoreCursor();
 
 private:
     QAbstractItemView* m_view;
     SelectionToggle* m_toggle;
     bool m_connected;
+    bool m_appliedPointingHandCursor;
 };
 
 #endif
index cbd273b11924f577db2a899a286775bc9987a782..c1272fa0f764385131dc65e1df264e4e8497adc0 100644 (file)
 #include <QTimer>
 #include <QTimeLine>
 
+#include <kdebug.h>
+
 SelectionToggle::SelectionToggle(QWidget* parent) :
     QAbstractButton(parent),
     m_isHovered(false),
     m_leftMouseButtonPressed(false),
-    m_appliedArrowCursor(false),
     m_fadingValue(0),
     m_margin(0),
     m_icon(),
@@ -106,25 +107,12 @@ void SelectionToggle::setVisible(bool visible)
 
 bool SelectionToggle::eventFilter(QObject* obj, QEvent* event)
 {
-    if (obj == parent()) {
-        switch (event->type()) {
-        case QEvent::Leave:
-            hide();
-            break;
-
-        case QEvent::MouseMove:
-            if (m_leftMouseButtonPressed) {
-                // Don't forward mouse move events to the viewport,
-                // otherwise a rubberband selection will be shown when
-                // clicking on the selection toggle and moving the mouse
-                // above the viewport.
-                return true;
-            }
-            break;
-
-        default:
-            break;
-        }
+    if ((obj == parent()) && (event->type() == QEvent::MouseMove) && m_leftMouseButtonPressed) {
+        // Don't forward mouse move events to the viewport,
+        // otherwise a rubberband selection will be shown when
+        // clicking on the selection toggle and moving the mouse
+        // above the viewport.
+        return true;
     }
 
     return QAbstractButton::eventFilter(obj, event);
@@ -134,19 +122,6 @@ void SelectionToggle::enterEvent(QEvent* event)
 {
     QAbstractButton::enterEvent(event);
 
-    if (!m_appliedArrowCursor) {
-        m_appliedArrowCursor = true;
-        // Apply the arrow asynchronously. This is required for
-        // the following usecase:
-        // 1. Cursor is above the viewport left beside an item
-        // 2. Cursor is moved above the item, so that the selection-toggle
-        //    and the item are entered equally.
-        // In this situation it is not defined who gets the enter-event first.
-        // As the selection-toggle is above the item, it should overwrite possible
-        // cursor changes done by the item.
-        QTimer::singleShot(0, this, SLOT(applyArrowCursor()));
-    }
-
     // if the mouse cursor is above the selection toggle, display
     // it immediately without fading timer
     m_isHovered = true;
@@ -163,13 +138,6 @@ void SelectionToggle::leaveEvent(QEvent* event)
 {
     QAbstractButton::leaveEvent(event);
 
-    if (m_appliedArrowCursor) {
-        // Reset the cursor asynchronously. See SelectionToggle::enterEvent()
-        // for a more information.
-        m_appliedArrowCursor = false;
-        QTimer::singleShot(0, this, SLOT(restoreCursor()));
-    }
-
     m_isHovered = false;
     update();
 }
@@ -245,16 +213,6 @@ void SelectionToggle::refreshIcon()
     setIconOverlay(isChecked());
 }
 
-void SelectionToggle::applyArrowCursor()
-{
-    QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
-}
-
-void SelectionToggle::restoreCursor()
-{
-    QApplication::restoreOverrideCursor();
-}
-
 void SelectionToggle::startFading()
 {
     Q_ASSERT(m_fadingTimeLine == 0);
index 26aa3005041db4d00e4a592d6121a870a253e08b..210f1a3aa5b4e6b2c0bf61a56e2a89b28a1938cb 100644 (file)
@@ -82,9 +82,6 @@ private slots:
     void setIconOverlay(bool checked);
     void refreshIcon();
 
-    void applyArrowCursor();
-    void restoreCursor();
-
 private:
     void startFading();
     void stopFading();
@@ -92,7 +89,6 @@ private:
 private:
     bool m_isHovered;
     bool m_leftMouseButtonPressed;
-    bool m_appliedArrowCursor;
     int m_fadingValue;
     int m_margin;
     QPixmap m_icon;
index 1523962538dcd88b35acf7e1e0123e38e23a984e..5dabd66cc4ac2e69622919660acdc1a3069407c5 100644 (file)
@@ -43,7 +43,6 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
                                              DolphinViewController* dolphinViewController,
                                              const ViewModeController* viewModeController) :
     QObject(view),
-    m_appliedPointingHandCursor(false),
     m_view(view),
     m_dolphinViewController(dolphinViewController),
     m_toolTipManager(0),
@@ -129,11 +128,6 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
             this, SLOT(slotNameFilterChanged(const QString&)));
 
     view->viewport()->installEventFilter(this);
-
-    // Apply a pointing-hand cursor when hovering files
-    connect(view, SIGNAL(entered(const QModelIndex&)), SLOT(applyPointingHandCursor()));
-    connect(view, SIGNAL(viewportEntered()), SLOT(restoreCursor()));
-    connect(viewModeController, SIGNAL(urlChanged(const KUrl&)), SLOT(restoreCursor()));
 }
 
 ViewExtensionsFactory::~ViewExtensionsFactory()
@@ -163,21 +157,9 @@ bool ViewExtensionsFactory::autoFolderExpandingEnabled() const
 bool ViewExtensionsFactory::eventFilter(QObject* watched, QEvent* event)
 {
     Q_UNUSED(watched);
-
-    switch (event->type()) {
-    case QEvent::Wheel:
-        if (m_selectionManager != 0) {
-            m_selectionManager->reset();
-        }
-        break;
-
-    case QEvent::Leave:
-        restoreCursor();
-        break;
-
-    default: break;
+    if ((event->type() == QEvent::Wheel) && (m_selectionManager != 0)) {
+        m_selectionManager->reset();
     }
-
     return false;
 }
 
@@ -254,22 +236,6 @@ void ViewExtensionsFactory::requestActivation()
     m_dolphinViewController->requestActivation();
 }
 
-void ViewExtensionsFactory::applyPointingHandCursor()
-{
-    if (!m_appliedPointingHandCursor &&  !(QApplication::mouseButtons() & Qt::LeftButton)) {
-        QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
-        m_appliedPointingHandCursor = true;
-    }
-}
-
-void ViewExtensionsFactory::restoreCursor()
-{
-    if (m_appliedPointingHandCursor) {
-        QApplication::restoreOverrideCursor();
-        m_appliedPointingHandCursor = false;
-    }
-}
-
 DolphinSortFilterProxyModel* ViewExtensionsFactory::proxyModel() const
 {
     return static_cast<DolphinSortFilterProxyModel*>(m_view->model());
index 0ab3d06d0be09d4971f1fb24d8e466e10279aa69..9324932ac684f6e8a08bd311be2e21d89f5400d7 100644 (file)
@@ -85,14 +85,11 @@ private slots:
     void slotNameFilterChanged(const QString& nameFilter);
     void slotRequestVersionControlActions(const KFileItemList& items);
     void requestActivation();
-    void applyPointingHandCursor();
-    void restoreCursor();
 
 private:
     DolphinSortFilterProxyModel* proxyModel() const;
 
 private:
-    bool m_appliedPointingHandCursor;
     QAbstractItemView* m_view;
     DolphinViewController* m_dolphinViewController;
     ToolTipManager* m_toolTipManager;