using installEventFilter if the target is a QGraphicsWidget, else

installSceneEventFilter because sceneEventFilter doesn't get GraphicsSceneResize events

svn path=/trunk/KDE/kdelibs/; revision=1027316
This commit is contained in:
Giulio Camuffo 2009-09-23 20:29:56 +00:00
parent cfb045bf3d
commit b363df741e
2 changed files with 23 additions and 6 deletions

View File

@ -124,12 +124,12 @@ void ItemBackground::setTarget(const QRectF &newGeometry)
void ItemBackground::setTargetItem(QGraphicsItem *target)
{
if (d->target && d->target != target) {
d->target->removeSceneEventFilter(this);
QObject *obj = 0;
if (d->target->isWidget()) {
obj = static_cast<QGraphicsWidget*>(d->target);
obj->removeEventFilter(this);
} else {
d->target->removeSceneEventFilter(this);
obj = dynamic_cast<QObject *>(d->target);
}
@ -147,12 +147,12 @@ void ItemBackground::setTargetItem(QGraphicsItem *target)
setTarget(rect);
if (d->target != target) {
target->installSceneEventFilter(this);
QObject *obj = 0;
if (target->isWidget()) {
obj = static_cast<QGraphicsWidget*>(target);
obj->installEventFilter(this);
} else {
d->target->installSceneEventFilter(this);
obj = dynamic_cast<QObject *>(target);
}
@ -165,11 +165,23 @@ void ItemBackground::setTargetItem(QGraphicsItem *target)
}
}
bool ItemBackground::eventFilter(QObject *watched, QEvent *event)
{
QGraphicsWidget *targetWidget = static_cast<QGraphicsWidget *>(d->target);
if (watched == targetWidget) {
if (event->type() == QEvent::GraphicsSceneResize ||
event->type() == QEvent::GraphicsSceneMove) {
setTargetItem(targetWidget);
}
}
return false;
}
bool ItemBackground::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
{
if (watched == d->target) {
if (event->type() == QEvent::GraphicsSceneResize ||
event->type() == QEvent::GraphicsSceneMove) {
if (event->type() == QEvent::GraphicsSceneMove) {
setTargetItem(d->target);
}
}

View File

@ -74,6 +74,11 @@ protected:
*/
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* @reimp from QObject
*/
bool eventFilter(QObject *watched, QEvent *event);
/**
* @reimp from QGraphicsItem
*/