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.

Task-number: QTBUG-1180

[ChangeLog][QtWidgets][QTBUG-1180] Dragging an item outside the QListView in icon
mode doesn't lose the icon.

Change-Id: I14f864a8f947997f3bdad1a05fabd200de026d66
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Samuel Gaist 2013-10-10 16:32:31 +02:00 committed by The Qt Project
parent fbfc8ffbf3
commit c3bf3bd8b7
2 changed files with 17 additions and 28 deletions

View File

@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2013 Samuel Gaist <samuel.gaist@deltech.ch>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@ -1833,6 +1834,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()->setPageStep(viewport()->width());
@ -1902,13 +1912,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;
@ -2651,23 +2654,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());
QStyleOptionViewItem option = viewOptions();
option.state &= ~QStyle::State_MouseOver;
QVector<QModelIndex>::const_iterator it = draggedItems.constBegin();
QListViewItem item = indexToListViewItem(*it);
for (; it != draggedItems.constEnd(); ++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(),
@ -2682,8 +2668,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->setMimeData(dd->model->mimeData(indexes));
drag->setPixmap(pixmap);
drag->setHotSpot(dd->pressedPosition - rect.topLeft());
Qt::DropAction action = drag->exec(supportedActions, Qt::CopyAction);
draggedItems.clear();
if (action == Qt::MoveAction)

View File

@ -147,7 +147,7 @@ public:
virtual void setPositionForIndex(const QPoint &, const QModelIndex &) { }
#ifndef QT_NO_DRAGANDDROP
virtual void paintDragDrop(QPainter *painter) = 0;
virtual 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);