still experimental and to me made work better: extendergroups store items in a scrollwidget

svn path=/trunk/KDE/kdelibs/; revision=1109959
This commit is contained in:
Marco Martin 2010-04-01 11:43:51 +00:00
parent 1ce5890d24
commit 7d853de323
5 changed files with 42 additions and 15 deletions

View File

@ -426,9 +426,9 @@ void Extender::dropEvent(QGraphicsSceneDragDropEvent *event)
void Extender::itemAddedEvent(ExtenderItem *item, const QPointF &pos) void Extender::itemAddedEvent(ExtenderItem *item, const QPointF &pos)
{ {
if (!item->group()) {
if (pos == QPointF(-1, -1)) { if (pos == QPointF(-1, -1)) {
//if just plain adding an item, add it at a sane position: //if just plain adding an item, add it at a sane position:
if (!item->group()) {
if (appearance() == BottomUpStacked) { if (appearance() == BottomUpStacked) {
//at the top //at the top
d->layout->insertItem(0, item); d->layout->insertItem(0, item);
@ -436,13 +436,10 @@ void Extender::itemAddedEvent(ExtenderItem *item, const QPointF &pos)
//at the bottom //at the bottom
d->layout->addItem(item); d->layout->addItem(item);
} }
} else {
//at the top in the group it belongs to
d->layout->insertItem(d->insertIndexFromPos(item->group()->pos()) + 1, item);
}
} else { } else {
d->layout->insertItem(d->insertIndexFromPos(pos), item); d->layout->insertItem(d->insertIndexFromPos(pos), item);
} }
}
//remove the empty extender message if needed. //remove the empty extender message if needed.
d->updateEmptyExtenderLabel(); d->updateEmptyExtenderLabel();

View File

@ -23,11 +23,13 @@
#include <QString> #include <QString>
#include <QList> #include <QList>
#include <QtGui/QGraphicsWidget> #include <QtGui/QGraphicsWidget>
#include <QtGui/QGraphicsLinearLayout>
#include "applet.h" #include "applet.h"
#include "extender.h" #include "extender.h"
#include "extenderitem.h" #include "extenderitem.h"
#include "theme.h" #include "theme.h"
#include "widgets/scrollwidget.h"
#include "private/extendergroup_p.h" #include "private/extendergroup_p.h"
@ -45,6 +47,19 @@ ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId)
config().writeEntry("isGroup", true); config().writeEntry("isGroup", true);
//FIXME: this ain't pretty
setPreferredHeight(300);
QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(layout());
d->scrollWidget = new ScrollWidget(this);
d->scrollWidget->show();
lay->addItem(d->scrollWidget);
d->scrollWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
d->scrollWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->childsWidget = new QGraphicsWidget(d->scrollWidget);
d->scrollWidget->setWidget(d->childsWidget);
d->layout = new QGraphicsLinearLayout(Qt::Vertical, d->childsWidget);
QAction *expand = new QAction(this); QAction *expand = new QAction(this);
expand->setVisible(true); expand->setVisible(true);
expand->setToolTip(i18n("Show this group.")); expand->setToolTip(i18n("Show this group."));
@ -183,6 +198,12 @@ void ExtenderGroup::collapseGroup()
} }
} }
void ExtenderGroup::resizeEvent(QGraphicsSceneResizeEvent *event)
{
ExtenderItem::resizeEvent(event);
d->scrollWidget->setGeometry(0, 70, size().width(), 400);
}
ExtenderGroupPrivate::ExtenderGroupPrivate(ExtenderGroup *group) ExtenderGroupPrivate::ExtenderGroupPrivate(ExtenderGroup *group)
: q(group), : q(group),
@ -200,17 +221,16 @@ ExtenderGroupPrivate::~ExtenderGroupPrivate()
void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item) void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item)
{ {
if (item->group() == q) { if (item->group() == q) {
layout->addItem(item);
item->setParentItem(childsWidget);
childsWidget->resize(childsWidget->size().width(),
childsWidget->effectiveSizeHint(Qt::PreferredSize).height());
if (!q->isVisible() && !q->items().isEmpty()) { if (!q->isVisible() && !q->items().isEmpty()) {
q->extender()->itemAddedEvent(q); q->extender()->itemAddedEvent(q);
q->show(); q->show();
} }
if (collapsed) { scrollWidget->setVisible(!q->isCollapsed());
q->extender()->itemRemovedEvent(item);
item->hide();
} else {
q->extender()->itemAddedEvent(item);
item->show();
}
} }
} }
@ -221,6 +241,7 @@ void ExtenderGroupPrivate::removeItemFromGroup(Plasma::ExtenderItem *item)
q->extender()->itemRemovedEvent(q); q->extender()->itemRemovedEvent(q);
q->hide(); q->hide();
} }
layout->removeItem(item);
} }
} }

View File

@ -114,6 +114,9 @@ class PLASMA_EXPORT ExtenderGroup : public ExtenderItem
*/ */
void collapseGroup(); void collapseGroup();
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
private: private:
ExtenderGroupPrivate * const d; ExtenderGroupPrivate * const d;

View File

@ -203,7 +203,7 @@ void ExtenderItem::setWidget(QGraphicsItem *widget)
if (d->widget && d->widget->isWidget()) { if (d->widget && d->widget->isWidget()) {
d->layout->removeItem(static_cast<QGraphicsWidget *>(d->widget)); d->layout->removeItem(static_cast<QGraphicsWidget *>(d->widget));
} }
d->layout->addItem(static_cast<QGraphicsWidget *>(widget)); d->layout->insertItem(1, static_cast<QGraphicsWidget *>(widget));
d->widget = widget; d->widget = widget;
} else { } else {
widget->installSceneEventFilter(this); widget->installSceneEventFilter(this);
@ -857,6 +857,7 @@ void ExtenderItemPrivate::themeChanged()
} }
background->getMargins(bgLeft, bgTop, bgRight, bgBottom); background->getMargins(bgLeft, bgTop, bgRight, bgBottom);
layout->setContentsMargins(bgLeft, bgTop, bgRight, bgBottom);
dragger->setImagePath("widgets/extender-dragger"); dragger->setImagePath("widgets/extender-dragger");
@ -878,6 +879,7 @@ void ExtenderItemPrivate::themeChanged()
QSizeF panelSize(QSizeF(q->size().width() - bgLeft - bgRight, QSizeF panelSize(QSizeF(q->size().width() - bgLeft - bgRight,
iconSize + dragTop + dragBottom)); iconSize + dragTop + dragBottom));
//TODO: all this stuff will die after using the layout for everything
//resize the collapse icon. //resize the collapse icon.
collapseIcon->resize(collapseIcon->sizeFromIconSize(iconSize)); collapseIcon->resize(collapseIcon->sizeFromIconSize(iconSize));

View File

@ -23,6 +23,7 @@
namespace Plasma namespace Plasma
{ {
class ScrollWidget;
class ExtenderGroup; class ExtenderGroup;
class ExtenderItem; class ExtenderItem;
class Svg; class Svg;
@ -39,6 +40,9 @@ class ExtenderGroupPrivate
Plasma::ExtenderGroup *q; Plasma::ExtenderGroup *q;
Plasma::Svg *svg; Plasma::Svg *svg;
Plasma::ScrollWidget *scrollWidget;
QGraphicsWidget *childsWidget;
QGraphicsLinearLayout *layout;
bool collapsed; bool collapsed;
bool autoHide; bool autoHide;
bool autoCollapse; bool autoCollapse;