9#include <QtCore/qtemporarydir.h>
10#include <QtCore/private/qcore_mac_p.h>
11#include <QtWidgets/private/qapplication_p.h>
12#include <QtPrintSupport/qprinter.h>
13#include <QtPrintSupport/qprintengine.h>
14#include <qpa/qplatformprintdevice.h>
16#include <QtPrintSupport/private/qprintengine_mac_p.h>
55- (instancetype)initWithNSPrintInfo:(NSPrintInfo *)nsPrintInfo
63- (
void)printPanelDidEnd:(NSPrintPanel *)printPanel
64 returnCode:(
int)returnCode contextInfo:(
void *)contextInfo
71 if (returnCode == NSModalResponseOK) {
72 PMPrintSession session =
static_cast<PMPrintSession
>(
printInfo.PMPrintSession);
73 PMPrintSettings
settings =
static_cast<PMPrintSettings
>(
printInfo.PMPrintSettings);
75 UInt32 frompage, topage;
78 topage =
qMin(UInt32(INT_MAX), topage);
79 dialog->setFromTo(frompage, topage);
84 if (
dialog->fromPage() == 1 &&
dialog->toPage() == INT_MAX) {
96 PMDestinationType dest;
97 PMSessionGetDestinationType(session,
settings, &dest);
98 if (dest == kPMDestinationFile) {
100 PMSessionCopyDestinationLocation(session,
settings, &
file);
101 UInt8 localFile[2048];
102 CFURLGetFileSystemRepresentation(
file,
true, localFile,
sizeof(localFile));
108 }
else if (dest == kPMDestinationPreview) {
110 auto documentName = printer->
docName();
111 if (documentName.isEmpty())
120 dispatch_async(dispatch_get_main_queue(), ^{
121 [NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:fileName.toNSString()]];
123 }
else if (dest == kPMDestinationProcessPDF) {
124 qWarning(
"Printing workflows are not supported");
125 }
else if (dest == kPMDestinationPrinter) {
126 PMPrinter macPrinter;
127 PMSessionGetCurrentPrinter(session, &macPrinter);
128 QString printerId = QString::fromCFString(PMPrinterGetID(macPrinter)).
trimmed();
137 PMPageFormat pageFormat =
static_cast<PMPageFormat
>([printInfo PMPageFormat]);
139 PMGetPageFormatPaper(pageFormat, &paper);
140 PMOrientation orientation;
141 PMGetOrientation(pageFormat, &orientation);
147 PMPaperGetPPDPaperName(paper, &
key);
148 if (PMPaperGetWidth(paper, &
width) == noErr && PMPaperGetHeight(paper, &
height) == noErr) {
192 const auto dictionary = [NSPrintInfo.sharedPrintInfo dictionary];
193 printInfo = [[NSPrintInfo alloc] initWithDictionary:dictionary];
195 ? NSPaperOrientationLandscape : NSPaperOrientationPortrait;
204 PMPrintSettings
settings =
static_cast<PMPrintSettings
>([
printInfo PMPrintSettings]);
205 PMSetPageRange(
settings,
q->minPage(),
q->maxPage());
207 PMSetFirstPage(
settings,
q->fromPage(),
false);
208 PMSetLastPage(
settings,
q->toPage(),
false);
212 QPrintDialog::PrintDialogOptions qtOptions =
q->options();
213 NSPrintPanelOptions macOptions = NSPrintPanelShowsCopies;
215 macOptions |= NSPrintPanelShowsPageRange;
217 macOptions |= NSPrintPanelShowsPaperSize | NSPrintPanelShowsPageSetupAccessory
218 | NSPrintPanelShowsOrientation;
220 printPanel = [NSPrintPanel printPanel];
229 QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) alloc] initWithNSPrintInfo:printInfo];
232 qWarning(
"QPrintDialog is required to be modal on OS X");
236 "clearCurrentThreadCocoaEventDispatcherInterruptFlag");
238 int rval = [
printPanel runModalWithPrintInfo:printInfo];
239 [delegate printPanelDidEnd:printPanel returnCode:rval contextInfo:q];
242 QWindow *parentWindow =
q->parentWidget()->windowHandle();
243 NSWindow *
window =
static_cast<NSWindow *
>(
qApp->platformNativeInterface()->nativeResourceForWindow(
"nswindow", parentWindow));
245 modalForWindow:window
247 didEndSelector:@selector(printPanelDidEnd:returnCode:contextInfo:)
284 d->closeCocoaPrintPanel();
299 bool isCurrentlyVisible = (
d->printPanel != 0);
301 if (!
visible == !isCurrentlyVisible)
315 d->openCocoaPrintPanel(modality);
319 d->closeCocoaPrintPanel();
327#include "moc_qprintdialog.cpp"
The QAbstractPrintDialog class provides a base implementation for print dialogs used to configure pri...
The QDialog class is the base class of dialog windows.
int result() const
In general returns the modal dialog's result code, Accepted or Rejected.
void done(int result) override
\reimp
\inmodule QtCore \reentrant
QString applicationDisplayName
the user-visible name of this application
Unit
This enum type is used to specify the measurement unit for page layout and margins.
Orientation orientation() const
Returns the page orientation of the page layout.
QPageSize pageSize() const
Returns the page size of the page layout.
bool isValid() const
Returns true if this page size is valid.
QSizeF size(Unit units) const
Returns the size of the page in the required units.
bool isEquivalentTo(const QPageSize &other) const
Returns true if this page is equivalent to the other page, i.e.
virtual bool setPageOrientation(QPageLayout::Orientation orientation)
virtual bool setPageSize(const QPageSize &pageSize)
QPageLayout pageLayout() const
virtual void setPageRanges(const QPageRanges &ranges)
QPrintDialog * printDialog()
NSPrintPanel * printPanel
void closeCocoaPrintPanel()
void openCocoaPrintPanel(Qt::WindowModality modality)
The QPrintDialog class provides a dialog for specifying the printer's configuration.
int exec() override
\reimp
~QPrintDialog()
Destroys the print dialog.
QPrintDialog(QPrinter *printer, QWidget *parent=nullptr)
Constructs a new modal printer dialog for the given printer with the given parent.
QPrintEngine * printEngine() const
QString docName() const
Returns the document name.
void setOutputFileName(const QString &)
Sets the name of the output file to fileName.
QString printerName() const
Returns the printer name.
OutputFormat outputFormat() const
void setPrinterName(const QString &)
Sets the printer name to name.
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString trimmed() const &
\inmodule QtCore \reentrant
QString filePath(const QString &fileName) const
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
static QString outputFile
int qRound(qfloat16 d) noexcept
constexpr const T & qMin(const T &a, const T &b)
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
qreal qt_pointMultiplier(QPageLayout::Unit unit)
#define QT_MANGLE_NAMESPACE(name)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
QFuture< QSet< QString > > dictionary
QSettings settings("MySoft", "Star Runner")
[0]
QFileDialog dialog(this)
[1]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent