summaryrefslogtreecommitdiffstats
path: root/tests/manual/wasm
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@gmail.com>2022-04-04 18:08:41 +1000
committerMorten Johan Sørvig <morten.sorvig@qt.io>2022-05-10 01:20:45 +0000
commitd490501641b1f3990382d3ad3523233fdbf3da61 (patch)
tree4b52e4e083c0175a9dad058b8c40345747f8955f /tests/manual/wasm
parent877c158c5976bebffd0ff02c39b6b66a842c6344 (diff)
wasm: add support for drag into browser window
Drag and drop into the browser will work. Drag and drop out of the browser will not. Fixes: QTBUG-102242 Change-Id: Id9981ab6f9514535e1409bec18068790833a67a6 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'tests/manual/wasm')
-rw-r--r--tests/manual/wasm/clipboard/mainwindow.cpp71
-rw-r--r--tests/manual/wasm/clipboard/mainwindow.h5
-rw-r--r--tests/manual/wasm/clipboard/mainwindow.ui14
3 files changed, 83 insertions, 7 deletions
diff --git a/tests/manual/wasm/clipboard/mainwindow.cpp b/tests/manual/wasm/clipboard/mainwindow.cpp
index 2b8a162c2d..a4cb4d0c0d 100644
--- a/tests/manual/wasm/clipboard/mainwindow.cpp
+++ b/tests/manual/wasm/clipboard/mainwindow.cpp
@@ -57,6 +57,8 @@
#include <QRandomGenerator>
#include <QPainter>
#include <QKeyEvent>
+#include <QMimeDatabase>
+#include <QFileInfo>
#ifdef Q_OS_WASM
#include <emscripten.h>
@@ -79,6 +81,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ui->imageLabel->setScaledContents(true);
+ setAcceptDrops(true);
+
clipboard = QGuiApplication::clipboard();
connect(
clipboard, &QClipboard::dataChanged,
@@ -283,5 +287,72 @@ void MainWindow::on_pasteHtmlButton_clicked()
void MainWindow::on_clearButton_clicked()
{
ui->textEdit_2->clear();
+ ui->imageLabel->clear();
+ ui->imageLabel->setText("Paste or drop image here");
}
+void MainWindow::dragEnterEvent(QDragEnterEvent* e)
+{
+ e->acceptProposedAction();
+}
+
+void MainWindow::dropEvent(QDropEvent* e)
+{
+ QString sizeStr;
+ ui->textEdit_2->insertPlainText("New Drop has mime formats: " + e->mimeData()->formats().join(", ") + "\n");
+
+ QString urlMessage = QString(" Drop contains %1 urls\n").arg(e->mimeData()->urls().count());
+ ui->textEdit_2->insertPlainText(urlMessage);
+
+ foreach (const QUrl &url, e->mimeData()->urls()) {
+
+ QString urlStr = url.toDisplayString();
+ int size = urlStr.length();
+ sizeStr.setNum(size);
+ ui->textEdit_2->insertPlainText(" Drop has url data length: " + sizeStr + "\n");
+ ui->textEdit_2->insertPlainText(urlStr + "\n");
+
+ QString fname = url.toLocalFile();
+ QFileInfo info(fname);
+ if (info.exists()) { // this is a file
+ QMimeDatabase db;
+ QMimeType mt = db.mimeTypeForFile(info);
+ if (mt.name().contains("image")) {
+ QImage image = QImage(fname);
+ setImage(image);
+ }
+ }
+ }
+
+ if (e->mimeData()->hasImage()) {
+ qsizetype imageSize = qvariant_cast<QImage>(e->mimeData()->imageData()).sizeInBytes();
+ sizeStr.setNum(imageSize);
+ ui->textEdit_2->insertPlainText(" Drop has Image data length: " + sizeStr + "\n");
+ QImage image = qvariant_cast<QImage>(e->mimeData()->imageData());
+ setImage(image);
+ const QString message = tr("Obtained image from drop, %1x%2, Depth: %3")
+ .arg(image.width()).arg(image.height()).arg(image.depth());
+ statusBar()->showMessage(message);
+ }
+
+ if (e->mimeData()->hasHtml()) {
+ int size = e->mimeData()->html().length();
+ sizeStr.setNum(size);
+ ui->textEdit_2->insertPlainText(" Drop has html data length: " + sizeStr + "\n");
+ ui->textEdit_2->insertPlainText(e->mimeData()->html()+"\n");
+ ui->textEdit->insertHtml(e->mimeData()->html()+"<br>");
+ }
+ if (e->mimeData()->hasText()) {
+ int size = e->mimeData()->text().length();
+ sizeStr.setNum(size);
+ ui->textEdit_2->insertPlainText(" Drop has text data length: " + sizeStr + "\n");
+ ui->textEdit_2->insertPlainText(e->mimeData()->text());
+ }
+
+ const QString message = tr(" Drop accepted, %1 ")
+ .arg(e->mimeData()->formats().join(' '));
+
+ statusBar()->showMessage(message + sizeStr);
+
+ e->acceptProposedAction();
+}
diff --git a/tests/manual/wasm/clipboard/mainwindow.h b/tests/manual/wasm/clipboard/mainwindow.h
index 69e21ba8a2..f4fb04d42f 100644
--- a/tests/manual/wasm/clipboard/mainwindow.h
+++ b/tests/manual/wasm/clipboard/mainwindow.h
@@ -90,5 +90,10 @@ private:
bool eventFilter(QObject *obj, QEvent *event) override;
QColor generateRandomColor();
+
+protected:
+ void dragEnterEvent(QDragEnterEvent *e) override;
+ void dropEvent(QDropEvent *e) override;
+
};
#endif // MAINWINDOW_H
diff --git a/tests/manual/wasm/clipboard/mainwindow.ui b/tests/manual/wasm/clipboard/mainwindow.ui
index 84606598cc..17368fdc68 100644
--- a/tests/manual/wasm/clipboard/mainwindow.ui
+++ b/tests/manual/wasm/clipboard/mainwindow.ui
@@ -144,13 +144,13 @@
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
-&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;meta charset=&quot;utf-8&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;img src=&quot;:/data/qticon64.png&quot; /&gt;&lt;/p&gt;
-&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;a name=&quot;tw-target&quot;&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'monospace'; font-weight:600;&quot;&gt;L&lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-weight:600;&quot;&gt;orem&lt;/span&gt;&lt;span style=&quot; font-family:'monospace';&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-style:italic;&quot;&gt;ipsum&lt;/span&gt;&lt;span style=&quot; font-family:'monospace';&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; text-decoration: underline;&quot;&gt;dolor&lt;/span&gt;&lt;span style=&quot; font-family:'monospace';&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; vertical-align:super;&quot;&gt;sit&lt;/span&gt;&lt;span style=&quot; font-family:'monospace';&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; vertical-align:sub;&quot;&gt;amet&lt;/span&gt;&lt;span style=&quot; font-family:'monospace';&quot;&gt;, &lt;/span&gt;&lt;a href=&quot;http://localhost&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;consectetur&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'monospace';&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; color:#7320a4;&quot;&gt;adipiscing&lt;/span&gt;&lt;span style=&quot; font-family:'monospace';&quot;&gt; elit. Som medlemmer av byrået ønsker imidlertid en eiendomsmegler. Ullamcorper største lekseforfatter. Dolor et consectetuer litt ernæring. Maecenas smile jord sitter Vulputate medlemmer og, basketball ethvert problem. Reservert lever nå propaganda. På makroen investere laoreet kan, av enhver latter. Jasmine som en TV -tegneserie.&lt;/span&gt;&lt;/p&gt;
-&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
-&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'monospace';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;a name=&quot;tw-target&quot;&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt; font-weight:600;&quot;&gt;L&lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt; font-weight:600;&quot;&gt;orem&lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt; font-style:italic;&quot;&gt;ipsum&lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt; text-decoration: underline;&quot;&gt;dolor&lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt; vertical-align:super;&quot;&gt;sit&lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt; vertical-align:sub;&quot;&gt;amet&lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt;&quot;&gt;, &lt;/span&gt;&lt;a href=&quot;http://localhost&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:9pt; text-decoration: underline; color:#0000ff;&quot;&gt;consectetur&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt; color:#7320a4;&quot;&gt;adipiscing&lt;/span&gt;&lt;span style=&quot; font-family:'monospace'; font-size:9pt;&quot;&gt; elit. Som medlemmer av byrået ønsker imidlertid en eiendomsmegler. Ullamcorper største lekseforfatter. Dolor et consectetuer litt ernæring. Maecenas smile jord sitter Vulputate medlemmer og, basketball ethvert problem. Reservert lever nå propaganda. På makroen investere laoreet kan, av enhver latter. Jasmine som en TV -tegneserie.&lt;/span&gt;&lt;/p&gt;
+&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
+&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'monospace'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@@ -172,7 +172,7 @@ p, li { white-space: pre-wrap; }
<enum>QFrame::Raised</enum>
</property>
<property name="text">
- <string>Paste image here</string>
+ <string>Paste or drop content here</string>
</property>
<property name="scaledContents">
<bool>true</bool>
@@ -211,7 +211,7 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>1222</width>
- <height>29</height>
+ <height>24</height>
</rect>
</property>
</widget>