move applet handle handling (*cough*) to applet instead of contaiment
much cleaner and eliminates the possibility of odd crashes BUG:253421
This commit is contained in:
parent
223795818f
commit
dd122bc011
74
applet.cpp
74
applet.cpp
@ -1265,6 +1265,18 @@ void Applet::flushPendingConstraintsEvents()
|
||||
}
|
||||
}
|
||||
|
||||
if (!unlocked && d->handle) {
|
||||
AppletHandle *h = d->handle.data();
|
||||
disconnect(this);
|
||||
|
||||
QGraphicsScene *s = scene();
|
||||
if (s && h->scene() == s) {
|
||||
s->removeItem(h);
|
||||
}
|
||||
|
||||
h->deleteLater();
|
||||
}
|
||||
|
||||
emit immutabilityChanged(immutability());
|
||||
}
|
||||
|
||||
@ -1754,6 +1766,40 @@ bool Applet::eventFilter(QObject *o, QEvent *e)
|
||||
|
||||
bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
{
|
||||
if (watched == this) {
|
||||
switch (event->type()) {
|
||||
case QEvent::GraphicsSceneHoverEnter:
|
||||
//kDebug() << "got hoverenterEvent" << immutability() << " " << immutability();
|
||||
if (immutability() == Mutable) {
|
||||
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
|
||||
if (d->handle) {
|
||||
d->handle.data()->setHoverPos(he->pos());
|
||||
} else {
|
||||
//kDebug() << "generated applet handle";
|
||||
AppletHandle *handle = new AppletHandle(containment(), this, he->pos());
|
||||
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
|
||||
this, SLOT(handleDisappeared(AppletHandle*)));
|
||||
connect(this, SIGNAL(geometryChanged()),
|
||||
handle, SLOT(appletResized()));
|
||||
d->handle = handle;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneHoverMove:
|
||||
if (d->handle && !d->handle.data()->shown() && immutability() == Mutable) {
|
||||
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
|
||||
d->handle.data()->setHoverPos(he->pos());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (event->type()) {
|
||||
case QEvent::GraphicsSceneMouseMove:
|
||||
case QEvent::GraphicsSceneMousePress:
|
||||
@ -2359,6 +2405,16 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ItemParentHasChanged:
|
||||
{
|
||||
Containment *c = containment();
|
||||
if (c && c->containmentType() == Containment::DesktopContainment) {
|
||||
installSceneEventFilter(this);
|
||||
} else {
|
||||
removeSceneEventFilter(this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ItemPositionHasChanged:
|
||||
emit geometryChanged();
|
||||
// fall through!
|
||||
@ -2868,6 +2924,24 @@ void AppletPrivate::resetConfigurationObject()
|
||||
}
|
||||
}
|
||||
|
||||
void AppletPrivate::handleDisappeared(AppletHandle *h)
|
||||
{
|
||||
if (h == handle.data()) {
|
||||
h->detachApplet();
|
||||
QGraphicsScene *scene = q->scene();
|
||||
if (scene && h->scene() == scene) {
|
||||
scene->removeItem(h);
|
||||
}
|
||||
h->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void ContainmentPrivate::checkRemoveAction()
|
||||
{
|
||||
q->enableAction("remove", q->immutability() == Mutable);
|
||||
}
|
||||
|
||||
|
||||
uint AppletPrivate::s_maxAppletId = 0;
|
||||
int AppletPrivate::s_maxZValue = 0;
|
||||
int AppletPrivate::s_minZValue = 0;
|
||||
|
1
applet.h
1
applet.h
@ -1124,6 +1124,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state))
|
||||
Q_PRIVATE_SLOT(d, void globalShortcutChanged())
|
||||
Q_PRIVATE_SLOT(d, void propagateConfigChanged())
|
||||
Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsItem
|
||||
|
102
containment.cpp
102
containment.cpp
@ -67,7 +67,6 @@
|
||||
#include "remote/accessmanager.h"
|
||||
|
||||
#include "private/applet_p.h"
|
||||
#include "private/applethandle_p.h"
|
||||
#include "private/containmentactionspluginsconfig_p.h"
|
||||
#include "private/extenderitemmimedata_p.h"
|
||||
#include "private/extenderapplet_p.h"
|
||||
@ -888,9 +887,6 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
|
||||
applet->removeSceneEventFilter(currentContainment);
|
||||
KConfigGroup oldConfig = applet->config();
|
||||
currentContainment->d->applets.removeAll(applet);
|
||||
if (currentContainment->d->handles.contains(applet)) {
|
||||
currentContainment->d->handles.remove(applet);
|
||||
}
|
||||
applet->setParentItem(this);
|
||||
applet->setParent(this);
|
||||
|
||||
@ -918,12 +914,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
|
||||
applet->setPos(pos);
|
||||
}
|
||||
|
||||
if (delayInit || currentContainment) {
|
||||
if (d->type == DesktopContainment) {
|
||||
applet->installSceneEventFilter(this);
|
||||
//applet->setWindowFlags(Qt::Window);
|
||||
}
|
||||
} else {
|
||||
if (!delayInit && !currentContainment) {
|
||||
applet->restore(*applet->d->mainConfigGroup());
|
||||
applet->init();
|
||||
Plasma::Animation *anim = Plasma::Animator::create(Plasma::Animator::AppearAnimation);
|
||||
@ -1696,51 +1687,8 @@ void Containment::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
|
||||
bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
{
|
||||
Applet *applet = qgraphicsitem_cast<Applet*>(watched);
|
||||
|
||||
// Otherwise we're watching something we shouldn't be...
|
||||
Q_ASSERT(applet != 0);
|
||||
if (!d->applets.contains(applet)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//kDebug() << "got sceneEvent";
|
||||
switch (event->type()) {
|
||||
case QEvent::GraphicsSceneHoverEnter:
|
||||
//kDebug() << "got hoverenterEvent" << immutability() << " " << applet->immutability();
|
||||
if (immutability() == Mutable && applet->immutability() == Mutable) {
|
||||
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
|
||||
if (d->handles.contains(applet)) {
|
||||
AppletHandle *handle = d->handles.value(applet);
|
||||
if (handle) {
|
||||
handle->setHoverPos(he->pos());
|
||||
}
|
||||
} else {
|
||||
//kDebug() << "generated applet handle";
|
||||
AppletHandle *handle = new AppletHandle(this, applet, he->pos());
|
||||
d->handles[applet] = handle;
|
||||
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
|
||||
this, SLOT(handleDisappeared(AppletHandle*)));
|
||||
connect(applet, SIGNAL(geometryChanged()),
|
||||
handle, SLOT(appletResized()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::GraphicsSceneHoverMove:
|
||||
if (immutability() == Mutable && applet->immutability() == Mutable) {
|
||||
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
|
||||
if (d->handles.contains(applet)) {
|
||||
AppletHandle *handle = d->handles.value(applet);
|
||||
if (handle) {
|
||||
handle->setHoverPos(he->pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Q_UNUSED(watched)
|
||||
Q_UNUSED(event)
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2205,24 +2153,6 @@ void ContainmentPrivate::triggerShowAddWidgets()
|
||||
emit q->showAddWidgetsInterface(QPointF());
|
||||
}
|
||||
|
||||
void ContainmentPrivate::handleDisappeared(AppletHandle *handle)
|
||||
{
|
||||
if (handles.contains(handle->applet())) {
|
||||
handles.remove(handle->applet());
|
||||
handle->detachApplet();
|
||||
QGraphicsScene *scene = q->scene();
|
||||
if (scene && handle->scene() == scene) {
|
||||
scene->removeItem(handle);
|
||||
}
|
||||
handle->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void ContainmentPrivate::checkRemoveAction()
|
||||
{
|
||||
q->enableAction("remove", q->immutability() == Mutable);
|
||||
}
|
||||
|
||||
void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constraints)
|
||||
{
|
||||
if (!q->isContainment()) {
|
||||
@ -2242,22 +2172,6 @@ void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constra
|
||||
a->setImmutability(q->immutability());
|
||||
a->updateConstraints(ImmutableConstraint);
|
||||
}
|
||||
|
||||
//clear handles on lock
|
||||
if (!unlocked) {
|
||||
QMap<Applet*, AppletHandle*> h = handles;
|
||||
handles.clear();
|
||||
|
||||
foreach (AppletHandle *handle, h) {
|
||||
handle->disconnect(q);
|
||||
|
||||
if (q->scene()) {
|
||||
q->scene()->removeItem(handle);
|
||||
}
|
||||
|
||||
handle->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pass on the constraints that are relevant here
|
||||
@ -2341,10 +2255,6 @@ void ContainmentPrivate::appletDestroyed(Plasma::Applet *applet)
|
||||
focusedApplet = 0;
|
||||
}
|
||||
|
||||
if (handles.contains(applet)) {
|
||||
handles.remove(applet);
|
||||
}
|
||||
|
||||
emit q->appletRemoved(applet);
|
||||
emit q->configNeedsSaving();
|
||||
}
|
||||
@ -2362,11 +2272,7 @@ void ContainmentPrivate::appletAppearAnimationComplete()
|
||||
|
||||
void ContainmentPrivate::appletAppeared(Applet *applet)
|
||||
{
|
||||
kDebug() << type << Containment::DesktopContainment;
|
||||
if (type == Containment::DesktopContainment) {
|
||||
applet->installSceneEventFilter(q);
|
||||
}
|
||||
|
||||
//kDebug() << type << Containment::DesktopContainment;
|
||||
KConfigGroup *cg = applet->d->mainConfigGroup();
|
||||
applet->save(*cg);
|
||||
emit q->configNeedsSaving();
|
||||
|
@ -644,7 +644,6 @@ Q_SIGNALS:
|
||||
Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*))
|
||||
Q_PRIVATE_SLOT(d, void appletAppearAnimationComplete())
|
||||
Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())
|
||||
Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
|
||||
Q_PRIVATE_SLOT(d, void positionToolBox())
|
||||
Q_PRIVATE_SLOT(d, void requestConfiguration())
|
||||
Q_PRIVATE_SLOT(d, void updateToolBoxVisibility())
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <kconfigdialog.h>
|
||||
|
||||
#include "plasma/animator.h"
|
||||
#include "plasma/private/applethandle_p.h"
|
||||
#include "plasma/private/dataengineconsumer_p.h"
|
||||
#include "plasma/ui_publish.h"
|
||||
|
||||
@ -107,6 +108,7 @@ public:
|
||||
*/
|
||||
void setIsContainment(bool isContainment, bool forceUpdate = false);
|
||||
|
||||
void handleDisappeared(AppletHandle *handle);
|
||||
QString globalName() const;
|
||||
QString instanceName();
|
||||
void scheduleConstraintsUpdate(Plasma::Constraints c);
|
||||
@ -174,17 +176,18 @@ public:
|
||||
AppletOverlayWidget *messageOverlay;
|
||||
QGraphicsProxyWidget *messageOverlayProxy;
|
||||
Plasma::BusyWidget *busyWidget;
|
||||
|
||||
// sripting and package stuff
|
||||
AppletScript *script;
|
||||
Package *package;
|
||||
ConfigLoader *configLoader;
|
||||
QWeakPointer<Plasma::PushButton> messageOkButton;
|
||||
QWeakPointer<Plasma::PushButton> messageYesButton;
|
||||
QWeakPointer<Plasma::PushButton> messageNoButton;
|
||||
QWeakPointer<Plasma::PushButton> messageCancelButton;
|
||||
QWeakPointer<QAction> messageCloseAction;
|
||||
|
||||
// sripting and package stuff
|
||||
AppletScript *script;
|
||||
Package *package;
|
||||
ConfigLoader *configLoader;
|
||||
QWeakPointer<AppletHandle> handle;
|
||||
|
||||
// actions stuff; put activationAction into actions?
|
||||
KActionCollection *actions;
|
||||
KAction *activationAction;
|
||||
|
@ -58,10 +58,10 @@ qreal _k_pointAngle(QPointF point);
|
||||
QPointF _k_rotatePoint(QPointF point, qreal angle);
|
||||
QPointF _k_projectPoint(QPointF point, QPointF v);
|
||||
|
||||
AppletHandle::AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos)
|
||||
AppletHandle::AppletHandle(Containment *containment, Applet *applet, const QPointF &hoverPos)
|
||||
: QGraphicsObject(applet),
|
||||
m_pressedButton(NoButton),
|
||||
m_containment(parent),
|
||||
m_containment(containment),
|
||||
m_applet(applet),
|
||||
m_iconSize(KIconLoader::SizeSmall),
|
||||
m_opacity(0.0),
|
||||
@ -116,6 +116,11 @@ AppletHandle::~AppletHandle()
|
||||
delete m_backgroundBuffer;
|
||||
}
|
||||
|
||||
bool AppletHandle::shown() const
|
||||
{
|
||||
return !m_hoverTimer->isActive();
|
||||
}
|
||||
|
||||
Applet *AppletHandle::applet() const
|
||||
{
|
||||
return m_applet;
|
||||
|
@ -61,8 +61,9 @@ class AppletHandle : public QGraphicsObject
|
||||
AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos);
|
||||
virtual ~AppletHandle();
|
||||
|
||||
void detachApplet ();
|
||||
bool shown() const;
|
||||
|
||||
void detachApplet();
|
||||
Applet *applet() const;
|
||||
|
||||
QRectF boundingRect() const;
|
||||
|
@ -96,7 +96,6 @@ public:
|
||||
QPointF preferredPos(Corona *corona) const;
|
||||
QPointF preferredPanelPos(Corona *corona) const;
|
||||
void setLockToolText();
|
||||
void handleDisappeared(AppletHandle *handle);
|
||||
void appletDestroyed(Applet*);
|
||||
void appletAppearAnimationComplete();
|
||||
void appletAppeared(Applet*);
|
||||
@ -172,7 +171,6 @@ public:
|
||||
Applet::List applets;
|
||||
Applet *focusedApplet;
|
||||
Plasma::Wallpaper *wallpaper;
|
||||
QMap<Applet*, AppletHandle*> handles;
|
||||
QHash<QString, ContainmentActions*> localActionPlugins;
|
||||
int screen;
|
||||
int lastScreen;
|
||||
|
Loading…
Reference in New Issue
Block a user