From 871d74ff77b260ce37782d5f8269d8dcf5213236 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Sun, 1 Nov 2020 16:51:10 +0100 Subject: 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 (cherry picked from commit 4edcea762d9ce334c4c1a78234c90c118b81da87) Reviewed-by: Qt Cherry-pick Bot --- examples/widgets/draganddrop/dropsite/droparea.cpp | 3 +++ examples/widgets/draganddrop/dropsite/dropsitewindow.cpp | 2 ++ 2 files changed, 5 insertions(+) (limited to 'examples') 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(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")) { -- cgit v1.2.1