Implement the same sizeHint() logic in Plasma::Widget as QWidget. It returns the layout's sizeHint() if there is a layout or an invalid QSizeF otherwise. Implement sizeHint() in Plasma::Applet. It returns the same as contentSize() if there is no border or the content size hint plus the border size otherwise. Many of the applets need changes for setGeometry() to work properly on them. Fix various warnings.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=701192
This commit is contained in:
Robert Knight 2007-08-17 15:05:01 +00:00
parent c86bf6caea
commit 93070ce1fd
4 changed files with 60 additions and 52 deletions

View File

@ -252,7 +252,7 @@ public:
p2->drawPixmap(leftOffset, topOffset, *cachedBackground);
}
void paintHover(QPainter* painter, Applet* q)
void paintHover(QPainter* , Applet* )
{
//TODO draw hover interface for close, configure, info and move
}
@ -296,6 +296,18 @@ public:
return appletDescription.service()->library() + QString::number(appletId);
}
void getBorderSize(int& left , int& top, int &right, int& bottom)
{
if (!background) {
top = left = right = bottom = 0;
} else {
top = background->elementSize("top").height();
left = background->elementSize("left").width();
right = background->elementSize("right").width();
bottom = background->elementSize("bottom").height();
}
}
//TODO: examine the usage of memory here; there's a pretty large
// number of members at this point.
uint appletId;
@ -330,8 +342,8 @@ Applet::Applet(QGraphicsItem *parent,
d->init(this);
}
Applet::Applet(QObject* parent, const QStringList& args)
: Widget(0),
Applet::Applet(QObject* parentObject, const QStringList& args)
: Widget(0,parentObject),
d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0] : QString()),
args.count() > 1 ? args[1].toInt() : 0))
{
@ -609,17 +621,27 @@ int Applet::type() const
QRectF Applet::boundingRect() const
{
QRectF rect = QRectF(QPointF(0,0), d->contentSize(this));
if (!d->background) {
return rect;
}
const int topHeight = d->background->elementSize("top").height();
const int leftWidth = d->background->elementSize("left").width();
const int rightWidth = d->background->elementSize("right").width();
const int bottomHeight = d->background->elementSize("bottom").height();
int left;
int right;
int top;
int bottom;
rect.adjust(0 - leftWidth, 0 - topHeight, rightWidth, bottomHeight);
return rect;
d->getBorderSize(left,top,right,bottom);
return rect.adjusted(-left,-top,right,bottom);
}
QSizeF Applet::sizeHint() const
{
int left;
int right;
int top;
int bottom;
d->getBorderSize(left,top,right,bottom);
return contentSize() + QSizeF(left+right,top+bottom);
}
QList<QAction*> Applet::contextActions()
@ -685,9 +707,9 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
painter->setBrush(QBrush(color(), Qt::SolidPattern));
painter->drawRoundRect(boundingRect());
int iconDim = KIconLoader().currentSize(K3Icon::Desktop);
int midX = (boundingRect().width() / 2) - (iconDim / 2);
int midY = (boundingRect().height() / 2) - (iconDim / 2);
KIcon(icon()).paint(painter, midX, midY, iconDim, iconDim);
qreal midX = (boundingRect().width() / 2) - (iconDim / 2);
qreal midY = (boundingRect().height() / 2) - (iconDim / 2);
KIcon(icon()).paint(painter, (int)midX, (int)midY, iconDim, iconDim);
}/* else if (zoomLevel == scalingFactor(Plasma::OverviewZoom)) { //Show Groups only
} */
}
@ -953,6 +975,8 @@ void Applet::setShadowShown(bool shown)
delete d->shadow;
d->shadow = 0;
}
#else
Q_UNUSED(shown);
#endif
}

View File

@ -550,6 +550,11 @@ class PLASMA_EXPORT Applet : public Widget
*/
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
// reimplemented from LayoutItem
// value is the same as contentSize() if drawStandardBackground() is false
// or contentSize() plus the size of the border otherwise.
virtual QSizeF sizeHint() const;
protected Q_SLOTS:
/**
* @internal used to show the configuration of an applet on first show

View File

@ -66,8 +66,9 @@ bool Widget::Private::shouldPaint(QPainter *painter, const QTransform &transform
return (fabs(zoomLevel - scalingFactor(Plasma::DesktopZoom))) < std::numeric_limits<double>::epsilon();
}
Widget::Widget(QGraphicsItem *parent)
: QGraphicsItem(parent),
Widget::Widget(QGraphicsItem *parent,QObject* parentObject)
: QObject(parentObject),
QGraphicsItem(parent),
d(new Private)
{
setFlag(QGraphicsItem::ItemClipsToShape, true);
@ -145,13 +146,15 @@ qreal Widget::widthForHeight(qreal h) const
QRectF Widget::geometry() const
{
return QRectF(pos(), size());
return QRectF(pos(),d->size);
}
#if 0
QRectF Widget::localGeometry() const
{
return QRectF(QPointF(0.0f, 0.0f), size());
return QRectF(QPointF(0.0f, 0.0f), boundingRect().size);
}
#endif
void Widget::setGeometry(const QRectF& geometry)
{
@ -187,32 +190,20 @@ void Widget::invalidate()
QSizeF Widget::sizeHint() const
{
return size();
}
void Widget::setSize(const QSizeF &newSize)
{
if ( newSize != d->size )
return;
prepareGeometryChange();
qreal width = qBound(d->minimumSize.width(), newSize.width(), d->maximumSize.width());
qreal height = qBound(d->minimumSize.height(), newSize.height(), d->maximumSize.height());
d->size.setWidth(width);
d->size.setHeight(height);
update();
if (layout()) {
return layout()->sizeHint();
} else {
return QSizeF();
}
}
QSizeF Widget::size() const
{
return d->size;
return geometry().size();
}
QRectF Widget::boundingRect() const
{
return QRectF(QPointF(0.0f, 0.0f), size());
return QRectF(QPointF(0,0),geometry().size());
}
void Widget::resize(const QSizeF& size)

View File

@ -54,9 +54,8 @@ class PLASMA_EXPORT Widget : public QObject,
Q_PROPERTY( QSizeF minimumSize READ minimumSize WRITE setMinimumSize )
Q_PROPERTY( QSizeF maximumSize READ maximumSize WRITE setMaximumSize )
Q_PROPERTY( QRectF geometry READ geometry WRITE setGeometry )
Q_PROPERTY( QRectF localGeometry READ localGeometry )
Q_PROPERTY( QSizeF sizeHint READ sizeHint )
Q_PROPERTY( QSizeF size READ size WRITE setSize )
Q_PROPERTY( QSizeF size READ size WRITE resize )
public:
@ -65,7 +64,7 @@ public:
* Creates a new Plasma::Widget.
* @param parent the QGraphicsItem this icon is parented to.
*/
explicit Widget(QGraphicsItem *parent = 0);
explicit Widget(QGraphicsItem *parent = 0 , QObject *parentObject = 0);
/**
* Destroys a Plasma::Widget.
@ -136,11 +135,6 @@ public:
*/
QRectF geometry() const;
/**
* @return geometry of this widget in local coordinates.
*/
QRectF localGeometry() const;
/**
* Sets the geometry of this Widget.
*/
@ -170,12 +164,6 @@ public:
*/
virtual QSizeF sizeHint() const;
/**
* Sets the size of this Plasma::Widget.
* @param size the size of this Plasma::Widget
*/
void setSize(const QSizeF &size);
/**
* @return the size of this Plasma::Widget
*/