Modularize drag and drop documentation

- Move dnd docs and examples out of QtDoc module to gui library in QtBase
- Remove info related to Motif dnd since Qt5 doesn't implement it

Change-Id: Id7eb4eb422f4294a36dd92709ce3007903371f03
Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
This commit is contained in:
Gatis Paeglis 2012-10-16 18:11:42 +02:00 committed by The Qt Project
parent 59009cfd0c
commit 4c41cb48d0
36 changed files with 2561 additions and 27 deletions

View File

@ -76,8 +76,8 @@ MainWindow::MainWindow()
//! [3] //! [3]
clipboard = QApplication::clipboard(); clipboard = QApplication::clipboard();
#endif
//! [3] //! [3]
#endif
//! [4] //! [4]
connect(fontCombo, SIGNAL(currentFontChanged(QFont)), connect(fontCombo, SIGNAL(currentFontChanged(QFont)),

View File

@ -39,12 +39,7 @@ sourcedirs += .. \
../../../examples/gui/doc ../../../examples/gui/doc
exampledirs += ../../../examples/gui \ exampledirs += ../../../examples/gui \
../../../doc/src/snippets \ ../../../examples/widgets \
../ \
snippets snippets
excludedirs += snippets imagedirs += images
imagedirs += images \
../../../doc/src/images \
../../../examples/gui/doc/images

View File

@ -0,0 +1,3 @@
HEADERS = clipwindow.h
SOURCES = clipwindow.cpp \
main.cpp

View File

@ -0,0 +1,103 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 <QtGui>
#include "clipwindow.h"
ClipWindow::ClipWindow(QWidget *parent)
: QMainWindow(parent)
{
clipboard = QApplication::clipboard();
QWidget *centralWidget = new QWidget(this);
QWidget *currentItem = new QWidget(centralWidget);
QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), currentItem);
mimeTypeCombo = new QComboBox(currentItem);
QLabel *dataLabel = new QLabel(tr("Data:"), currentItem);
dataInfoLabel = new QLabel("", currentItem);
previousItems = new QListWidget(centralWidget);
//! [0]
connect(clipboard, SIGNAL(dataChanged()), this, SLOT(updateClipboard()));
//! [0]
connect(mimeTypeCombo, SIGNAL(activated(const QString &)),
this, SLOT(updateData(const QString &)));
QVBoxLayout *currentLayout = new QVBoxLayout(currentItem);
currentLayout->addWidget(mimeTypeLabel);
currentLayout->addWidget(mimeTypeCombo);
currentLayout->addWidget(dataLabel);
currentLayout->addWidget(dataInfoLabel);
currentLayout->addStretch(1);
QHBoxLayout *mainLayout = new QHBoxLayout(centralWidget);
mainLayout->addWidget(currentItem, 1);
mainLayout->addWidget(previousItems);
setCentralWidget(centralWidget);
setWindowTitle(tr("Clipboard"));
}
//! [1]
void ClipWindow::updateClipboard()
{
QStringList formats = clipboard->mimeData()->formats();
QByteArray data = clipboard->mimeData()->data(format);
//! [1]
mimeTypeCombo->clear();
mimeTypeCombo->insertStringList(formats);
int size = clipboard->mimeData()->data(formats[0]).size();
QListWidgetItem *newItem = new QListWidgetItem(previousItems);
newItem->setText(tr("%1 (%2 bytes)").arg(formats[0]).arg(size));
updateData(formats[0]);
//! [2]
}
//! [2]
void ClipWindow::updateData(const QString &format)
{
QByteArray data = clipboard->mimeData()->data(format);
dataInfoLabel->setText(tr("%1 bytes").arg(data.size()));
}

View File

@ -0,0 +1,72 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 CLIPWINDOW_H
#define CLIPWINDOW_H
#include <QMainWindow>
class QClipboard;
class QComboBox;
class QLabel;
class QListWidget;
class QMimeData;
class QWidget;
class ClipWindow : public QMainWindow
{
Q_OBJECT
public:
ClipWindow(QWidget *parent = 0);
public slots:
void updateClipboard();
void updateData(const QString &format);
private:
int currentItem;
QClipboard *clipboard;
QComboBox *mimeTypeCombo;
QLabel *dataInfoLabel;
QListWidget *previousItems;
};
#endif

View File

@ -0,0 +1,52 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 "clipwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ClipWindow *window = new ClipWindow;
window->resize(640, 480);
window->show();
return app.exec();
}

View File

@ -0,0 +1,5 @@
HEADERS = dragwidget.h \
mainwindow.h
SOURCES = dragwidget.cpp \
main.cpp \
mainwindow.cpp

View File

@ -0,0 +1,153 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 <QtGui>
#include "dragwidget.h"
DragWidget::DragWidget(QWidget *parent)
: QFrame(parent)
{
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
dragDropLabel = new QLabel("", this);
dragDropLabel->setAlignment(Qt::AlignHCenter);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addStretch(0);
layout->addWidget(dragDropLabel);
layout->addStretch(0);
setAcceptDrops(true);
}
// Accept all actions, but deal with them separately later.
//! [0]
void DragWidget::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
//! [0]
//! [1]
void DragWidget::dropEvent(QDropEvent *event)
{
if (event->source() == this && event->possibleActions() & Qt::MoveAction)
return;
//! [1]
//! [2]
if (event->proposedAction() == Qt::MoveAction) {
event->acceptProposedAction();
// Process the data from the event.
//! [2]
emit dragResult(tr("The data was moved here."));
//! [3]
} else if (event->proposedAction() == Qt::CopyAction) {
event->acceptProposedAction();
// Process the data from the event.
//! [3]
emit dragResult(tr("The data was copied here."));
//! [4]
} else {
// Ignore the drop.
return;
}
//! [4]
// End of quote
emit mimeTypes(event->mimeData()->formats());
setData(event->mimeData()->formats()[0],
event->mimeData()->data(event->mimeData()->formats()[0]));
//! [5]
}
//! [5]
//! [6]
void DragWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
dragStartPosition = event->pos();
}
//! [6]
//! [7]
void DragWidget::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - dragStartPosition).manhattanLength()
< QApplication::startDragDistance())
return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setData(mimeType, data);
drag->setMimeData(mimeData);
Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
//! [7]
switch (dropAction) {
case Qt::CopyAction:
emit dragResult(tr("The text was copied."));
break;
case Qt::MoveAction:
emit dragResult(tr("The text was moved."));
break;
default:
emit dragResult(tr("Unknown action."));
break;
}
//! [8]
}
//! [8]
void DragWidget::setData(const QString &mimetype, const QByteArray &newData)
{
mimeType = mimetype;
data = QByteArray(newData);
dragDropLabel->setText(tr("%1 bytes").arg(data.size()));
QStringList formats;
formats << mimetype;
emit mimeTypes(formats);
}

