Doc: Compile droparea snippet

droparea.h has been removed. Remove all code that depends on that header
except the one snippet that is still used. Add minimal code to allow
the snippet to be compiled.

Done-with: Nico Vertriest <nico.vertriest@qt.io>
Task-number: QTBUG-81486
Change-Id: I58c80d3527c82389ccff97567f4c75c33aec0f5e
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
This commit is contained in:
Paul Wicking 2020-08-29 07:11:10 +02:00
parent e596f15a45
commit 03887ab8a3
4 changed files with 21 additions and 81 deletions

View File

@ -47,55 +47,18 @@
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QApplication>
#include <QClipboard>
#include <QMimeData>
#include <QWidget>
#include <QtGui>
#include "droparea.h"
DropArea::DropArea(QWidget *parent)
: QLabel(parent)
{
setMinimumSize(200, 200);
setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
setAlignment(Qt::AlignCenter);
setAcceptDrops(true);
setAutoFillBackground(true);
clear();
}
void DropArea::dragEnterEvent(QDragEnterEvent *event)
{
setText(tr("<drop content>"));
setBackgroundRole(QPalette::Highlight);
event->acceptProposedAction();
emit changed(event->mimeData());
}
void DropArea::dragMoveEvent(QDragMoveEvent *event)
{
event->acceptProposedAction();
}
void DropArea::dropEvent(QDropEvent *event)
{
const QMimeData *mimeData = event->mimeData();
if (mimeData->hasImage()) {
setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
} else if (mimeData->hasHtml()) {
setText(mimeData->html());
setTextFormat(Qt::RichText);
} else if (mimeData->hasText()) {
setText(mimeData->text());
setTextFormat(Qt::PlainText);
} else {
setText(tr("Cannot display data"));
}
setBackgroundRole(QPalette::Dark);
event->acceptProposedAction();
}
namespace droparea {
struct DropArea : public QWidget {
void paste();
void setPixmap(QPixmap);
void setText(QString);
void setTextFormat(Qt::TextFormat);
};
//![0]
void DropArea::paste()
@ -114,37 +77,7 @@ void DropArea::paste()
} else {
setText(tr("Cannot display data"));
}
}
//![0]
emit changed(mimeData);
setBackgroundRole(QPalette::Dark);
//event->acceptProposedAction();
}
void DropArea::dragLeaveEvent(QDragLeaveEvent *event)
{
clear();
event->accept();
}
void DropArea::clear()
{
setText(tr("<drop content>"));
setBackgroundRole(QPalette::Dark);
emit changed();
}
QPixmap DropArea::extractPixmap(const QByteArray &data, const QString &format)
{
const QList<QByteArray> imageFormats = QImageReader::supportedImageFormats();
QPixmap pixmap;
for (const QByteArray &imageFormat : imageFormats) {
if (format.mid(6) == QString(imageFormat)) {
pixmap.loadFromData(data, imageFormat);
break;
}
}
return pixmap;
}
} // droparea

View File

@ -0,0 +1,6 @@
TEMPLATE = lib
TARGET = droparea_snippets
QT += core gui widgets
SOURCES = \
droparea.cpp

View File

@ -7,6 +7,7 @@ contains(QT_BUILD_PARTS, tests) {
clipboard \
code \
draganddrop \
droparea \
qfontdatabase \
textdocument-blocks \
textdocument-charformats \

View File

@ -83,7 +83,7 @@ QT_BEGIN_NAMESPACE
A typical example of the use of these functions follows:
\snippet droparea.cpp 0
\snippet droparea/droparea.cpp 0
\section1 Notes for X11 Users