]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Allow using a common drag and drop pixmap also for the KCategorizedView. The code...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 20 Nov 2007 22:36:21 +0000 (22:36 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 20 Nov 2007 22:36:21 +0000 (22:36 +0000)
CCMAIL: ereslibre@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=739375

src/dolphiniconsview.cpp
src/dolphiniconsview.h
src/kcategorizedview.cpp
src/kcategorizedview.h

index c04a70fabf85586dd12c1081219a2633ff0531e8..fbb5f31c6f9c2e8d23ab8ffbdb3e6543b6328ffd 100644 (file)
@@ -142,8 +142,12 @@ QRect DolphinIconsView::visualRect(const QModelIndex& index) const
         itemRect.setHeight(maxHeight);
     }
 
-    if (leftToRightFlow && bypassVisualRectIssue()) {
-        // TODO: check inline comment inside bypassVisualRectIssue() for details
+    KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model());
+    if (leftToRightFlow && !proxyModel->isCategorizedModel()) {
+        // TODO: QListView::visualRect() calculates a wrong position of the items under
+        // certain circumstances (e. g. if the text is too long). This issue is bypassed
+        // by the following code (I'll try create a patch for Qt but as Dolphin must also work with
+        // Qt 4.3.0 this workaround must get applied at least for KDE 4.0).
         const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
         const int margin = settings->gridSpacing();
         const int gridWidth = gridSize().width();
@@ -180,12 +184,10 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event)
 
 void DolphinIconsView::startDrag(Qt::DropActions supportedActions)
 {
-    if (bypassVisualRectIssue()) {
-        // TODO: check inline comment inside bypassVisualRectIssue() for details
-        DragAndDropHelper::startDrag(this, supportedActions);
-    } else {
-        KCategorizedView::startDrag(supportedActions);
-    }
+    // TODO: invoking KCategorizedView::startDrag() should not be necessary, we'll
+    // fix this in KDE 4.1
+    KCategorizedView::startDrag(supportedActions);
+    DragAndDropHelper::startDrag(this, supportedActions);
 }
 
 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
@@ -198,12 +200,7 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 
 void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
 {
-    if (bypassVisualRectIssue()) {
-        // TODO: check inline comment inside bypassVisualRectIssue() for details
-        QAbstractItemView::dragLeaveEvent(event);
-    } else {
-        KCategorizedView::dragLeaveEvent(event);
-    }
+    KCategorizedView::dragLeaveEvent(event);
 
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     m_dragging = false;
@@ -212,12 +209,7 @@ void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
 
 void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
 {
-    if (bypassVisualRectIssue()) {
-        // TODO: check inline comment inside bypassVisualRectIssue() for details
-        QAbstractItemView::dragMoveEvent(event);
-    } else {
-        KCategorizedView::dragMoveEvent(event);
-    }
+    KCategorizedView::dragMoveEvent(event);
 
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     const QModelIndex index = indexAt(event->pos());
@@ -244,12 +236,7 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
         }
     }
 
-    if (bypassVisualRectIssue()) {
-        // TODO: check inline comment inside bypassVisualRectIssue() for details
-        QAbstractItemView::dropEvent(event);
-    } else {
-        KCategorizedView::dropEvent(event);
-    }
+    KCategorizedView::dropEvent(event);
 
     m_dragging = false;
 }
@@ -457,21 +444,4 @@ KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const
     return dirModel->itemForIndex(dirIndex);
 }
 
