Replace hideIfEmpty with autoHide: don't show the group widget unless there are multiple items in that group. With one item we can just display that item.

svn path=/trunk/KDE/kdelibs/; revision=955463
This commit is contained in:
Rob Scheepmaker 2009-04-17 17:58:49 +00:00
parent d625d40ecc
commit 70dc8b1c76
3 changed files with 33 additions and 19 deletions

View File

@ -67,7 +67,7 @@ ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId)
}
}
if (items().isEmpty() && d->hideIfEmpty && !isDetached()) {
if (items().isEmpty() && d->autoHide && !isDetached()) {
hide();
extender()->itemRemovedEvent(this);
}
@ -93,18 +93,18 @@ QList<ExtenderItem*> ExtenderGroup::items() const
return result;
}
bool ExtenderGroup::hideIfEmpty() const
bool ExtenderGroup::autoHide() const
{
return d->hideIfEmpty;
return d->autoHide;
}
void ExtenderGroup::setHideIfEmpty(bool hideIfEmpty)
void ExtenderGroup::setAutoHide(bool autoHide)
{
d->hideIfEmpty = hideIfEmpty;
if (hideIfEmpty && items().isEmpty()) {
d->autoHide = autoHide;
if (autoHide && items().count() < 2) {
hide();
extender()->itemRemovedEvent(this);
} else if (!hideIfEmpty && !isVisible()) {
} else if (!autoHide && !isVisible()) {
extender()->itemAddedEvent(this);
show();
}
@ -139,7 +139,7 @@ void ExtenderGroup::collapseGroup()
ExtenderGroupPrivate::ExtenderGroupPrivate(ExtenderGroup *group)
: collapsed(true),
hideIfEmpty(true)
autoHide(true)
{
q = group;
}
@ -151,16 +151,26 @@ ExtenderGroupPrivate::~ExtenderGroupPrivate()
void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item)
{
if (item->group() == q) {
if (collapsed) {
int itemCount = q->items().count();
if (collapsed && !(autoHide && itemCount == 1)) {
//the group is collapsed, so hide the new item unless there's only one item and autohide
//is true, in which case we hide this group, and not the item in it.
q->extender()->itemRemovedEvent(item);
item->hide();
} else {
//the group isn't collapsed so show and readd this item to the extender, which takes
//care of placing the new item directly under the group widget.
q->extender()->itemAddedEvent(item);
item->show();
}
if (!q->isVisible()) {
if (!q->isVisible() && (itemCount > 1 || !autoHide)) {
//show the group if needed, depending on autoHide policy.
q->extender()->itemAddedEvent(q);
q->show();
if (collapsed) {
q->extender()->itemRemovedEvent(q->items().first());
q->items().first()->hide();
}
}
}
}
@ -168,10 +178,14 @@ void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item)
void ExtenderGroupPrivate::removeItemFromGroup(Plasma::ExtenderItem *item)
{
if (item->group() == q) {
if (q->items().isEmpty() && hideIfEmpty && !q->isDetached()) {
if (q->items().count() < 2 && autoHide && !q->isDetached()) {
q->extender()->itemRemovedEvent(q);
q->hide();
}
if (q->items().count() == 1 && autoHide) {
q->extender()->itemAddedEvent(q->items().first());
q->items().first()->show();
}
}
}

View File

@ -42,15 +42,15 @@ class Applet;
* To be able to group multiple items together, you'll need to instantiate an ExtenderGroup, and
* call setGroup() on all extender items you wish to add to this group.
* This ExtenderGroup is just the same as any other ExtenderItem, except for the expand group and
* collapse group buttons it provides, and the fact that it will automatically hide itself if no
* other items belong to this group and hideIfEmpty is set to true.
* collapse group buttons it provides, and the fact that it will automatically hide itself if less
* then one item belong to this group and autoHide is set to true.
*
* @since 4.3
*/
class PLASMA_EXPORT ExtenderGroup : public ExtenderItem
{
Q_OBJECT
Q_PROPERTY(bool hideIfEmpty READ hideIfEmpty WRITE setHideIfEmpty)
Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
public:
/**
@ -67,14 +67,14 @@ class PLASMA_EXPORT ExtenderGroup : public ExtenderItem
QList<ExtenderItem*> items() const;
/**
* @return whether or not this item hides itself if no other items belong to this group.
* @return whether or not this item hides itself if there are less then 2 items in.
*/
bool hideIfEmpty() const;
bool autoHide() const;
/**
* @param hideIfEmpty whether or not this item hides itself if no other items belong to this group.
* @param autoHide whether or not this item hides itself if less then 2 items belong to this group.
*/
void setHideIfEmpty(bool hideIfEmpty);
void setAutoHide(bool autoHide);
public Q_SLOTS:
/**

View File

@ -38,7 +38,7 @@ class ExtenderGroupPrivate
Plasma::ExtenderGroup *q;
bool collapsed;
bool hideIfEmpty;
bool autoHide;
};
}