now the toolbox can be accessed by subclasses, so funny things can happen, bury it under a QWeakPointer so

svn path=/trunk/KDE/kdelibs/; revision=1054267
This commit is contained in:
Marco Martin 2009-11-25 19:46:33 +00:00
parent 8e9e547933
commit 08ae083579
3 changed files with 30 additions and 32 deletions

View File

@ -1330,7 +1330,7 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
//update the view transform of the toolbox, since it ignores transforms //update the view transform of the toolbox, since it ignores transforms
if (v && c && c->d->toolBox) { if (v && c && c->d->toolBox) {
InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(c->d->toolBox); InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(c->d->toolBox.data());
if (toolBox && toolBox->viewTransform().isScaling() && !v->transform().isScaling()) { if (toolBox && toolBox->viewTransform().isScaling() && !v->transform().isScaling()) {
c->d->positionToolBox(); c->d->positionToolBox();
} }

View File

@ -227,15 +227,15 @@ void Containment::init()
} }
if (d->type == DesktopContainment && d->toolBox) { if (d->type == DesktopContainment && d->toolBox) {
d->toolBox->addTool(this->action("add widgets")); d->toolBox.data()->addTool(this->action("add widgets"));
d->toolBox->addTool(this->action("zoom in")); d->toolBox.data()->addTool(this->action("zoom in"));
//TODO: do we need some way to allow this be overridden? //TODO: do we need some way to allow this be overridden?
// it's always available because shells rely on this // it's always available because shells rely on this
// to offer their own custom configuration as well // to offer their own custom configuration as well
QAction *configureContainment = this->action("configure"); QAction *configureContainment = this->action("configure");
if (configureContainment) { if (configureContainment) {
d->toolBox->addTool(configureContainment); d->toolBox.data()->addTool(configureContainment);
} }
} }
@ -379,7 +379,7 @@ void Containment::restore(KConfigGroup &group)
setWallpaper(group.readEntry("wallpaperplugin", defaultWallpaper), setWallpaper(group.readEntry("wallpaperplugin", defaultWallpaper),
group.readEntry("wallpaperpluginmode", defaultWallpaperMode)); group.readEntry("wallpaperpluginmode", defaultWallpaperMode));
InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(d->toolBox); InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(d->toolBox.data());
if (toolBox) { if (toolBox) {
toolBox->load(group); toolBox->load(group);
} }
@ -426,7 +426,7 @@ void Containment::save(KConfigGroup &g) const
group.writeEntry("location", (int)d->location); group.writeEntry("location", (int)d->location);
group.writeEntry("activity", d->context()->currentActivity()); group.writeEntry("activity", d->context()->currentActivity());
InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(d->toolBox); InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(d->toolBox.data());
if (toolBox) { if (toolBox) {
toolBox->save(group); toolBox->save(group);
} }
@ -496,8 +496,7 @@ void Containment::setContainmentType(Containment::Type type)
return; return;
} }
delete d->toolBox; delete d->toolBox.data();
d->toolBox = 0;
d->type = type; d->type = type;
if (!isContainment()) { if (!isContainment()) {
@ -814,7 +813,7 @@ void Containment::setFormFactor(FormFactor formFactor)
d->positionPanel(true); d->positionPanel(true);
} }
InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(d->toolBox); InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(d->toolBox.data());
if (toolBox) { if (toolBox) {
if (d->formFactor == Vertical) { if (d->formFactor == Vertical) {
toolBox->setCorner(InternalToolBox::Bottom); toolBox->setCorner(InternalToolBox::Bottom);
@ -1219,7 +1218,7 @@ void ContainmentPrivate::showDropZoneDelayed()
void Containment::dragMoveEvent(QGraphicsSceneDragDropEvent *event) void Containment::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{ {
QGraphicsItem *item = scene()->itemAt(event->scenePos()); QGraphicsItem *item = scene()->itemAt(event->scenePos());
event->setAccepted(item == this || item == d->toolBox || !item); event->setAccepted(item == this || item == d->toolBox.data() || !item);
//kDebug() << event->isAccepted() << d->showDropZoneDelayTimer->isActive(); //kDebug() << event->isAccepted() << d->showDropZoneDelayTimer->isActive();
if (!event->isAccepted()) { if (!event->isAccepted()) {
if (d->showDropZoneDelayTimer) { if (d->showDropZoneDelayTimer) {
@ -1561,20 +1560,20 @@ void ContainmentPrivate::mimeTypeRetrieved(KIO::Job *job, const QString &mimetyp
const QGraphicsItem *Containment::toolBoxItem() const const QGraphicsItem *Containment::toolBoxItem() const
{ {
return d->toolBox; return d->toolBox.data();
} }
void Containment::setToolBox(AbstractToolBox *toolBox) void Containment::setToolBox(AbstractToolBox *toolBox)
{ {
if (d->toolBox) { if (d->toolBox.data()) {
d->toolBox->deleteLater(); d->toolBox.data()->deleteLater();
} }
d->toolBox = toolBox; d->toolBox = toolBox;
} }
AbstractToolBox *Containment::toolBox() const AbstractToolBox *Containment::toolBox() const
{ {
return d->toolBox; return d->toolBox.data();
} }
void Containment::resizeEvent(QGraphicsSceneResizeEvent *event) void Containment::resizeEvent(QGraphicsSceneResizeEvent *event)
@ -1729,14 +1728,14 @@ void Containment::addToolBoxAction(QAction *action)
} }
if (d->toolBox) { if (d->toolBox) {
d->toolBox->addTool(action); d->toolBox.data()->addTool(action);
} }
} }
void Containment::removeToolBoxAction(QAction *action) void Containment::removeToolBoxAction(QAction *action)
{ {
if (d->toolBox) { if (d->toolBox) {
d->toolBox->removeTool(action); d->toolBox.data()->removeTool(action);
} }
} }
@ -1751,16 +1750,16 @@ void Containment::setToolBoxOpen(bool open)
void Containment::openToolBox() void Containment::openToolBox()
{ {
if (d->toolBox && !d->toolBox->isShowing()) { if (d->toolBox && !d->toolBox.data()->isShowing()) {
d->toolBox->setShowing(true); d->toolBox.data()->setShowing(true);
emit toolBoxVisibilityChanged(true); emit toolBoxVisibilityChanged(true);
} }
} }
void Containment::closeToolBox() void Containment::closeToolBox()
{ {
if (d->toolBox && d->toolBox->isShowing()) { if (d->toolBox && d->toolBox.data()->isShowing()) {
d->toolBox->setShowing(false); d->toolBox.data()->setShowing(false);
emit toolBoxVisibilityChanged(false); emit toolBoxVisibilityChanged(false);
} }
} }
@ -1951,7 +1950,7 @@ void Containment::setActivity(const QString &activity)
c.writeEntry("activity", activity); c.writeEntry("activity", activity);
if (d->toolBox) { if (d->toolBox) {
d->toolBox->update(); d->toolBox.data()->update();
} }
emit configNeedsSaving(); emit configNeedsSaving();
} }
@ -2109,9 +2108,9 @@ AbstractToolBox *ContainmentPrivate::createToolBox()
} }
if (toolBox) { if (toolBox) {
InternalToolBox *internalToolBox = qobject_cast<InternalToolBox *>(toolBox); InternalToolBox *internalToolBox = qobject_cast<InternalToolBox *>(toolBox.data());
QObject::connect(toolBox, SIGNAL(toggled()), q, SIGNAL(toolBoxToggled())); QObject::connect(toolBox.data(), SIGNAL(toggled()), q, SIGNAL(toolBoxToggled()));
QObject::connect(toolBox, SIGNAL(toggled()), q, SLOT(updateToolBoxVisibility())); QObject::connect(toolBox.data(), SIGNAL(toggled()), q, SLOT(updateToolBoxVisibility()));
if (internalToolBox) { if (internalToolBox) {
internalToolBox->load(); internalToolBox->load();
positionToolBox(); positionToolBox();
@ -2119,12 +2118,12 @@ AbstractToolBox *ContainmentPrivate::createToolBox()
} }
} }
return toolBox; return toolBox.data();
} }
void ContainmentPrivate::positionToolBox() void ContainmentPrivate::positionToolBox()
{ {
InternalToolBox *internalToolBox = qobject_cast<InternalToolBox *>(toolBox); InternalToolBox *internalToolBox = qobject_cast<InternalToolBox *>(toolBox.data());
if (internalToolBox) { if (internalToolBox) {
internalToolBox->reposition(); internalToolBox->reposition();
} }
@ -2132,7 +2131,7 @@ void ContainmentPrivate::positionToolBox()
void ContainmentPrivate::updateToolBoxVisibility() void ContainmentPrivate::updateToolBoxVisibility()
{ {
emit q->toolBoxVisibilityChanged(toolBox->isShowing()); emit q->toolBoxVisibilityChanged(toolBox.data()->isShowing());
} }
void ContainmentPrivate::triggerShowAddWidgets() void ContainmentPrivate::triggerShowAddWidgets()
@ -2178,9 +2177,9 @@ void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constra
if (toolBox) { if (toolBox) {
if (type == Containment::PanelContainment || type == Containment::CustomPanelContainment) { if (type == Containment::PanelContainment || type == Containment::CustomPanelContainment) {
toolBox->setVisible(unlocked); toolBox.data()->setVisible(unlocked);
} else { } else {
InternalToolBox *internalToolBox = qobject_cast<InternalToolBox *>(toolBox); InternalToolBox *internalToolBox = qobject_cast<InternalToolBox *>(toolBox.data());
if (internalToolBox) { if (internalToolBox) {
internalToolBox->setIsMovable(unlocked); internalToolBox->setIsMovable(unlocked);
} }
@ -2221,7 +2220,7 @@ void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constra
if (toolBox && if (toolBox &&
constraints & Plasma::StartupCompletedConstraint && constraints & Plasma::StartupCompletedConstraint &&
type < Containment::CustomContainment) { type < Containment::CustomContainment) {
toolBox->addTool(q->action("remove")); toolBox.data()->addTool(q->action("remove"));
checkRemoveAction(); checkRemoveAction();
} }
} }

View File

@ -48,7 +48,6 @@ public:
wallpaper(0), wallpaper(0),
screen(-1), // no screen screen(-1), // no screen
desktop(-1), // all desktops desktop(-1), // all desktops
toolBox(0),
con(0), con(0),
type(Containment::NoContainmentType), type(Containment::NoContainmentType),
showDropZoneDelayTimer(0), showDropZoneDelayTimer(0),
@ -157,7 +156,7 @@ public:
QHash<QString, ContainmentActions*> actionPlugins; QHash<QString, ContainmentActions*> actionPlugins;
int screen; int screen;
int desktop; int desktop;
AbstractToolBox *toolBox; QWeakPointer<AbstractToolBox> toolBox;
Context *con; Context *con;
Containment::Type type; Containment::Type type;
QHash<KJob*, QPointF> dropPoints; QHash<KJob*, QPointF> dropPoints;