-bool DolphinIconsView::bypassVisualRectIssue() const
-{
-    // TODO: QListView::visualRect() calculates a wrong position of the items under
-    // certain circumstances (e. g. if the text is too long). This issue is bypassed
-    // inside DolphinIconsView::visualRect(), but internally QListView does not use
-    // visualRect() but the (non-virtual) QListView::rectForIndex(). This leads
-    // to problems in combination with drag & drop operations: visual fragments get
-    // created. To bypass the drag & drop issue the calls for QListView::dragMoveEvent(),
-    // QListView::dropEvent() are replaced by the QAbstractItemView counterparts and
-    // QAbstractItemView::startDrag() has been reimplemented.
-    //
-    // I'll try create a patch for Qt but as Dolphin must also work with
-    // Qt 4.3.0 this workaround must get applied at least for KDE 4.0.
-    KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model());
-    return !proxyModel->isCategorizedModel();
-}
-
 #include "dolphiniconsview.moc"
index 6c3f6fa3858e170137674322d4fad7f761f614aa..752f6e3171ad7cef16bf66ff0c531d95c074d292 100644 (file)
@@ -88,13 +88,6 @@ private:
 
     KFileItem itemForIndex(const QModelIndex& index) const;
 
-    /**
-     * Returns true, if the QListView-issue in QListView::visualRect()
-     * must be bypassed. TODO: this method is only temporary to have
-     * a usable drag & drop behavior until the issue in Qt is fixed.
-     */
-    bool bypassVisualRectIssue() const;
-
 private:
     DolphinController* m_controller;
     DolphinCategoryDrawer* m_categoryDrawer;
index 4f542f9c7fc0e12849f0633d1dbe0a27f316b4f1..894da2caeeea2328163782cb9ee50938b5288b50 100644 (file)
 #include "kcategorydrawer.h"
 #include "kcategorizedsortfilterproxymodel.h"
 
+// By defining DOLPHIN_DRAGANDDROP the custom drag and drop implementation of
+// KCategorizedView is bypassed to have a consistent drag and drop look for all
+// views. Hopefully transparent pixmaps for drag objects will be supported in
+// Qt 4.4, so that this workaround can be skipped.
+#define DOLPHIN_DRAGANDDROP
+
 KCategorizedView::Private::Private(KCategorizedView *listView)
     : listView(listView)
     , categoryDrawer(0)
@@ -1055,7 +1061,9 @@ void KCategorizedView::startDrag(Qt::DropActions supportedActions)
     //        ARGB window so it is no transparent. Use QAbstractItemView when
     //        this is fixed on Qt.
     // QAbstractItemView::startDrag(supportedActions);
+#if !defined(DOLPHIN_DRAGANDDROP)
     QListView::startDrag(supportedActions);
+#endif
 
     d->isDragging = false;
     d->mouseButtonPressed = false;
@@ -1081,7 +1089,11 @@ void KCategorizedView::dragMoveEvent(QDragMoveEvent *event)
     if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
         !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
     {
+#if defined(DOLPHIN_DRAGANDDROP)
+        QAbstractItemView::dragMoveEvent(event);
+#else
         QListView::dragMoveEvent(event);
+#endif
         return;
     }
 
@@ -1092,7 +1104,20 @@ void KCategorizedView::dragLeaveEvent(QDragLeaveEvent *event)
 {
     d->dragLeftViewport = true;
 
+#if defined(DOLPHIN_DRAGANDDROP)
+    QAbstractItemView::dragLeaveEvent(event);
+#else
     QListView::dragLeaveEvent(event);
+#endif
+}
+
+void KCategorizedView::dropEvent(QDropEvent *event)
+{
+#if defined(DOLPHIN_DRAGANDDROP)
+    QAbstractItemView::dropEvent(event);
+#else
+    QListView::dropEvent(event);
+#endif
 }
 
 QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction,
index 8544392d99e64d921bf321e37ccf6cce1e5b31e4..e2bc61d871e2d84c3a08be285ebd1330f8fb641d 100644 (file)
@@ -85,6 +85,8 @@ protected:
 
     virtual void dragLeaveEvent(QDragLeaveEvent *event);
 
+    virtual void dropEvent(QDropEvent *event);
+
     virtual QModelIndex moveCursor(CursorAction cursorAction,
                                    Qt::KeyboardModifiers modifiers);