View File

@ -0,0 +1,79 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 DRAGWIDGET_H
#define DRAGWIDGET_H
#include <QByteArray>
#include <QFrame>
#include <QString>
#include <QStringList>
class QComboBox;
class QFrame;
class QLabel;
class QTextBrowser;
class DragWidget : public QFrame
{
Q_OBJECT
public:
DragWidget(QWidget *parent);
void setData(const QString &mimetype, const QByteArray &newData);
signals:
void dragResult(const QString &actionText);
void mimeTypes(const QStringList &types);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
QByteArray data;
QLabel *dragDropLabel;
QPoint dragStartPosition;
QString mimeType;
};
#endif

View File

@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 <QtGui>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow *window1 = new MainWindow;
MainWindow *window2 = new MainWindow;
window1->show();
window2->show();
return app.exec();
}

View File

@ -0,0 +1,84 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 <QtGui>
#include "dragwidget.h"
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QFrame *centralWidget = new QFrame(this);
QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), centralWidget);
mimeTypeCombo = new QComboBox(centralWidget);
QLabel *dataLabel = new QLabel(tr("Amount of data (bytes):"), centralWidget);
dragWidget = new DragWidget(centralWidget);
connect(dragWidget, SIGNAL(mimeTypes(const QStringList &)),
this, SLOT(setMimeTypes(const QStringList &)));
connect(dragWidget, SIGNAL(dragResult(const QString &)),
this, SLOT(setDragResult(const QString &)));
QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget);
mainLayout->addWidget(mimeTypeLabel);
mainLayout->addWidget(mimeTypeCombo);
mainLayout->addSpacing(32);
mainLayout->addWidget(dataLabel);
mainLayout->addWidget(dragWidget);
statusBar();
dragWidget->setData(QString("text/plain"), QByteArray("Hello world"));
setCentralWidget(centralWidget);
setWindowTitle(tr("Drag and Drop"));
}
void MainWindow::setDragResult(const QString &actionText)
{
statusBar()->showMessage(actionText);
}
void MainWindow::setMimeTypes(const QStringList &types)
{
mimeTypeCombo->clear();
mimeTypeCombo->addItems(types);
}

View File

@ -0,0 +1,71 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPixmap>
#include <QPoint>
class QComboBox;
class QLabel;
class QLineEdit;
class QMouseEvent;
class QTextEdit;
class DragWidget;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
public slots:
void setDragResult(const QString &actionText);
void setMimeTypes(const QStringList &types);
private:
QComboBox *mimeTypeCombo;
DragWidget *dragWidget;
};
#endif

View File

@ -0,0 +1,5 @@
QT += widgets
HEADERS += mainwindow.h
RESOURCES += images.qrc
SOURCES += main.cpp \
mainwindow.cpp

View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/file.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

View File

@ -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 documentation 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 <QtGui>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow *window = new MainWindow;
window->show();
return app.exec();
}

View File

@ -0,0 +1,71 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPixmap>
#include <QPoint>
class QLabel;
class QLineEdit;
class QMouseEvent;
class QTextEdit;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
protected:
void mousePressEvent(QMouseEvent *event);
private:
QLabel *iconLabel;
QLineEdit *nameEdit;
QPixmap iconPixmap;
QPoint dragStartPosition;
QTextEdit *commentEdit;
};
#endif

View File

@ -0,0 +1,3 @@
HEADERS = window.h
SOURCES = main.cpp \
window.cpp

View File

@ -0,0 +1,52 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 <QtGui>
#include "window.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window *window = new Window;
window->show();
return app.exec();
}

View File

@ -0,0 +1,87 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 <QtGui>
#include "window.h"
//! [0]
Window::Window(QWidget *parent)
: QWidget(parent)
{
//! [0]
QLabel *textLabel = new QLabel(tr("Data:"), this);
textBrowser = new QTextBrowser(this);
QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), this);
mimeTypeCombo = new QComboBox(this);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(textLabel);
layout->addWidget(textBrowser);
layout->addWidget(mimeTypeLabel);
layout->addWidget(mimeTypeCombo);
//! [1]
setAcceptDrops(true);
//! [1]
setWindowTitle(tr("Drop Events"));
//! [2]
}
//! [2]
//! [3]
void Window::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat("text/plain"))
event->acceptProposedAction();
}
//! [3]
//! [4]
void Window::dropEvent(QDropEvent *event)
{
textBrowser->setPlainText(event->mimeData()->text());
mimeTypeCombo->clear();
mimeTypeCombo->addItems(event->mimeData()->formats());
event->acceptProposedAction();
}
//! [4]

View File

@ -0,0 +1,71 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 WINDOW_H
#define WINDOW_H
#include <QString>
#include <QStringList>
#include <QWidget>
class QComboBox;
class QFrame;
class QTextBrowser;
class Window : public QWidget
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
private:
QComboBox *mimeTypeCombo;
QFrame *dropFrame;
QTextBrowser *textBrowser;
QString oldText;
QStringList oldMimeTypes;
};
#endif

View File

@ -0,0 +1,3 @@
HEADERS = window.h
SOURCES = main.cpp \
window.cpp

