Krita Source Code Documentation
Loading...
Searching...
No Matches
KoDrag.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2007-2008 Thorsten Zachmann <zachmann@kde.org>
3 * SPDX-FileCopyrightText: 2009 Thomas Zander <zander@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#include "KoDrag.h"
9
10#include <QApplication>
11#include <QBuffer>
12#include <QByteArray>
13#include <QClipboard>
14#include <QMimeData>
15#include <QString>
16
17#include <FlakeDebug.h>
18
19#include <KoStore.h>
20#include <KoXmlWriter.h>
22
23#include <KoShapeContainer.h>
24#include <KoShape.h>
25
26#include <QRect>
27#include <SvgWriter.h>
28
29
31public:
34 QMimeData *mimeData;
35};
36
38 : d(new KoDragPrivate())
39{
40}
41
43{
44 delete d;
45}
46
47bool KoDrag::setSvg(const QList<KoShape *> originalShapes)
48{
49 QRectF boundingRect;
50 QList<KoShape*> shapes;
51
52 Q_FOREACH (KoShape *shape, originalShapes) {
53 boundingRect |= shape->boundingRect();
54
55 KoShape *clonedShape = shape->cloneShapeAndBakeAbsoluteTransform();
56 shapes.append(clonedShape);
57 }
58
59 std::sort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
60
61 QBuffer buffer;
62 QLatin1String mimeType("image/svg+xml");
63
64 buffer.open(QIODevice::WriteOnly);
65
66 const QSizeF pageSize(boundingRect.right(), boundingRect.bottom());
67 SvgWriter writer(shapes);
68 writer.save(buffer, pageSize);
69
70 buffer.close();
71
72 qDeleteAll(shapes);
73
74 setData(mimeType, buffer.data());
75 return true;
76}
77
78void KoDrag::setData(const QString &mimeType, const QByteArray &data)
79{
80 if (d->mimeData == 0) {
81 d->mimeData = new QMimeData();
82 }
83 d->mimeData->setData(mimeType, data);
84}
85
87{
88 if (d->mimeData) {
89 QApplication::clipboard()->setMimeData(d->mimeData);
90 d->mimeData = 0;
91 }
92}
93
94QMimeData * KoDrag::mimeData()
95{
96 QMimeData *mimeData = d->mimeData;
97 d->mimeData = 0;
98 return mimeData;
99}
QMimeData * mimeData
Definition KoDrag.cpp:34
KoDrag()
Definition KoDrag.cpp:37
KoDragPrivate *const d
Definition KoDrag.h:60
void setData(const QString &mimeType, const QByteArray &data)
Definition KoDrag.cpp:78
bool setSvg(const QList< KoShape * > shapes)
Definition KoDrag.cpp:47
void addToClipboard()
Definition KoDrag.cpp:86
QMimeData * mimeData()
Definition KoDrag.cpp:94
~KoDrag()
Definition KoDrag.cpp:42
KoShape * cloneShapeAndBakeAbsoluteTransform() const
creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the result...
Definition KoShape.cpp:207
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
Definition KoShape.cpp:434
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
Implements exporting shapes to SVG.
Definition SvgWriter.h:33
bool save(QIODevice &outputDevice, const QSizeF &pageSize)
Writes svg to specified output device.
Definition SvgWriter.cpp:82