From 9775682bef4dbe7bd74d2ef993730a4bcfb634f5 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Tue, 22 Nov 2011 13:29:02 +0100 Subject: [PATCH 1/2] use a QWeakPointer with the graphics widget handed in as we don't own it --- popupapplet.cpp | 5 ++--- private/popupapplet_p.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/popupapplet.cpp b/popupapplet.cpp index 116d0a12a..c35419f59 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -160,8 +160,8 @@ void PopupApplet::setWidget(QWidget *widget) QGraphicsWidget *PopupApplet::graphicsWidget() { - if (d->graphicsWidget != 0) { - return d->graphicsWidget; + if (d->graphicsWidget) { + return d->graphicsWidget.data(); } else { return static_cast(this)->d->extender.data(); } @@ -668,7 +668,6 @@ PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet) : q(applet), icon(0), widget(0), - graphicsWidget(0), popupPlacement(Plasma::FloatingPopup), popupAlignment(Qt::AlignLeft), savedAspectRatio(Plasma::InvalidAspectRatioMode), diff --git a/private/popupapplet_p.h b/private/popupapplet_p.h index eab42c32d..5bcede470 100644 --- a/private/popupapplet_p.h +++ b/private/popupapplet_p.h @@ -55,7 +55,7 @@ public: QWeakPointer dialogPtr; QWeakPointerproxy; QWidget *widget; - QGraphicsWidget *graphicsWidget; + QWeakPointer graphicsWidget; Plasma::PopupPlacement popupPlacement; Qt::AlignmentFlag popupAlignment; Plasma::AspectRatioMode savedAspectRatio; From 7ed45afaafd96472adee9eb3a78b533e784f6554 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Tue, 22 Nov 2011 13:56:35 +0100 Subject: [PATCH 2/2] if the graphicswidget isn't on a corona, use the applet's scene --- popupapplet.cpp | 99 +++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/popupapplet.cpp b/popupapplet.cpp index c35419f59..831b99eea 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -341,8 +341,8 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) q->resize(prefSize); emit q->appletTransformedItself(); } - //Applet on popup } else { + //Applet on popup if (icon && lay) { lay->addItem(icon); } @@ -363,56 +363,57 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) delete proxy.data(); } - if (!dialogPtr) { - //save the aspect ratio mode in case we drag'n drop in the Desktop later - savedAspectRatio = q->aspectRatioMode(); + //save the aspect ratio mode in case we drag'n drop in the Desktop later + savedAspectRatio = q->aspectRatioMode(); - if (icon) { - icon->show(); - q->setAspectRatioMode(Plasma::ConstrainedSquare); - } - - Dialog *dialog = new Dialog(); - dialog->d->appletPtr = q; - dialogPtr = dialog; - - if (icon) { - dialog->setAspectRatioMode(savedAspectRatio); - } - - //no longer use Qt::Popup since that seems to cause a lot of problem when you drag - //stuff out of your Dialog (extenders). Monitor WindowDeactivate events so we can - //emulate the same kind of behavior as Qt::Popup (close when you click somewhere - //else. - - if (gWidget) { - Corona *corona = qobject_cast(gWidget->scene()); - - if (corona) { - corona->addOffscreenWidget(gWidget); - } - - dialog->setGraphicsWidget(gWidget); - //gWidget->resize(gWidget->preferredSize()); - dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | (gWidget->windowFlags() & Qt::X11BypassWindowManagerHint)); - } else if (qWidget) { - QVBoxLayout *l_layout = new QVBoxLayout(dialog); - l_layout->setSpacing(0); - l_layout->setMargin(0); - l_layout->addWidget(qWidget); - dialog->adjustSize(); - dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | (qWidget->windowFlags() & Qt::X11BypassWindowManagerHint)); - } else { - dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); - } - - restoreDialogSize(); - KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager); - dialog->installEventFilter(q); - - QObject::connect(dialog, SIGNAL(dialogResized()), q, SLOT(dialogSizeChanged())); - QObject::connect(dialog, SIGNAL(dialogVisible(bool)), q, SLOT(dialogStatusChanged(bool))); + if (icon) { + icon->show(); + q->setAspectRatioMode(Plasma::ConstrainedSquare); } + + Dialog *dialog = new Dialog(); + dialog->d->appletPtr = q; + dialogPtr = dialog; + + if (icon) { + dialog->setAspectRatioMode(savedAspectRatio); + } + + //no longer use Qt::Popup since that seems to cause a lot of problem when you drag + //stuff out of your Dialog (extenders). Monitor WindowDeactivate events so we can + //emulate the same kind of behavior as Qt::Popup (close when you click somewhere + //else. + + if (gWidget) { + Corona *corona = qobject_cast(gWidget->scene()); + if (!corona) { + corona = qobject_cast(q->scene()); + } + + if (corona) { + corona->addOffscreenWidget(gWidget); + } + + gWidget->show(); + dialog->setGraphicsWidget(gWidget); + dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | (gWidget->windowFlags() & Qt::X11BypassWindowManagerHint)); + } else if (qWidget) { + QVBoxLayout *l_layout = new QVBoxLayout(dialog); + l_layout->setSpacing(0); + l_layout->setMargin(0); + l_layout->addWidget(qWidget); + dialog->adjustSize(); + dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | (qWidget->windowFlags() & Qt::X11BypassWindowManagerHint)); + } else { + dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + } + + restoreDialogSize(); + KWindowSystem::setState(dialog->winId(), NET::SkipTaskbar | NET::SkipPager); + dialog->installEventFilter(q); + + QObject::connect(dialog, SIGNAL(dialogResized()), q, SLOT(dialogSizeChanged())); + QObject::connect(dialog, SIGNAL(dialogVisible(bool)), q, SLOT(dialogStatusChanged(bool))); } }