summaryrefslogtreecommitdiffstats
path: root/examples/draganddrop/dropsite
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /examples/draganddrop/dropsite
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'examples/draganddrop/dropsite')
-rw-r--r--examples/draganddrop/dropsite/droparea.cpp126
-rw-r--r--examples/draganddrop/dropsite/droparea.h77
-rw-r--r--examples/draganddrop/dropsite/dropsite.pro13
-rw-r--r--examples/draganddrop/dropsite/dropsitewindow.cpp143
-rw-r--r--examples/draganddrop/dropsite/dropsitewindow.h77
-rw-r--r--examples/draganddrop/dropsite/main.cpp53
6 files changed, 489 insertions, 0 deletions
diff --git a/examples/draganddrop/dropsite/droparea.cpp b/examples/draganddrop/dropsite/droparea.cpp
new file mode 100644
index 0000000000..2a83de888e
--- /dev/null
+++ b/examples/draganddrop/dropsite/droparea.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 Nokia Corporation 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 <QtGui>
+
+#include "droparea.h"
+
+//! [DropArea constructor]
+DropArea::DropArea(QWidget *parent)
+ : QLabel(parent)
+{
+ setMinimumSize(200, 200);
+ setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
+ setAlignment(Qt::AlignCenter);
+ setAcceptDrops(true);
+ setAutoFillBackground(true);
+ clear();
+}
+//! [DropArea constructor]
+
+//! [dragEnterEvent() function]
+void DropArea::dragEnterEvent(QDragEnterEvent *event)
+{
+ setText(tr("<drop content>"));
+ setBackgroundRole(QPalette::Highlight);
+
+ event->acceptProposedAction();
+ emit changed(event->mimeData());
+}
+//! [dragEnterEvent() function]
+
+//! [dragMoveEvent() function]
+void DropArea::dragMoveEvent(QDragMoveEvent *event)
+{
+ event->acceptProposedAction();
+}
+//! [dragMoveEvent() function]
+
+//! [dropEvent() function part1]
+void DropArea::dropEvent(QDropEvent *event)
+{
+ const QMimeData *mimeData = event->mimeData();
+//! [dropEvent() function part1]
+
+//! [dropEvent() function part2]
+ if (mimeData->hasImage()) {
+ setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
+ } else if (mimeData->hasHtml()) {
+ setText(mimeData->html());
+ setTextFormat(Qt::RichText);
+ } else if (mimeData->hasText()) {
+ setText(mimeData->text());
+ setTextFormat(Qt::PlainText);
+ } else if (mimeData->hasUrls()) {
+ QList<QUrl> urlList = mimeData->urls();
+ QString text;
+ for (int i = 0; i < urlList.size() && i < 32; ++i) {
+ QString url = urlList.at(i).path();
+ text += url + QString("\n");
+ }
+ setText(text);
+ } else {
+ setText(tr("Cannot display data"));
+ }
+//! [dropEvent() function part2]
+
+//! [dropEvent() function part3]
+ setBackgroundRole(QPalette::Dark);
+ event->acceptProposedAction();
+}
+//! [dropEvent() function part3]
+
+//! [dragLeaveEvent() function]
+void DropArea::dragLeaveEvent(QDragLeaveEvent *event)
+{
+ clear();
+ event->accept();
+}
+//! [dragLeaveEvent() function]
+
+//! [clear() function]
+void DropArea::clear()
+{
+ setText(tr("<drop content>"));
+ setBackgroundRole(QPalette::Dark);
+
+ emit changed();
+}
+//! [clear() function]
diff --git a/examples/draganddrop/dropsite/droparea.h b/examples/draganddrop/dropsite/droparea.h
new file mode 100644
index 0000000000..9c2259d4d0
--- /dev/null
+++ b/examples/draganddrop/dropsite/droparea.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 Nokia Corporation 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 DROPAREA_H
+#define DROPAREA_H
+
+#include <QLabel>
+
+QT_BEGIN_NAMESPACE
+class QMimeData;
+QT_END_NAMESPACE
+
+//! [DropArea header part1]
+class DropArea : public QLabel
+{
+ Q_OBJECT
+
+public:
+ DropArea(QWidget *parent = 0);
+
+public slots:
+ void clear();
+
+signals:
+ void changed(const QMimeData *mimeData = 0);
+//! [DropArea header part1]
+
+//! [DropArea header part2]
+protected:
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dragLeaveEvent(QDragLeaveEvent *event);
+ void dropEvent(QDropEvent *event);
+
+private:
+ QLabel *label;
+};
+//! [DropArea header part2]
+
+#endif
diff --git a/examples/draganddrop/dropsite/dropsite.pro b/examples/draganddrop/dropsite/dropsite.pro
new file mode 100644
index 0000000000..22b587ad7a
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsite.pro
@@ -0,0 +1,13 @@
+HEADERS = droparea.h \
+ dropsitewindow.h
+SOURCES = droparea.cpp \
+ dropsitewindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/dropsite
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/dropsite
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/draganddrop/dropsite/dropsitewindow.cpp b/examples/draganddrop/dropsite/dropsitewindow.cpp
new file mode 100644
index 0000000000..db7d6e3566
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsitewindow.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 Nokia Corporation 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 <QtGui>
+
+#include "droparea.h"
+#include "dropsitewindow.h"
+
+//! [constructor part1]
+DropSiteWindow::DropSiteWindow()
+{
+ abstractLabel = new QLabel(tr("This example accepts drags from other "
+ "applications and displays the MIME types "
+ "provided by the drag object."));
+ abstractLabel->setWordWrap(true);
+ abstractLabel->adjustSize();
+//! [constructor part1]
+
+//! [constructor part2]
+ dropArea = new DropArea;
+ connect(dropArea, SIGNAL(changed(const QMimeData*)),
+ this, SLOT(updateFormatsTable(const QMimeData*)));
+//! [constructor part2]
+
+//! [constructor part3]
+ QStringList labels;
+ labels << tr("Format") << tr("Content");
+
+ formatsTable = new QTableWidget;
+ formatsTable->setColumnCount(2);
+ formatsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ formatsTable->setHorizontalHeaderLabels(labels);
+ formatsTable->horizontalHeader()->setStretchLastSection(true);
+//! [constructor part3]
+
+//! [constructor part4]
+ clearButton = new QPushButton(tr("Clear"));
+ quitButton = new QPushButton(tr("Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ connect(quitButton, SIGNAL(pressed()), this, SLOT(close()));
+ connect(clearButton, SIGNAL(pressed()), dropArea, SLOT(clear()));
+//! [constructor part4]
+
+//! [constructor part5]
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(abstractLabel);
+ mainLayout->addWidget(dropArea);
+ mainLayout->addWidget(formatsTable);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Drop Site"));
+ setMinimumSize(350, 500);
+}
+//! [constructor part5]
+
+//! [updateFormatsTable() part1]
+void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
+{
+ formatsTable->setRowCount(0);
+ if (!mimeData)
+ return;
+//! [updateFormatsTable() part1]
+
+//! [updateFormatsTable() part2]
+ foreach (QString format, mimeData->formats()) {
+ QTableWidgetItem *formatItem = new QTableWidgetItem(format);
+ formatItem->setFlags(Qt::ItemIsEnabled);
+ formatItem->setTextAlignment(Qt::AlignTop | Qt::AlignLeft);
+//! [updateFormatsTable() part2]
+
+//! [updateFormatsTable() part3]
+ QString text;
+ if (format == "text/plain") {
+ text = mimeData->text().simplified();
+ } else if (format == "text/html") {
+ text = mimeData->html().simplified();
+ } else if (format == "text/uri-list") {
+ QList<QUrl> urlList = mimeData->urls();
+ for (int i = 0; i < urlList.size() && i < 32; ++i)
+ text.append(urlList[i].toString() + " ");
+ } else {
+ QByteArray data = mimeData->data(format);
+ for (int i = 0; i < data.size() && i < 32; ++i) {
+ QString hex = QString("%1").arg(uchar(data[i]), 2, 16,
+ QChar('0'))
+ .toUpper();
+ text.append(hex + " ");
+ }
+ }
+//! [updateFormatsTable() part3]
+
+//! [updateFormatsTable() part4]
+ int row = formatsTable->rowCount();
+ formatsTable->insertRow(row);
+ formatsTable->setItem(row, 0, new QTableWidgetItem(format));
+ formatsTable->setItem(row, 1, new QTableWidgetItem(text));
+ }
+
+ formatsTable->resizeColumnToContents(0);
+}
+//! [updateFormatsTable() part4]
diff --git a/examples/draganddrop/dropsite/dropsitewindow.h b/examples/draganddrop/dropsite/dropsitewindow.h
new file mode 100644
index 0000000000..f4cb2a8f61
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsitewindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 Nokia Corporation 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 DROPSITEWINDOW_H
+#define DROPSITEWINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QMimeData;
+class QPushButton;
+class QTableWidget;
+QT_END_NAMESPACE
+class DropArea;
+
+//! [DropSiteWindow header]
+class DropSiteWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ DropSiteWindow();
+
+public slots:
+ void updateFormatsTable(const QMimeData *mimeData);
+
+private:
+ DropArea *dropArea;
+ QLabel *abstractLabel;
+ QTableWidget *formatsTable;
+
+ QPushButton *clearButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+};
+//! [DropSiteWindow header]
+
+#endif
diff --git a/examples/draganddrop/dropsite/main.cpp b/examples/draganddrop/dropsite/main.cpp
new file mode 100644
index 0000000000..8f57cb88a6
--- /dev/null
+++ b/examples/draganddrop/dropsite/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** 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 Nokia Corporation 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 "dropsitewindow.h"
+
+//! [main() function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ DropSiteWindow window;
+ window.show();
+ return app.exec();
+}
+//! [main() function]