2
* Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "stackinggroup.h"
22
#include <QtGui/QGraphicsSceneDragDropEvent>
25
#include <Plasma/PaintUtils>
26
#include <Plasma/Corona>
28
#include "groupingcontainment.h"
31
REGISTER_GROUP(StackingGroup)
33
StackingGroup::StackingGroup(QGraphicsItem *parent, Qt::WindowFlags wFlags)
34
: AbstractGroup(parent, wFlags),
35
m_spacer(new Spacer(this))
38
setGroupType(AbstractGroup::ConstrainedGroup);
42
connect(this, SIGNAL(appletRemovedFromGroup(Plasma::Applet*,AbstractGroup*)),
43
this, SLOT(onAppletRemoved(Plasma::Applet*,AbstractGroup*)));
44
connect(this, SIGNAL(appletAddedInGroup(Plasma::Applet*,AbstractGroup*)),
45
this, SLOT(onAppletAdded(Plasma::Applet*,AbstractGroup*)));
46
connect(this, SIGNAL(subGroupRemovedFromGroup(AbstractGroup*,AbstractGroup*)),
47
this, SLOT(onSubGroupRemoved(AbstractGroup*, AbstractGroup*)));
48
connect(this, SIGNAL(subGroupAddedInGroup(AbstractGroup*,AbstractGroup*)),
49
this, SLOT(onSubGroupAdded(AbstractGroup*,AbstractGroup*)));
52
StackingGroup::~StackingGroup()
57
QString StackingGroup::pluginName() const
59
return QString("stacking");
62
void StackingGroup::restoreChildGroupInfo(QGraphicsWidget *child, const KConfigGroup &group)
64
int from = m_children.indexOf(child);
65
int to = group.readEntry("Index", 0);
67
if (m_children.size() > to) {
68
m_children.move(from, to);
74
void StackingGroup::saveChildGroupInfo(QGraphicsWidget *child, KConfigGroup group) const
76
group.writeEntry("Index", m_children.indexOf(child));
79
void StackingGroup::layoutChild(QGraphicsWidget *child, const QPointF &)
81
if (!m_children.contains(child)) {
84
m_children << m_children.takeAt(m_children.indexOf(child));
87
if (m_spacer->isVisible()) {
88
m_children.removeOne(m_spacer);
95
void StackingGroup::drawStack()
98
foreach (QGraphicsWidget *widget, m_children) {
100
QRectF rect(QPointF(gap, gap), contentsRect().size());
101
widget->setMaximumSize(rect.size());
102
widget->setGeometry(rect);
103
widget->setZValue(gap);
109
void StackingGroup::resizeEvent(QGraphicsSceneResizeEvent *event)
111
AbstractGroup::resizeEvent(event);
116
void StackingGroup::wheelEvent(QGraphicsSceneWheelEvent *event)
118
if (m_children.size() < 2) {
122
if (event->delta() > 0) {
123
m_children.move(m_children.size() - 1, 0);
125
m_children << m_children.takeAt(0);
134
void StackingGroup::releaseChild(QGraphicsWidget *child)
136
m_children.removeOne(child);
139
void StackingGroup::onAppletAdded(Plasma::Applet *applet, AbstractGroup *)
141
if (!m_children.contains(applet)) {
142
m_children << applet;
143
connect(applet, SIGNAL(activate()), this, SLOT(onAppletActivated()));
144
applet->installEventFilter(this);
148
void StackingGroup::onAppletRemoved(Plasma::Applet *applet, AbstractGroup *)
150
m_children.removeOne(applet);
151
applet->removeEventFilter(this);
156
void StackingGroup::onSubGroupAdded(AbstractGroup *subGroup, AbstractGroup *)
158
if (!m_children.contains(subGroup)) {
159
m_children << subGroup;
160
subGroup->installEventFilter(this);
164
void StackingGroup::onSubGroupRemoved(AbstractGroup *subGroup, AbstractGroup *)
166
m_children.removeOne(subGroup);
167
subGroup->removeEventFilter(this);
172
bool StackingGroup::showDropZone(const QPointF &pos)
176
m_children.removeOne(m_spacer);
178
} else if (!m_spacer->isVisible()) {
180
m_children << m_spacer;
188
void StackingGroup::onAppletActivated()
190
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(sender());
192
if (applet && m_children.contains(applet)) {
193
m_children << m_children.takeAt(m_children.indexOf(applet));
199
bool StackingGroup::eventFilter(QObject *obj, QEvent *event)
201
if (event->type() == QEvent::GraphicsSceneMousePress) {
202
QGraphicsWidget *widget = qobject_cast<QGraphicsWidget *>(obj);
203
if (m_children.contains(widget)) {
204
m_children << m_children.takeAt(m_children.indexOf(widget));
210
return AbstractGroup::eventFilter(obj, event);
213
GroupInfo StackingGroup::groupInfo()
215
GroupInfo gi("stacking", i18n("Stacking Group"));
216
gi.setIcon("object-order-raise"); //FIXME: isn't there a better one?
221
#include "stackinggroup.moc"