diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:18:55 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:18:55 (GMT) |
commit | e5fcad302d86d316390c6b0f62759a067313e8a9 (patch) | |
tree | c2afbf6f1066b6ce261f14341cf6d310e5595bc1 /examples/draganddrop/delayedencoding | |
download | Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2 |
Long live Qt 4.5!
Diffstat (limited to 'examples/draganddrop/delayedencoding')
-rw-r--r-- | examples/draganddrop/delayedencoding/delayedencoding.pro | 14 | ||||
-rw-r--r-- | examples/draganddrop/delayedencoding/delayedencoding.qrc | 6 | ||||
-rw-r--r-- | examples/draganddrop/delayedencoding/images/drag.png | bin | 0 -> 977 bytes | |||
-rw-r--r-- | examples/draganddrop/delayedencoding/images/example.svg | 59 | ||||
-rw-r--r-- | examples/draganddrop/delayedencoding/main.cpp | 52 | ||||
-rw-r--r-- | examples/draganddrop/delayedencoding/mimedata.cpp | 66 | ||||
-rw-r--r-- | examples/draganddrop/delayedencoding/mimedata.h | 64 | ||||
-rw-r--r-- | examples/draganddrop/delayedencoding/sourcewidget.cpp | 115 | ||||
-rw-r--r-- | examples/draganddrop/delayedencoding/sourcewidget.h | 71 |
9 files changed, 447 insertions, 0 deletions
diff --git a/examples/draganddrop/delayedencoding/delayedencoding.pro b/examples/draganddrop/delayedencoding/delayedencoding.pro new file mode 100644 index 0000000..c7b95b6 --- /dev/null +++ b/examples/draganddrop/delayedencoding/delayedencoding.pro @@ -0,0 +1,14 @@ +QT += svg + +HEADERS = mimedata.h \ + sourcewidget.h +RESOURCES = delayedencoding.qrc +SOURCES = main.cpp \ + mimedata.cpp \ + sourcewidget.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/delayedencoding +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/delayedencoding +INSTALLS += target sources diff --git a/examples/draganddrop/delayedencoding/delayedencoding.qrc b/examples/draganddrop/delayedencoding/delayedencoding.qrc new file mode 100644 index 0000000..374f211 --- /dev/null +++ b/examples/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/draganddrop/delayedencoding/images/drag.png b/examples/draganddrop/delayedencoding/images/drag.png Binary files differnew file mode 100644 index 0000000..dd795cf --- /dev/null +++ b/examples/draganddrop/delayedencoding/images/drag.png diff --git a/examples/draganddrop/delayedencoding/images/example.svg b/examples/draganddrop/delayedencoding/images/example.svg new file mode 100644 index 0000000..4707cf8 --- /dev/null +++ b/examples/draganddrop/delayedencoding/images/example.svg @@ -0,0 +1,59 @@ +<?xml version="1.0" standalone="no"?> +<!-- *********************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $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/draganddrop/delayedencoding/main.cpp b/examples/draganddrop/delayedencoding/main.cpp new file mode 100644 index 0000000..801e474 --- /dev/null +++ b/examples/draganddrop/delayedencoding/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $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/draganddrop/delayedencoding/mimedata.cpp b/examples/draganddrop/delayedencoding/mimedata.cpp new file mode 100644 index 0000000..5c7c23c --- /dev/null +++ b/examples/draganddrop/delayedencoding/mimedata.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#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/draganddrop/delayedencoding/mimedata.h b/examples/draganddrop/delayedencoding/mimedata.h new file mode 100644 index 0000000..13e834d --- /dev/null +++ b/examples/draganddrop/delayedencoding/mimedata.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $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/draganddrop/delayedencoding/sourcewidget.cpp b/examples/draganddrop/delayedencoding/sourcewidget.cpp new file mode 100644 index 0000000..f5aed89 --- /dev/null +++ b/examples/draganddrop/delayedencoding/sourcewidget.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#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:")); + 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(const QString &)), + this, SLOT(createData(const 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/draganddrop/delayedencoding/sourcewidget.h b/examples/draganddrop/delayedencoding/sourcewidget.h new file mode 100644 index 0000000..8d6a690 --- /dev/null +++ b/examples/draganddrop/delayedencoding/sourcewidget.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $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 |