when is possible (i.e. when widget is actually a QGraphicsWidget) use real layouts

svn path=/trunk/KDE/kdelibs/; revision=1109927
This commit is contained in:
Marco Martin 2010-04-01 09:18:00 +00:00
parent 6fc15a4687
commit 5809b052d6
2 changed files with 36 additions and 25 deletions

View File

@ -82,6 +82,10 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
KConfigGroup cg = hostExtender->d->applet->config("ExtenderItems");
KConfigGroup dg = KConfigGroup(&cg, QString::number(d->extenderItemId));
//create own layout
d->layout = new QGraphicsLinearLayout(Qt::Vertical, this);
d->layout->addItem(d->toolbox);
uint sourceAppletId = dg.readEntry("sourceAppletId", 0);
//check if we're creating a new item or reinstantiating an existing one.
@ -192,13 +196,23 @@ void ExtenderItem::setWidget(QGraphicsItem *widget)
}
widget->setParentItem(this);
widget->installSceneEventFilter(this);
QSizeF panelSize(QSizeF(size().width() - d->bgLeft - d->bgRight,
d->iconSize + d->dragTop + d->dragBottom));
widget->setPos(QPointF(d->bgLeft + d->dragLeft, panelSize.height() + d->bgTop));
d->widget = widget;
d->updateSizeHints();
if (widget->isWidget()) {
if (d->widget && d->widget->isWidget()) {
d->layout->removeItem(static_cast<QGraphicsWidget *>(d->widget));
}
d->layout->addItem(static_cast<QGraphicsWidget *>(widget));
d->widget = widget;
} else {
widget->installSceneEventFilter(this);
QSizeF panelSize(QSizeF(size().width() - d->bgLeft - d->bgRight,
d->iconSize + d->dragTop + d->dragBottom));
widget->setPos(QPointF(d->bgLeft + d->dragLeft, panelSize.height() + d->bgTop));
d->widget = widget;
d->updateSizeHints();
}
d->widget->setVisible(!d->collapsed);
}
@ -697,15 +711,18 @@ void ExtenderItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QSizeF ExtenderItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
Q_UNUSED(constraint)
switch (which) {
case Qt::MinimumSize:
return d->minimumSize;
case Qt::MaximumSize:
return d->maximumSize;
case Qt::PreferredSize:
default:
return d->preferredSize;
if (d->widget->isWidget()) {
return QGraphicsWidget::sizeHint(which, constraint);
} else {
switch (which) {
case Qt::MinimumSize:
return d->minimumSize;
case Qt::MaximumSize:
return d->maximumSize;
case Qt::PreferredSize:
default:
return d->preferredSize;
}
}
}
@ -965,16 +982,9 @@ void ExtenderItemPrivate::updateSizeHints()
QSizeF pref;
QSizeF max;
if (widget->isWidget()) {
QGraphicsWidget *graphicsWidget = static_cast<QGraphicsWidget*>(widget);
min = graphicsWidget->effectiveSizeHint(Qt::MinimumSize);
pref = graphicsWidget->effectiveSizeHint(Qt::PreferredSize);
max = graphicsWidget->effectiveSizeHint(Qt::MaximumSize);
} else {
min = widget->boundingRect().size();
pref = widget->boundingRect().size();
max = widget->boundingRect().size();
}
min = widget->boundingRect().size();
pref = widget->boundingRect().size();
max = widget->boundingRect().size();
if (collapsed) {
preferredSize = QSizeF(pref.width() + marginWidth,

View File

@ -63,6 +63,7 @@ class ExtenderItemPrivate
QGraphicsItem *widget;
QGraphicsWidget *toolbox;
QGraphicsLinearLayout *toolboxLayout;
QGraphicsLinearLayout *layout;
Extender *extender;
Applet *sourceApplet;