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>
This commit is contained in:
parent
877c158c59
commit
d490501641
@ -27,6 +27,7 @@ qt_internal_add_plugin(QWasmIntegrationPlugin
|
||||
qwasmtheme.cpp qwasmtheme.h
|
||||
qwasmwindow.cpp qwasmwindow.h
|
||||
qwasminputcontext.cpp qwasminputcontext.h
|
||||
qwasmdrag.cpp qwasmdrag.h
|
||||
DEFINES
|
||||
QT_EGL_NO_X11
|
||||
QT_NO_FOREACH
|
||||
|
@ -136,6 +136,11 @@ void QWasmCompositor::deregisterEventHandlers()
|
||||
emscripten_set_touchend_callback(canvasSelector.constData(), 0, 0, NULL);
|
||||
emscripten_set_touchmove_callback(canvasSelector.constData(), 0, 0, NULL);
|
||||
emscripten_set_touchcancel_callback(canvasSelector.constData(), 0, 0, NULL);
|
||||
|
||||
val canvas = screen()->canvas();
|
||||
canvas.call<void>("removeEventListener",
|
||||
std::string("drop"),
|
||||
val::module_property("qtDrop"), val(true));
|
||||
}
|
||||
|
||||
void QWasmCompositor::destroy()
|
||||
@ -193,6 +198,13 @@ void QWasmCompositor::initEventHandlers()
|
||||
emscripten_set_touchend_callback(canvasSelector.constData(), (void *)this, 1, &touchCallback);
|
||||
emscripten_set_touchmove_callback(canvasSelector.constData(), (void *)this, 1, &touchCallback);
|
||||
emscripten_set_touchcancel_callback(canvasSelector.constData(), (void *)this, 1, &touchCallback);
|
||||
|
||||
val canvas = screen()->canvas();
|
||||
canvas.call<void>("addEventListener",
|
||||
std::string("drop"),
|
||||
val::module_property("qtDrop"), val(true));
|
||||
canvas.set("data-qtdropcontext", // ? unique
|
||||
emscripten::val(quintptr(reinterpret_cast<void *>(screen()))));
|
||||
}
|
||||
|
||||
void QWasmCompositor::setEnabled(bool enabled)
|
||||
@ -1145,7 +1157,6 @@ bool QWasmCompositor::processMouse(int eventType, const EmscriptenMouseEvent *mo
|
||||
|
||||
if (eventType == EMSCRIPTEN_EVENT_MOUSEDOWN && !accepted)
|
||||
QGuiApplicationPrivate::instance()->closeAllPopups();
|
||||
|
||||
return accepted;
|
||||
}
|
||||
|
||||
|
236
src/plugins/platforms/wasm/qwasmdrag.cpp
Normal file
236
src/plugins/platforms/wasm/qwasmdrag.cpp
Normal file
@ -0,0 +1,236 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2022 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:GPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 or (at your option) any later version
|
||||
** approved by the KDE Free Qt Foundation. The licenses are as published by
|
||||
** the Free Software Foundation and appearing in the file LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwasmdrag.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <QMimeDatabase>
|
||||
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/html5.h>
|
||||
#include <emscripten/val.h>
|
||||
#include <emscripten/bind.h>
|
||||
#include <private/qstdweb_p.h>
|
||||
#include <qpa/qwindowsysteminterface.h>
|
||||
#include <private/qsimpledrag_p.h>
|
||||
#include "qwasmcompositor.h"
|
||||
#include "qwasmeventtranslator.h"
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QMimeData>
|
||||
#include <private/qshapedpixmapdndwindow_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
static void getTextPlainCallback(val m_string)
|
||||
{
|
||||
QWasmDrag *thisDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag());
|
||||
thisDrag->m_mimeData->setText(QString::fromStdString(m_string.as<std::string>()));
|
||||
thisDrag->qWasmDrop();
|
||||
}
|
||||
|
||||
static void getTextUrlCallback(val m_string)
|
||||
{
|
||||
QWasmDrag *thisDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag());
|
||||
thisDrag->m_mimeData->setData(QStringLiteral("text/uri-list"),
|
||||
QByteArray::fromStdString(m_string.as<std::string>()));
|
||||
|
||||
thisDrag->qWasmDrop();
|
||||
}
|
||||
|
||||
static void getTextHtmlCallback(val m_string)
|
||||
{
|
||||
QWasmDrag *thisDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag());
|
||||
thisDrag->m_mimeData->setHtml(QString::fromStdString(m_string.as<std::string>()));
|
||||
|
||||
thisDrag->qWasmDrop();
|
||||
}
|
||||
|
||||
static void dropEvent(val event)
|
||||
{
|
||||
// someone dropped a file into the browser window
|
||||
// event is dataTransfer object
|
||||
// if drop event from outside browser, we do not get any mouse release, maybe mouse move
|
||||
// after the drop event
|
||||
|
||||
// data-context thing was not working here :(
|
||||
QWasmDrag *wasmDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag());
|
||||
|
||||
wasmDrag->m_wasmScreen =
|
||||
reinterpret_cast<QWasmScreen*>(event["target"]["data-qtdropcontext"].as<quintptr>());
|
||||
|
||||
wasmDrag->m_mouseDropPoint = QPoint(event["x"].as<int>(), event["y"].as<int>());
|
||||
if (wasmDrag->m_mimeData)
|
||||
delete wasmDrag->m_mimeData;
|
||||
wasmDrag->m_mimeData = new QMimeData;
|
||||
int button = event["button"].as<int>();
|
||||
wasmDrag->m_qButton = QWasmEventTranslator::translateMouseButton(button);
|
||||
|
||||
wasmDrag->m_keyModifiers = Qt::NoModifier;
|
||||
if (event["altKey"].as<bool>())
|
||||
wasmDrag->m_keyModifiers |= Qt::AltModifier;
|
||||
if (event["ctrlKey"].as<bool>())
|
||||
wasmDrag->m_keyModifiers |= Qt::ControlModifier;
|
||||
if (event["metaKey"].as<bool>())
|
||||
wasmDrag->m_keyModifiers |= Qt::MetaModifier;
|
||||
|
||||
event.call<void>("preventDefault"); // prevent browser from handling drop event
|
||||
|
||||
std::string dEffect = event["dataTransfer"]["dropEffect"].as<std::string>();
|
||||
|
||||
wasmDrag->m_dropActions = Qt::IgnoreAction;
|
||||
if (dEffect == "copy")
|
||||
wasmDrag->m_dropActions = Qt::CopyAction;
|
||||
if (dEffect == "move")
|
||||
wasmDrag->m_dropActions = Qt::MoveAction;
|
||||
if (dEffect == "link")
|
||||
wasmDrag->m_dropActions = Qt::LinkAction;
|
||||
|
||||
val dt = event["dataTransfer"]["items"]["length"];
|
||||
|
||||
val typesCount = event["dataTransfer"]["types"]["length"];
|
||||
|
||||
// handle mimedata
|
||||
int count = dt.as<int>();
|
||||
wasmDrag->m_mimeTypesCount = count;
|
||||
// kind is file type: file or string
|
||||
for (int i=0; i < count; i++) {
|
||||
val item = event["dataTransfer"]["items"][i];
|
||||
val kind = item["kind"];
|
||||
val fileType = item["type"];
|
||||
|
||||
if (kind.as<std::string>() == "file") {
|
||||
val m_file = item.call<val>("getAsFile");
|
||||
if (m_file.isUndefined()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qstdweb::File file(m_file);
|
||||
|
||||
QString mimeFormat = QString::fromStdString(file.type());
|
||||
QByteArray fileContent;
|
||||
fileContent.resize(file.size());
|
||||
|
||||
file.stream(fileContent.data(), [=]() {
|
||||
if (!fileContent.isEmpty()) {
|
||||
|
||||
if (mimeFormat.contains("image")) {
|
||||
QImage image;
|
||||
image.loadFromData(fileContent, nullptr);
|
||||
wasmDrag->m_mimeData->setImageData(image);
|
||||
} else {
|
||||
wasmDrag->m_mimeData->setData(mimeFormat, fileContent.data());
|
||||
}
|
||||
wasmDrag->qWasmDrop();
|
||||
}
|
||||
});
|
||||
|
||||
} else { // string
|
||||
|
||||
if (fileType.as<std::string>() == "text/uri-list"
|
||||
|| fileType.as<std::string>() == "text/x-moz-url") {
|
||||
item.call<val>("getAsString", val::module_property("qtgetTextUrl"));
|
||||
} else if (fileType.as<std::string>() == "text/html") {
|
||||
item.call<val>("getAsString", val::module_property("qtgetTextHtml"));
|
||||
} else { // handle everything else here as plain text
|
||||
item.call<val>("getAsString", val::module_property("qtgetTextPlain"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(drop_module) {
|
||||
function("qtDrop", &dropEvent);
|
||||
function("qtgetTextPlain", &getTextPlainCallback);
|
||||
function("qtgetTextUrl", &getTextUrlCallback);
|
||||
function("qtgetTextHtml", &getTextHtmlCallback);
|
||||
}
|
||||
|
||||
|
||||
QWasmDrag::QWasmDrag()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
QWasmDrag::~QWasmDrag()
|
||||
{
|
||||
if (m_mimeData)
|
||||
delete m_mimeData;
|
||||
}
|
||||
|
||||
void QWasmDrag::init()
|
||||
{
|
||||
}
|
||||
|
||||
void QWasmDrag::drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
|
||||
{
|
||||
QSimpleDrag::drop(globalPos, b, mods);
|
||||
}
|
||||
|
||||
void QWasmDrag::move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
|
||||
{
|
||||
QSimpleDrag::move(globalPos, b, mods);
|
||||
}
|
||||
|
||||
void QWasmDrag::qWasmDrop()
|
||||
{
|
||||
// collect mime
|
||||
QWasmDrag *thisDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag());
|
||||
|
||||
if (thisDrag->m_mimeTypesCount != thisDrag->m_mimeData->formats().size())
|
||||
return; // keep collecting mimetypes
|
||||
|
||||
// start drag enter
|
||||
QWindowSystemInterface::handleDrag(thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint),
|
||||
thisDrag->m_mimeData,
|
||||
thisDrag->m_mouseDropPoint,
|
||||
thisDrag->m_dropActions,
|
||||
thisDrag->m_qButton,
|
||||
thisDrag->m_keyModifiers);
|
||||
|
||||
// drag drop
|
||||
QWindowSystemInterface::handleDrop(thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint),
|
||||
thisDrag->m_mimeData,
|
||||
thisDrag->m_mouseDropPoint,
|
||||
thisDrag->m_dropActions,
|
||||
thisDrag->m_qButton,
|
||||
thisDrag->m_keyModifiers);
|
||||
|
||||
// drag leave
|
||||
QWindowSystemInterface::handleDrag(thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint),
|
||||
nullptr,
|
||||
QPoint(),
|
||||
Qt::IgnoreAction, { }, { });
|
||||
|
||||
thisDrag->m_mimeData->clear();
|
||||
thisDrag->m_mimeTypesCount = 0;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
69
src/plugins/platforms/wasm/qwasmdrag.h
Normal file
69
src/plugins/platforms/wasm/qwasmdrag.h
Normal file
@ -0,0 +1,69 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2022 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:GPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 or (at your option) any later version
|
||||
** approved by the KDE Free Qt Foundation. The licenses are as published by
|
||||
** the Free Software Foundation and appearing in the file LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWASMDRAG_H
|
||||
#define QWASMDRAG_H
|
||||
|
||||
#include <qpa/qplatformdrag.h>
|
||||
#include <private/qsimpledrag_p.h>
|
||||
#include <private/qstdweb_p.h>
|
||||
#include <QDrag>
|
||||
#include "qwasmscreen.h"
|
||||
|
||||
QT_REQUIRE_CONFIG(draganddrop);
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWasmDrag : public QSimpleDrag
|
||||
{
|
||||
public:
|
||||
|
||||
QWasmDrag();
|
||||
~QWasmDrag();
|
||||
|
||||
void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
|
||||
void move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
|
||||
|
||||
Qt::MouseButton m_qButton;
|
||||
QPoint m_mouseDropPoint;
|
||||
QFlags<Qt::KeyboardModifier> m_keyModifiers;
|
||||
Qt::DropActions m_dropActions;
|
||||
QWasmScreen *m_wasmScreen = nullptr;
|
||||
int m_mimeTypesCount = 0;
|
||||
QMimeData *m_mimeData = nullptr;
|
||||
void qWasmDrop();
|
||||
|
||||
private:
|
||||
void init();
|
||||
};
|
||||
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWASMDRAG_H
|
@ -57,7 +57,7 @@
|
||||
|
||||
// this is where EGL headers are pulled in, make sure it is last
|
||||
#include "qwasmscreen.h"
|
||||
|
||||
#include <private/qsimpledrag_p.h>
|
||||
using namespace emscripten;
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -176,6 +176,7 @@ QWasmIntegration::QWasmIntegration()
|
||||
visualViewport.call<void>("addEventListener", val("resize"),
|
||||
val::module_property("qtResizeAllScreens"));
|
||||
}
|
||||
m_drag = new QWasmDrag();
|
||||
}
|
||||
|
||||
QWasmIntegration::~QWasmIntegration()
|
||||
@ -192,6 +193,7 @@ QWasmIntegration::~QWasmIntegration()
|
||||
delete m_desktopServices;
|
||||
if (m_platformInputContext)
|
||||
delete m_platformInputContext;
|
||||
delete m_drag;
|
||||
|
||||
for (const auto &elementAndScreen : m_screens)
|
||||
QWindowSystemInterface::handleScreenRemoved(elementAndScreen.second);
|
||||
@ -374,4 +376,11 @@ quint64 QWasmIntegration::getTimestamp()
|
||||
return emscripten_performance_now();
|
||||
}
|
||||
|
||||
#if QT_CONFIG(draganddrop)
|
||||
QPlatformDrag *QWasmIntegration::drag() const
|
||||
{
|
||||
return m_drag;
|
||||
}
|
||||
#endif // QT_CONFIG(draganddrop)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -45,6 +45,10 @@
|
||||
#include "qwasminputcontext.h"
|
||||
#include <private/qstdweb_p.h>
|
||||
|
||||
#if QT_CONFIG(draganddrop)
|
||||
#include "qwasmdrag.h"
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWasmEventTranslator;
|
||||
@ -91,6 +95,10 @@ public:
|
||||
void initialize() override;
|
||||
QPlatformInputContext *inputContext() const override;
|
||||
|
||||
#if QT_CONFIG(draganddrop)
|
||||
QPlatformDrag *drag() const override;
|
||||
#endif
|
||||
|
||||
QWasmClipboard *getWasmClipboard() { return m_clipboard; }
|
||||
QWasmInputContext *getWasmInputContext() { return m_platformInputContext; }
|
||||
static QWasmIntegration *get() { return s_instance; }
|
||||
@ -117,6 +125,11 @@ private:
|
||||
static QWasmIntegration *s_instance;
|
||||
|
||||
mutable QWasmInputContext *m_platformInputContext = nullptr;
|
||||
|
||||
#if QT_CONFIG(draganddrop)
|
||||
QWasmDrag *m_drag;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -58,6 +58,11 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmCompositor *compositor, QWasmBackingSt
|
||||
|
||||
// Pure OpenGL windows draw directly using egl, disable the compositor.
|
||||
m_compositor->setEnabled(w->surfaceType() != QSurface::OpenGLSurface);
|
||||
|
||||
static std::unique_ptr<qstdweb::EventCallback> windowResizeEvent;
|
||||
auto resizeCallback = [=](emscripten::val) { QPlatformWindow::requestActivateWindow();};
|
||||
windowResizeEvent.reset(new qstdweb::EventCallback(emscripten::val::global("window"),
|
||||
"resize", resizeCallback));
|
||||
}
|
||||
|
||||
QWasmWindow::~QWasmWindow()
|
||||
@ -243,6 +248,7 @@ QRegion QWasmWindow::titleGeometry() const
|
||||
|
||||
QRegion QWasmWindow::resizeRegion() const
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
int border = borderWidth();
|
||||
QRegion result(window()->frameGeometry().adjusted(-border, -border, border, border));
|
||||
result -= window()->frameGeometry().adjusted(border, border, -border, -border);
|
||||
@ -417,6 +423,7 @@ qreal QWasmWindow::devicePixelRatio() const
|
||||
|
||||
void QWasmWindow::requestUpdate()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if (m_compositor) {
|
||||
m_compositor->requestUpdateWindow(this, QWasmCompositor::UpdateRequestDelivery);
|
||||
return;
|
||||
@ -451,6 +458,7 @@ bool QWasmWindow::windowIsPopupType(Qt::WindowFlags flags) const
|
||||
|
||||
void QWasmWindow::requestActivateWindow()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if (window()->isTopLevel())
|
||||
raise();
|
||||
QPlatformWindow::requestActivateWindow();
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -144,13 +144,13 @@
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
</style></head><body style=" font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><img src=":/data/qticon64.png" /></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a name="tw-target"></a><span style=" font-family:'monospace'; font-weight:600;">L</span><span style=" font-family:'monospace'; font-weight:600;">orem</span><span style=" font-family:'monospace';"> </span><span style=" font-family:'monospace'; font-style:italic;">ipsum</span><span style=" font-family:'monospace';"> </span><span style=" font-family:'monospace'; text-decoration: underline;">dolor</span><span style=" font-family:'monospace';"> </span><span style=" font-family:'monospace'; vertical-align:super;">sit</span><span style=" font-family:'monospace';"> </span><span style=" font-family:'monospace'; vertical-align:sub;">amet</span><span style=" font-family:'monospace';">, </span><a href="http://localhost"><span style=" text-decoration: underline; color:#0000ff;">consectetur</span></a><span style=" font-family:'monospace';"> </span><span style=" font-family:'monospace'; color:#7320a4;">adipiscing</span><span style=" font-family:'monospace';"> 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.</span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
|
||||
<p style="-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';"><br /></p></body></html></string>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a name="tw-target"></a><span style=" font-family:'monospace'; font-size:9pt; font-weight:600;">L</span><span style=" font-family:'monospace'; font-size:9pt; font-weight:600;">orem</span><span style=" font-family:'monospace'; font-size:9pt;"> </span><span style=" font-family:'monospace'; font-size:9pt; font-style:italic;">ipsum</span><span style=" font-family:'monospace'; font-size:9pt;"> </span><span style=" font-family:'monospace'; font-size:9pt; text-decoration: underline;">dolor</span><span style=" font-family:'monospace'; font-size:9pt;"> </span><span style=" font-family:'monospace'; font-size:9pt; vertical-align:super;">sit</span><span style=" font-family:'monospace'; font-size:9pt;"> </span><span style=" font-family:'monospace'; font-size:9pt; vertical-align:sub;">amet</span><span style=" font-family:'monospace'; font-size:9pt;">, </span><a href="http://localhost"><span style=" font-family:'Sans Serif'; font-size:9pt; text-decoration: underline; color:#0000ff;">consectetur</span></a><span style=" font-family:'monospace'; font-size:9pt;"> </span><span style=" font-family:'monospace'; font-size:9pt; color:#7320a4;">adipiscing</span><span style=" font-family:'monospace'; font-size:9pt;"> 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.</span></p>
|
||||
<p style="-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;"><br /></p>
|
||||
<p style="-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;"><br /></p></body></html></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>
|
||||
|
Loading…
Reference in New Issue
Block a user