View File

@ -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 documentation 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 <QtGui>
#include "window.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window *window = new Window;
window->show();
return app.exec();
}

View File

@ -0,0 +1,96 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 <QtGui>
#include "window.h"
Window::Window(QWidget *parent)
: QWidget(parent)
{
QLabel *textLabel = new QLabel(tr("Data:"), this);
textBrowser = new QTextBrowser(this);
QLabel *mimeTypeLabel = new QLabel(tr("MIME types:"), this);
mimeTypeCombo = new QComboBox(this);
dropFrame = new QFrame(this);
dropFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
QLabel *dropLabel = new QLabel(tr("Drop items here"), dropFrame);
dropLabel->setAlignment(Qt::AlignHCenter);
QVBoxLayout *dropFrameLayout = new QVBoxLayout(dropFrame);
dropFrameLayout->addWidget(dropLabel);
QHBoxLayout *dropLayout = new QHBoxLayout;
dropLayout->addStretch(0);
dropLayout->addWidget(dropFrame);
dropLayout->addStretch(0);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(textLabel);
mainLayout->addWidget(textBrowser);
mainLayout->addWidget(mimeTypeLabel);
mainLayout->addWidget(mimeTypeCombo);
mainLayout->addSpacing(32);
mainLayout->addLayout(dropLayout);
setAcceptDrops(true);
setWindowTitle(tr("Drop Rectangle"));
}
//! [0]
void Window::dragMoveEvent(QDragMoveEvent *event)
{
if (event->mimeData()->hasFormat("text/plain")
&& event->answerRect().intersects(dropFrame->geometry()))
event->acceptProposedAction();
}
//! [0]
void Window::dropEvent(QDropEvent *event)
{
textBrowser->setPlainText(event->mimeData()->text());
mimeTypeCombo->clear();
mimeTypeCombo->addItems(event->mimeData()->formats());
event->acceptProposedAction();
}

View File

@ -0,0 +1,71 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 WINDOW_H
#define WINDOW_H
#include <QString>
#include <QStringList>
#include <QWidget>
class QComboBox;
class QFrame;
class QTextBrowser;
class Window : public QWidget
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
protected:
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
private:
QComboBox *mimeTypeCombo;
QFrame *dropFrame;
QTextBrowser *textBrowser;
QString oldText;
QStringList oldMimeTypes;
};
#endif

View File

@ -0,0 +1,77 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 FINALWIDGET_H
#define FINALWIDGET_H
#include <QFrame>
#include <QImage>
#include <QPoint>
#include <QSize>
class QGridLayout;
class QLabel;
class QMouseEvent;
class QWidget;
class FinalWidget : public QFrame
{
Q_OBJECT
public:
FinalWidget(QWidget *parent, const QString &name, const QSize &labelSize);
void setPixmap(const QPixmap &pixmap);
const QPixmap *pixmap() const;
protected:
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
void createImage();
bool hasImage;
QImage originalImage;
QLabel *imageLabel;
QLabel *nameLabel;
QPoint dragStartPosition;
};
#endif

View File

@ -0,0 +1,50 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 "viewer.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Viewer viewer;
viewer.show();
return app.exec();
}

View File

