commit fcd6c1567df8527173a892e5a0d82c24126c0dc0
Author: Pavel Sanda <[email protected]>
Date: Thu Sep 17 10:45:00 2026 +0200
Restore "Paste as PDF" on macOS with Qt6
The PDF flavor of the macOS pasteboard is unknown to Qt. LyX makes it
visible by registering its own converter, QMacPasteboardMimeGraphics,
which maps the UTI com.adobe.pdf to the application/pdf mime type. That
class was excluded from Qt6 builds in a9b0f5faae, because Qt6 had dropped
QMacPasteboardMime and it no longer compiled.
Without the converter hasGraphicsContents(PdfGraphicsType) is never true
and LinkBack paste writes an empty file, since getAsGraphics() reads the
PDF mime type for it as well. This is why the feature disappeared when
the macOS builds moved from Qt5 to Qt6 in 2.5.
Qt 6.5 reintroduced the API as the public class QUtiMimeConverter, with
the same four virtual functions under new names. Select the base class by
Qt version, following the scheme already used for the Windows converter
in the same file.
Tested & reviewed by Stephan.
https://www.mail-archive.com/[email protected]/msg226801.html
Assisted-by: Claude Opus 5
---
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 e48087bba6..c4dc059074 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>
@@ -782,12 +788,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)
{}
@@ -830,6 +874,7 @@ public:
ret.append(data.toByteArray());
return ret;
}
+#endif
};
#endif
@@ -1090,7 +1135,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