]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Drag & drop fixes for all views: assure that a consistent pixmap for the drag object...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 20 Nov 2007 21:11:48 +0000 (21:11 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 20 Nov 2007 21:11:48 +0000 (21:11 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=739322

13 files changed:
src/CMakeLists.txt
src/dolphincolumnwidget.cpp
src/dolphincolumnwidget.h
src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphindetailsview.cpp
src/dolphindetailsview.h
src/dolphiniconsview.cpp
src/dolphiniconsview.h
src/draganddrophelper.cpp [new file with mode: 0644]
src/draganddrophelper.h [new file with mode: 0644]
src/sidebartreeview.cpp
src/sidebartreeview.h

index 1cfbc9adf007e8814419ea89d8e898dd1326edfb..c2025178612195f235c1dcb68ba217784383067c 100644 (file)
@@ -12,6 +12,7 @@ set(dolphinprivate_LIB_SRCS
     dolphiniconsview.cpp
     dolphincolumnview.cpp
     dolphincolumnwidget.cpp
     dolphiniconsview.cpp
     dolphincolumnview.cpp
     dolphincolumnwidget.cpp
+    draganddrophelper.cpp
     kcategorizedview.cpp
     kcategorydrawer.cpp
     dolphinmodel.cpp
     kcategorizedview.cpp
     kcategorydrawer.cpp
     dolphinmodel.cpp
@@ -81,6 +82,7 @@ set(dolphin_SRCS
    dolphindirlister.cpp
    dolphincontextmenu.cpp
    dolphinsettingsdialog.cpp
    dolphindirlister.cpp
    dolphincontextmenu.cpp
    dolphinsettingsdialog.cpp
+   draganddrophelper.cpp
    filterbar.cpp
    generalsettingspage.cpp
    generalviewsettingspage.cpp
    filterbar.cpp
    generalsettingspage.cpp
    generalviewsettingspage.cpp
index 2dc3bc1530bf6f0be7bf12f741f3bc9a7f909a65..1a7f712f38e2a3681f81fd941eab1239c4409973 100644 (file)
@@ -26,8 +26,8 @@
 #include "dolphinmodel.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinsettings.h"
 #include "dolphinmodel.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinsettings.h"
-
 #include "dolphin_columnmodesettings.h"
 #include "dolphin_columnmodesettings.h"
+#include "draganddrophelper.h"
 
 #include <kcolorutils.h>
 #include <kcolorscheme.h>
 
 #include <kcolorutils.h>
 #include <kcolorscheme.h>
@@ -197,6 +197,11 @@ void DolphinColumnWidget::setNameFilter(const QString& nameFilter)
     m_proxyModel->setFilterRegExp(nameFilter);
 }
 
     m_proxyModel->setFilterRegExp(nameFilter);
 }
 
+void DolphinColumnWidget::startDrag(Qt::DropActions supportedActions)
+{
+    DragAndDropHelper::startDrag(this, supportedActions);
+}
+
 void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
 void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
@@ -271,7 +276,7 @@ void DolphinColumnWidget::paintEvent(QPaintEvent* event)
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
-        DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
+        DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
     }
 }
 
     }
 }
 
index fdb0471f2eb6b90b55c7aca6fb8b0e4dd79c36af..e8fea3bf595afb1f1587eb878e3b423e50fd094b 100644 (file)
@@ -92,6 +92,7 @@ public:
 
 protected:
     virtual QStyleOptionViewItem viewOptions() const;
 
 protected:
     virtual QStyleOptionViewItem viewOptions() const;
+    virtual void startDrag(Qt::DropActions supportedActions);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
index 58f6f681f5122ea6633a659dea13987c9ae1ba6d..f5fd5e83670b4dd38801a7bef7478b789c531246 100644 (file)
@@ -19,8 +19,6 @@
 
 #include "dolphincontroller.h"
 
 
 #include "dolphincontroller.h"
 
-#include <QPainter>
-
 DolphinController::DolphinController(DolphinView* dolphinView) :
     QObject(dolphinView),
     m_zoomInPossible(false),
 DolphinController::DolphinController(DolphinView* dolphinView) :
     QObject(dolphinView),
     m_zoomInPossible(false),
@@ -98,33 +96,6 @@ void DolphinController::triggerZoomOut()
     emit zoomOut();
 }
 
     emit zoomOut();
 }
 
