From ca60a5a6cffec7ea86f2cab918f64150fdb9f90f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 6 Nov 2009 20:20:35 +0000 Subject: [PATCH] convert the function to a qgraphicswidget: sceneeventfilter appears to eat events always and in this way i can remove elements from dragHandles when they get deleted svn path=/trunk/KDE/kdelibs/; revision=1045818 --- widgets/scrollwidget.cpp | 44 ++++++++++++++++++---------------------- widgets/scrollwidget.h | 6 +++--- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/widgets/scrollwidget.cpp b/widgets/scrollwidget.cpp index 63c278afc..23b411048 100644 --- a/widgets/scrollwidget.cpp +++ b/widgets/scrollwidget.cpp @@ -213,6 +213,11 @@ public: (widget->pos() + delta).toPoint()); } + void cleanupDragHandles(QObject *destroyed) + { + dragHandles.remove(static_cast(destroyed)); + } + ScrollWidget *q; QGraphicsWidget *scrollingWidget; QGraphicsWidget *widget; @@ -228,7 +233,7 @@ public: Qt::ScrollBarPolicy horizontalScrollBarPolicy; QString styleSheet; QRectF rectToBeVisible; - QSetdragHandles; + QSetdragHandles; bool dragging; int animId; static const int borderSize = 4; @@ -345,9 +350,9 @@ void ScrollWidget::ensureItemVisible(QGraphicsItem *item) QTimer::singleShot(0, this, SLOT(makeRectVisible())); } -void ScrollWidget::registerAsDragHandle(QGraphicsItem *item) +void ScrollWidget::registerAsDragHandle(QGraphicsWidget *item) { - if (!d->widget || !item) { + if (!d->widget || !item || d->dragHandles.contains(item)) { return; } @@ -360,14 +365,15 @@ void ScrollWidget::registerAsDragHandle(QGraphicsItem *item) parentOfItem = parentOfItem->parentItem(); } - item->installSceneEventFilter(this); + connect(item, SIGNAL(destroyed(QObject *)), this, SLOT(cleanupDragHandles(QObject *))); + item->installEventFilter(this); d->dragHandles.insert(item); } -void ScrollWidget::unregisterAsDragHandle(QGraphicsItem *item) +void ScrollWidget::unregisterAsDragHandle(QGraphicsWidget *item) { if (item) { - item->removeSceneEventFilter(this); + item->removeEventFilter(this); d->dragHandles.remove(item); } } @@ -482,24 +488,6 @@ void ScrollWidget::wheelEvent(QGraphicsSceneWheelEvent *event) } -bool ScrollWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event) -{ - if (!d->widget && !scene()) { - return false; - } - - if (d->dragHandles.contains(watched)) { - if (event->type() == QEvent::GraphicsSceneMousePress || - event->type() == QEvent::GraphicsSceneMouseMove || - event->type() == QEvent::GraphicsSceneMouseRelease) { - if (scene()) { - scene()->sendEvent(d->widget, event); - } - } - } - return false; -} - bool ScrollWidget::eventFilter(QObject *watched, QEvent *event) { if (!d->widget) { @@ -518,6 +506,14 @@ bool ScrollWidget::eventFilter(QObject *watched, QEvent *event) d->verticalScrollBar->setValue(-d->widget->pos().y()/10); d->horizontalScrollBar->blockSignals(false); d->verticalScrollBar->blockSignals(false); + } else if (d->dragHandles.contains(static_cast(watched))) { + if (event->type() == QEvent::GraphicsSceneMousePress || + event->type() == QEvent::GraphicsSceneMouseMove || + event->type() == QEvent::GraphicsSceneMouseRelease) { + if (scene()) { + scene()->sendEvent(this, event); + } + } } return false; diff --git a/widgets/scrollwidget.h b/widgets/scrollwidget.h index 37cdf95d6..c6397c509 100644 --- a/widgets/scrollwidget.h +++ b/widgets/scrollwidget.h @@ -129,13 +129,13 @@ public: * it's not necessary to call this function. * @since 4.4 */ - void registerAsDragHandle(QGraphicsItem *item); + void registerAsDragHandle(QGraphicsWidget *item); /** * Unregister the given item as drag handle (if it was registered) * @since 4.4 */ - void unregisterAsDragHandle(QGraphicsItem *item); + void unregisterAsDragHandle(QGraphicsWidget *item); /** * The geometry of the viewport. @@ -191,7 +191,6 @@ protected: bool eventFilter(QObject *watched, QEvent *event); void focusInEvent(QFocusEvent *event); QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const; - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); private: ScrollWidgetPrivate * const d; @@ -199,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 cleanupDragHandles(QObject *destroyed)) }; } // namespace Plasma