diff options
author | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2012-08-17 13:23:19 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-20 12:20:55 +0200 |
commit | 806dda08d685bc5f9ed71dfe8b61f21848d48066 (patch) | |
tree | a63533a1c4a335ae17adc105abb0ae4e62e2f26e /examples/widgets/draganddrop/dropsite | |
parent | 9f942014e31842b512c3198de035d041c59f54a9 (diff) |
Moving .qdoc files under examples/widgets/doc
Updated those .qdoc files to refer to the new relative examples
emplacement. Images and snippets to be moved later.
Also grouped all widgets related examples under widgets.
Change-Id: Ib29696e2d8948524537f53e8dda88f9ee26a597f
Reviewed-by: J-P Nurmi <j-p.nurmi@nokia.com>
Diffstat (limited to 'examples/widgets/draganddrop/dropsite')
-rw-r--r-- | examples/widgets/draganddrop/dropsite/droparea.cpp | 126 | ||||
-rw-r--r-- | examples/widgets/draganddrop/dropsite/droparea.h | 77 | ||||
-rw-r--r-- | examples/widgets/draganddrop/dropsite/dropsite.desktop | 11 | ||||
-rw-r--r-- | examples/widgets/draganddrop/dropsite/dropsite.pro | 14 | ||||
-rw-r--r-- | examples/widgets/draganddrop/dropsite/dropsitewindow.cpp | 143 | ||||
-rw-r--r-- | examples/widgets/draganddrop/dropsite/dropsitewindow.h | 77 | ||||
-rw-r--r-- | examples/widgets/draganddrop/dropsite/main.cpp | 53 |
7 files changed, 501 insertions, 0 deletions
diff --git a/examples/widgets/draganddrop/dropsite/droparea.cpp b/examples/widgets/draganddrop/dropsite/droparea.cpp new file mode 100644 index 0000000000..95bbd3000c --- /dev/null +++ b/examples/widgets/draganddrop/dropsite/droparea.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 <QtWidgets> + +#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/widgets/draganddrop/dropsite/droparea.h b/examples/widgets/draganddrop/dropsite/droparea.h new file mode 100644 index 0000000000..e1586990df --- /dev/null +++ b/examples/widgets/draganddrop/dropsite/droparea.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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/widgets/draganddrop/dropsite/dropsite.desktop b/examples/widgets/draganddrop/dropsite/dropsite.desktop new file mode 100644 index 0000000000..70a192f2b1 --- /dev/null +++ b/examples/widgets/draganddrop/dropsite/dropsite.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Drop Site +Exec=/opt/usr/bin/dropsite +Icon=dropsite +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/draganddrop/dropsite/dropsite.pro b/examples/widgets/draganddrop/dropsite/dropsite.pro new file mode 100644 index 0000000000..8198b19e79 --- /dev/null +++ b/examples/widgets/draganddrop/dropsite/dropsite.pro @@ -0,0 +1,14 @@ +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 + +QT += widgets +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp new file mode 100644 index 0000000000..f7fc5aa1ab --- /dev/null +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 <QtWidgets> + +#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/widgets/draganddrop/dropsite/dropsitewindow.h b/examples/widgets/draganddrop/dropsite/dropsitewindow.h new file mode 100644 index 0000000000..049e9593f4 --- /dev/null +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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/widgets/draganddrop/dropsite/main.cpp b/examples/widgets/draganddrop/dropsite/main.cpp new file mode 100644 index 0000000000..f6220fa42e --- /dev/null +++ b/examples/widgets/draganddrop/dropsite/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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] |