Run clang-format on qwasmdrag.h/.cpp

Change-Id: Id67238566b6e25d8bf1645b5b83d898622eb5f89
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Mikolaj Boc 2022-12-20 16:51:38 +01:00
parent 3e78331dac
commit 0f18dadd5d
2 changed files with 26 additions and 35 deletions

View File

@ -25,23 +25,23 @@ using namespace emscripten;
static void getTextPlainCallback(val m_string) static void getTextPlainCallback(val m_string)
{ {
QWasmDrag *thisDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag()); QWasmDrag *thisDrag = static_cast<QWasmDrag *>(QWasmIntegration::get()->drag());
thisDrag->m_mimeData->setText(QString::fromStdString(m_string.as<std::string>())); thisDrag->m_mimeData->setText(QString::fromStdString(m_string.as<std::string>()));
thisDrag->qWasmDrop(); thisDrag->qWasmDrop();
} }
static void getTextUrlCallback(val m_string) static void getTextUrlCallback(val m_string)
{ {
QWasmDrag *thisDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag()); QWasmDrag *thisDrag = static_cast<QWasmDrag *>(QWasmIntegration::get()->drag());
thisDrag->m_mimeData->setData(QStringLiteral("text/uri-list"), thisDrag->m_mimeData->setData(QStringLiteral("text/uri-list"),
QByteArray::fromStdString(m_string.as<std::string>())); QByteArray::fromStdString(m_string.as<std::string>()));
thisDrag->qWasmDrop(); thisDrag->qWasmDrop();
} }
static void getTextHtmlCallback(val m_string) static void getTextHtmlCallback(val m_string)
{ {
QWasmDrag *thisDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag()); QWasmDrag *thisDrag = static_cast<QWasmDrag *>(QWasmIntegration::get()->drag());
thisDrag->m_mimeData->setHtml(QString::fromStdString(m_string.as<std::string>())); thisDrag->m_mimeData->setHtml(QString::fromStdString(m_string.as<std::string>()));
thisDrag->qWasmDrop(); thisDrag->qWasmDrop();
@ -55,10 +55,10 @@ static void dropEvent(val event)
// after the drop event // after the drop event
// data-context thing was not working here :( // data-context thing was not working here :(
QWasmDrag *wasmDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag()); QWasmDrag *wasmDrag = static_cast<QWasmDrag *>(QWasmIntegration::get()->drag());
wasmDrag->m_wasmScreen = wasmDrag->m_wasmScreen =
reinterpret_cast<QWasmScreen*>(event["target"]["data-qtdropcontext"].as<quintptr>()); reinterpret_cast<QWasmScreen *>(event["target"]["data-qtdropcontext"].as<quintptr>());
wasmDrag->m_mouseDropPoint = QPoint(event["x"].as<int>(), event["y"].as<int>()); wasmDrag->m_mouseDropPoint = QPoint(event["x"].as<int>(), event["y"].as<int>());
wasmDrag->m_mimeData = std::make_unique<QMimeData>(); wasmDrag->m_mimeData = std::make_unique<QMimeData>();
@ -78,11 +78,11 @@ static void dropEvent(val event)
wasmDrag->m_dropActions = Qt::IgnoreAction; wasmDrag->m_dropActions = Qt::IgnoreAction;
if (dEffect == "copy") if (dEffect == "copy")
wasmDrag->m_dropActions = Qt::CopyAction; wasmDrag->m_dropActions = Qt::CopyAction;
if (dEffect == "move") if (dEffect == "move")
wasmDrag->m_dropActions = Qt::MoveAction; wasmDrag->m_dropActions = Qt::MoveAction;
if (dEffect == "link") if (dEffect == "link")
wasmDrag->m_dropActions = Qt::LinkAction; wasmDrag->m_dropActions = Qt::LinkAction;
val dt = event["dataTransfer"]["items"]["length"]; val dt = event["dataTransfer"]["items"]["length"];
@ -92,7 +92,7 @@ static void dropEvent(val event)
int count = dt.as<int>(); int count = dt.as<int>();
wasmDrag->m_mimeTypesCount = count; wasmDrag->m_mimeTypesCount = count;
// kind is file type: file or string // kind is file type: file or string
for (int i=0; i < count; i++) { for (int i = 0; i < count; i++) {
val item = event["dataTransfer"]["items"][i]; val item = event["dataTransfer"]["items"][i];
val kind = item["kind"]; val kind = item["kind"];
val fileType = item["type"]; val fileType = item["type"];
@ -126,7 +126,7 @@ static void dropEvent(val event)
} else { // string } else { // string
if (fileType.as<std::string>() == "text/uri-list" if (fileType.as<std::string>() == "text/uri-list"
|| fileType.as<std::string>() == "text/x-moz-url") { || fileType.as<std::string>() == "text/x-moz-url") {
item.call<val>("getAsString", val::module_property("qtgetTextUrl")); item.call<val>("getAsString", val::module_property("qtgetTextUrl"));
} else if (fileType.as<std::string>() == "text/html") { } else if (fileType.as<std::string>() == "text/html") {
item.call<val>("getAsString", val::module_property("qtgetTextHtml")); item.call<val>("getAsString", val::module_property("qtgetTextHtml"));
@ -137,14 +137,14 @@ static void dropEvent(val event)
} }
} }
EMSCRIPTEN_BINDINGS(drop_module) { EMSCRIPTEN_BINDINGS(drop_module)
{
function("qtDrop", &dropEvent); function("qtDrop", &dropEvent);
function("qtgetTextPlain", &getTextPlainCallback); function("qtgetTextPlain", &getTextPlainCallback);
function("qtgetTextUrl", &getTextUrlCallback); function("qtgetTextUrl", &getTextUrlCallback);
function("qtgetTextHtml", &getTextHtmlCallback); function("qtgetTextHtml", &getTextHtmlCallback);
} }
QWasmDrag::QWasmDrag() QWasmDrag::QWasmDrag()
{ {
init(); init();
@ -152,9 +152,7 @@ QWasmDrag::QWasmDrag()
QWasmDrag::~QWasmDrag() = default; QWasmDrag::~QWasmDrag() = default;
void QWasmDrag::init() void QWasmDrag::init() { }
{
}
void QWasmDrag::drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) void QWasmDrag::drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
{ {
@ -169,32 +167,27 @@ void QWasmDrag::move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardMo
void QWasmDrag::qWasmDrop() void QWasmDrag::qWasmDrop()
{ {
// collect mime // collect mime
QWasmDrag *thisDrag = static_cast<QWasmDrag*>(QWasmIntegration::get()->drag()); QWasmDrag *thisDrag = static_cast<QWasmDrag *>(QWasmIntegration::get()->drag());
if (thisDrag->m_mimeTypesCount != thisDrag->m_mimeData->formats().size()) if (thisDrag->m_mimeTypesCount != thisDrag->m_mimeData->formats().size())
return; // keep collecting mimetypes return; // keep collecting mimetypes
// start drag enter // start drag enter
QWindowSystemInterface::handleDrag(thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint), QWindowSystemInterface::handleDrag(
thisDrag->m_mimeData.get(), thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint),
thisDrag->m_mouseDropPoint, thisDrag->m_mimeData.get(), thisDrag->m_mouseDropPoint, thisDrag->m_dropActions,
thisDrag->m_dropActions, thisDrag->m_qButton, thisDrag->m_keyModifiers);
thisDrag->m_qButton,
thisDrag->m_keyModifiers);
// drag drop // drag drop
QWindowSystemInterface::handleDrop(thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint), QWindowSystemInterface::handleDrop(
thisDrag->m_mimeData.get(), thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint),
thisDrag->m_mouseDropPoint, thisDrag->m_mimeData.get(), thisDrag->m_mouseDropPoint, thisDrag->m_dropActions,
thisDrag->m_dropActions, thisDrag->m_qButton, thisDrag->m_keyModifiers);
thisDrag->m_qButton,
thisDrag->m_keyModifiers);
// drag leave // drag leave
QWindowSystemInterface::handleDrag(thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint), QWindowSystemInterface::handleDrag(
nullptr, thisDrag->m_wasmScreen->topLevelAt(thisDrag->m_mouseDropPoint), nullptr, QPoint(),
QPoint(), Qt::IgnoreAction, {}, {});
Qt::IgnoreAction, { }, { });
thisDrag->m_mimeData->clear(); thisDrag->m_mimeData->clear();
thisDrag->m_mimeTypesCount = 0; thisDrag->m_mimeTypesCount = 0;

View File

@ -17,7 +17,6 @@ QT_BEGIN_NAMESPACE
class QWasmDrag : public QSimpleDrag class QWasmDrag : public QSimpleDrag
{ {
public: public:
QWasmDrag(); QWasmDrag();
~QWasmDrag(); ~QWasmDrag();
@ -37,7 +36,6 @@ private:
void init(); void init();
}; };
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QWASMDRAG_H #endif // QWASMDRAG_H