Optimization. Avoid calling prepareGeometryChange() if the new and old geometry have the same size. Added a graphicsItem() method to LayoutItem which returns the associated graphics item (if any). Needed for effects during layouting.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=699494
This commit is contained in:
Robert Knight 2007-08-13 09:01:00 +00:00
parent ca39faf71a
commit 482f9824ba
4 changed files with 40 additions and 4 deletions

View File

@ -56,6 +56,11 @@ LayoutItem::~LayoutItem()
delete d;
}
QGraphicsItem* LayoutItem::graphicsItem()
{
return 0;
}
bool LayoutItem::hasHeightForWidth() const
{
return false;

View File

@ -24,6 +24,8 @@
#include <plasma/plasma_export.h>
class QGraphicsItem;
namespace Plasma
{
@ -137,6 +139,14 @@ class PLASMA_EXPORT LayoutItem
**/
Layout* managingLayout() const;
/**
* Returns the graphics item associated with this layout item or 0
* if there is no associated graphics item.
*
* The default implementation returns 0.
*/
virtual QGraphicsItem* graphicsItem();
private:
class Private;
Private *const d;

View File

@ -39,6 +39,7 @@ class Widget::Private
public:
Private()
: parent(0)
, opacity(1.0)
{ }
~Private() { }
@ -49,9 +50,16 @@ class Widget::Private
Widget *parent;
QList<Widget *> childList;
qreal opacity;
bool shouldPaint(QPainter *painter, const QTransform &transform);
};
QGraphicsItem* Widget::graphicsItem()
{
return this;
}
bool Widget::Private::shouldPaint(QPainter *painter, const QTransform &transform)
{
qreal zoomLevel = painter->transform().m11() / transform.m11();
@ -77,6 +85,11 @@ Widget::~Widget()
delete d;
}
void Widget::setOpacity(qreal opacity)
{
d->opacity = opacity;
}
Qt::Orientations Widget::expandingDirections() const
{
return 0;
@ -138,12 +151,14 @@ QRectF Widget::localGeometry() const
void Widget::setGeometry(const QRectF& geometry)
{
prepareGeometryChange();
bool sizeChange = d->size != geometry.size();
if ( sizeChange ) {
prepareGeometryChange();
d->size = geometry.size();
}
setPos(geometry.topLeft());
d->size = geometry.size();
updateGeometry();
update();
}
@ -152,7 +167,7 @@ void Widget::updateGeometry()
prepareGeometryChange();
if (layout()) {
kDebug() << (void *) this << " updating geometry to " << size();
// kDebug() << (void *) this << " updating geometry to " << size();
layout()->setGeometry(geometry());
}
}
@ -227,6 +242,8 @@ void Widget::addChild(Widget *w)
void Widget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setOpacity(d->opacity);
if (d->shouldPaint(painter, transform())) {
paintWidget(painter, option, widget);
}

View File

@ -218,6 +218,10 @@ public:
*/
Q_INVOKABLE void addChild(Widget *widget);
void setOpacity(qreal opacity);
virtual QGraphicsItem* graphicsItem();
protected:
/**
* Paints the widget