From: Peter Penz Date: Sat, 2 Jun 2007 17:28:59 +0000 (+0000) Subject: Provide a hover information when dragging items above other items. TODO: this code... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/e78615f172a2b9f549da6eef2b343a472d42f45f Provide a hover information when dragging items above other items. TODO: this code can be removed again when issue #160611 is solved in Qt 4.4. svn path=/trunk/KDE/kdebase/apps/; revision=670848 --- diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 961fb15a3..28901bea7 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -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) diff --git a/src/dolphindetailsview.h b/src/dolphindetailsview.h index 290e3cc06..8792881fd 100644 --- a/src/dolphindetailsview.h +++ b/src/dolphindetailsview.h @@ -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; diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 3f2e978c3..a4d7fe454 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -31,11 +31,13 @@ #include #include +#include #include 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) diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index c1301cd89..d2fc6b4ab 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -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