diff options
Diffstat (limited to 'examples/svg/draganddrop/delayedencoding')
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/delayedencoding.pro | 15 | ||||
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/delayedencoding.qrc | 6 | ||||
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/images/drag.png | bin | 0 -> 977 bytes | |||
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/images/example.svg | 58 | ||||
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/main.cpp | 51 | ||||
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/mimedata.cpp | 65 | ||||
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/mimedata.h | 63 | ||||
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/sourcewidget.cpp | 115 | ||||
-rw-r--r-- | examples/svg/draganddrop/delayedencoding/sourcewidget.h | 70 |
9 files changed, 443 insertions, 0 deletions
diff --git a/examples/svg/draganddrop/delayedencoding/delayedencoding.pro b/examples/svg/draganddrop/delayedencoding/delayedencoding.pro new file mode 100644 index 0000000..2cb82f5 --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/delayedencoding.pro @@ -0,0 +1,15 @@ +QT += svg + +HEADERS = mimedata.h \ + sourcewidget.h +RESOURCES = delayedencoding.qrc +SOURCES = main.cpp \ + mimedata.cpp \ + sourcewidget.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/svg/draganddrop/delayedencoding +INSTALLS += target + +simulator: warning(This example does not work on Simulator platform) +QT+=widgets diff --git a/examples/svg/draganddrop/delayedencoding/delayedencoding.qrc b/examples/svg/draganddrop/delayedencoding/delayedencoding.qrc new file mode 100644 index 0000000..374f211 --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/delayedencoding.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix=""> + <file>images/drag.png</file> + <file>images/example.svg</file> +</qresource> +</RCC> diff --git a/examples/svg/draganddrop/delayedencoding/images/drag.png b/examples/svg/draganddrop/delayedencoding/images/drag.png Binary files differnew file mode 100644 index 0000000..dd795cf --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/images/drag.png diff --git a/examples/svg/draganddrop/delayedencoding/images/example.svg b/examples/svg/draganddrop/delayedencoding/images/example.svg new file mode 100644 index 0000000..89a9129 --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/images/example.svg @@ -0,0 +1,58 @@ +<?xml version="1.0" standalone="no"?> +<!-- *********************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +************************************************************************ --> +<svg width="8cm" height="8cm" viewBox="0 0 400 400" + xmlns="http://www.w3.org/2000/svg" baseProfile="tiny" version="1.1"> + <title>Sphere</title> + <desc>A gradient filled sphere.</desc> + <g> + <defs> + <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse" + cx="200" cy="200" r="100" fx="150" fy="150"> + <stop offset="0%" stop-color="white" /> + <stop offset="75%" stop-color="blue" /> + <stop offset="100%" stop-color="black" /> + </radialGradient> + </defs> + <rect fill="lightblue" x="0" y="0" width="400" height="400" /> + <circle fill="url(#blueSphere)" stroke="black" stroke-width="2" + cx="200" cy="200" r="100"/> + </g> +</svg> diff --git a/examples/svg/draganddrop/delayedencoding/main.cpp b/examples/svg/draganddrop/delayedencoding/main.cpp new file mode 100644 index 0000000..6b6063b --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "sourcewidget.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + SourceWidget window; + window.show(); + return app.exec(); +} + diff --git a/examples/svg/draganddrop/delayedencoding/mimedata.cpp b/examples/svg/draganddrop/delayedencoding/mimedata.cpp new file mode 100644 index 0000000..efa096e --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/mimedata.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> +#include "mimedata.h" + +MimeData::MimeData() + : QMimeData() +{ +} + +//![0] +QStringList MimeData::formats() const +{ + return QMimeData::formats() << "image/png"; +} +//![0] + +//![1] +QVariant MimeData::retrieveData(const QString &mimeType, QVariant::Type type) + const +{ + emit dataRequested(mimeType); + + return QMimeData::retrieveData(mimeType, type); +} +//![1] + diff --git a/examples/svg/draganddrop/delayedencoding/mimedata.h b/examples/svg/draganddrop/delayedencoding/mimedata.h new file mode 100644 index 0000000..4d84bd0 --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/mimedata.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MIMEDATA_H +#define MIMEDATA_H + +#include <QMimeData> + +//![0] +class MimeData : public QMimeData +{ + Q_OBJECT + +public: + MimeData(); + QStringList formats() const; + +signals: + void dataRequested(const QString &mimeType) const; + +protected: + QVariant retrieveData(const QString &mimetype, QVariant::Type type) const; +}; +//![0] + +#endif diff --git a/examples/svg/draganddrop/delayedencoding/sourcewidget.cpp b/examples/svg/draganddrop/delayedencoding/sourcewidget.cpp new file mode 100644 index 0000000..0373edb --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/sourcewidget.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> +#include <QtSvg> +#include "mimedata.h" +#include "sourcewidget.h" + +SourceWidget::SourceWidget(QWidget *parent) + : QWidget(parent) +{ + QFile imageFile(":/images/example.svg"); + imageFile.open(QIODevice::ReadOnly); + imageData = imageFile.readAll(); + imageFile.close(); + + QScrollArea *imageArea = new QScrollArea; + imageLabel = new QSvgWidget; + imageLabel->renderer()->load(imageData); + imageArea->setWidget(imageLabel); + //imageLabel->setMinimumSize(imageLabel->renderer()->viewBox().size()); + + QLabel *instructTopLabel = new QLabel(tr("This is an SVG drawing:")); + QLabel *instructBottomLabel = new QLabel( + tr("Drag the icon to copy the drawing as a PNG file:")); + instructBottomLabel->setWordWrap(true); + QPushButton *dragIcon = new QPushButton(tr("Export")); + dragIcon->setIcon(QIcon(":/images/drag.png")); + + connect(dragIcon, SIGNAL(pressed()), this, SLOT(startDrag())); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(instructTopLabel, 0, 0, 1, 2); + layout->addWidget(imageArea, 1, 0, 2, 2); + layout->addWidget(instructBottomLabel, 3, 0); + layout->addWidget(dragIcon, 3, 1); + setLayout(layout); + setWindowTitle(tr("Delayed Encoding")); +} + +//![1] +void SourceWidget::createData(const QString &mimeType) +{ + if (mimeType != "image/png") + return; + + QImage image(imageLabel->size(), QImage::Format_RGB32); + QPainter painter; + painter.begin(&image); + imageLabel->renderer()->render(&painter); + painter.end(); + + QByteArray data; + QBuffer buffer(&data); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); + buffer.close(); + + mimeData->setData("image/png", data); +} +//![1] + +//![0] +void SourceWidget::startDrag() +{ + mimeData = new MimeData; + + connect(mimeData, SIGNAL(dataRequested(QString)), + this, SLOT(createData(QString)), Qt::DirectConnection); + + QDrag *drag = new QDrag(this); + drag->setMimeData(mimeData); + drag->setPixmap(QPixmap(":/images/drag.png")); + + drag->exec(Qt::CopyAction); +} +//![0] + diff --git a/examples/svg/draganddrop/delayedencoding/sourcewidget.h b/examples/svg/draganddrop/delayedencoding/sourcewidget.h new file mode 100644 index 0000000..ef2766a --- /dev/null +++ b/examples/svg/draganddrop/delayedencoding/sourcewidget.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SOURCEWIDGET_H +#define SOURCEWIDGET_H + +#include <QByteArray> +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QSvgWidget; +QT_END_NAMESPACE +class MimeData; + +class SourceWidget : public QWidget +{ + Q_OBJECT + +public: + SourceWidget(QWidget *parent = 0); +//![0] +public slots: + void createData(const QString &mimetype); + void startDrag(); + +private: + QByteArray imageData; + QSvgWidget *imageLabel; + MimeData *mimeData; +//![0] +}; + +#endif |