From e9989989c56073cb21e66d1dea379f6fc7217552 Mon Sep 17 00:00:00 2001 From: Rob Scheepmaker Date: Fri, 23 May 2008 17:21:14 +0000 Subject: [PATCH] Check if containment() actually returns a containment, and if view() actually returns a view. Should fix a crash reported by chani. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=811785 --- applet.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/applet.cpp b/applet.cpp index 74422fd5d..e636ddb21 100644 --- a/applet.cpp +++ b/applet.cpp @@ -1325,11 +1325,25 @@ QRect Applet::screenRect() const bottomRight.setX(bottomRight.x() + size().width()); bottomRight.setY(bottomRight.y() + size().height()); - QPoint tL = containment()->view()->mapToGlobal(containment()->view()->mapFromScene(pos())); - QPoint bR = containment()->view()->mapToGlobal(containment()->view()->mapFromScene(bottomRight)); - kDebug() << "screenRect = " << QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y()); + Containment *c; + c = containment(); - return QRect(QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y())); + if (c) { + QGraphicsView *v; + v = c->view(); + + if (v) { + QPoint tL = v->mapToGlobal(v->mapFromScene(pos())); + QPoint bR = v->mapToGlobal(v->mapFromScene(bottomRight)); + + kDebug() << "screenRect = " << QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y()); + return QRect(QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y())); + } + } + + //The applet isn't in any containment, or in a containment that doesn't have a view on it. + //So a screenRect isn't relevant. + return QRect(QPoint(0, 0), QSize(0, 0)); } void Applet::raise()