when an item is added to the layout, give it a chance to react. in the case of Widget, we're going to set the movable state of the QGraphicsItem. the result: items move, or don't, based on whether or not they are in a layout. finally, you can't just move shit around in the panel.

it's pretty hackish since we have to special case FreeLayout but hey, since when were layouts in plasma ever sane?

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=728764
This commit is contained in:
Aaron J. Seigo 2007-10-24 06:54:26 +00:00
parent 97ddf36df4
commit b448d9bb90
4 changed files with 36 additions and 8 deletions

View File

@ -115,6 +115,7 @@ void LayoutItem::setManagingLayout(Layout* layout)
} }
d->managingLayout = layout; d->managingLayout = layout;
managingLayoutChanged();
} }
void LayoutItem::unsetManagingLayout(Layout* layout) void LayoutItem::unsetManagingLayout(Layout* layout)
@ -122,6 +123,11 @@ void LayoutItem::unsetManagingLayout(Layout* layout)
if (d->managingLayout == layout) { if (d->managingLayout == layout) {
d->managingLayout = 0; d->managingLayout = 0;
} }
managingLayoutChanged();
}
void LayoutItem::managingLayoutChanged()
{
} }
Layout* LayoutItem::managingLayout() const Layout* LayoutItem::managingLayout() const

View File

@ -149,6 +149,12 @@ class PLASMA_EXPORT LayoutItem
*/ */
virtual QGraphicsItem* graphicsItem(); virtual QGraphicsItem* graphicsItem();
protected:
/**
* Reimplement to respond to a change in managing layout
*/
virtual void managingLayoutChanged();
private: private:
class Private; class Private;
Private *const d; Private *const d;

View File

@ -34,7 +34,7 @@
#include <KDebug> #include <KDebug>
#include "layout.h" #include "freelayout.h"
#include "plasma/plasma.h" #include "plasma/plasma.h"
namespace Plasma namespace Plasma
@ -44,12 +44,13 @@ class Widget::Private
{ {
public: public:
Private() Private()
: minimumSize(0,0) : minimumSize(0,0),
, maximumSize(std::numeric_limits<qreal>::infinity(), maximumSize(std::numeric_limits<qreal>::infinity(),
std::numeric_limits<qreal>::infinity()) std::numeric_limits<qreal>::infinity()),
, parent(0) parent(0),
, opacity(1.0) opacity(1.0),
, cachePaintMode(Widget::NoCacheMode) cachePaintMode(Widget::NoCacheMode),
wasMovable(false)
{ } { }
~Private() { } ~Private() { }
@ -71,6 +72,8 @@ class Widget::Private
QString cacheKey; QString cacheKey;
QRectF cacheInvalidated; QRectF cacheInvalidated;
bool wasMovable;
bool shouldPaint(QPainter *painter, const QTransform &transform); bool shouldPaint(QPainter *painter, const QTransform &transform);
}; };
@ -292,7 +295,7 @@ void Widget::addChild(Widget *w)
w->reparent(this); w->reparent(this);
d->childList.append(w); d->childList.append(w);
qDebug("Added Child Widget : %p", (void*)w); //kDebug() << "Added Child Widget" << w;
if (layout()) { if (layout()) {
layout()->addItem(w); layout()->addItem(w);
@ -433,5 +436,17 @@ void Widget::reparent(Widget *w)
update(); update();
} }
void Widget::managingLayoutChanged()
{
if (managingLayout()) {
d->wasMovable = flags() & ItemIsMovable;
if (!dynamic_cast<FreeLayout*>(managingLayout())) {
setFlag(ItemIsMovable, false);
}
} else {
setFlag(ItemIsMovable, d->wasMovable);
}
}
} // Plasma namespace } // Plasma namespace

View File

@ -257,6 +257,7 @@ protected:
*/ */
virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void setSize(const QSizeF& size); void setSize(const QSizeF& size);
void managingLayoutChanged();
private: private:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);