2009-03-23 17:30:32 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2009-04-02 18:40:28 +02:00
|
|
|
#include "extendergroup.h"
|
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
#include <QAction>
|
|
|
|
#include <QString>
|
|
|
|
#include <QList>
|
|
|
|
#include <QtGui/QGraphicsWidget>
|
|
|
|
|
|
|
|
#include "applet.h"
|
|
|
|
#include "extender.h"
|
|
|
|
#include "extenderitem.h"
|
2009-04-02 18:40:28 +02:00
|
|
|
#include "theme.h"
|
2009-03-23 17:30:32 +01:00
|
|
|
|
2009-03-25 14:03:04 +01:00
|
|
|
#include "private/extendergroup_p.h"
|
2009-03-23 17:30:32 +01:00
|
|
|
|
2009-03-25 14:03:04 +01:00
|
|
|
namespace Plasma
|
2009-03-23 17:30:32 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId)
|
|
|
|
: ExtenderItem(parent, groupId),
|
|
|
|
d(new ExtenderGroupPrivate(this))
|
|
|
|
{
|
|
|
|
connect(extender(), SIGNAL(itemAttached(Plasma::ExtenderItem*)),
|
|
|
|
this, SLOT(addItemToGroup(Plasma::ExtenderItem*)));
|
|
|
|
connect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
|
|
|
|
this, SLOT(removeItemFromGroup(Plasma::ExtenderItem*)));
|
|
|
|
|
|
|
|
config().writeEntry("isGroup", true);
|
|
|
|
|
|
|
|
QAction *expand = new QAction(this);
|
|
|
|
expand->setVisible(true);
|
|
|
|
expand->setToolTip(i18n("Show this group."));
|
|
|
|
connect(expand, SIGNAL(triggered()), this, SLOT(expandGroup()));
|
|
|
|
addAction("expand", expand);
|
|
|
|
|
|
|
|
QAction *collapse = new QAction(this);
|
|
|
|
collapse->setVisible(false);
|
|
|
|
collapse->setToolTip(i18n("Hide this group."));
|
|
|
|
connect(collapse, SIGNAL(triggered()), this, SLOT(collapseGroup()));
|
|
|
|
addAction("collapse", collapse);
|
|
|
|
|
2009-04-02 18:40:28 +02:00
|
|
|
d->themeChanged();
|
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
QString groupName;
|
|
|
|
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
|
|
|
groupName = item->config().readEntry("group", "");
|
2009-04-02 18:40:28 +02:00
|
|
|
if (!groupName.isEmpty() && groupName == name()) {
|
2009-03-23 17:30:32 +01:00
|
|
|
item->setGroup(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 19:58:49 +02:00
|
|
|
if (items().isEmpty() && d->autoHide && !isDetached()) {
|
2009-03-23 17:30:32 +01:00
|
|
|
extender()->itemRemovedEvent(this);
|
2009-04-26 19:03:15 +02:00
|
|
|
hide();
|
2009-03-23 17:30:32 +01:00
|
|
|
}
|
2009-04-02 18:40:28 +02:00
|
|
|
|
2009-04-27 01:49:22 +02:00
|
|
|
if (!config().readEntry("groupCollapsed", true)) {
|
|
|
|
expandGroup();
|
|
|
|
}
|
|
|
|
|
2009-04-02 18:40:28 +02:00
|
|
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
|
|
|
|
this, SLOT(themeChanged()));
|
2009-03-23 17:30:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ExtenderGroup::~ExtenderGroup()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<ExtenderItem*> ExtenderGroup::items() const
|
|
|
|
{
|
|
|
|
QList<ExtenderItem*> result;
|
|
|
|
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
|
|
|
if (item->group() == this) {
|
|
|
|
result.append(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-04-17 19:58:49 +02:00
|
|
|
bool ExtenderGroup::autoHide() const
|
2009-03-23 17:30:32 +01:00
|
|
|
{
|
2009-04-17 19:58:49 +02:00
|
|
|
return d->autoHide;
|
2009-03-23 17:30:32 +01:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:58:49 +02:00
|
|
|
void ExtenderGroup::setAutoHide(bool autoHide)
|
2009-03-23 17:30:32 +01:00
|
|
|
{
|
2009-04-17 19:58:49 +02:00
|
|
|
d->autoHide = autoHide;
|
2009-04-26 19:03:15 +02:00
|
|
|
if (autoHide && items().isEmpty()) {
|
2009-03-23 17:30:32 +01:00
|
|
|
extender()->itemRemovedEvent(this);
|
2009-04-26 19:03:15 +02:00
|
|
|
hide();
|
2009-04-17 19:58:49 +02:00
|
|
|
} else if (!autoHide && !isVisible()) {
|
2009-04-04 18:42:59 +02:00
|
|
|
extender()->itemAddedEvent(this);
|
|
|
|
show();
|
2009-03-23 17:30:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-26 14:02:53 +01:00
|
|
|
bool ExtenderGroup::isAutoCollapse() const
|
|
|
|
{
|
|
|
|
return d->autoCollapse;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderGroup::setAutoCollapse(bool collapse)
|
|
|
|
{
|
|
|
|
d->autoCollapse = collapse;
|
|
|
|
if (collapse) {
|
|
|
|
setCollapsed(d->collapsed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExtenderGroup::isGroupCollapsed() const
|
|
|
|
{
|
|
|
|
return d->collapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderGroup::setGroupCollapsed(bool collapsed)
|
|
|
|
{
|
|
|
|
if (collapsed) {
|
|
|
|
collapseGroup();
|
|
|
|
} else {
|
|
|
|
expandGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
void ExtenderGroup::expandGroup()
|
|
|
|
{
|
2009-12-26 14:02:53 +01:00
|
|
|
if (d->autoCollapse) {
|
|
|
|
setCollapsed(false);
|
|
|
|
}
|
2009-12-26 13:16:45 +01:00
|
|
|
if (d->collapsed == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
d->collapsed = false;
|
2009-04-27 01:49:22 +02:00
|
|
|
config().writeEntry("groupCollapsed", d->collapsed);
|
2009-03-23 17:30:32 +01:00
|
|
|
action("collapse")->setVisible(true);
|
|
|
|
action("expand")->setVisible(false);
|
|
|
|
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
|
|
|
if (item->group() == this) {
|
|
|
|
item->show();
|
|
|
|
extender()->itemAddedEvent(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderGroup::collapseGroup()
|
|
|
|
{
|
2009-12-26 14:02:53 +01:00
|
|
|
if (d->autoCollapse) {
|
|
|
|
setCollapsed(true);
|
|
|
|
}
|
2009-12-26 13:16:45 +01:00
|
|
|
if (d->collapsed == true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
d->collapsed = true;
|
2009-04-27 01:49:22 +02:00
|
|
|
config().writeEntry("groupCollapsed", d->collapsed);
|
2009-03-23 17:30:32 +01:00
|
|
|
action("collapse")->setVisible(false);
|
|
|
|
action("expand")->setVisible(true);
|
|
|
|
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
|
|
|
if (item != this && item->group() == this) {
|
|
|
|
item->hide();
|
|
|
|
extender()->itemRemovedEvent(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-25 14:03:04 +01:00
|
|
|
|
|
|
|
ExtenderGroupPrivate::ExtenderGroupPrivate(ExtenderGroup *group)
|
2009-04-30 02:46:57 +02:00
|
|
|
: q(group),
|
|
|
|
svg(new Svg(group)),
|
|
|
|
collapsed(true),
|
2009-12-26 14:02:53 +01:00
|
|
|
autoHide(true),
|
2009-12-28 13:02:42 +01:00
|
|
|
autoCollapse(false)
|
2009-03-25 14:03:04 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtenderGroupPrivate::~ExtenderGroupPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item)
|
|
|
|
{
|
|
|
|
if (item->group() == q) {
|
2009-04-26 19:03:15 +02:00
|
|
|
if (!q->isVisible() && !q->items().isEmpty()) {
|
|
|
|
q->extender()->itemAddedEvent(q);
|
|
|
|
q->show();
|
|
|
|
}
|
|
|
|
if (collapsed) {
|
2009-03-25 14:03:04 +01:00
|
|
|
q->extender()->itemRemovedEvent(item);
|
|
|
|
item->hide();
|
2009-04-08 18:16:00 +02:00
|
|
|
} else {
|
|
|
|
q->extender()->itemAddedEvent(item);
|
|
|
|
item->show();
|
2009-03-25 14:03:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderGroupPrivate::removeItemFromGroup(Plasma::ExtenderItem *item)
|
|
|
|
{
|
|
|
|
if (item->group() == q) {
|
2009-04-26 19:03:15 +02:00
|
|
|
if (q->items().isEmpty() && autoHide && !q->isDetached()) {
|
2009-03-25 14:03:04 +01:00
|
|
|
q->extender()->itemRemovedEvent(q);
|
|
|
|
q->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-02 18:40:28 +02:00
|
|
|
void ExtenderGroupPrivate::themeChanged()
|
|
|
|
{
|
|
|
|
svg->setImagePath("widgets/configuration-icons");
|
|
|
|
svg->resize();
|
|
|
|
|
|
|
|
q->action("expand")->setIcon(QIcon(svg->pixmap("restore")));
|
|
|
|
q->action("collapse")->setIcon(QIcon(svg->pixmap("collapse")));
|
|
|
|
}
|
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "extendergroup.moc"
|