QGraphicsView - fix rubberband to expand on wheel event

In SHA 51914375b6 the rubberband
selection was fixed, so it followed the scene-point on mousemove.

However wheelEvent could move the view - but avoid update of the
rubberband (that would not be updated until next mouse-move).

This patch fixes that (and generally improves rubberband behavior)
since QGraphicsViewPrivate::mouseMoveEventHandler is called by
replayLastMouseEvent, which is called from various places,
where we need to update the rubberband (e.g scrollContentsBy).

Change-Id: I1b78c27edaaecea797a2319086d7a11d437d2bd3
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-12-02 17:04:47 +01:00 committed by The Qt Project
parent d0a6d6a215
commit 9cf56b3e09
2 changed files with 18 additions and 11 deletions

View File

@ -616,6 +616,10 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
{
Q_Q(QGraphicsView);
#ifndef QT_NO_RUBBERBAND
updateRubberBand(event);
#endif
storeMouseEvent(event);
lastMouseEvent.setAccepted(false);
@ -3263,10 +3267,6 @@ void QGraphicsView::mouseMoveEvent(QMouseEvent *event)
{
Q_D(QGraphicsView);
#ifndef QT_NO_RUBBERBAND
d->updateRubberBand(event);
#endif
if (d->dragMode == QGraphicsView::ScrollHandDrag) {
if (d->handScrolling) {
QScrollBar *hBar = horizontalScrollBar();

View File

@ -69,11 +69,17 @@ public:
protected:
void mouseMoveEvent(QMouseEvent *event)
{
QGraphicsView::mouseMoveEvent(event);
int rightmostInView = viewport()->mapToGlobal(viewport()->geometry().topRight()).x();
int xglobal = event->globalX();
if (xglobal > rightmostInView)
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 10);
QGraphicsView::mouseMoveEvent(event);
int bottomPos = viewport()->mapToGlobal(viewport()->geometry().bottomRight()).y();
int yglobal = event->globalY();
if (yglobal > bottomPos)
verticalScrollBar()->setValue(verticalScrollBar()->value() + 10);
}
};
@ -82,17 +88,18 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
MyGraphicsView v;
QGraphicsScene s(0.0, 0.0, 10000.0, 100.0);
QGraphicsScene s(0.0, 0.0, 5000.0, 5000.0);
v.setScene(&s);
v.setInteractive(true);
v.setRubberBandSelectionMode(Qt::IntersectsItemBoundingRect);
s.addRect( (qreal) 0.0, 0.0, 1000.0, 50.0, QPen(),QBrush(QColor(0,0,255)));
for (int u = 0; u < 100; ++u) {
MyGraphicsItem *item = new MyGraphicsItem();
item->setRect(QRectF(u * 100, 50.0, 50.0, 20.0));
s.addItem(item);
}
for (int u = 0; u < 100; ++u)
for (int v = 0; v < 100; ++v) {
MyGraphicsItem *item = new MyGraphicsItem();
item->setRect(QRectF(v * 80.0, u * 80.0, 50.0, 20.0));
s.addItem(item);
}
v.show();
app.exec();
return 0;