-void DolphinController::drawHoverIndication(QWidget* widget,
-                                            const QRect& bounds,
-                                            const QBrush& brush)
-{
-    QPainter painter(widget);
-    painter.save();
-    QBrush blendedBrush(brush);
-    QColor color = blendedBrush.color();
-    color.setAlpha(64);
-    blendedBrush.setColor(color);
-
-    const int radius = 10;
-    QPainterPath path(QPointF(bounds.left(), bounds.top() + radius));
-    path.quadTo(bounds.left(), bounds.top(), bounds.left() + radius, bounds.top());
-    path.lineTo(bounds.right() - radius, bounds.top());
-    path.quadTo(bounds.right(), bounds.top(), bounds.right(), bounds.top() + radius);
-    path.lineTo(bounds.right(), bounds.bottom() - radius);
-    path.quadTo(bounds.right(), bounds.bottom(), bounds.right() - radius, bounds.bottom());
-    path.lineTo(bounds.left() + radius, bounds.bottom());
-    path.quadTo(bounds.left(), bounds.bottom(), bounds.left(), bounds.bottom() - radius);
-    path.closeSubpath();
-
-    painter.setRenderHint(QPainter::Antialiasing);
-    painter.fillPath(path, blendedBrush);
-    painter.restore();
-}
-
 void DolphinController::triggerItem(const KFileItem& item)
 {
     emit itemTriggered(item);
 void DolphinController::triggerItem(const KFileItem& item)
 {
     emit itemTriggered(item);
index 16b5f5587122f311b34be9f4c48a3f5b1b5d95b3..e08e9e49031acf958b2873152efd2be5b03a0845 100644 (file)
@@ -192,11 +192,6 @@ public:
     void setZoomOutPossible(bool possible);
     bool isZoomOutPossible() const;
 
     void setZoomOutPossible(bool possible);
     bool isZoomOutPossible() const;
 
-    // TODO: remove this method when the issue #160611 is solved in Qt 4.4
-    static void drawHoverIndication(QWidget* widget,
-                                    const QRect& bounds,
-                                    const QBrush& brush);
-
 public slots:
     /**
      * Emits the signal itemTriggered(). The method should be invoked by the
 public slots:
     /**
      * Emits the signal itemTriggered(). The method should be invoked by the
index f4bba2f039c1748a264feae271081d854fcdfd94..3fd1e94680dc6b654ede2cf107a06dbba14db05f 100644 (file)
@@ -24,6 +24,7 @@
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
 #include "dolphinsortfilterproxymodel.h"
+#include "draganddrophelper.h"
 #include "viewproperties.h"
 
 #include "dolphin_detailsmodesettings.h"
 #include "viewproperties.h"
 
 #include "dolphin_detailsmodesettings.h"
@@ -212,6 +213,11 @@ void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
     }
 }
 
     }
 }
 
+void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
+{
+    DragAndDropHelper::startDrag(this, supportedActions);
+}
+
 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
@@ -294,7 +300,7 @@ void DolphinDetailsView::paintEvent(QPaintEvent* event)
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
-        DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
+        DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
     }
 }
 
     }
 }
 
index f00b263d17c77f49f3257d9b7f5eb90f09a37339..1b21690c0b46896fe7003fc55068dc8f96b7c1e3 100644 (file)
@@ -51,6 +51,7 @@ protected:
     virtual void mousePressEvent(QMouseEvent* event);
     virtual void mouseMoveEvent(QMouseEvent* event);
     virtual void mouseReleaseEvent(QMouseEvent* event);
     virtual void mousePressEvent(QMouseEvent* event);
     virtual void mouseMoveEvent(QMouseEvent* event);
     virtual void mouseReleaseEvent(QMouseEvent* event);
+    virtual void startDrag(Qt::DropActions supportedActions);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
index ea553c8bee1b299f8943fe4a6d0990170c4bc39b..c04a70fabf85586dd12c1081219a2633ff0531e8 100644 (file)
@@ -23,6 +23,7 @@
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
 #include "dolphin_iconsmodesettings.h"
 #include "dolphincontroller.h"
 #include "dolphinsettings.h"
 #include "dolphin_iconsmodesettings.h"
+#include "draganddrophelper.h"
 
 #include <kcategorizedsortfilterproxymodel.h>
 #include <kdialog.h>
 
 #include <kcategorizedsortfilterproxymodel.h>
 #include <kdialog.h>
@@ -45,7 +46,10 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     setViewMode(QListView::IconMode);
     setResizeMode(QListView::Adjust);
     setSpacing(KDialog::spacingHint());
     setViewMode(QListView::IconMode);
     setResizeMode(QListView::Adjust);
     setSpacing(KDialog::spacingHint());
-    setMovement(QListView::Snap);
+    setMovement(QListView::Static);
+    setDragEnabled(true);
+    viewport()->setAcceptDrops(true);
+
     setMouseTracking(true);
     viewport()->setAttribute(Qt::WA_Hover);
 
     setMouseTracking(true);
     viewport()->setAttribute(Qt::WA_Hover);
 
@@ -138,12 +142,8 @@ QRect DolphinIconsView::visualRect(const QModelIndex& index) const
         itemRect.setHeight(maxHeight);
     }
 
         itemRect.setHeight(maxHeight);
     }
 
-    KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model());
-    if (leftToRightFlow && !proxyModel->isCategorizedModel()) {
-        // TODO: This workaround bypasses a layout issue in QListView::visualRect(), where
-        // the horizontal position of items might get calculated in a wrong manner when the item
-        // name is too long. 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.
+    if (leftToRightFlow && bypassVisualRectIssue()) {
+        // TODO: check inline comment inside bypassVisualRectIssue() for details
         const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
         const int margin = settings->gridSpacing();
         const int gridWidth = gridSize().width();
         const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
         const int margin = settings->gridSpacing();
         const int gridWidth = gridSize().width();
@@ -178,6 +178,16 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event)
     KCategorizedView::mousePressEvent(event);
 }
 
     KCategorizedView::mousePressEvent(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);
+    }
+}
+
 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
@@ -188,7 +198,12 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 
 void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
 {
 
 void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
 {
-    KCategorizedView::dragLeaveEvent(event);
+    if (bypassVisualRectIssue()) {
+        // TODO: check inline comment inside bypassVisualRectIssue() for details
+        QAbstractItemView::dragLeaveEvent(event);
+    } else {
+        KCategorizedView::dragLeaveEvent(event);
+    }
 
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     m_dragging = false;
 
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     m_dragging = false;
@@ -197,7 +212,12 @@ void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
 
 void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
 {
 
 void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
 {
-    KCategorizedView::dragMoveEvent(event);
+    if (bypassVisualRectIssue()) {
+        // TODO: check inline comment inside bypassVisualRectIssue() for details
+        QAbstractItemView::dragMoveEvent(event);
+    } else {
+        KCategorizedView::dragMoveEvent(event);
+    }
 
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     const QModelIndex index = indexAt(event->pos());
 
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     const QModelIndex index = indexAt(event->pos());
@@ -224,7 +244,13 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
         }
     }
 
         }
     }
 
-    KCategorizedView::dropEvent(event);
+    if (bypassVisualRectIssue()) {
+        // TODO: check inline comment inside bypassVisualRectIssue() for details
+        QAbstractItemView::dropEvent(event);
+    } else {
+        KCategorizedView::dropEvent(event);
+    }
+
     m_dragging = false;
 }
 
     m_dragging = false;
 }
 
@@ -235,7 +261,7 @@ void DolphinIconsView::paintEvent(QPaintEvent* event)
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
-        DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
+        DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
     }
 }
 
     }
 }
 
@@ -431,5 +457,21 @@ KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const
     return dirModel->itemForIndex(dirIndex);
 }
 
     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"
 
 #include "dolphiniconsview.moc"
index ae0a6299dfbb6d7e9928b792e10b70247d7dbb12..6c3f6fa3858e170137674322d4fad7f761f614aa 100644 (file)
@@ -54,6 +54,7 @@ protected:
     virtual QStyleOptionViewItem viewOptions() const;
     virtual void contextMenuEvent(QContextMenuEvent* event);
     virtual void mousePressEvent(QMouseEvent* event);
     virtual QStyleOptionViewItem viewOptions() const;
     virtual void contextMenuEvent(QContextMenuEvent* event);
     virtual void mousePressEvent(QMouseEvent* event);
+    virtual void startDrag(Qt::DropActions supportedActions);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
@@ -87,6 +88,13 @@ private:
 
     KFileItem itemForIndex(const QModelIndex& index) const;
 
 
     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;
 private:
     DolphinController* m_controller;
     DolphinCategoryDrawer* m_categoryDrawer;
diff --git a/src/draganddrophelper.cpp b/src/draganddrophelper.cpp
new file mode 100644 (file)
index 0000000..d918867
--- /dev/null
@@ -0,0 +1,85 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at>                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#include "draganddrophelper.h"
+
+#include <kdirmodel.h>
+#include <kicon.h>
+
+#include <QAbstractItemView>
+#include <QAbstractProxyModel>
+#include <QBrush>
+#include <QDrag>
+#include <QPainter>
+#include <QRect>
+#include <QWidget>
+
+void DragAndDropHelper::startDrag(QAbstractItemView* itemView, Qt::DropActions supportedActions)
+{
+    QModelIndexList indexes = itemView->selectionModel()->selectedIndexes();
+    if (indexes.count() > 0) {
+        QMimeData *data = itemView->model()->mimeData(indexes);
+        if (data == 0) {
+            return;
+        }
+
+        QDrag* drag = new QDrag(itemView);
+        QPixmap pixmap;
+        if (indexes.count() == 1) {
+            QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(itemView->model());
+            KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+            const QModelIndex index = proxyModel->mapToSource(indexes.first());
+
+            const KFileItem item = dirModel->itemForIndex(index);
+            pixmap = item.pixmap(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
+        } else {
+            pixmap = KIcon("item-drag-multiple").pixmap(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
+        }
+        drag->setPixmap(pixmap);
+        drag->setMimeData(data);
+        drag->exec(supportedActions);
+    }
+}
+
+void DragAndDropHelper::drawHoverIndication(QWidget* widget,
+                                            const QRect& bounds,
+                                            const QBrush& brush)
+{
+    QPainter painter(widget);
+    painter.save();
+    QBrush blendedBrush(brush);
+    QColor color = blendedBrush.color();
+    color.setAlpha(64);
+    blendedBrush.setColor(color);
+
+    const int radius = 10;
+    QPainterPath path(QPointF(bounds.left(), bounds.top() + radius));
+    path.quadTo(bounds.left(), bounds.top(), bounds.left() + radius, bounds.top());
+    path.lineTo(bounds.right() - radius, bounds.top());
+    path.quadTo(bounds.right(), bounds.top(), bounds.right(), bounds.top() + radius);
+    path.lineTo(bounds.right(), bounds.bottom() - radius);
+    path.quadTo(bounds.right(), bounds.bottom(), bounds.right() - radius, bounds.bottom());
+    path.lineTo(bounds.left() + radius, bounds.bottom());
+    path.quadTo(bounds.left(), bounds.bottom(), bounds.left(), bounds.bottom() - radius);
+    path.closeSubpath();
+
+    painter.setRenderHint(QPainter::Antialiasing);
+    painter.fillPath(path, blendedBrush);
+    painter.restore();
+}
diff --git a/src/draganddrophelper.h b/src/draganddrophelper.h
new file mode 100644 (file)
index 0000000..9e17495
--- /dev/null
@@ -0,0 +1,52 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at>                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef DRAGANDDROPHELPER_H
+#define DRAGANDDROPHELPER_H
+
+#include <Qt>
+
+class QAbstractItemView;
+class QBrush;
+class QRect;
+class QWidget;
+
+/**
+ * @brief Helper class to bypass some drag & drop limitations in Qt.
+ *
+ * The class is used by DolphinIconsView, DolphinDetailsView,
+ * DolphinColumnView and SidebarTreeView to have a consistent
+ * drag and drop behavior between all views.
+ */
+class DragAndDropHelper
+{
+
+public:
+    /**
+     * Creates a drag object for the view \a itemView for all selected items.
+     */
+    static void startDrag(QAbstractItemView* itemView, Qt::DropActions supportedActions);
+
+    // TODO: remove this method when the issue #160611 is solved in Qt 4.4
+    static void drawHoverIndication(QWidget* widget,
+                                    const QRect& bounds,
+                                    const QBrush& brush);
+};
+
+#endif
index ae6c26224c0ea4361a2b592ea187bd27b9b75c1b..3567c35d6b11676ac01c88c536cb35ff25ad5ea1 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "dolphincontroller.h"
 #include "dolphinmodel.h"
 
 #include "dolphincontroller.h"
 #include "dolphinmodel.h"
+#include "draganddrophelper.h"
 
 #include <kfileitemdelegate.h>
 #include <QKeyEvent>
 
 #include <kfileitemdelegate.h>
 #include <QKeyEvent>
@@ -95,6 +96,11 @@ bool SidebarTreeView::event(QEvent* event)
     return QTreeView::event(event);
 }
 
     return QTreeView::event(event);
 }
 
+void SidebarTreeView::startDrag(Qt::DropActions supportedActions)
+{
+    DragAndDropHelper::startDrag(this, supportedActions);
+}
+
 void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
 void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
@@ -146,7 +152,7 @@ void SidebarTreeView::paintEvent(QPaintEvent* event)
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = palette().brush(QPalette::Normal, QPalette::Highlight);
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = palette().brush(QPalette::Normal, QPalette::Highlight);
-        DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
+        DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
     }
 }
 
     }
 }
 
index ba8fd74851287ce5ecf3a387b8949df65565bee9..b2e42e24fbb80c058de8303301397c84e7258a54 100644 (file)
@@ -46,6 +46,7 @@ signals:
 
 protected:
     virtual bool event(QEvent* event);
 
 protected:
     virtual bool event(QEvent* event);
+    virtual void startDrag(Qt::DropActions supportedActions);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dragLeaveEvent(QDragLeaveEvent* event);
     virtual void dragMoveEvent(QDragMoveEvent* event);