From b448d9bb90961843689bd42e61b2836c4ea85f6a Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 24 Oct 2007 06:54:26 +0000 Subject: [PATCH] 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 --- widgets/layoutitem.cpp | 6 ++++++ widgets/layoutitem.h | 6 ++++++ widgets/widget.cpp | 31 +++++++++++++++++++++++-------- widgets/widget.h | 1 + 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/widgets/layoutitem.cpp b/widgets/layoutitem.cpp index 6b45df022..e485c32e1 100644 --- a/widgets/layoutitem.cpp +++ b/widgets/layoutitem.cpp @@ -115,6 +115,7 @@ void LayoutItem::setManagingLayout(Layout* layout) } d->managingLayout = layout; + managingLayoutChanged(); } void LayoutItem::unsetManagingLayout(Layout* layout) @@ -122,6 +123,11 @@ void LayoutItem::unsetManagingLayout(Layout* layout) if (d->managingLayout == layout) { d->managingLayout = 0; } + managingLayoutChanged(); +} + +void LayoutItem::managingLayoutChanged() +{ } Layout* LayoutItem::managingLayout() const diff --git a/widgets/layoutitem.h b/widgets/layoutitem.h index 85c235f82..74645b297 100644 --- a/widgets/layoutitem.h +++ b/widgets/layoutitem.h @@ -149,6 +149,12 @@ class PLASMA_EXPORT LayoutItem */ virtual QGraphicsItem* graphicsItem(); + protected: + /** + * Reimplement to respond to a change in managing layout + */ + virtual void managingLayoutChanged(); + private: class Private; Private *const d; diff --git a/widgets/widget.cpp b/widgets/widget.cpp index 7b11e39c8..9f73dcffe 100644 --- a/widgets/widget.cpp +++ b/widgets/widget.cpp @@ -34,7 +34,7 @@ #include -#include "layout.h" +#include "freelayout.h" #include "plasma/plasma.h" namespace Plasma @@ -44,12 +44,13 @@ class Widget::Private { public: Private() - : minimumSize(0,0) - , maximumSize(std::numeric_limits::infinity(), - std::numeric_limits::infinity()) - , parent(0) - , opacity(1.0) - , cachePaintMode(Widget::NoCacheMode) + : minimumSize(0,0), + maximumSize(std::numeric_limits::infinity(), + std::numeric_limits::infinity()), + parent(0), + opacity(1.0), + cachePaintMode(Widget::NoCacheMode), + wasMovable(false) { } ~Private() { } @@ -71,6 +72,8 @@ class Widget::Private QString cacheKey; QRectF cacheInvalidated; + bool wasMovable; + bool shouldPaint(QPainter *painter, const QTransform &transform); }; @@ -292,7 +295,7 @@ void Widget::addChild(Widget *w) w->reparent(this); d->childList.append(w); - qDebug("Added Child Widget : %p", (void*)w); + //kDebug() << "Added Child Widget" << w; if (layout()) { layout()->addItem(w); @@ -433,5 +436,17 @@ void Widget::reparent(Widget *w) update(); } +void Widget::managingLayoutChanged() +{ + if (managingLayout()) { + d->wasMovable = flags() & ItemIsMovable; + if (!dynamic_cast(managingLayout())) { + setFlag(ItemIsMovable, false); + } + } else { + setFlag(ItemIsMovable, d->wasMovable); + } +} + } // Plasma namespace diff --git a/widgets/widget.h b/widgets/widget.h index 4bf940361..cf66f94d7 100644 --- a/widgets/widget.h +++ b/widgets/widget.h @@ -257,6 +257,7 @@ protected: */ virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void setSize(const QSizeF& size); + void managingLayoutChanged(); private: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);