3
$Id: UngroupCmd.cc,v 1.19 2001/03/12 15:27:35 rm Exp $
5
This file is part of KIllustrator.
6
Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de)
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU Library General Public License as
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU Library General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
#include <UngroupCmd.h>
28
#include <GDocument.h>
32
UngroupCmd::UngroupCmd (GDocument* doc) : Command(i18n("Ungroup")) {
34
groups.setAutoDelete(true);
36
for(QListIterator<GObject> it(doc->activePage()->getSelection()); it.current(); ++it) {
38
if (o->isA ("GGroup")) {
39
GGroup* gobj = (GGroup *) o;
48
UngroupCmd::~UngroupCmd () {
49
for (GPair *p=groups.first(); p!=0L; p=groups.next()) {
51
for (GObject *o=p->members.first(); o!=0L; o=p->members.next())
56
void UngroupCmd::execute () {
57
for (GPair *p=groups.first(); p!=0L; p=groups.next()) {
58
GGroup *group = p->group;
59
int pos = document->activePage()->findIndexOfObject (group);
61
document->setAutoUpdate (false);
62
// extract the members of the group
63
QList <GObject> members = group->getMembers ();
64
GObject *mo=members.first();
65
for (int offs = 0; mo!=0L; mo=members.next(), offs++) {
66
// transform it according to the group transformation matrix
67
mo->transform (group->matrix (), true);
69
// and insert it into the object list at the former position
70
// of the group object
71
document->activePage()->insertObjectAtIndex(mo, pos + offs);
72
document->activePage()->selectObject (mo);
73
p->members.append(mo);
76
// remove the group object
77
document->activePage()->deleteObject (group);
78
document->setAutoUpdate (true);
83
void UngroupCmd::unexecute () {
84
document->setAutoUpdate (false);
85
document->activePage()->unselectAllObjects ();
86
for (GPair *p=groups.first(); p!=0L; p=groups.next()) {
87
QWMatrix m = p->group->matrix ().invert ();
89
for (GObject *o=p->members.first(); o!=0L; o=p->members.next()) {
90
o->transform (m, true);
91
p->group->addObject (o);
92
document->activePage()->deleteObject (o);
94
document->activePage()->insertObject (p->group);
95
document->activePage()->selectObject (p->group);
97
document->setAutoUpdate (true);