3
$Id: CutCmd.cc,v 1.18 2001/06/29 21:41:19 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.
27
#include <qclipboard.h>
29
#include <qtextstream.h>
30
#include <qdragobject.h>
35
#include "GDocument.h"
39
CutCmd::CutCmd (GDocument* doc)
40
: Command(i18n("Cut"))
43
objects.setAutoDelete(true);
44
for(QListIterator<GObject> it(doc->activePage()->getSelection()); it.current(); ++it)
49
// store the old position of the object
50
p->pos = doc->activePage()->findIndexOfObject(p->o);
57
for (MyPair *p=objects.first(); p!=0L; p=objects.next())
61
void CutCmd::execute()
63
QDomDocument docu("killustrator");
64
docu.appendChild( docu.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
65
QDomElement doc=docu.createElement("killustrator");
66
doc.setAttribute ("mime", KILLUSTRATOR_MIMETYPE);
67
docu.appendChild(doc);
68
QDomElement layer=docu.createElement("layer");
69
doc.appendChild(layer);
71
for (MyPair *p=objects.first(); p!=0L; p=objects.next())
73
layer.appendChild(p->o->writeToXml(docu));
74
document->activePage()->deleteObject (p->o);
78
buffer.open( IO_WriteOnly );
79
QTextStream stream( &buffer );
80
stream.setEncoding( QTextStream::UnicodeUTF8 );
84
QStoredDrag *drag = new QStoredDrag( "application/x-killustrator-snippet" );
85
drag->setEncodedData( buffer.buffer() );
87
QApplication::clipboard()->setData(drag);
90
void CutCmd::unexecute ()
92
QApplication::clipboard ()->clear ();
93
document->activePage()->unselectAllObjects ();
95
for (MyPair *p=objects.first(); p!=0; p=objects.next())
97
// insert the object at the old position
99
document->activePage()->insertObjectAtIndex (p->o, p->pos);
100
document->activePage()->selectObject (p->o);