actually make plasmoid removal work and harden the applet handle against the applet being removed from under it
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=739867
This commit is contained in:
parent
e9d29e93b5
commit
9c52d8f067
@ -77,12 +77,17 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_applet->setParentItem(this);
|
m_applet->setParentItem(this);
|
||||||
|
connect(m_applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed()));
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
startFading(FadeIn);
|
startFading(FadeIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppletHandle::~AppletHandle()
|
AppletHandle::~AppletHandle()
|
||||||
{
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QRectF rect(m_applet->boundingRect());
|
QRectF rect(m_applet->boundingRect());
|
||||||
QPointF center = rect.center();
|
QPointF center = rect.center();
|
||||||
|
|
||||||
@ -162,7 +167,7 @@ void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_applet->hasConfigurationInterface()) {
|
if (m_applet && m_applet->hasConfigurationInterface()) {
|
||||||
painter->drawPixmap(point + shiftC, KIcon("configure").pixmap(ICON_SIZE, ICON_SIZE));
|
painter->drawPixmap(point + shiftC, KIcon("configure").pixmap(ICON_SIZE, ICON_SIZE));
|
||||||
point += QPointF(0.0, ICON_SIZE + ICON_MARGIN);
|
point += QPointF(0.0, ICON_SIZE + ICON_MARGIN);
|
||||||
}
|
}
|
||||||
@ -187,7 +192,7 @@ AppletHandle::ButtonType AppletHandle::mapToButton(const QPointF &point) const
|
|||||||
|
|
||||||
QPolygonF activeArea = QPolygonF(QRectF(basePoint, QSizeF(ICON_SIZE, ICON_SIZE)));
|
QPolygonF activeArea = QPolygonF(QRectF(basePoint, QSizeF(ICON_SIZE, ICON_SIZE)));
|
||||||
|
|
||||||
if (m_applet->hasConfigurationInterface()) {
|
if (m_applet && m_applet->hasConfigurationInterface()) {
|
||||||
if (activeArea.containsPoint(point, Qt::OddEvenFill)) {
|
if (activeArea.containsPoint(point, Qt::OddEvenFill)) {
|
||||||
return ConfigureButton;
|
return ConfigureButton;
|
||||||
}
|
}
|
||||||
@ -223,12 +228,12 @@ void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
{
|
{
|
||||||
ButtonType releasedAtButton = mapToButton(event->pos());
|
ButtonType releasedAtButton = mapToButton(event->pos());
|
||||||
|
|
||||||
if (event->button()==Qt::LeftButton && m_pressedButton==releasedAtButton) {
|
if (m_applet && event->button() == Qt::LeftButton && m_pressedButton==releasedAtButton) {
|
||||||
if (m_pressedButton==ConfigureButton) {
|
if (m_pressedButton == ConfigureButton) {
|
||||||
//FIXME: Remove this call once the configuration management change was done
|
//FIXME: Remove this call once the configuration management change was done
|
||||||
m_containment->emitLaunchActivated();
|
m_containment->emitLaunchActivated();
|
||||||
m_applet->showConfigurationInterface();
|
m_applet->showConfigurationInterface();
|
||||||
} else if (m_pressedButton==RemoveButton) {
|
} else if (m_pressedButton == RemoveButton) {
|
||||||
Phase::self()->animateItem(m_applet, Phase::Disappear);
|
Phase::self()->animateItem(m_applet, Phase::Disappear);
|
||||||
forceDisappear();
|
forceDisappear();
|
||||||
}
|
}
|
||||||
@ -258,7 +263,10 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
{
|
{
|
||||||
static const qreal snapAngle = 3.14159 / 2.0;
|
static const qreal snapAngle = 3.14159 / 2.0;
|
||||||
|
|
||||||
if (m_pressedButton == MoveButton) {
|
if (!m_applet) {
|
||||||
|
QGraphicsItem::mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
else if (m_pressedButton == MoveButton) {
|
||||||
QPointF delta = event->pos()-event->lastPos();
|
QPointF delta = event->pos()-event->lastPos();
|
||||||
setPos(pos()+delta);
|
setPos(pos()+delta);
|
||||||
} else if (m_pressedButton == RotateButton) {
|
} else if (m_pressedButton == RotateButton) {
|
||||||
@ -318,6 +326,12 @@ void AppletHandle::fadeAnimation(qreal progress)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppletHandle::appletDestroyed()
|
||||||
|
{
|
||||||
|
m_applet = 0;
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
void AppletHandle::startFading(FadeType anim)
|
void AppletHandle::startFading(FadeType anim)
|
||||||
{
|
{
|
||||||
if (m_animId!=0) {
|
if (m_animId!=0) {
|
||||||
|
@ -58,6 +58,7 @@ class AppletHandle : public QObject, public QGraphicsItem
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void fadeAnimation(qreal progress);
|
void fadeAnimation(qreal progress);
|
||||||
|
void appletDestroyed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int HANDLE_WIDTH = 5;
|
static const int HANDLE_WIDTH = 5;
|
||||||
|
@ -254,6 +254,18 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
desktopMenu.exec(event->screenPos());
|
desktopMenu.exec(event->screenPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Containment::destroyApplet()
|
||||||
|
{
|
||||||
|
QAction *action = qobject_cast<QAction*>(sender());
|
||||||
|
|
||||||
|
if (!action) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>());
|
||||||
|
Phase::self()->animateItem(applet, Phase::Disappear);
|
||||||
|
}
|
||||||
|
|
||||||
void Containment::setFormFactor(FormFactor formFactor)
|
void Containment::setFormFactor(FormFactor formFactor)
|
||||||
{
|
{
|
||||||
if (d->formFactor == formFactor && layout()) {
|
if (d->formFactor == formFactor && layout()) {
|
||||||
@ -400,12 +412,18 @@ void Containment::appletDestroyed(QObject* object)
|
|||||||
void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Phase::Animation anim)
|
void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Phase::Animation anim)
|
||||||
{
|
{
|
||||||
if (anim == Phase::Disappear) {
|
if (anim == Phase::Disappear) {
|
||||||
if (item->parentItem() == this) {
|
QGraphicsItem *parent = item->parentItem();
|
||||||
Applet *applet = qgraphicsitem_cast<Applet*>(item);
|
|
||||||
|
|
||||||
if (applet) {
|
while (parent) {
|
||||||
applet->destroy();
|
if (parent == this) {
|
||||||
|
Applet *applet = qgraphicsitem_cast<Applet*>(item);
|
||||||
|
|
||||||
|
if (applet) {
|
||||||
|
applet->destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parent = parent->parentItem();
|
||||||
}
|
}
|
||||||
} else if (anim == Phase::Appear) {
|
} else if (anim == Phase::Appear) {
|
||||||
if (containmentType() == DesktopContainment) {
|
if (containmentType() == DesktopContainment) {
|
||||||
|
@ -283,6 +283,7 @@ class PLASMA_EXPORT Containment : public Applet
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void handleDisappeared(AppletHandle *handle);
|
void handleDisappeared(AppletHandle *handle);
|
||||||
|
void destroyApplet();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(Containment)
|
Q_DISABLE_COPY(Containment)
|
||||||
|
Loading…
Reference in New Issue
Block a user