@ -0,0 +1,217 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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$
**
****************************************************************************/
/*
screenwidget.cpp
A widget to display colour components from an image using independently
selected colors. Controls are provided to allow the image to be inverted, and
the color to be selection via a standard dialog. The image is displayed in a
label widget.
*/
#include <QApplication>
#include <QColorDialog>
#include <QGridLayout>
#include <QImage>
#include <QLabel>
#include <QMenu>
#include <QMimeData>
#include <QMouseEvent>
#include <QPixmap>
#include <QPushButton>
#include <QWidget>
#include "screenwidget.h"
/*!
Initializes the paint color, the mask color (cyan, magenta,
or yellow), connects the color selector and invert checkbox to functions,
and creates a two-by-two grid layout.
*/
ScreenWidget::ScreenWidget(QWidget *parent, QColor initialColor,
const QString &name, Separation mask,
const QSize &labelSize)
: QFrame(parent)
{
paintColor = initialColor;
maskColor = mask;
inverted = false;
imageLabel = new QLabel;
imageLabel->setFrameShadow(QFrame::Sunken);
imageLabel->setFrameShape(QFrame::StyledPanel);
imageLabel->setMinimumSize(labelSize);
nameLabel = new QLabel(name);
colorButton = new QPushButton(tr("Modify..."));
colorButton->setBackgroundRole(QPalette::Button);
colorButton->setMinimumSize(32, 32);
QPalette palette(colorButton->palette());
palette.setColor(QPalette::Button, initialColor);
colorButton->setPalette(palette);
invertButton = new QPushButton(tr("Invert"));
//invertButton->setToggleButton(true);
//invertButton->setOn(inverted);
invertButton->setEnabled(false);
connect(colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
connect(invertButton, SIGNAL(clicked()), this, SLOT(invertImage()));
QGridLayout *gridLayout = new QGridLayout;
gridLayout->addWidget(imageLabel, 0, 0, 1, 2);
gridLayout->addWidget(nameLabel, 1, 0);
gridLayout->addWidget(colorButton, 1, 1);
gridLayout->addWidget(invertButton, 2, 1, 1, 1);
setLayout(gridLayout);
}
/*!
Creates a new image by separating out the cyan, magenta, or yellow
component, depending on the mask color specified in the constructor.
The amount of the component found in each pixel of the image is used
to determine how much of a user-selected ink is used for each pixel
in the new image for the label widget.
*/
void ScreenWidget::createImage()
{
newImage = originalImage.copy();
// Create CMY components for the ink being used.
float cyanInk = (255 - paintColor.red())/255.0;
float magentaInk = (255 - paintColor.green())/255.0;
float yellowInk = (255 - paintColor.blue())/255.0;
int (*convert)(QRgb);
switch (maskColor) {
case Cyan:
convert = qRed;
break;
case Magenta:
convert = qGreen;
break;
case Yellow:
convert = qBlue;
break;
}
for (int y = 0; y < newImage.height(); ++y) {
for (int x = 0; x < newImage.width(); ++x) {
QRgb p(originalImage.pixel(x, y));
// Separate the source pixel into its cyan component.
int amount;
if (inverted)
amount = convert(p);
else
amount = 255 - convert(p);
QColor newColor(
255 - qMin(int(amount * cyanInk), 255),
255 - qMin(int(amount * magentaInk), 255),
255 - qMin(int(amount * yellowInk), 255));
newImage.setPixel(x, y, newColor.rgb());
}
}
imageLabel->setPixmap(QPixmap::fromImage(newImage));
}
/*!
Returns a pointer to the modified image.
*/
QImage* ScreenWidget::image()
{
return &newImage;
}
/*!
Sets whether the amount of ink applied to the canvas is to be inverted
(subtracted from the maximum value) before the ink is applied.
*/
void ScreenWidget::invertImage()
{
//inverted = invertButton->isOn();
inverted = !inverted;
createImage();
emit imageChanged();
}
/*!
Separate the current image into cyan, magenta, and yellow components.
Create a representation of how each component might appear when applied
to a blank white piece of paper.
*/
void ScreenWidget::setColor()
{
QColor newColor = QColorDialog::getColor(paintColor);
if (newColor.isValid()) {
paintColor = newColor;
QPalette palette(colorButton->palette());
palette.setColor(QPalette::Button, paintColor);
colorButton->setPalette(palette);
createImage();
emit imageChanged();
}
}
/*!
Records the original image selected by the user, creates a color
separation, and enables the invert image checkbox.
*/
void ScreenWidget::setImage(QImage &image)
{
originalImage = image;
createImage();
invertButton->setEnabled(true);
}

View File

@ -0,0 +1,86 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 SCREENWIDGET_H
#define SCREENWIDGET_H
#include <QColor>
#include <QFrame>
#include <QImage>
#include <QSize>
class QGridLayout;
class QLabel;
class QPushButton;
class QWidget;
class ScreenWidget : public QFrame
{
Q_OBJECT
public:
enum Separation { Cyan, Magenta, Yellow };
ScreenWidget(QWidget *parent, QColor initialColor, const QString &name,
Separation mask, const QSize &labelSize);
void setImage(QImage &image);
QImage* image();
signals:
void imageChanged();
public slots:
void setColor();
void invertImage();
private:
void createImage();
bool inverted;
QColor paintColor;
QImage newImage;
QImage originalImage;
QLabel *imageLabel;
QLabel *nameLabel;
QPushButton *colorButton;
QPushButton *invertButton;
Separation maskColor;
};
#endif

View File

@ -0,0 +1,7 @@
HEADERS = finalwidget.h \
screenwidget.h \
viewer.h
SOURCES = finalwidget.cpp \
main.cpp \
screenwidget.cpp \
viewer.cpp

View File

@ -0,0 +1,54 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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$
**
****************************************************************************/
/*
\example painting/separations
\title Color Separations Example
This example enables simple color manipulation of images and demonstrates a
number of image-related features of Qt, from per-pixel image manipulation to
drag and drop handling of images.
\image separations-example.png
The application allows the user to load an image, shown in the top-left
part of the main window, and to adjust its color balance by replacing its
initial cyan, magenta, and yellow components with different colors.
*/

View File

@ -0,0 +1,328 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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$
**
****************************************************************************/
/*
viewer.cpp
Provides a main window for displaying a user-specified original image
with three color separations in a grid layout.
A main menu provides entries for selecting files, and adjusting the
brightness of the separations.
*/
#include <QtGui>
#include "finalwidget.h"
#include "screenwidget.h"
#include "viewer.h"
/*
Constructor: initializes a default value for the brightness, creates
the main menu entries, and constructs a central widget that contains
enough space for images to be displayed.
*/
Viewer::Viewer()
{
setWindowTitle(tr("QImage Color Separations"));
brightness = 255;
createMenus();
setCentralWidget(createCentralWidget());
}
/*
Creates a main menu with two entries: a File menu, to allow the image
to be selected, and a Brightness menu to allow the brightness of the
separations to be changed.
Initially, the Brightness menu items are disabled, but the first entry in
the menu is checked to reflect the default brightness.
*/
void Viewer::createMenus()
{
fileMenu = new QMenu(tr("&File"), this);
brightnessMenu = new QMenu(tr("&Brightness"), this);
QAction *openAction = fileMenu->addAction(tr("&Open..."));
openAction->setShortcut(QKeySequence("Ctrl+O"));
saveAction = fileMenu->addAction(tr("&Save..."));
saveAction->setShortcut(QKeySequence("Ctrl+S"));
saveAction->setEnabled(false);
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcut(QKeySequence("Ctrl+Q"));
QAction *noBrightness = brightnessMenu->addAction(tr("&0%"));
noBrightness->setCheckable(true);
QAction *quarterBrightness = brightnessMenu->addAction(tr("&25%"));
quarterBrightness->setCheckable(true);
QAction *halfBrightness = brightnessMenu->addAction(tr("&50%"));
halfBrightness->setCheckable(true);
QAction *threeQuartersBrightness = brightnessMenu->addAction(tr("&75%"));
threeQuartersBrightness->setCheckable(true);
QAction *fullBrightness = brightnessMenu->addAction(tr("&100%"));
fullBrightness->setCheckable(true);
menuMap[noBrightness] = None;
menuMap[quarterBrightness] = Quarter;
menuMap[halfBrightness] = Half;
menuMap[threeQuartersBrightness] = ThreeQuarters;
menuMap[fullBrightness] = Full;
currentBrightness = fullBrightness;
currentBrightness->setChecked(true);
brightnessMenu->setEnabled(false);
menuBar()->addMenu(fileMenu);
menuBar()->addMenu(brightnessMenu);
connect(openAction, SIGNAL(triggered()), this, SLOT(chooseFile()));
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveImage()));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(brightnessMenu, SIGNAL(triggered(QAction *)), this,
SLOT(setBrightness(QAction *)));
}
/*
Constructs a central widget for the window consisting of a two-by-two
grid of labels, each of which will contain an image. We restrict the
size of the labels to 256 pixels, and ensure that the window cannot
be resized.
*/
QFrame* Viewer::createCentralWidget()
{
QFrame* frame = new QFrame(this);
grid = new QGridLayout(frame);
grid->setSpacing(8);
grid->setMargin(4);
layout()->setSizeConstraint(QLayout::SetFixedSize);
QSize labelSize(256, 256);
finalWidget = new FinalWidget(frame, tr("Final image"), labelSize);
cyanWidget = new ScreenWidget(frame, Qt::cyan, tr("Cyan"),
ScreenWidget::Cyan, labelSize);
magentaWidget = new ScreenWidget(frame, Qt::magenta, tr("Magenta"),
ScreenWidget::Magenta, labelSize);
yellowWidget = new ScreenWidget(frame, Qt::yellow, tr("Yellow"),
ScreenWidget::Yellow, labelSize);
connect(cyanWidget, SIGNAL(imageChanged()), this, SLOT(createImage()));
connect(magentaWidget, SIGNAL(imageChanged()), this, SLOT(createImage()));
connect(yellowWidget, SIGNAL(imageChanged()), this, SLOT(createImage()));
grid->addWidget(finalWidget, 0, 0, Qt::AlignTop | Qt::AlignHCenter);
grid->addWidget(cyanWidget, 0, 1, Qt::AlignTop | Qt::AlignHCenter);
grid->addWidget(magentaWidget, 1, 0, Qt::AlignTop | Qt::AlignHCenter);
grid->addWidget(yellowWidget, 1, 1, Qt::AlignTop | Qt::AlignHCenter);
return frame;
}
/*
Provides a dialog window to allow the user to specify an image file.
If a file is selected, the appropriate function is called to process
and display it.
*/
void Viewer::chooseFile()
{
QString imageFile = QFileDialog::getOpenFileName(this,
tr("Choose an image file to open"), path, tr("Images (*.*)"));
if (!imageFile.isEmpty()) {
openImageFile(imageFile);
path = imageFile;
}
}
/*
Changes the value of the brightness according to the entry selected in the
Brightness menu. The selected entry is checked, and the previously selected
entry is unchecked.
The color separations are updated to use the new value for the brightness.
*/
void Viewer::setBrightness(QAction *action)
{
if (!menuMap.contains(action) || scaledImage.isNull())
return;
Brightness amount = menuMap[action];
switch (amount) {
case None:
brightness = 0; break;
case Quarter:
brightness = 64; break;
case Half:
brightness = 128; break;
case ThreeQuarters:
brightness = 191; break;
case Full:
brightness = 255; break;
default: return;
}
currentBrightness->setChecked(false);
currentBrightness = action;
currentBrightness->setChecked(true);
createImage();
}
/*
Load the image from the file given, and create four pixmaps based
on the original image.
The window caption is set, and the Brightness menu enabled if the image file
can be loaded.
*/
void Viewer::openImageFile(QString &imageFile)
{
QImage originalImage;
if (originalImage.load(imageFile)) {
setWindowTitle(imageFile);
//menuBar()->setItemEnabled(brightnessMenuId, true);
saveAction->setEnabled(true);
brightnessMenu->setEnabled(true);
/* Note: the ScaleMin value may be different for Qt 4. */
scaledImage = originalImage.scaled(256, 256, Qt::KeepAspectRatio);
cyanWidget->setImage(scaledImage);
magentaWidget->setImage(scaledImage);
yellowWidget->setImage(scaledImage);
createImage();
}
else
(void) QMessageBox::warning(this, tr("Cannot open file"),
tr("The selected file could not be opened."),
QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton);
}
/*
Creates an image by combining the contents of the three screens
to present a page preview.
The image associated with each screen is separated into cyan,
magenta, and yellow components. We add up the values for each
component from the three screen images, and subtract the totals
from the maximum value for each corresponding primary color.
*/
void Viewer::createImage()
{
QImage newImage = scaledImage.copy();
QImage *image1 = cyanWidget->image();
QImage *image2 = magentaWidget->image();
QImage *image3 = yellowWidget->image();
int darkness = 255 - brightness;
for (int y = 0; y < newImage.height(); ++y) {
for (int x = 0; x < newImage.width(); ++x) {
// Create three screens, using the quantities of the source
// CMY components to determine how much of each of the
// inks are to be put on each screen.
QRgb p1(image1->pixel(x, y));
float cyan1 = 255 - qRed(p1);
float magenta1 = 255 - qGreen(p1);
float yellow1 = 255 - qBlue(p1);
QRgb p2(image2->pixel(x, y));
float cyan2 = 255 - qRed(p2);
float magenta2 = 255 - qGreen(p2);
float yellow2 = 255 - qBlue(p2);
QRgb p3(image3->pixel(x, y));
float cyan3 = 255 - qRed(p3);
float magenta3 = 255 - qGreen(p3);
float yellow3 = 255 - qBlue(p3);
QColor newColor(
qMax(255 - int(cyan1+cyan2+cyan3) - darkness, 0),
qMax(255 - int(magenta1+magenta2+magenta3) - darkness, 0),
qMax(255 - int(yellow1+yellow2+yellow3) - darkness, 0));
newImage.setPixel(x, y, newColor.rgb());
}
}
finalWidget->setPixmap(QPixmap::fromImage(newImage));
}
/*
Provides a dialog window to allow the user to save the image file.
*/
void Viewer::saveImage()
{
QString imageFile = QFileDialog::getSaveFileName(this,
tr("Choose a filename to save the image"), "", tr("Images (*.png)"));
QFileInfo info(imageFile);
if (!info.baseName().isEmpty()) {
QString newImageFile = QFileInfo(info.absoluteDir(),
info.baseName() + ".png").absoluteFilePath();
if (!finalWidget->pixmap()->save(newImageFile, "PNG"))
(void) QMessageBox::warning(this, tr("Cannot save file"),
tr("The file could not be saved."),
QMessageBox::Cancel, QMessageBox::NoButton,
QMessageBox::NoButton);
}
else
(void) QMessageBox::warning(this, tr("Cannot save file"),
tr("Please enter a valid filename."),
QMessageBox::Cancel, QMessageBox::NoButton,
QMessageBox::NoButton);
}

