From d29ea0a9266b3f9e75c2d2251823b9ec4b0b9993 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sat, 10 Apr 2010 16:43:56 +0000 Subject: [PATCH] -is possible to drop items at any place of an extender group -fix build svn path=/trunk/KDE/kdelibs/; revision=1113376 --- extenders/extendergroup.cpp | 6 +++--- extenders/extenderitem.cpp | 8 +++++++- extenders/extenderitem.h | 10 ++++++++++ private/extender_p.h | 20 +++++++++++++++++++- private/extendergroup_p.h | 5 ++++- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/extenders/extendergroup.cpp b/extenders/extendergroup.cpp index abe30f1f1..9a4a8fb49 100644 --- a/extenders/extendergroup.cpp +++ b/extenders/extendergroup.cpp @@ -276,7 +276,7 @@ void ExtenderGroup::dropEvent(QGraphicsSceneDragDropEvent *event) qobject_cast(event->mimeData()); if (mimeData) { - mimeData->extenderItem()->setGroup(this); + mimeData->extenderItem()->setGroup(this, event->pos()); QApplication::restoreOverrideCursor(); d->layout->removeItem(d->spacerWidget); d->spacerWidget->deleteLater(); @@ -307,12 +307,12 @@ ExtenderGroupPrivate::~ExtenderGroupPrivate() { } -void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item) +void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item, const QPointF &pos) { if (item->group() == q) { item->setParentItem(childsWidget); item->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - layout->insertItem(0, item); + layout->insertItem(insertIndexFromPos(pos), item); layout->activate(); childsWidget->resize(childsWidget->size().width(), diff --git a/extenders/extenderitem.cpp b/extenders/extenderitem.cpp index aba088aa5..0ef47b922 100644 --- a/extenders/extenderitem.cpp +++ b/extenders/extenderitem.cpp @@ -366,7 +366,13 @@ Extender *ExtenderItem::extender() const return d->extender; } +//TODO KDE5: only one setGroup() void ExtenderItem::setGroup(ExtenderGroup *group) +{ + setGroup(group, QPointF(-1, -1)); +} + +void ExtenderItem::setGroup(ExtenderGroup *group, const QPointF &pos) { if (isGroup()) { //nesting extender groups is just insane. I don't think we'd even want to support that. @@ -384,7 +390,7 @@ void ExtenderItem::setGroup(ExtenderGroup *group) kDebug() << "moving to another extender because we're joining a detached group."; setExtender(group->extender()); } - group->d->addItemToGroup(this); + group->d->addItemToGroup(this, pos); } else { if (oldGroup) { oldGroup->d->removeItemFromGroup(this); diff --git a/extenders/extenderitem.h b/extenders/extenderitem.h index 58b6a9a9d..9233bbcf4 100644 --- a/extenders/extenderitem.h +++ b/extenders/extenderitem.h @@ -179,6 +179,16 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget */ void setGroup(ExtenderGroup *group); + /** + * @param group the group you want this item to belong to. Note that you can't nest + * ExtenderGroups. + * + * @param group the new group + * @param pos position inside the extender group + * @since 4.5 + */ + void setGroup(ExtenderGroup *group, const QPointF &pos); + /** * @returns the group this item belongs to. * @since 4.3 diff --git a/private/extender_p.h b/private/extender_p.h index 9b961cb48..38204d3d9 100644 --- a/private/extender_p.h +++ b/private/extender_p.h @@ -37,9 +37,27 @@ class Extender; class ExtenderGroup; class ExtenderItem; class Label; -class Spacer; class Svg; +class Spacer : public QGraphicsWidget +{ +public: + Spacer(QGraphicsItem *parent); + ~Spacer(); + + void setMargins(qreal left, qreal top, qreal right, qreal bottom); + +protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0); + + +private: + qreal m_left; + qreal m_top; + qreal m_right; + qreal m_bottom; +}; + class ExtenderPrivate { public: diff --git a/private/extendergroup_p.h b/private/extendergroup_p.h index 4bf900c1a..a55341ee2 100644 --- a/private/extendergroup_p.h +++ b/private/extendergroup_p.h @@ -27,6 +27,7 @@ class ScrollWidget; class ExtenderGroup; class ExtenderItem; class Svg; +class Spacer; class ExtenderGroupPrivate { @@ -34,11 +35,13 @@ class ExtenderGroupPrivate ExtenderGroupPrivate(ExtenderGroup *group); ~ExtenderGroupPrivate(); - void addItemToGroup(Plasma::ExtenderItem *item); + void addItemToGroup(Plasma::ExtenderItem *item, const QPointF &pos = QPointF(-1, -1)); void removeItemFromGroup(Plasma::ExtenderItem *item); void themeChanged(); + int insertIndexFromPos(const QPointF &pos) const; Plasma::ExtenderGroup *q; + Spacer *spacerWidget; Plasma::Svg *svg; Plasma::ScrollWidget *scrollWidget; QGraphicsWidget *childsWidget;