commit d4c51b00339bc472e6c7f6aa6f31949c76f6b062
Author: Pavel Sanda <[email protected]>
Date: Thu Sep 17 10:45:00 2026 +0200
Backport fcd6c1567df8 - Restore "Paste as PDF" on macOS with Qt6
---
src/frontends/qt/GuiApplication.cpp | 57 +++++++++++++++++++++++++++++++++----
1 file changed, 51 insertions(+), 6 deletions(-)
diff --git a/src/frontends/qt/GuiApplication.cpp
b/src/frontends/qt/GuiApplication.cpp
index 3e19b24180..24dd9f1765 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -156,8 +156,14 @@ using QWindowsApplication =
QNativeInterface::Private::QWindowsApplication;
# include <objidl.h>
#endif
-#if defined(Q_OS_MAC) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
-#include <QMacPasteboardMime>
+#if defined(Q_OS_MAC)
+# if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
+# include <QtGui/QUtiMimeConverter>
+# define QMACMIME QUtiMimeConverter
+# elif (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+# include <QMacPasteboardMime>
+# define QMACMIME QMacPasteboardMime
+# endif
#endif // Q_OS_MAC
#include <exception>
@@ -798,12 +804,50 @@ public:
//
////////////////////////////////////////////////////////////////////////
-#if defined(Q_OS_MAC) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
-// QMacPasteboardMimeGraphics can only be compiled on Mac.
+#ifdef QMACMIME
+// QMacPasteboardMimeGraphics can only be compiled on Mac. It teaches Qt the
+// com.adobe.pdf UTI, which it does not know about: without this converter
+// the PDF flavor of the pasteboard is invisible to us, and neither "Paste as
+// PDF" nor LinkBack work at all.
-class QMacPasteboardMimeGraphics : public QMacPasteboardMime
+class QMacPasteboardMimeGraphics : public QMACMIME
{
public:
+#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
+ QString utiForMime(QString const & mime) const override
+ {
+ LYXERR(Debug::ACTION, "utiForMime " << mime);
+ if (mime == pdfMimeType())
+ return QLatin1String("com.adobe.pdf");
+ return QString();
+ }
+
+ QString mimeForUti(QString const & uti) const override
+ {
+ LYXERR(Debug::ACTION, "mimeForUti " << uti);
+ if (uti == QLatin1String("com.adobe.pdf"))
+ return pdfMimeType();
+ return QString();
+ }
+
+ QVariant convertToMime(QString const & /*mime*/,
+ QList<QByteArray> const & data, QString const & /*uti*/) const
override
+ {
+ if (data.isEmpty())
+ return QVariant();
+ if (data.count() > 1)
+ qWarning("QMacPasteboardMimeGraphics: Cannot handle
multiple member data");
+ return data.first();
+ }
+
+ QList<QByteArray> convertFromMime(QString const & /*mime*/,
+ QVariant const & data, QString const & /*uti*/) const override
+ {
+ QList<QByteArray> ret;
+ ret.append(data.toByteArray());
+ return ret;
+ }
+#else
QMacPasteboardMimeGraphics()
: QMacPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL)
{}
@@ -846,6 +890,7 @@ public:
ret.append(data.toByteArray());
return ret;
}
+#endif
};
#endif
@@ -1106,7 +1151,7 @@ struct GuiApplication::Private
/// Holds previous application state on Mac
Qt::ApplicationState last_state_;
-#if defined(Q_OS_MAC) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+#ifdef QMACMIME
/// Linkback mime handler for macOS.
QMacPasteboardMimeGraphics mac_pasteboard_mime_;
#endif
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs