From 38fa728aa607af2fb890f4d602d68ed1ae9d2278 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Wed, 12 Mar 2008 16:49:55 +0000 Subject: [PATCH] As the Qt-issue 160611 is solved in Qt4.4 and Fredrik has improved KFileItemDelegate, it is not necessary anymore drawing a custom drag & drop indication. svn path=/trunk/KDE/kdebase/apps/; revision=784851 --- src/dolphincolumnwidget.cpp | 13 ------------ src/dolphincolumnwidget.h | 3 +-- src/dolphindetailsview.cpp | 17 +-------------- src/dolphindetailsview.h | 3 +-- src/dolphiniconsview.cpp | 21 ------------------- src/dolphiniconsview.h | 5 +---- src/draganddrophelper.cpp | 41 ------------------------------------- src/draganddrophelper.h | 7 +------ src/sidebartreeview.cpp | 21 +------------------ src/sidebartreeview.h | 4 +--- 10 files changed, 7 insertions(+), 128 deletions(-) diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index f0656808d..bbaa5f793 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -60,7 +60,6 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_dolphinModel(0), m_proxyModel(0), m_iconManager(0), - m_dragging(false), m_dropRect() { setMouseTracking(true); @@ -251,16 +250,11 @@ void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event) if (event->mimeData()->hasUrls()) { event->acceptProposedAction(); } - - m_dragging = true; } void DolphinColumnWidget::dragLeaveEvent(QDragLeaveEvent* event) { QListView::dragLeaveEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - m_dragging = false; setDirtyRegion(m_dropRect); } @@ -301,7 +295,6 @@ void DolphinColumnWidget::dropEvent(QDropEvent* event) event->acceptProposedAction(); } QListView::dropEvent(event); - m_dragging = false; } void DolphinColumnWidget::paintEvent(QPaintEvent* event) @@ -326,12 +319,6 @@ void DolphinColumnWidget::paintEvent(QPaintEvent* event) } QListView::paintEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - if (m_dragging) { - const QBrush& brush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight); - DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush); - } } void DolphinColumnWidget::mousePressEvent(QMouseEvent* event) diff --git a/src/dolphincolumnwidget.h b/src/dolphincolumnwidget.h index b8113cd6f..3472f95d8 100644 --- a/src/dolphincolumnwidget.h +++ b/src/dolphincolumnwidget.h @@ -139,8 +139,7 @@ private: IconManager* m_iconManager; - 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 + QRect m_dropRect; }; inline bool DolphinColumnWidget::isActive() const diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 11b993849..2eb631a64 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -49,7 +49,6 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr m_controller(controller), m_font(), m_decorationSize(), - m_dragging(false), m_showElasticBand(false), m_elasticBandOrigin(), m_elasticBandDestination() @@ -261,15 +260,11 @@ void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event) updateElasticBand(); m_showElasticBand = false; } - m_dragging = true; } void DolphinDetailsView::dragLeaveEvent(QDragLeaveEvent* event) { QTreeView::dragLeaveEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - m_dragging = false; setDirtyRegion(m_dropRect); } @@ -280,10 +275,7 @@ void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event) // TODO: remove this code when the issue #160611 is solved in Qt 4.4 setDirtyRegion(m_dropRect); const QModelIndex index = indexAt(event->pos()); - if (!index.isValid() || (index.column() != DolphinModel::Name)) { - m_dragging = false; - } else { - m_dragging = true; + if (index.isValid() && (index.column() == DolphinModel::Name)) { const KFileItem item = m_controller->itemForIndex(index); if (!item.isNull() && item.isDir()) { m_dropRect = visualRect(index); @@ -314,7 +306,6 @@ void DolphinDetailsView::dropEvent(QDropEvent* event) item); } QTreeView::dropEvent(event); - m_dragging = false; } void DolphinDetailsView::paintEvent(QPaintEvent* event) @@ -335,12 +326,6 @@ void DolphinDetailsView::paintEvent(QPaintEvent* event) style()->drawControl(QStyle::CE_RubberBand, &opt, &painter); painter.restore(); } - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - if (m_dragging) { - const QBrush& brush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight); - DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush); - } } void DolphinDetailsView::keyPressEvent(QKeyEvent* event) diff --git a/src/dolphindetailsview.h b/src/dolphindetailsview.h index 295936258..88471746d 100644 --- a/src/dolphindetailsview.h +++ b/src/dolphindetailsview.h @@ -161,8 +161,7 @@ private: QFont m_font; QSize m_decorationSize; - 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 + QRect m_dropRect; bool m_showElasticBand; QPoint m_elasticBandOrigin; diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index e92d8ba3b..dda538e16 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -46,7 +46,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle m_decorationPosition(QStyleOptionViewItem::Top), m_displayAlignment(Qt::AlignHCenter), m_itemSize(), - m_dragging(false), m_dropRect() { Q_ASSERT(controller != 0); @@ -57,9 +56,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle setDragEnabled(true); viewport()->setAcceptDrops(true); - setMouseTracking(true); - viewport()->setAttribute(Qt::WA_Hover); - // TODO: Connecting to the signal 'activated()' is not possible, as kstyle // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is // necessary connecting the signal 'singleClick()' or 'doubleClick' and to handle the @@ -221,15 +217,11 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) if (event->mimeData()->hasUrls()) { event->acceptProposedAction(); } - m_dragging = true; } void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event) { KCategorizedView::dragLeaveEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - m_dragging = false; setDirtyRegion(m_dropRect); } @@ -273,19 +265,6 @@ void DolphinIconsView::dropEvent(QDropEvent* event) } KCategorizedView::dropEvent(event); - - m_dragging = false; -} - -void DolphinIconsView::paintEvent(QPaintEvent* event) -{ - KCategorizedView::paintEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - if (m_dragging) { - const QBrush& brush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight); - DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush); - } } void DolphinIconsView::keyPressEvent(QKeyEvent* event) diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index 20d41051a..d96d7c7e9 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -60,7 +60,6 @@ protected: virtual void dragLeaveEvent(QDragLeaveEvent* event); virtual void dragMoveEvent(QDragMoveEvent* event); virtual void dropEvent(QDropEvent* event); - virtual void paintEvent(QPaintEvent* event); virtual void keyPressEvent(QKeyEvent* event); virtual void wheelEvent(QWheelEvent* event); @@ -104,9 +103,7 @@ private: Qt::Alignment m_displayAlignment; QSize m_itemSize; - - 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 + QRect m_dropRect; }; #endif diff --git a/src/draganddrophelper.cpp b/src/draganddrophelper.cpp index 7095346bc..ab674cd5c 100644 --- a/src/draganddrophelper.cpp +++ b/src/draganddrophelper.cpp @@ -25,11 +25,7 @@ #include #include -#include #include -#include -#include -#include void DragAndDropHelper::startDrag(QAbstractItemView* itemView, Qt::DropActions supportedActions) { @@ -57,40 +53,3 @@ void DragAndDropHelper::startDrag(QAbstractItemView* itemView, Qt::DropActions s drag->exec(supportedActions, Qt::IgnoreAction); } } - -void DragAndDropHelper::drawHoverIndication(QAbstractItemView* itemView, - const QRect& bounds, - const QBrush& brush) -{ - if (bounds.isEmpty()) { - return; - } - - QWidget* widget = itemView->viewport(); - - QPainter painter(widget); - painter.save(); - QBrush blendedBrush(brush); - QColor color = blendedBrush.color(); - color.setAlpha(64); - blendedBrush.setColor(color); - - if (dynamic_cast(itemView)) { - 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); - } else { - painter.fillRect(bounds, blendedBrush); - } - painter.restore(); -} diff --git a/src/draganddrophelper.h b/src/draganddrophelper.h index 8e1e4531f..93f9ddd12 100644 --- a/src/draganddrophelper.h +++ b/src/draganddrophelper.h @@ -28,7 +28,7 @@ class QRect; class QWidget; /** - * @brief Helper class to bypass some drag & drop limitations in Qt. + * @brief Helper class for having a common drag and drop behavior. * * The class is used by DolphinIconsView, DolphinDetailsView, * DolphinColumnView and SidebarTreeView to have a consistent @@ -42,11 +42,6 @@ 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(QAbstractItemView* itemView, - const QRect& bounds, - const QBrush& brush); }; #endif diff --git a/src/sidebartreeview.cpp b/src/sidebartreeview.cpp index 5ac3b0cbf..f14ddbacb 100644 --- a/src/sidebartreeview.cpp +++ b/src/sidebartreeview.cpp @@ -30,8 +30,7 @@ #include SidebarTreeView::SidebarTreeView(QWidget* parent) : - QTreeView(parent), - m_dragging(false) + QTreeView(parent) { setAcceptDrops(true); setUniformRowHeights(true); @@ -95,20 +94,14 @@ void SidebarTreeView::startDrag(Qt::DropActions supportedActions) void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event) { QTreeView::dragEnterEvent(event); - if (event->mimeData()->hasUrls()) { event->acceptProposedAction(); } - - m_dragging = true; } void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event) { QTreeView::dragLeaveEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - m_dragging = false; setDirtyRegion(m_dropRect); } @@ -140,18 +133,6 @@ void SidebarTreeView::dropEvent(QDropEvent* event) emit urlsDropped(urls, index); } } - m_dragging = false; -} - -void SidebarTreeView::paintEvent(QPaintEvent* event) -{ - QTreeView::paintEvent(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); - DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush); - } } #include "sidebartreeview.moc" diff --git a/src/sidebartreeview.h b/src/sidebartreeview.h index b2e42e24f..a181290f2 100644 --- a/src/sidebartreeview.h +++ b/src/sidebartreeview.h @@ -51,11 +51,9 @@ protected: virtual void dragLeaveEvent(QDragLeaveEvent* event); virtual void dragMoveEvent(QDragMoveEvent* event); virtual void dropEvent(QDropEvent* event); - virtual void paintEvent(QPaintEvent* event); private: - 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 + QRect m_dropRect; }; #endif -- 2.47.3