View File

@ -0,0 +1,89 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation 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 VIEWER_H
#define VIEWER_H
#include <QImage>
#include <QMainWindow>
#include <QMap>
class QAction;
class QFrame;
class QGridLayout;
class QLabel;
class QMenu;
class FinalWidget;
class ScreenWidget;
class Viewer : public QMainWindow
{
Q_OBJECT
public:
enum Brightness { None, Quarter, Half, ThreeQuarters, Full };
Viewer();
public slots:
void chooseFile();
void setBrightness(QAction *action);
void createImage();
void saveImage();
private:
void createMenus();
QFrame *createCentralWidget();
void openImageFile(QString &filePath);
FinalWidget *finalWidget;
int brightness;
QAction *currentBrightness;
QAction *saveAction;
QGridLayout *grid;
QImage scaledImage;
QMap <QAction*,Brightness> menuMap;
QMenu *brightnessMenu;
QMenu *fileMenu;
QString path;
ScreenWidget *cyanWidget;
ScreenWidget *magentaWidget;
ScreenWidget *yellowWidget;
};
#endif

401
src/gui/doc/src/dnd.qdoc Normal file
View File

@ -0,0 +1,401 @@
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page dnd.html
\title Drag and Drop
\brief An overview of the drag and drop system provided by Qt.
\ingroup qt-gui-concepts
Drag and drop provides a simple visual mechanism which users can use
to transfer information between and within applications. (In the
literature this is referred to as a "direct manipulation model".) Drag
and drop is similar in function to the clipboard's cut and paste
mechanism.
\tableofcontents
This document describes the basic drag and drop mechanism and
outlines the approach used to enable it in custom widgets. Drag
and drop operations are also supported by Qt's item views and by
the graphics view framework. More information is available in
\l{Using drag and drop with item views} and \l{Graphics View
Framework}.
\section1 Drag and Drop Classes
These classes deal with drag and drop and the necessary mime type
encoding and decoding.
\annotatedlist draganddrop
\section1 Configuration
The QApplication object provides some properties that are related
to drag and drop operations:
\list
\li \l{QApplication::startDragTime} describes the amount of time in
milliseconds that the user must hold down a mouse button over an
object before a drag will begin.
\li \l{QApplication::startDragDistance} indicates how far the user has to
move the mouse while holding down a mouse button before the movement
will be interpreted as dragging. Use of high values for this quantity
prevents accidental dragging when the user only meant to click on an
object.
\endlist
These quantities provide sensible default values for you to use if you
provide drag and drop support in your widgets.
\section1 Dragging
To start a drag, create a QDrag object, and call its
exec() function. In most applications, it is a good idea to begin a drag
and drop operation only after a mouse button has been pressed and the
cursor has been moved a certain distance. However, the simplest way to
enable dragging from a widget is to reimplement the widget's
\l{QWidget::mousePressEvent()}{mousePressEvent()} and start a drag
and drop operation:
\snippet dragging/mainwindow.cpp 0
\dots 8
\snippet dragging/mainwindow.cpp 2
Although the user may take some time to complete the dragging operation,
as far as the application is concerned the exec() function is a blocking
function that returns with \l{Qt::DropActions}{one of several values}.
These indicate how the operation ended, and are described in more detail
below.
Note that the exec() function does not block the main event loop.
For widgets that need to distinguish between mouse clicks and drags, it
is useful to reimplement the widget's
\l{QWidget::mousePressEvent()}{mousePressEvent()} function to record to
start position of the drag:
\snippet draganddrop/dragwidget.cpp 6
Later, in \l{QWidget::mouseMoveEvent()}{mouseMoveEvent()}, we can determine
whether a drag should begin, and construct a drag object to handle the
operation:
\snippet draganddrop/dragwidget.cpp 7
\dots
\snippet draganddrop/dragwidget.cpp 8
This particular approach uses the \l QPoint::manhattanLength() function
to get a rough estimate of the distance between where the mouse click
occurred and the current cursor position. This function trades accuracy
for speed, and is usually suitable for this purpose.
\section1 Dropping
To be able to receive media dropped on a widget, call
\l{QWidget::setAcceptDrops()}{setAcceptDrops(true)} for the widget,
and reimplement the \l{QWidget::dragEnterEvent()}{dragEnterEvent()} and
\l{QWidget::dropEvent()}{dropEvent()} event handler functions.
For example, the following code enables drop events in the constructor of
a QWidget subclass, making it possible to usefully implement drop event
handlers:
\snippet dropevents/window.cpp 0
\dots
\snippet dropevents/window.cpp 1
\snippet dropevents/window.cpp 2
The dragEnterEvent() function is typically used to inform Qt about the
types of data that the widget accepts.
You must reimplement this function if you want to receive either
QDragMoveEvent or QDropEvent in your reimplementations of
\l{QWidget::dragMoveEvent()}{dragMoveEvent()} and
\l{QWidget::dropEvent()}{dropEvent()}.
The following code shows how \l{QWidget::dragEnterEvent()}{dragEnterEvent()}
can be reimplemented to
tell the drag and drop system that we can only handle plain text:
\snippet dropevents/window.cpp 3
The \l{QWidget::dropEvent()}{dropEvent()} is used to unpack dropped data
and handle it in way that is suitable for your application.
In the following code, the text supplied in the event is passed to a
QTextBrowser and a QComboBox is filled with the list of MIME types that
are used to describe the data:
\snippet dropevents/window.cpp 4
In this case, we accept the proposed action without checking what it is.
In a real world application, it may be necessary to return from the
\l{QWidget::dropEvent()}{dropEvent()} function without accepting the
proposed action or handling
the data if the action is not relevant. For example, we may choose to
ignore Qt::LinkAction actions if we do not support
links to external sources in our application.
\section2 Overriding Proposed Actions
We may also ignore the proposed action, and perform some other action on
the data. To do this, we would call the event object's
\l{QDropEvent::setDropAction()}{setDropAction()} with the preferred
action from Qt::DropAction before calling \l{QEvent::}{accept()}.
This ensures that the replacement drop action is used instead of the
proposed action.
For more sophisticated applications, reimplementing
\l{QWidget::dragMoveEvent()}{dragMoveEvent()} and
\l{QWidget::dragLeaveEvent()}{dragLeaveEvent()} will let you make
certain parts of your widgets sensitive to drop events, and give you more
control over drag and drop in your application.
\section2 Subclassing Complex Widgets
Certain standard Qt widgets provide their own support for drag and drop.
When subclassing these widgets, it may be necessary to reimplement
\l{QWidget::dragMoveEvent()}{dragMoveEvent()} in addition to
\l{QWidget::dragEnterEvent()}{dragEnterEvent()} and
\l{QWidget::dropEvent()}{dropEvent()} to prevent the base class from
providing default drag and drop handling, and to handle any special
cases you are interested in.
\section1 Drag and Drop Actions
In the simplest case, the target of a drag and drop action receives a
copy of the data being dragged, and the source decides whether to
delete the original. This is described by the \c CopyAction action.
The target may also choose to handle other actions, specifically the
\c MoveAction and \c LinkAction actions. If the source calls
QDrag::exec(), and it returns \c MoveAction, the source is responsible
for deleting any original data if it chooses to do so. The QMimeData
and QDrag objects created by the source widget \e{should not be deleted}
- they will be destroyed by Qt. The target is responsible for taking
ownership of the data sent in the drag and drop operation; this is
usually done by keeping references to the data.
If the target understands the \c LinkAction action, it should
store its own reference to the original information; the source
does not need to perform any further processing on the data. The
most common use of drag and drop actions is when performing a
Move within the same widget; see the section on \l{Drop Actions}
for more information about this feature.
The other major use of drag actions is when using a reference type
such as text/uri-list, where the dragged data are actually references
to files or objects.
\section1 Adding New Drag and Drop Types
Drag and drop is not limited to text and images. Any type of information
can be transferred in a drag and drop operation. To drag information
between applications, the applications must be able to indicate to each
other which data formats they can accept and which they can produce.
This is achieved using
\l{http://www.rfc-editor.org/rfc/rfc1341.txt}{MIME types}. The QDrag
object constructed by the source contains a list of MIME types that it
uses to represent the data (ordered from most appropriate to least
appropriate), and the drop target uses one of these to access the data.
For common data types, the convenience functions handle the MIME types
used transparently but, for custom data types, it is necessary to
state them explicitly.
To implement drag and drop actions for a type of information that is
not covered by the QDrag convenience functions, the first and most
important step is to look for existing formats that are appropriate:
The Internet Assigned Numbers Authority (\l{http://www.iana.org}{IANA})
provides a
\l{http://www.iana.org/assignments/media-types/}{hierarchical
list of MIME media types} at the Information Sciences Institute
(\l{http://www.isi.edu}{ISI}).
Using standard MIME types maximizes the interoperability of
your application with other software now and in the future.
To support an additional media type, simply set the data in the QMimeData
object with the \l{QMimeData::setData()}{setData()} function, supplying
the full MIME type and a QByteArray containing the data in the appropriate
format. The following code takes a pixmap from a label and stores it
as a Portable Network Graphics (PNG) file in a QMimeData object:
\snippet separations/finalwidget.cpp 0
Of course, for this case we could have simply used
\l{QMimeData::setImageData()}{setImageData()} instead to supply image data
in a variety of formats:
\snippet separations/finalwidget.cpp 1
The QByteArray approach is still useful in this case because it provides
greater control over the amount of data stored in the QMimeData object.
Note that custom datatypes used in item views must be declared as
\l{QMetaObject}{meta objects} and that stream operators for them
must be implemented.
\section1 Drop Actions
In the clipboard model, the user can \e cut or \e copy the source
information, then later paste it. Similarly in the drag and drop
model, the user can drag a \e copy of the information or they can drag
the information itself to a new place (\e moving it). The
drag and drop model has an additional complication for the programmer:
The program doesn't know whether the user wants to cut or copy the
information until the operation is complete. This often makes no
difference when dragging information between applications, but within
an application it is important to check which drop action was used.
We can reimplement the mouseMoveEvent() for a widget, and start a drag
and drop operation with a combination of possible drop actions. For
example, we may want to ensure that dragging always moves objects in
the widget:
\snippet draganddrop/dragwidget.cpp 7
\dots
\snippet draganddrop/dragwidget.cpp 8
The action returned by the exec() function may default to a
\c CopyAction if the information is dropped into another application
but, if it is dropped in another widget in the same application, we
may obtain a different drop action.
The proposed drop actions can be filtered in a widget's dragMoveEvent()
function. However, it is possible to accept all proposed actions in
the dragEnterEvent() and let the user decide which they want to accept
later:
\snippet draganddrop/dragwidget.cpp 0
When a drop occurs in the widget, the dropEvent() handler function is
called, and we can deal with each possible action in turn. First, we
deal with drag and drop operations within the same widget:
\snippet draganddrop/dragwidget.cpp 1
In this case, we refuse to deal with move operations. Each type of drop
action that we accept is checked and dealt with accordingly:
\snippet draganddrop/dragwidget.cpp 2
\snippet draganddrop/dragwidget.cpp 3
\snippet draganddrop/dragwidget.cpp 4
\dots
\snippet draganddrop/dragwidget.cpp 5
Note that we checked for individual drop actions in the above code.
As mentioned above in the section on
\l{#Overriding Proposed Actions}{Overriding Proposed Actions}, it is
sometimes necessary to override the proposed drop action and choose a
different one from the selection of possible drop actions.
To do this, you need to check for the presence of each action in the value
supplied by the event's \l{QDropEvent::}{possibleActions()}, set the drop
action with \l{QDropEvent::}{setDropAction()}, and call
\l{QEvent::}{accept()}.
\section1 Drop Rectangles
The widget's dragMoveEvent() can be used to restrict drops to certain parts
of the widget by only accepting the proposed drop actions when the cursor
is within those areas. For example, the following code accepts any proposed
drop actions when the cursor is over a child widget (\c dropFrame):
\snippet droprectangle/window.cpp 0
The dragMoveEvent() can also be used if you need to give visual
feedback during a drag and drop operation, to scroll the window, or
whatever is appropriate.
\section1 The Clipboard
Applications can also communicate with each other by putting data on
the clipboard. To access this, you need to obtain a QClipboard object
from the QApplication object:
\snippet widgets/charactermap/mainwindow.cpp 3
The QMimeData class is used to represent data that is transferred to and
from the clipboard. To put data on the clipboard, you can use the
setText(), setImage(), and setPixmap() convenience functions for common
data types. These functions are similar to those found in the QMimeData
class, except that they also take an additional argument that controls
where the data is stored: If \l{QClipboard::Mode}{Clipboard} is
specified, the data is placed on the clipboard; if
\l{QClipboard::Mode}{Selection} is specified, the data is placed in the
mouse selection (on X11 only). By default, data is put on the clipboard.
For example, we can copy the contents of a QLineEdit to the clipboard
with the following code:
\snippet widgets/charactermap/mainwindow.cpp 11
Data with different MIME types can also be put on the clipboard.
Construct a QMimeData object and set data with setData() function in
the way described in the previous section; this object can then be
put on the clipboard with the
\l{QClipboard::setMimeData()}{setMimeData()} function.
The QClipboard class can notify the application about changes to the
data it contains via its \l{QClipboard::dataChanged()}{dataChanged()}
signal. For example, we can monitor the clipboard by connecting this
signal to a slot in a widget:
\snippet clipboard/clipwindow.cpp 0
The slot connected to this signal can read the data on the clipboard
using one of the MIME types that can be used to represent it:
\snippet clipboard/clipwindow.cpp 1
\dots
\snippet clipboard/clipwindow.cpp 2
The \l{QClipboard::selectionChanged()}{selectionChanged()} signal can
be used on X11 to monitor the mouse selection.
\section1 Examples
\list
\li \l{draganddrop/draggableicons}{Draggable Icons}
\li \l{draganddrop/draggabletext}{Draggable Text}
\li \l{draganddrop/dropsite}{Drop Site}
\li \l{draganddrop/fridgemagnets}{Fridge Magnets}
\li \l{draganddrop/puzzle}{Drag and Drop Puzzle}
\endlist
\section1 Interoperating with Other Applications
On X11, the public \l{http://www.newplanetsoftware.com/xdnd/}{XDND
protocol} is used, while on Windows Qt uses the OLE standard, and
Qt for Mac OS X uses the Cocoa Drag Manager. On X11, XDND uses MIME,
so no translation is necessary. The Qt API is the same regardless of
the platform. On Windows, MIME-aware applications can communicate by
using clipboard format names that are MIME types. Already some
Windows applications use MIME naming conventions for their
clipboard formats. Internally, Qt uses QWindowsMime and
QMacPasteboardMime for translating proprietary clipboard formats
to and from MIME types.
*/

View File

@ -158,7 +158,9 @@
QtGui now contains only a small set of enablers, which are generally QtGui now contains only a small set of enablers, which are generally
useful for all graphical applications. useful for all graphical applications.
\section1 Drag and Drop
More info in \l{Drag and Drop}
\section1 Reference \section1 Reference
\list \list

View File

@ -680,8 +680,6 @@ void QXcbDrag::handleEnter(QWindow *window, const xcb_client_message_event_t *ev
DEBUG() << "handleEnter" << window; DEBUG() << "handleEnter" << window;
xdnd_types.clear(); xdnd_types.clear();
// motifdnd_active = false;
// last_enter_event.xclient = xe->xclient;
int version = (int)(event->data.data32[1] >> 24); int version = (int)(event->data.data32[1] >> 24);
if (version > xdnd_version) if (version > xdnd_version)
@ -1217,9 +1215,7 @@ QXcbDropData::~QXcbDropData()
QVariant QXcbDropData::retrieveData_sys(const QString &mimetype, QVariant::Type requestedType) const QVariant QXcbDropData::retrieveData_sys(const QString &mimetype, QVariant::Type requestedType) const
{ {
QByteArray mime = mimetype.toLatin1(); QByteArray mime = mimetype.toLatin1();
QVariant data = /*X11->motifdnd_active QVariant data = xdndObtainData(mime, requestedType);
? X11->motifdndObtainData(mime)
:*/ xdndObtainData(mime, requestedType);
return data; return data;
} }
@ -1260,20 +1256,11 @@ bool QXcbDropData::hasFormat_sys(const QString &format) const
QStringList QXcbDropData::formats_sys() const QStringList QXcbDropData::formats_sys() const
{ {
QStringList formats; QStringList formats;
// if (X11->motifdnd_active) { for (int i = 0; i < drag->xdnd_types.size(); ++i) {
// int i = 0; QString f = mimeAtomToString(drag->connection(), drag->xdnd_types.at(i));
// QByteArray fmt; if (!formats.contains(f))
// while (!(fmt = X11->motifdndFormat(i)).isEmpty()) { formats.append(f);
// formats.append(QLatin1String(fmt)); }
// ++i;
// }
// } else {
for (int i = 0; i < drag->xdnd_types.size(); ++i) {
QString f = mimeAtomToString(drag->connection(), drag->xdnd_types.at(i));
if (!formats.contains(f))
formats.append(f);
}
// }
return formats; return formats;
} }