summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-11-01 16:51:10 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-11-02 19:04:13 +0000
commit871d74ff77b260ce37782d5f8269d8dcf5213236 (patch)
treea95618a47d70f1d9860f91bc94674359169abb0c /examples/widgets
parente962f19067b9970231b58cf1c482ff6655d70796 (diff)
DropSite example: support markdown
If the mime data includes text/markdown, display it decoded in the QLabel, and also display the raw markdown in the table below. QLabel supports markdown since 51cbd5288c85cb4de382cb23d6f5559c2b626126. Ideally we should add proper support for markdown to QMimeData, but it's too late to do that for Qt 5. Change-Id: I2a9998e4b239658fe49f39786e7c4fdd0c08b21a Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 4edcea762d9ce334c4c1a78234c90c118b81da87) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.cpp3
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp2
2 files changed, 5 insertions, 0 deletions
diff --git a/examples/widgets/draganddrop/dropsite/droparea.cpp b/examples/widgets/draganddrop/dropsite/droparea.cpp
index 886bfd6890..19644ed573 100644
--- a/examples/widgets/draganddrop/dropsite/droparea.cpp
+++ b/examples/widgets/draganddrop/dropsite/droparea.cpp
@@ -93,6 +93,9 @@ void DropArea::dropEvent(QDropEvent *event)
//! [dropEvent() function part2]
if (mimeData->hasImage()) {
setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
+ } else if (mimeData->hasFormat(QLatin1String("text/markdown"))) {
+ setText(QString::fromUtf8(mimeData->data(QLatin1String("text/markdown"))));
+ setTextFormat(Qt::MarkdownText);
} else if (mimeData->hasHtml()) {
setText(mimeData->html());
setTextFormat(Qt::RichText);
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
index a937e24a4c..d96ebce2e3 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
@@ -132,6 +132,8 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
QString text;
if (format == QLatin1String("text/plain")) {
text = mimeData->text().simplified();
+ } else if (format == QLatin1String("text/markdown")) {
+ text = QString::fromUtf8(mimeData->data(QLatin1String("text/markdown")));
} else if (format == QLatin1String("text/html")) {
text = mimeData->html().simplified();
} else if (format == QLatin1String("text/uri-list")) {