since the QGrahicsWidget we're given originates from the outside, don't assume it'll stay around nicely; use a QWeakPointer to track it

svn path=/branches/KDE/4.4/kdelibs/; revision=1073415
This commit is contained in:
Aaron J. Seigo 2010-01-12 08:20:14 +00:00
parent 9c042dff8f
commit 4014e41a7f

View File

@ -65,7 +65,6 @@ public:
: q(dialog), : q(dialog),
background(0), background(0),
view(0), view(0),
graphicsWidget(0),
resizeCorners(Dialog::NoCorner), resizeCorners(Dialog::NoCorner),
resizeStartCorner(Dialog::NoCorner), resizeStartCorner(Dialog::NoCorner),
moveTimer(0), moveTimer(0),
@ -90,7 +89,7 @@ public:
*/ */
Plasma::FrameSvg *background; Plasma::FrameSvg *background;
QGraphicsView *view; QGraphicsView *view;
QGraphicsWidget *graphicsWidget; QWeakPointer<QGraphicsWidget> graphicsWidgetPtr;
Dialog::ResizeCorners resizeCorners; Dialog::ResizeCorners resizeCorners;
QMap<Dialog::ResizeCorner, QRect> resizeAreas; QMap<Dialog::ResizeCorner, QRect> resizeAreas;
int resizeStartCorner; int resizeStartCorner;
@ -101,6 +100,8 @@ public:
void DialogPrivate::themeChanged() void DialogPrivate::themeChanged()
{ {
QGraphicsWidget *graphicsWidget = graphicsWidgetPtr.data();
qreal topHeight; qreal topHeight;
qreal leftWidth; qreal leftWidth;
qreal rightWidth; qreal rightWidth;
@ -197,6 +198,7 @@ void DialogPrivate::themeChanged()
void DialogPrivate::adjustView() void DialogPrivate::adjustView()
{ {
QGraphicsWidget *graphicsWidget = graphicsWidgetPtr.data();
if (view && graphicsWidget) { if (view && graphicsWidget) {
const int prevStartCorner = resizeStartCorner; const int prevStartCorner = resizeStartCorner;
resizeStartCorner = -1; resizeStartCorner = -1;
@ -444,14 +446,15 @@ void Dialog::resizeEvent(QResizeEvent *e)
setMask(QRect(QPoint(0, 0), size())); setMask(QRect(QPoint(0, 0), size()));
} }
if (d->resizeStartCorner != -1 && d->view && d->graphicsWidget) { if (d->resizeStartCorner != -1 && d->view && d->graphicsWidgetPtr) {
d->graphicsWidget->resize(d->view->size()); QGraphicsWidget *graphicsWidget = d->graphicsWidgetPtr.data();
graphicsWidget->resize(d->view->size());
QRectF sceneRect(d->graphicsWidget->sceneBoundingRect()); QRectF sceneRect(graphicsWidget->sceneBoundingRect());
sceneRect.setWidth(qMax(qreal(1), sceneRect.width())); sceneRect.setWidth(qMax(qreal(1), sceneRect.width()));
sceneRect.setHeight(qMax(qreal(1), sceneRect.height())); sceneRect.setHeight(qMax(qreal(1), sceneRect.height()));
d->view->setSceneRect(sceneRect); d->view->setSceneRect(sceneRect);
d->view->centerOn(d->graphicsWidget); d->view->centerOn(graphicsWidget);
} }
d->updateResizeCorners(); d->updateResizeCorners();
@ -500,11 +503,11 @@ void DialogPrivate::updateResizeCorners()
void Dialog::setGraphicsWidget(QGraphicsWidget *widget) void Dialog::setGraphicsWidget(QGraphicsWidget *widget)
{ {
if (d->graphicsWidget) { if (d->graphicsWidgetPtr) {
d->graphicsWidget->removeEventFilter(this); d->graphicsWidgetPtr.data()->removeEventFilter(this);
} }
d->graphicsWidget = widget; d->graphicsWidgetPtr = widget;
if (widget) { if (widget) {
if (!layout()) { if (!layout()) {
@ -539,12 +542,12 @@ void Dialog::setGraphicsWidget(QGraphicsWidget *widget)
//BIC FIXME: should be const //BIC FIXME: should be const
QGraphicsWidget *Dialog::graphicsWidget() QGraphicsWidget *Dialog::graphicsWidget()
{ {
return d->graphicsWidget; return d->graphicsWidgetPtr.data();
} }
bool Dialog::eventFilter(QObject *watched, QEvent *event) bool Dialog::eventFilter(QObject *watched, QEvent *event)
{ {
if (d->resizeStartCorner == Dialog::NoCorner && watched == d->graphicsWidget && if (d->resizeStartCorner == Dialog::NoCorner && watched == d->graphicsWidgetPtr.data() &&
(event->type() == QEvent::GraphicsSceneResize || event->type() == QEvent::GraphicsSceneMove)) { (event->type() == QEvent::GraphicsSceneResize || event->type() == QEvent::GraphicsSceneMove)) {
d->adjustViewTimer->start(150); d->adjustViewTimer->start(150);
} }
@ -566,7 +569,8 @@ void Dialog::showEvent(QShowEvent * event)
d->themeChanged(); d->themeChanged();
d->updateResizeCorners(); d->updateResizeCorners();
if (d->graphicsWidget && d->view && d->graphicsWidget->size().toSize() != d->view->size()) { QGraphicsWidget *graphicsWidget = d->graphicsWidgetPtr.data();
if (graphicsWidget && d->view && graphicsWidget->size().toSize() != d->view->size()) {
d->adjustView(); d->adjustView();
} }
@ -574,8 +578,8 @@ void Dialog::showEvent(QShowEvent * event)
d->view->setFocus(); d->view->setFocus();
} }
if (d->graphicsWidget) { if (graphicsWidget) {
d->graphicsWidget->setFocus(); graphicsWidget->setFocus();
} }
emit dialogVisible(true); emit dialogVisible(true);
@ -589,8 +593,9 @@ void Dialog::focusInEvent(QFocusEvent *event)
d->view->setFocus(); d->view->setFocus();
} }
if (d->graphicsWidget) { QGraphicsWidget *graphicsWidget = d->graphicsWidgetPtr.data();
d->graphicsWidget->setFocus(); if (graphicsWidget) {
graphicsWidget->setFocus();
} }
} }