]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Provide a hover information when dragging items above other items. TODO: this code...
authorPeter Penz <peter.penz19@gmail.com>
Sat, 2 Jun 2007 17:28:59 +0000 (17:28 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 2 Jun 2007 17:28:59 +0000 (17:28 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=670848

src/dolphindetailsview.cpp
src/dolphindetailsview.h
src/dolphiniconsview.cpp
src/dolphiniconsview.h

index 961fb15a3c3f1e6c6a8999c1545a23f38535a929..28901bea776c07f545c5250a7ad583fbee4c001c 100644 (file)
@@ -39,6 +39,7 @@
 DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) :
     QTreeView(parent),
     m_controller(controller),
+    m_dragging(false),
     m_showElasticBand(false),
     m_elasticBandOrigin(),
     m_elasticBandDestination()
@@ -203,6 +204,19 @@ void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
         updateElasticBand();
         m_showElasticBand = false;
     }
+    m_dragging = true;
+}
+
+void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
+{
+    QTreeView::dragMoveEvent(event);
+
+    // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+    const QPoint pos(0, event->pos().y());
+    const QModelIndex index = indexAt(pos);
+    setDirtyRegion(m_dropRect);
+    m_dropRect = visualRect(index);
+    setDirtyRegion(m_dropRect);
 }
 
 void DolphinDetailsView::dropEvent(QDropEvent* event)
@@ -215,6 +229,7 @@ void DolphinDetailsView::dropEvent(QDropEvent* event)
                                           event->source());
     }
     QTreeView::dropEvent(event);
+    m_dragging = false;
 }
 
 void DolphinDetailsView::paintEvent(QPaintEvent* event)
@@ -235,6 +250,18 @@ void DolphinDetailsView::paintEvent(QPaintEvent* event)
         style()->drawControl(QStyle::CE_RubberBand, &opt, &painter);
         painter.restore();
     }
+
+    if (m_dragging) {
+        // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+        QPainter painter(viewport());
+        painter.save();
+        QBrush brush(m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight));
+        QColor color = brush.color();
+        color.setAlpha(64);
+        brush.setColor(color);
+        painter.fillRect(m_dropRect, brush);
+        painter.restore();
+    }
 }
 
 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
index 290e3cc06000d47ec987826e52ed33b8ff1808ab..8792881fda1f73f0595a03cadefa7690bdbbb2c0 100644 (file)
@@ -52,6 +52,7 @@ protected:
     virtual void mouseMoveEvent(QMouseEvent* event);
     virtual void mouseReleaseEvent(QMouseEvent* event);
     virtual void dragEnterEvent(QDragEnterEvent* event);
+    virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dropEvent(QDropEvent* event);
     virtual void paintEvent(QPaintEvent* event);
 
@@ -120,6 +121,9 @@ private:
     DolphinController* m_controller;
     QStyleOptionViewItem m_viewOptions;
 
+    bool m_dragging;   // TODO: remove this property when the issue #160611 is solved in Qt 4.4
+    QRect m_dropRect;  // TODO: remove this property when the issue #160611 is solved in Qt 4.4
+
     bool m_showElasticBand;
     QPoint m_elasticBandOrigin;
     QPoint m_elasticBandDestination;
index 3f2e978c38abed07f407c7263aa1030a5ae2aba6..a4d7fe454584341905b6553cd84005ffdec675e1 100644 (file)
 
 #include <QAbstractProxyModel>
 #include <QApplication>
+#include <QPainter>
 #include <QPoint>
 
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     KListView(parent),
-    m_controller(controller)
+    m_controller(controller),
+    m_dragging(false)
 {
     Q_ASSERT(controller != 0);
     setViewMode(QListView::IconMode);
@@ -129,6 +131,18 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
     if (event->mimeData()->hasUrls()) {
         event->acceptProposedAction();
     }
+    m_dragging = true;
+}
+
+void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
+{
+    KListView::dragMoveEvent(event);
+
+    // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+    const QModelIndex index = indexAt(event->pos());
+    setDirtyRegion(m_dropRect);
+    m_dropRect = visualRect(index);
+    setDirtyRegion(m_dropRect);
 }
 
 void DolphinIconsView::dropEvent(QDropEvent* event)
@@ -141,6 +155,24 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
         event->acceptProposedAction();
     }
     KListView::dropEvent(event);
+    m_dragging = false;
+}
+
+void DolphinIconsView::paintEvent(QPaintEvent* event)
+{
+    KListView::paintEvent(event);
+
+    if (m_dragging) {
+        // TODO: remove this code when the issue #160611 is solved in Qt 4.4
+        QPainter painter(viewport());
+        painter.save();
+        QBrush brush(m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight));
+        QColor color = brush.color();
+        color.setAlpha(64);
+        brush.setColor(color);
+        painter.fillRect(m_dropRect, brush);
+        painter.restore();
+    }
 }
 
 void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
index c1301cd8936c94dd7371b85542e12d6194a0d81d..d2fc6b4abcea5b476147197a0fe59ec4a4d23b5f 100644 (file)
@@ -49,7 +49,9 @@ protected:
     virtual void mousePressEvent(QMouseEvent* event);
     virtual void mouseReleaseEvent(QMouseEvent* event);
     virtual void dragEnterEvent(QDragEnterEvent* event);
+    virtual void dragMoveEvent(QDragMoveEvent* event);
     virtual void dropEvent(QDropEvent* event);
+    virtual void paintEvent(QPaintEvent* event);
 
 private slots:
     void slotShowPreviewChanged(bool show);
@@ -76,6 +78,9 @@ private:
 private:
     DolphinController* m_controller;
     QStyleOptionViewItem m_viewOptions;
+
+    bool m_dragging;   // TODO: remove this property when the issue #160611 is solved in Qt 4.4
+    QRect m_dropRect;  // TODO: remove this property when the issue #160611 is solved in Qt 4.4
 };
 
 #endif