diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2013-10-18 10:46:05 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-18 10:47:45 (GMT) |
commit | 7126cdf48f5e28f1c2238c35960350921f849881 (patch) | |
tree | d19d0a0c3c28d20a611942e331f0ba88fe8abf6b | |
parent | c2f6d747ea997e0ba6bb970f5ec18ae3fe68514d (diff) | |
download | Qt-7126cdf48f5e28f1c2238c35960350921f849881.zip Qt-7126cdf48f5e28f1c2238c35960350921f849881.tar.gz Qt-7126cdf48f5e28f1c2238c35960350921f849881.tar.bz2 |
Properly paint QListView dragged item in icon mode
Currently, when dragging a QListView item in icon mode, only the
item is moved and once out of the view port, the visual feedback is
lost. This patch updates the QDrag pixmap to have a persistent view of
what is moved
Based on Qt 5 c3bf3bd8b74187b44ec91582e1cf2be546a73349
Task-number: QTBUG-1180
[ChangeLog][QtGui][QTBUG-1180] Dragging an item outside the QListView in icon mode doesn't lose the icon.
Change-Id: I9d7fee4c31a4d3d5467510f16fd573635eb6d6f0
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
-rw-r--r-- | src/gui/itemviews/qlistview.cpp | 40 | ||||
-rw-r--r-- | src/gui/itemviews/qlistview_p.h | 5 |
2 files changed, 17 insertions, 28 deletions
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index 962adbe..06b977a 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -1852,6 +1852,15 @@ void QCommonListViewBase::removeHiddenRow(int row) dd->hiddenRows.remove(dd->model->index(row, 0, qq->rootIndex())); } +#ifndef QT_NO_DRAGANDDROP +void QCommonListViewBase::paintDragDrop(QPainter *painter) +{ + // FIXME: Until the we can provide a proper drop indicator + // in IconMode, it makes no sense to show it + dd->paintDropIndicator(painter); +} +#endif + void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step) { horizontalScrollBar()->setSingleStep(step.width() + spacing()); @@ -1921,13 +1930,6 @@ int QCommonListViewBase::horizontalScrollToValue(const int /*index*/, QListView: */ #ifndef QT_NO_DRAGANDDROP -void QListModeViewBase::paintDragDrop(QPainter *painter) -{ - // FIXME: Until the we can provide a proper drop indicator - // in IconMode, it makes no sense to show it - dd->paintDropIndicator(painter); -} - QAbstractItemView::DropIndicatorPosition QListModeViewBase::position(const QPoint &pos, const QRect &rect, const QModelIndex &index) const { QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport; @@ -2669,23 +2671,6 @@ void QIconModeViewBase::removeHiddenRow(int row) } #ifndef QT_NO_DRAGANDDROP -void QIconModeViewBase::paintDragDrop(QPainter *painter) -{ - if (!draggedItems.isEmpty() && viewport()->rect().contains(draggedItemsPos)) { - //we need to draw the items that arre dragged - painter->translate(draggedItemsDelta()); - QStyleOptionViewItemV4 option = viewOptions(); - option.state &= ~QStyle::State_MouseOver; - QVector<QModelIndex>::const_iterator it = draggedItems.begin(); - QListViewItem item = indexToListViewItem(*it); - for (; it != draggedItems.end(); ++it) { - item = indexToListViewItem(*it); - option.rect = viewItemRect(item); - delegate(*it)->paint(painter, option, *it); - } - } -} - bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions) { // This function does the same thing as in QAbstractItemView::startDrag(), @@ -2700,7 +2685,14 @@ bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions) && (*it).column() == dd->column) draggedItems.push_back(*it); } + + QRect rect; + QPixmap pixmap = dd->renderToPixmap(indexes, &rect); + rect.adjust(horizontalOffset(), verticalOffset(), 0, 0); + QDrag *drag = new QDrag(qq); + drag->setPixmap(pixmap); + drag->setHotSpot(dd->pressedPosition - rect.topLeft()); drag->setMimeData(dd->model->mimeData(indexes)); Qt::DropAction action = drag->exec(supportedActions, Qt::CopyAction); draggedItems.clear(); diff --git a/src/gui/itemviews/qlistview_p.h b/src/gui/itemviews/qlistview_p.h index e4a88e8..a65b85f 100644 --- a/src/gui/itemviews/qlistview_p.h +++ b/src/gui/itemviews/qlistview_p.h @@ -147,7 +147,7 @@ public: virtual void setPositionForIndex(const QPoint &, const QModelIndex &) { } #ifndef QT_NO_DRAGANDDROP - virtual void paintDragDrop(QPainter *painter) = 0; + void paintDragDrop(QPainter *painter); virtual bool filterDragMoveEvent(QDragMoveEvent *) { return false; } virtual bool filterDragLeaveEvent(QDragLeaveEvent *) { return false; } virtual bool filterDropEvent(QDropEvent *) { return false; } @@ -231,8 +231,6 @@ public: void updateVerticalScrollBar(const QSize &step); #ifndef QT_NO_DRAGANDDROP - void paintDragDrop(QPainter *painter); - // The next two methods are to be used on LefToRight flow only. // WARNING: Plenty of duplicated code from QAbstractItemView{,Private}. QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const; @@ -279,7 +277,6 @@ public: void setPositionForIndex(const QPoint &position, const QModelIndex &index); #ifndef QT_NO_DRAGANDDROP - void paintDragDrop(QPainter *painter); bool filterDragMoveEvent(QDragMoveEvent *); bool filterDragLeaveEvent(QDragLeaveEvent *); bool filterDropEvent(QDropEvent *e); |