summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-11-01 16:51:10 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2020-11-02 16:08:36 +0100
commit4edcea762d9ce334c4c1a78234c90c118b81da87 (patch)
tree7f9b44bf1b680f4591cdf554fe357e19cd070d09 /examples/widgets
parent93ac7b9d174d8ba2fcd9762c3ac836c3a1b000f3 (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. Pick-to: 5.15 Change-Id: I2a9998e4b239658fe49f39786e7c4fdd0c08b21a Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
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")) {