From 0bfbed06aeb40c43713a312c2c756f1fa356f0c5 Mon Sep 17 00:00:00 2001 From: Rob Scheepmaker Date: Wed, 25 Mar 2009 13:03:04 +0000 Subject: [PATCH] Move ExtenderGroupPrivate to a seperate header file, so we can call addItemToGroup in setGroup. svn path=/trunk/KDE/kdelibs/; revision=944336 --- extendergroup.cpp | 84 ++++++++++++++++++--------------------- extendergroup.h | 2 + extenderitem.cpp | 2 + private/extendergroup_p.h | 44 ++++++++++++++++++++ 4 files changed, 86 insertions(+), 46 deletions(-) create mode 100644 private/extendergroup_p.h diff --git a/extendergroup.cpp b/extendergroup.cpp index 1920adb2b..34b03ea7f 100644 --- a/extendergroup.cpp +++ b/extendergroup.cpp @@ -27,55 +27,11 @@ #include "extendergroup.h" #include "extenderitem.h" +#include "private/extendergroup_p.h" + namespace Plasma { -class ExtenderGroupPrivate -{ - public: - ExtenderGroupPrivate(ExtenderGroup *group) - : collapsed(true), - hideIfEmpty(true) - { - q = group; - } - - ~ExtenderGroupPrivate() - { - } - - void addItemToGroup(Plasma::ExtenderItem *item) - { - if (item->group() == q) { - if (collapsed) { - q->extender()->itemRemovedEvent(item); - item->hide(); - } - if (!q->isVisible()) { - q->extender()->itemAddedEvent(q); - q->show(); - } - } - } - - void removeItemFromGroup(Plasma::ExtenderItem *item) - { - if (item->group() == q) { - if (q->items().isEmpty()) { - q->extender()->itemRemovedEvent(q); - q->hide(); - } - } - } - - ExtenderGroup *q; - bool collapsed; - bool hideIfEmpty; -}; - -class ExtenderItem; -class Applet; - ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId) : ExtenderItem(parent, groupId), d(new ExtenderGroupPrivate(this)) @@ -172,6 +128,42 @@ void ExtenderGroup::collapseGroup() } } + +ExtenderGroupPrivate::ExtenderGroupPrivate(ExtenderGroup *group) + : collapsed(true), + hideIfEmpty(true) +{ + q = group; +} + +ExtenderGroupPrivate::~ExtenderGroupPrivate() +{ +} + +void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item) +{ + if (item->group() == q) { + if (collapsed) { + q->extender()->itemRemovedEvent(item); + item->hide(); + } + if (!q->isVisible()) { + q->extender()->itemAddedEvent(q); + q->show(); + } + } +} + +void ExtenderGroupPrivate::removeItemFromGroup(Plasma::ExtenderItem *item) +{ + if (item->group() == q) { + if (q->items().isEmpty()) { + q->extender()->itemRemovedEvent(q); + q->hide(); + } + } +} + } // Plasma namespace #include "extendergroup.moc" diff --git a/extendergroup.h b/extendergroup.h index 8998b9b94..175784629 100644 --- a/extendergroup.h +++ b/extendergroup.h @@ -93,6 +93,8 @@ class PLASMA_EXPORT ExtenderGroup : public ExtenderItem Q_PRIVATE_SLOT(d, void addItemToGroup(Plasma::ExtenderItem *item)) Q_PRIVATE_SLOT(d, void removeItemFromGroup(Plasma::ExtenderItem *item)) + + friend class ExtenderItem; }; } // Plasma namespace diff --git a/extenderitem.cpp b/extenderitem.cpp index af31cf67f..765663bd5 100644 --- a/extenderitem.cpp +++ b/extenderitem.cpp @@ -51,6 +51,7 @@ #include "private/applethandle_p.h" #include "private/extender_p.h" #include "private/extenderapplet_p.h" +#include "private/extendergroup_p.h" #include "private/extenderitem_p.h" #include "private/extenderitemmimedata_p.h" @@ -286,6 +287,7 @@ void ExtenderItem::setGroup(ExtenderGroup *group) { d->group = group; config().writeEntry("group", group->name()); + group->d->addItemToGroup(this); } ExtenderGroup *ExtenderItem::group() const diff --git a/private/extendergroup_p.h b/private/extendergroup_p.h new file mode 100644 index 000000000..02c7440bd --- /dev/null +++ b/private/extendergroup_p.h @@ -0,0 +1,44 @@ +/* + * Copyright 2009 by Rob Scheepmaker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef PLASMA_EXTENDERGROUPPRIVATE_H +#define PLASMA_EXTENDERGROUPPRIVATE_H + +namespace Plasma +{ + +class ExtenderGroup; +class ExtenderItem; + +class ExtenderGroupPrivate +{ + public: + ExtenderGroupPrivate(ExtenderGroup *group); + ~ExtenderGroupPrivate(); + + void addItemToGroup(Plasma::ExtenderItem *item); + void removeItemFromGroup(Plasma::ExtenderItem *item); + + Plasma::ExtenderGroup *q; + bool collapsed; + bool hideIfEmpty; +}; +} + +#endif