~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to kontour/CutCmd.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- C++ -*-
2
 
 
3
 
  $Id: CutCmd.cc,v 1.18 2001/06/29 21:41:19 rm Exp $
4
 
 
5
 
  This file is part of KIllustrator.
6
 
  Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de)
7
 
 
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
10
 
  published by
11
 
  the Free Software Foundation; either version 2 of the License, or
12
 
  (at your option) any later version.
13
 
 
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.
18
 
 
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.
22
 
 
23
 
*/
24
 
 
25
 
#include "CutCmd.h"
26
 
 
27
 
#include <qclipboard.h>
28
 
#include <qbuffer.h>
29
 
#include <qtextstream.h>
30
 
#include <qdragobject.h>
31
 
#include <qdom.h>
32
 
#include <kapp.h>
33
 
#include <klocale.h>
34
 
 
35
 
#include "GDocument.h"
36
 
#include "GObject.h"
37
 
#include "GPage.h"
38
 
 
39
 
CutCmd::CutCmd (GDocument* doc)
40
 
  : Command(i18n("Cut"))
41
 
{
42
 
  document = doc;
43
 
  objects.setAutoDelete(true);
44
 
  for(QListIterator<GObject> it(doc->activePage()->getSelection()); it.current(); ++it)
45
 
  {
46
 
    MyPair *p=new MyPair;
47
 
    p->o = *it;
48
 
    p->o->ref ();
49
 
    // store the old position of the object
50
 
    p->pos = doc->activePage()->findIndexOfObject(p->o);
51
 
    objects.append(p);
52
 
  }
53
 
}
54
 
 
55
 
CutCmd::~CutCmd ()
56
 
{
57
 
  for (MyPair *p=objects.first(); p!=0L; p=objects.next())
58
 
    p->o->unref ();
59
 
}
60
 
 
61
 
void CutCmd::execute()
62
 
{
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);
70
 
 
71
 
  for (MyPair *p=objects.first(); p!=0L; p=objects.next())
72
 
  {
73
 
    layer.appendChild(p->o->writeToXml(docu));
74
 
    document->activePage()->deleteObject (p->o);
75
 
  }
76
 
    
77
 
  QBuffer buffer;
78
 
  buffer.open( IO_WriteOnly );
79
 
  QTextStream stream( &buffer );
80
 
  stream.setEncoding( QTextStream::UnicodeUTF8 );
81
 
  stream << docu;
82
 
  buffer.close();
83
 
 
84
 
  QStoredDrag *drag = new QStoredDrag( "application/x-killustrator-snippet" );
85
 
  drag->setEncodedData( buffer.buffer() );
86
 
 
87
 
  QApplication::clipboard()->setData(drag);
88
 
}
89
 
 
90
 
void CutCmd::unexecute ()
91
 
{
92
 
  QApplication::clipboard ()->clear ();
93
 
  document->activePage()->unselectAllObjects ();
94
 
 
95
 
  for (MyPair *p=objects.first(); p!=0; p=objects.next())
96
 
  {
97
 
    // insert the object at the old position
98
 
    p->o->ref ();
99
 
    document->activePage()->insertObjectAtIndex (p->o, p->pos);
100
 
    document->activePage()->selectObject (p->o);
101
 
  }
102
 
}
103