From 7e3bdb55e51bf326f2f8097a679dfd1e2aba2397 Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Tue, 1 Dec 2009 20:49:34 +0000 Subject: [PATCH] better wait for the parentItem to resize before calculating the rect of the item to be visible svn path=/trunk/KDE/kdelibs/; revision=1057266 --- widgets/scrollwidget.cpp | 14 +++++++++++--- widgets/scrollwidget.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/widgets/scrollwidget.cpp b/widgets/scrollwidget.cpp index 37795bb0c..f6c93fe1f 100644 --- a/widgets/scrollwidget.cpp +++ b/widgets/scrollwidget.cpp @@ -214,6 +214,14 @@ public: (widget->pos() + delta).toPoint()); } + void makeItemVisible() + { + QRectF rect(widget->mapFromScene(itemToBeVisible->scenePos()), itemToBeVisible->boundingRect().size()); + rectToBeVisible = rect; + + makeRectVisible(); + } + void cleanupDragHandles(QObject *destroyed) { dragHandles.remove(static_cast(destroyed)); @@ -233,6 +241,7 @@ public: ScrollBar *horizontalScrollBar; Qt::ScrollBarPolicy horizontalScrollBarPolicy; QString styleSheet; + QGraphicsItem *itemToBeVisible; QRectF rectToBeVisible; QPointF dragHandleClicked; QSetdragHandles; @@ -351,11 +360,10 @@ void ScrollWidget::ensureItemVisible(QGraphicsItem *item) parentOfItem = parentOfItem->parentItem(); } - QRectF rect(d->widget->mapFromScene(item->scenePos()), item->boundingRect().size()); - d->rectToBeVisible = rect; + d->itemToBeVisible = item; // We need to wait for the parent item to resize... - QTimer::singleShot(0, this, SLOT(makeRectVisible())); + QTimer::singleShot(0, this, SLOT(makeItemVisible())); } void ScrollWidget::registerAsDragHandle(QGraphicsWidget *item) diff --git a/widgets/scrollwidget.h b/widgets/scrollwidget.h index 2c1e5a0b4..59aed0eac 100644 --- a/widgets/scrollwidget.h +++ b/widgets/scrollwidget.h @@ -198,6 +198,7 @@ private: Q_PRIVATE_SLOT(d, void verticalScroll(int value)) Q_PRIVATE_SLOT(d, void horizontalScroll(int value)) Q_PRIVATE_SLOT(d, void makeRectVisible()) + Q_PRIVATE_SLOT(d, void makeItemVisible()) Q_PRIVATE_SLOT(d, void cleanupDragHandles(QObject *destroyed)) };