Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Add handling of "application/x-qt-image-has-alpha"

Dmitry Kazakov178da930544f
diff --git a/libs/ui/kis_mimedata.cpp b/libs/ui/kis_mimedata.cpp
index cb4aefe0fb..d5ae48f92f 100644
--- a/libs/ui/kis_mimedata.cpp
+++ b/libs/ui/kis_mimedata.cpp
@@ -145,6 +145,7 @@ QStringList KisMimeData::formats () const
QStringList f = QMimeData::formats();
if (m_nodes.size() > 0) {
f << "application/x-qt-image"
+ << "application/x-qt-image-has-alpha"
<< "application/zip"
<< "application/x-krita-node-internal-pointer";
}
@@ -314,6 +315,22 @@ QVariant KisMimeData::retrieveData(const QString &mimetype, QMetaType preferredT
result.setDotsPerMeterY(qRound(image->yRes() * 72.0 / 2.54 * 100.0));
return result;
}
+ else if (mimetype == "application/x-qt-image-has-alpha") {
+ /**
+ * In Krita, when adding an image to the clipboard (via "application/x-qt-image"),
+ * we **always** add alpha channel. We need to notify Qt about that separately, to
+ * make sure Qt does not request "application/x-qt-image" to build the entire QImage
+ * every time we add something to clipboard.
+ *
+ * [Windows-only] If we don't do that, for biggger imaged Krita may hang up for
+ * 500-800ms every time we create a mime data, i.e. press Ctrl+C or start D&D
+ * operation.
+ *
+ * NOTE: this mime type is a custom type that we patch into our version of Qt,
+ * it is not present upstream!
+ */
+ return QByteArray("1");
+ }
else if (mimetype == "application/zip") {
QByteArray result;