Fix drag&drop pixmap rendering

This commit is contained in:
Petr Mrázek 2014-02-02 16:57:00 +01:00
parent eb0ed082d8
commit 2cd9b06476

View File

@ -296,7 +296,7 @@ void GroupView::mousePressEvent(QMouseEvent *event)
void GroupView::mouseMoveEvent(QMouseEvent *event) void GroupView::mouseMoveEvent(QMouseEvent *event)
{ {
QPoint topLeft; QPoint topLeft;
QPoint bottomRight = event->pos(); QPoint pos = event->pos() + offset();
if (state() == ExpandingState || state() == CollapsingState) if (state() == ExpandingState || state() == CollapsingState)
{ {
@ -316,15 +316,13 @@ void GroupView::mouseMoveEvent(QMouseEvent *event)
return; return;
} }
QPersistentModelIndex index = indexAt(bottomRight);
if (selectionMode() != SingleSelection) if (selectionMode() != SingleSelection)
{ {
topLeft = m_pressedPosition - offset(); topLeft = m_pressedPosition - offset();
} }
else else
{ {
topLeft = bottomRight; topLeft = pos;
} }
if (m_pressedIndex.isValid() && (state() != DragSelectingState) && if (m_pressedIndex.isValid() && (state() != DragSelectingState) &&
@ -337,17 +335,9 @@ void GroupView::mouseMoveEvent(QMouseEvent *event)
if ((event->buttons() & Qt::LeftButton) && selectionModel()) if ((event->buttons() & Qt::LeftButton) && selectionModel())
{ {
setState(DragSelectingState); setState(DragSelectingState);
QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
if (m_ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate &&
command.testFlag(QItemSelectionModel::Toggle))
{
command &= ~QItemSelectionModel::Toggle;
command |= m_ctrlDragSelectionFlag;
}
// Do the normalize ourselves, since QRect::normalized() is flawed setSelection(QRect(pos, pos), QItemSelectionModel::ClearAndSelect);
QRect selectionRect = QRect(topLeft, bottomRight); QModelIndex index = indexAt(pos);
setSelection(selectionRect, command);
// set at the end because it might scroll the view // set at the end because it might scroll the view
if (index.isValid() && (index != selectionModel()->currentIndex()) && if (index.isValid() && (index != selectionModel()->currentIndex()) &&
@ -582,7 +572,7 @@ void GroupView::startDrag(Qt::DropActions supportedActions)
} }
QRect rect; QRect rect;
QPixmap pixmap = renderToPixmap(indexes, &rect); QPixmap pixmap = renderToPixmap(indexes, &rect);
rect.translate(offset()); //rect.translate(offset());
// rect.adjust(horizontalOffset(), verticalOffset(), 0, 0); // rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);
QDrag *drag = new QDrag(this); QDrag *drag = new QDrag(this);
drag->setPixmap(pixmap); drag->setPixmap(pixmap);
@ -699,12 +689,14 @@ void GroupView::setSelection(const QRect &rect,
for (int i = 0; i < model()->rowCount(); ++i) for (int i = 0; i < model()->rowCount(); ++i)
{ {
QModelIndex index = model()->index(i, 0); QModelIndex index = model()->index(i, 0);
if (geometryRect(index).intersects(rect)) QRect itemRect = geometryRect(index);
if (itemRect.intersects(rect))
{ {
selectionModel()->select(index, commands); selectionModel()->select(index, commands);
update(itemRect.translated(-offset()));
} }
} }
update();
} }
QPixmap GroupView::renderToPixmap(const QModelIndexList &indices, QRect *r) const QPixmap GroupView::renderToPixmap(const QModelIndexList &indices, QRect *r) const
@ -725,6 +717,7 @@ QPixmap GroupView::renderToPixmap(const QModelIndexList &indices, QRect *r) cons
option.rect = paintPairs.at(j).first.translated(-r->topLeft()); option.rect = paintPairs.at(j).first.translated(-r->topLeft());
const QModelIndex &current = paintPairs.at(j).second; const QModelIndex &current = paintPairs.at(j).second;
itemDelegate()->paint(&painter, option, current); itemDelegate()->paint(&painter, option, current);
painter.drawLine(0,0, r->width(), r->height());
} }
return pixmap; return pixmap;
} }
@ -740,13 +733,13 @@ QList<QPair<QRect, QModelIndex>> GroupView::draggablePaintPairs(const QModelInde
{ {
const QModelIndex &index = indices.at(i); const QModelIndex &index = indices.at(i);
const QRect current = geometryRect(index); const QRect current = geometryRect(index);
if (current.intersects(viewportRect)) //if (current.intersects(viewportRect))
{ //{
ret += qMakePair(current, index); ret += qMakePair(current, index);
rect |= current; rect |= current;
//}
} }
} //rect &= viewportRect;
rect &= viewportRect;
return ret; return ret;
} }