summaryrefslogtreecommitdiffstats
path: root/src/printsupport
diff options
context:
space:
mode:
Diffstat (limited to 'src/printsupport')
-rw-r--r--src/printsupport/CMakeLists.txt203
-rw-r--r--src/printsupport/configure.cmake69
-rw-r--r--src/printsupport/configure.json102
-rw-r--r--src/printsupport/dialogs/dialogs.pri46
-rw-r--r--src/printsupport/dialogs/images/printer-24.png (renamed from src/printsupport/dialogs/images/print-24.png)bin914 -> 914 bytes
-rw-r--r--src/printsupport/dialogs/images/printer-32.png (renamed from src/printsupport/dialogs/images/print-32.png)bin1202 -> 1202 bytes
-rw-r--r--src/printsupport/dialogs/images/view-pages-facing-24.png (renamed from src/printsupport/dialogs/images/view-page-sided-24.png)bin700 -> 700 bytes
-rw-r--r--src/printsupport/dialogs/images/view-pages-facing-32.png (renamed from src/printsupport/dialogs/images/view-page-sided-32.png)bin908 -> 908 bytes
-rw-r--r--src/printsupport/dialogs/images/view-pages-overview-24.png (renamed from src/printsupport/dialogs/images/view-page-multi-24.png)bin390 -> 390 bytes
-rw-r--r--src/printsupport/dialogs/images/view-pages-overview-32.png (renamed from src/printsupport/dialogs/images/view-page-multi-32.png)bin556 -> 556 bytes
-rw-r--r--src/printsupport/dialogs/images/view-pages-single-24.png (renamed from src/printsupport/dialogs/images/view-page-one-24.png)bin662 -> 662 bytes
-rw-r--r--src/printsupport/dialogs/images/view-pages-single-32.png (renamed from src/printsupport/dialogs/images/view-page-one-32.png)bin810 -> 810 bytes
-rw-r--r--src/printsupport/dialogs/images/zoom-fit-page-24.png (renamed from src/printsupport/dialogs/images/fit-page-24.png)bin985 -> 985 bytes
-rw-r--r--src/printsupport/dialogs/images/zoom-fit-page-32.png (renamed from src/printsupport/dialogs/images/fit-page-32.png)bin1330 -> 1330 bytes
-rw-r--r--src/printsupport/dialogs/images/zoom-fit-width-24.png (renamed from src/printsupport/dialogs/images/fit-width-24.png)bin706 -> 706 bytes
-rw-r--r--src/printsupport/dialogs/images/zoom-fit-width-32.png (renamed from src/printsupport/dialogs/images/fit-width-32.png)bin1004 -> 1004 bytes
-rw-r--r--src/printsupport/dialogs/qabstractprintdialog.cpp101
-rw-r--r--src/printsupport/dialogs/qabstractprintdialog.h51
-rw-r--r--src/printsupport/dialogs/qabstractprintdialog_p.h42
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog.cpp42
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog.h42
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_mac.mm54
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_p.h40
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_unix.cpp122
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_unix_p.h40
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_win.cpp87
-rw-r--r--src/printsupport/dialogs/qprintdialog.h40
-rw-r--r--src/printsupport/dialogs/qprintdialog.qdoc28
-rw-r--r--src/printsupport/dialogs/qprintdialog.qrc38
-rw-r--r--src/printsupport/dialogs/qprintdialog_mac.mm125
-rw-r--r--src/printsupport/dialogs/qprintdialog_unix.cpp296
-rw-r--r--src/printsupport/dialogs/qprintdialog_win.cpp110
-rw-r--r--src/printsupport/dialogs/qprintpreviewdialog.cpp140
-rw-r--r--src/printsupport/dialogs/qprintpreviewdialog.h40
-rw-r--r--src/printsupport/dialogs/qprintsettingsoutput.ui8
-rw-r--r--src/printsupport/doc/qtprintsupport.qdocconf15
-rw-r--r--src/printsupport/doc/snippets/CMakeLists.txt7
-rw-r--r--src/printsupport/doc/snippets/code/doc_src_qtprintsupport.cpp53
-rw-r--r--src/printsupport/doc/snippets/code/doc_src_qtprintsupport.pro3
-rw-r--r--src/printsupport/doc/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp51
-rw-r--r--src/printsupport/doc/snippets/printing-qprinter/errors.cpp57
-rw-r--r--src/printsupport/doc/snippets/printing-qprinter/object.cpp58
-rw-r--r--src/printsupport/doc/snippets/snippets.pro3
-rw-r--r--src/printsupport/doc/snippets/widgetprinting.cpp85
-rw-r--r--src/printsupport/doc/src/dontdocument.qdoc6
-rw-r--r--src/printsupport/doc/src/qt6-changes.qdoc28
-rw-r--r--src/printsupport/doc/src/qtprintsupport-index.qdoc100
-rw-r--r--src/printsupport/doc/src/qtprintsupport-module.qdoc41
-rw-r--r--src/printsupport/kernel/kernel.pri42
-rw-r--r--src/printsupport/kernel/qcups.cpp110
-rw-r--r--src/printsupport/kernel/qcups_p.h58
-rw-r--r--src/printsupport/kernel/qpaintengine_alpha.cpp62
-rw-r--r--src/printsupport/kernel/qpaintengine_alpha_p.h44
-rw-r--r--src/printsupport/kernel/qpaintengine_preview.cpp40
-rw-r--r--src/printsupport/kernel/qpaintengine_preview_p.h40
-rw-r--r--src/printsupport/kernel/qplatformprintdevice.cpp94
-rw-r--r--src/printsupport/kernel/qplatformprintdevice.h60
-rw-r--r--src/printsupport/kernel/qplatformprintersupport.cpp48
-rw-r--r--src/printsupport/kernel/qplatformprintersupport.h40
-rw-r--r--src/printsupport/kernel/qplatformprintplugin.cpp52
-rw-r--r--src/printsupport/kernel/qplatformprintplugin.h42
-rw-r--r--src/printsupport/kernel/qprint.cpp159
-rw-r--r--src/printsupport/kernel/qprint_p.h191
-rw-r--r--src/printsupport/kernel/qprintdevice.cpp56
-rw-r--r--src/printsupport/kernel/qprintdevice_p.h50
-rw-r--r--src/printsupport/kernel/qprintengine.h41
-rw-r--r--src/printsupport/kernel/qprintengine_pdf.cpp78
-rw-r--r--src/printsupport/kernel/qprintengine_pdf_p.h46
-rw-r--r--src/printsupport/kernel/qprinter.cpp685
-rw-r--r--src/printsupport/kernel/qprinter.h97
-rw-r--r--src/printsupport/kernel/qprinter_p.h51
-rw-r--r--src/printsupport/kernel/qprinterinfo.cpp118
-rw-r--r--src/printsupport/kernel/qprinterinfo.h49
-rw-r--r--src/printsupport/kernel/qprinterinfo_p.h40
-rw-r--r--src/printsupport/kernel/qtprintsupportglobal.h55
-rw-r--r--src/printsupport/kernel/qtprintsupportglobal_p.h40
-rw-r--r--src/printsupport/platform/macos/cocoa.json3
-rw-r--r--src/printsupport/platform/macos/qcocoaprintdevice.mm459
-rw-r--r--src/printsupport/platform/macos/qcocoaprintdevice_p.h92
-rw-r--r--src/printsupport/platform/macos/qcocoaprintersupport.mm101
-rw-r--r--src/printsupport/platform/macos/qcocoaprintersupport_p.h43
-rw-r--r--src/printsupport/platform/macos/qpaintengine_mac.mm1386
-rw-r--r--src/printsupport/platform/macos/qpaintengine_mac_p.h170
-rw-r--r--src/printsupport/platform/macos/qprintengine_mac.mm770
-rw-r--r--src/printsupport/platform/macos/qprintengine_mac_p.h123
-rw-r--r--src/printsupport/platform/windows/qprintengine_win.cpp (renamed from src/printsupport/kernel/qprintengine_win.cpp)204
-rw-r--r--src/printsupport/platform/windows/qprintengine_win_p.h (renamed from src/printsupport/kernel/qprintengine_win_p.h)138
-rw-r--r--src/printsupport/platform/windows/qwindowsprintdevice.cpp520
-rw-r--r--src/printsupport/platform/windows/qwindowsprintdevice_p.h119
-rw-r--r--src/printsupport/platform/windows/qwindowsprinterinfo.cpp86
-rw-r--r--src/printsupport/platform/windows/qwindowsprintersupport.cpp76
-rw-r--r--src/printsupport/platform/windows/qwindowsprintersupport_p.h44
-rw-r--r--src/printsupport/platform/windows/windows.json3
-rw-r--r--src/printsupport/printsupport.pro16
-rw-r--r--src/printsupport/qt_cmdline.cmake1
-rw-r--r--src/printsupport/widgets/qcupsjobwidget.cpp52
-rw-r--r--src/printsupport/widgets/qcupsjobwidget_p.h44
-rw-r--r--src/printsupport/widgets/qprintpreviewwidget.cpp85
-rw-r--r--src/printsupport/widgets/qprintpreviewwidget.h44
-rw-r--r--src/printsupport/widgets/widgets.pri13
100 files changed, 5443 insertions, 4010 deletions
diff --git a/src/printsupport/CMakeLists.txt b/src/printsupport/CMakeLists.txt
new file mode 100644
index 0000000000..25aad04caf
--- /dev/null
+++ b/src/printsupport/CMakeLists.txt
@@ -0,0 +1,203 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## PrintSupport Module:
+#####################################################################
+
+qt_internal_add_module(PrintSupport
+ PLUGIN_TYPES printsupport
+ SOURCES
+ kernel/qpaintengine_alpha.cpp kernel/qpaintengine_alpha_p.h
+ kernel/qplatformprintdevice.cpp kernel/qplatformprintdevice.h
+ kernel/qplatformprintersupport.cpp kernel/qplatformprintersupport.h
+ kernel/qplatformprintplugin.cpp kernel/qplatformprintplugin.h
+ kernel/qprint.cpp kernel/qprint_p.h
+ kernel/qprintdevice.cpp kernel/qprintdevice_p.h
+ kernel/qprintengine.h
+ kernel/qprintengine_pdf.cpp kernel/qprintengine_pdf_p.h
+ kernel/qprinter.cpp kernel/qprinter.h kernel/qprinter_p.h
+ kernel/qprinterinfo.cpp kernel/qprinterinfo.h kernel/qprinterinfo_p.h
+ kernel/qtprintsupportglobal.h kernel/qtprintsupportglobal_p.h
+ DEFINES
+ QT_NO_CONTEXTLESS_CONNECT
+ QT_NO_FOREACH
+ QT_NO_USING_NAMESPACE
+ QT_USE_NODISCARD_FILE_OPEN
+ INCLUDE_DIRECTORIES
+ dialogs
+ widgets
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::GuiPrivate
+ Qt::WidgetsPrivate
+ PUBLIC_LIBRARIES
+ Qt::Core
+ Qt::Gui
+ Qt::Widgets
+ PRIVATE_MODULE_INTERFACE
+ Qt::CorePrivate
+ Qt::GuiPrivate
+ Qt::WidgetsPrivate
+ GENERATE_CPP_EXPORTS
+ QPA_HEADER_FILTERS
+ "(^|/)qplatform.+\\.h$"
+)
+
+if(WIN32) # Static plugin link errors
+ set_target_properties(PrintSupport PROPERTIES UNITY_BUILD OFF)
+endif()
+
+## Scopes:
+#####################################################################
+
+qt_internal_extend_target(PrintSupport CONDITION MACOS
+ SOURCES
+ platform/macos/qcocoaprintdevice.mm platform/macos/qcocoaprintdevice_p.h
+ platform/macos/qcocoaprintersupport.mm platform/macos/qcocoaprintersupport_p.h
+ platform/macos/qpaintengine_mac.mm platform/macos/qpaintengine_mac_p.h
+ platform/macos/qprintengine_mac.mm platform/macos/qprintengine_mac_p.h
+ PUBLIC_LIBRARIES
+ ${FWApplicationServices}
+ Cups::Cups
+ NO_PCH_SOURCES
+ platform/macos/qcocoaprintersupport.mm
+)
+
+qt_internal_extend_target(PrintSupport CONDITION WIN32
+ SOURCES
+ platform/windows/qprintengine_win.cpp platform/windows/qprintengine_win_p.h
+ platform/windows/qwindowsprintdevice.cpp platform/windows/qwindowsprintdevice_p.h
+ platform/windows/qwindowsprintersupport.cpp platform/windows/qwindowsprintersupport_p.h
+ LIBRARIES
+ gdi32
+ user32
+ PUBLIC_LIBRARIES
+ comdlg32
+ winspool
+ NO_PCH_SOURCES
+ platform/windows/qwindowsprintersupport.cpp
+)
+
+qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_printpreviewwidget
+ SOURCES
+ kernel/qpaintengine_preview.cpp kernel/qpaintengine_preview_p.h
+ widgets/qprintpreviewwidget.cpp widgets/qprintpreviewwidget.h
+)
+
+qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_cups AND UNIX AND NOT APPLE
+ SOURCES
+ kernel/qcups.cpp kernel/qcups_p.h
+)
+
+qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_cupsjobwidget AND UNIX AND NOT APPLE
+ SOURCES
+ widgets/qcupsjobwidget.cpp widgets/qcupsjobwidget.ui widgets/qcupsjobwidget_p.h
+ ENABLE_AUTOGEN_TOOLS
+ uic
+)
+
+qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_printdialog
+ SOURCES
+ dialogs/qabstractprintdialog.cpp dialogs/qabstractprintdialog.h dialogs/qabstractprintdialog_p.h
+ dialogs/qpagesetupdialog.cpp dialogs/qpagesetupdialog.h dialogs/qpagesetupdialog_p.h
+ dialogs/qpagesetupwidget.ui
+ dialogs/qprintdialog.h
+ ENABLE_AUTOGEN_TOOLS
+ uic
+)
+
+if(QT_FEATURE_printdialog)
+ # Resources:
+ set(qprintdialog_resource_files
+ "dialogs/images/zoom-fit-page-24.png"
+ "dialogs/images/zoom-fit-page-32.png"
+ "dialogs/images/zoom-fit-width-24.png"
+ "dialogs/images/zoom-fit-width-32.png"
+ "dialogs/images/go-first-24.png"
+ "dialogs/images/go-first-32.png"
+ "dialogs/images/go-last-24.png"
+ "dialogs/images/go-last-32.png"
+ "dialogs/images/go-next-24.png"
+ "dialogs/images/go-next-32.png"
+ "dialogs/images/go-previous-24.png"
+ "dialogs/images/go-previous-32.png"
+ "dialogs/images/layout-landscape-24.png"
+ "dialogs/images/layout-landscape-32.png"
+ "dialogs/images/layout-portrait-24.png"
+ "dialogs/images/layout-portrait-32.png"
+ "dialogs/images/page-setup-24.png"
+ "dialogs/images/page-setup-32.png"
+ "dialogs/images/printer-24.png"
+ "dialogs/images/printer-32.png"
+ "dialogs/images/view-pages-overview-24.png"
+ "dialogs/images/view-pages-overview-32.png"
+ "dialogs/images/view-pages-single-24.png"
+ "dialogs/images/view-pages-single-32.png"
+ "dialogs/images/view-pages-facing-24.png"
+ "dialogs/images/view-pages-facing-32.png"
+ "dialogs/images/zoom-in-24.png"
+ "dialogs/images/zoom-in-32.png"
+ "dialogs/images/zoom-out-24.png"
+ "dialogs/images/zoom-out-32.png"
+ )
+
+ qt_internal_add_resource(PrintSupport "qprintdialog"
+ PREFIX
+ "/qt-project.org/dialogs/qprintpreviewdialog"
+ BASE
+ "dialogs"
+ FILES
+ ${qprintdialog_resource_files}
+ )
+ set(qprintdialog1_resource_files
+ "dialogs/images/status-color.png"
+ "dialogs/images/status-gray-scale.png"
+ )
+
+ qt_internal_add_resource(PrintSupport "qprintdialog1"
+ PREFIX
+ "/qt-project.org/dialogs/qprintdialog"
+ BASE
+ "dialogs"
+ FILES
+ ${qprintdialog1_resource_files}
+ )
+endif()
+
+qt_internal_extend_target(PrintSupport CONDITION MACOS AND QT_FEATURE_printdialog
+ SOURCES
+ dialogs/qpagesetupdialog_mac.mm
+ dialogs/qprintdialog_mac.mm
+ LIBRARIES
+ ${FWAppKit}
+)
+
+qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_printdialog AND WIN32
+ SOURCES
+ dialogs/qpagesetupdialog_win.cpp
+ dialogs/qprintdialog_win.cpp
+)
+
+qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_printdialog AND UNIX AND NOT APPLE
+ SOURCES
+ dialogs/qpagesetupdialog_unix.cpp dialogs/qpagesetupdialog_unix_p.h
+ dialogs/qprintdialog_unix.cpp
+ dialogs/qprintpropertieswidget.ui
+ dialogs/qprintsettingsoutput.ui
+ dialogs/qprintwidget.ui
+ NO_UNITY_BUILD_SOURCES
+ dialogs/qprintdialog_unix.cpp # Clashes with CUPS headers
+ INCLUDE_DIRECTORIES
+ ${QtBase_SOURCE_DIR}/src/plugins/printsupport/cups
+ ENABLE_AUTOGEN_TOOLS
+ uic
+)
+
+qt_internal_extend_target(PrintSupport CONDITION QT_FEATURE_printpreviewdialog
+ SOURCES
+ dialogs/qprintpreviewdialog.cpp dialogs/qprintpreviewdialog.h
+)
+qt_internal_add_docs(PrintSupport
+ doc/qtprintsupport.qdocconf
+)
diff --git a/src/printsupport/configure.cmake b/src/printsupport/configure.cmake
new file mode 100644
index 0000000000..2287789ac1
--- /dev/null
+++ b/src/printsupport/configure.cmake
@@ -0,0 +1,69 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+
+
+#### Inputs
+
+
+
+#### Libraries
+
+qt_find_package(Cups PROVIDED_TARGETS Cups::Cups MODULE_NAME printsupport QMAKE_LIB cups)
+
+
+#### Tests
+
+
+
+#### Features
+
+qt_feature("cups" PUBLIC PRIVATE
+ SECTION "Painting"
+ LABEL "CUPS"
+ PURPOSE "Provides support for the Common Unix Printing System."
+ CONDITION Cups_FOUND AND QT_FEATURE_printer AND QT_FEATURE_datestring
+)
+qt_feature_definition("cups" "QT_NO_CUPS" NEGATE VALUE "1")
+qt_feature("cupsjobwidget" PUBLIC PRIVATE
+ SECTION "Widgets"
+ LABEL "CUPS job control widget"
+ CONDITION ( QT_FEATURE_buttongroup ) AND ( QT_FEATURE_calendarwidget ) AND ( QT_FEATURE_checkbox ) AND ( QT_FEATURE_combobox ) AND ( QT_FEATURE_cups ) AND ( QT_FEATURE_datetimeedit ) AND ( QT_FEATURE_groupbox ) AND ( QT_FEATURE_tablewidget )
+)
+qt_feature_definition("cupsjobwidget" "QT_NO_CUPSJOBWIDGET" NEGATE VALUE "1")
+qt_feature("cupspassworddialog" PRIVATE
+ SECTION "Widgets"
+ LABEL "CUPS password dialog"
+ CONDITION ( QT_FEATURE_dialogbuttonbox ) AND ( QT_FEATURE_formlayout ) AND ( QT_FEATURE_lineedit )
+)
+qt_feature("printer" PUBLIC
+ SECTION "Painting"
+ LABEL "QPrinter"
+ PURPOSE "Provides a printer backend of QPainter."
+ CONDITION NOT UIKIT AND QT_FEATURE_picture AND QT_FEATURE_temporaryfile AND QT_FEATURE_pdf
+)
+qt_feature_definition("printer" "QT_NO_PRINTER" NEGATE VALUE "1")
+qt_feature("printpreviewwidget" PUBLIC
+ SECTION "Widgets"
+ LABEL "QPrintPreviewWidget"
+ PURPOSE "Provides a widget for previewing page layouts for printer output."
+ CONDITION QT_FEATURE_graphicsview AND QT_FEATURE_printer AND QT_FEATURE_mainwindow
+)
+qt_feature_definition("printpreviewwidget" "QT_NO_PRINTPREVIEWWIDGET" NEGATE VALUE "1")
+qt_feature("printdialog" PUBLIC
+ SECTION "Dialogs"
+ LABEL "QPrintDialog"
+ PURPOSE "Provides a dialog widget for specifying printer configuration."
+ CONDITION ( QT_FEATURE_buttongroup ) AND ( QT_FEATURE_checkbox ) AND ( QT_FEATURE_combobox ) AND ( QT_FEATURE_dialog ) AND ( QT_FEATURE_datetimeedit ) AND ( QT_FEATURE_dialogbuttonbox ) AND ( QT_FEATURE_formlayout ) AND ( QT_FEATURE_printer ) AND ( QT_FEATURE_radiobutton ) AND ( QT_FEATURE_spinbox ) AND ( QT_FEATURE_tabwidget ) AND ( QT_FEATURE_treeview )
+)
+qt_feature_definition("printdialog" "QT_NO_PRINTDIALOG" NEGATE VALUE "1")
+qt_feature("printpreviewdialog" PUBLIC
+ SECTION "Dialogs"
+ LABEL "QPrintPreviewDialog"
+ PURPOSE "Provides a dialog for previewing and configuring page layouts for printer output."
+ CONDITION QT_FEATURE_printpreviewwidget AND QT_FEATURE_printdialog AND QT_FEATURE_toolbar AND QT_FEATURE_formlayout
+)
+qt_feature_definition("printpreviewdialog" "QT_NO_PRINTPREVIEWDIALOG" NEGATE VALUE "1")
+qt_configure_add_summary_section(NAME "Qt PrintSupport")
+qt_configure_add_summary_entry(ARGS "cups")
+qt_configure_end_summary_section() # end of "Qt PrintSupport" section
diff --git a/src/printsupport/configure.json b/src/printsupport/configure.json
deleted file mode 100644
index 7183d2e737..0000000000
--- a/src/printsupport/configure.json
+++ /dev/null
@@ -1,102 +0,0 @@
-{
- "module": "printsupport",
- "depends": [
- "core",
- "gui",
- "widgets"
- ],
- "testDir": "../../config.tests",
-
- "commandline": {
- "options": {
- "cups": "boolean"
- }
- },
-
- "libraries": {
- "cups": {
- "label": "CUPS",
- "test": {
- "main": "cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); // CUPS 1.4 test"
- },
- "headers": "cups/cups.h",
- "sources": [
- "-lcups"
- ]
- }
- },
-
- "features": {
- "cups": {
- "label": "CUPS",
- "purpose": "Provides support for the Common Unix Printing System.",
- "section": "Painting",
- "condition": "libs.cups && features.printer && features.datestring",
- "output": [ "privateFeature", "feature" ]
- },
- "cupsjobwidget": {
- "label": "CUPS job control widget",
- "section": "Widgets",
- "condition": [
- "features.buttongroup",
- "features.calendarwidget",
- "features.checkbox",
- "features.combobox",
- "features.cups",
- "features.datetimeedit",
- "features.groupbox",
- "features.tablewidget"
- ],
- "output": [ "privateFeature", "feature" ]
- },
- "printer": {
- "label": "QPrinter",
- "purpose": "Provides a printer backend of QPainter.",
- "section": "Painting",
- "condition": "!config.uikit && !config.winrt && features.picture && features.temporaryfile && features.pdf",
- "output": [ "publicFeature", "feature" ]
- },
- "printpreviewwidget": {
- "label": "QPrintPreviewWidget",
- "purpose": "Provides a widget for previewing page layouts for printer output.",
- "section": "Widgets",
- "condition": "features.graphicsview && features.printer && features.mainwindow",
- "output": [ "publicFeature", "feature" ]
- },
- "printdialog": {
- "label": "QPrintDialog",
- "purpose": "Provides a dialog widget for specifying printer configuration.",
- "section": "Dialogs",
- "condition": [
- "features.buttongroup",
- "features.checkbox",
- "features.combobox",
- "features.dialog",
- "features.datetimeedit",
- "features.dialogbuttonbox",
- "features.printer",
- "features.radiobutton",
- "features.spinbox",
- "features.tabwidget",
- "features.treeview"
- ],
- "output": [ "publicFeature", "feature" ]
- },
- "printpreviewdialog": {
- "label": "QPrintPreviewDialog",
- "purpose": "Provides a dialog for previewing and configuring page layouts for printer output.",
- "section": "Dialogs",
- "condition": "features.printpreviewwidget && features.printdialog && features.toolbar && features.formlayout",
- "output": [ "publicFeature", "feature" ]
- }
- },
-
- "summary": [
- {
- "section": "Qt PrintSupport",
- "entries": [
- "cups"
- ]
- }
- ]
-}
diff --git a/src/printsupport/dialogs/dialogs.pri b/src/printsupport/dialogs/dialogs.pri
deleted file mode 100644
index 0a7b947c79..0000000000
--- a/src/printsupport/dialogs/dialogs.pri
+++ /dev/null
@@ -1,46 +0,0 @@
-# Qt dialogs module
-
-INCLUDEPATH += $$PWD
-
-qtConfig(printdialog) {
- HEADERS += \
- dialogs/qabstractprintdialog.h \
- dialogs/qabstractprintdialog_p.h \
- dialogs/qpagesetupdialog_p.h \
- dialogs/qpagesetupdialog.h \
- dialogs/qprintdialog.h
-
- macos {
- OBJECTIVE_SOURCES += dialogs/qpagesetupdialog_mac.mm \
- dialogs/qprintdialog_mac.mm
- LIBS_PRIVATE += -framework AppKit
- }
-
- win32 {
- SOURCES += dialogs/qpagesetupdialog_win.cpp \
- dialogs/qprintdialog_win.cpp
- }
-
- unix:!darwin {
- INCLUDEPATH += $$QT_SOURCE_TREE/src/plugins/printsupport/cups
- HEADERS += dialogs/qpagesetupdialog_unix_p.h
- SOURCES += dialogs/qprintdialog_unix.cpp \
- dialogs/qpagesetupdialog_unix.cpp
- FORMS += dialogs/qprintsettingsoutput.ui \
- dialogs/qprintwidget.ui \
- dialogs/qprintpropertieswidget.ui
- }
-
- SOURCES += \
- dialogs/qabstractprintdialog.cpp \
- dialogs/qpagesetupdialog.cpp
-
- FORMS += dialogs/qpagesetupwidget.ui
- RESOURCES += dialogs/qprintdialog.qrc
-}
-
-qtConfig(printpreviewdialog) {
- HEADERS += dialogs/qprintpreviewdialog.h
- SOURCES += dialogs/qprintpreviewdialog.cpp
-}
-
diff --git a/src/printsupport/dialogs/images/print-24.png b/src/printsupport/dialogs/images/printer-24.png
index c6bf3e8672..c6bf3e8672 100644
--- a/src/printsupport/dialogs/images/print-24.png
+++ b/src/printsupport/dialogs/images/printer-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/print-32.png b/src/printsupport/dialogs/images/printer-32.png
index 5830888653..5830888653 100644
--- a/src/printsupport/dialogs/images/print-32.png
+++ b/src/printsupport/dialogs/images/printer-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-sided-24.png b/src/printsupport/dialogs/images/view-pages-facing-24.png
index 2131305c41..2131305c41 100644
--- a/src/printsupport/dialogs/images/view-page-sided-24.png
+++ b/src/printsupport/dialogs/images/view-pages-facing-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-sided-32.png b/src/printsupport/dialogs/images/view-pages-facing-32.png
index e4d63f9992..e4d63f9992 100644
--- a/src/printsupport/dialogs/images/view-page-sided-32.png
+++ b/src/printsupport/dialogs/images/view-pages-facing-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-multi-24.png b/src/printsupport/dialogs/images/view-pages-overview-24.png
index 87241472ae..87241472ae 100644
--- a/src/printsupport/dialogs/images/view-page-multi-24.png
+++ b/src/printsupport/dialogs/images/view-pages-overview-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-multi-32.png b/src/printsupport/dialogs/images/view-pages-overview-32.png
index 130885a041..130885a041 100644
--- a/src/printsupport/dialogs/images/view-page-multi-32.png
+++ b/src/printsupport/dialogs/images/view-pages-overview-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-one-24.png b/src/printsupport/dialogs/images/view-pages-single-24.png
index 4c6457b892..4c6457b892 100644
--- a/src/printsupport/dialogs/images/view-page-one-24.png
+++ b/src/printsupport/dialogs/images/view-pages-single-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-one-32.png b/src/printsupport/dialogs/images/view-pages-single-32.png
index 537193984e..537193984e 100644
--- a/src/printsupport/dialogs/images/view-page-one-32.png
+++ b/src/printsupport/dialogs/images/view-pages-single-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/fit-page-24.png b/src/printsupport/dialogs/images/zoom-fit-page-24.png
index c7b39d8853..c7b39d8853 100644
--- a/src/printsupport/dialogs/images/fit-page-24.png
+++ b/src/printsupport/dialogs/images/zoom-fit-page-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/fit-page-32.png b/src/printsupport/dialogs/images/zoom-fit-page-32.png
index 98bc12d3ed..98bc12d3ed 100644
--- a/src/printsupport/dialogs/images/fit-page-32.png
+++ b/src/printsupport/dialogs/images/zoom-fit-page-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/fit-width-24.png b/src/printsupport/dialogs/images/zoom-fit-width-24.png
index a729ffda54..a729ffda54 100644
--- a/src/printsupport/dialogs/images/fit-width-24.png
+++ b/src/printsupport/dialogs/images/zoom-fit-width-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/fit-width-32.png b/src/printsupport/dialogs/images/zoom-fit-width-32.png
index 470a8b45d0..470a8b45d0 100644
--- a/src/printsupport/dialogs/images/fit-width-32.png
+++ b/src/printsupport/dialogs/images/zoom-fit-width-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/qabstractprintdialog.cpp b/src/printsupport/dialogs/qabstractprintdialog.cpp
index 1a2aa7afac..9cbba6bdbb 100644
--- a/src/printsupport/dialogs/qabstractprintdialog.cpp
+++ b/src/printsupport/dialogs/qabstractprintdialog.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qabstractprintdialog_p.h"
#include "qcoreapplication.h"
@@ -78,20 +42,12 @@ QT_BEGIN_NAMESPACE
Used to specify which parts of the print dialog should be visible.
- \value None None of the options are enabled.
\value PrintToFile The print to file option is enabled.
\value PrintSelection The print selection option is enabled.
\value PrintPageRange The page range selection option is enabled.
\value PrintShowPageSize Show the page size + margins page only if this is enabled.
\value PrintCollateCopies The collate copies option is enabled
\value PrintCurrentPage The print current page option is enabled
-
- This value is obsolete and does nothing since Qt 4.5:
-
- \value DontUseSheet In previous versions of Qt, exec() the print dialog
- would create a sheet by default the dialog was given a parent.
- This is no longer supported in Qt 4.5. If you want to use sheets, use
- QPrintDialog::open() instead.
*/
/*!
@@ -188,50 +144,6 @@ QPrintDialog::PrintDialogOptions QPrintDialog::options() const
}
/*!
- \obsolete
-
- Use QPrintDialog::setOptions() instead.
-*/
-void QAbstractPrintDialog::setEnabledOptions(PrintDialogOptions options)
-{
- Q_D(QAbstractPrintDialog);
- d->options = options;
-}
-
-/*!
- \obsolete
-
- Use QPrintDialog::setOption(\a option, true) instead.
-*/
-void QAbstractPrintDialog::addEnabledOption(PrintDialogOption option)
-{
- Q_D(QAbstractPrintDialog);
- d->options |= option;
-}
-
-/*!
- \obsolete
-
- Use QPrintDialog::options() instead.
-*/
-QAbstractPrintDialog::PrintDialogOptions QAbstractPrintDialog::enabledOptions() const
-{
- Q_D(const QAbstractPrintDialog);
- return d->options;
-}
-
-/*!
- \obsolete
-
- Use QPrintDialog::testOption(\a option) instead.
-*/
-bool QAbstractPrintDialog::isOptionEnabled(PrintDialogOption option) const
-{
- Q_D(const QAbstractPrintDialog);
- return d->options & option;
-}
-
-/*!
Sets the print range option in to be \a range.
*/
void QAbstractPrintDialog::setPrintRange(PrintRange range)
@@ -344,13 +256,6 @@ void QAbstractPrintDialogPrivate::setPrinter(QPrinter *newPrinter)
}
/*!
- \fn int QAbstractPrintDialog::exec()
-
- This virtual function is called to pop up the dialog. It must be
- reimplemented in subclasses.
-*/
-
-/*!
\class QPrintDialog
\brief The QPrintDialog class provides a dialog for specifying
@@ -490,3 +395,5 @@ void QPrintDialog::open(QObject *receiver, const char *member)
}
QT_END_NAMESPACE
+
+#include "moc_qabstractprintdialog.cpp"
diff --git a/src/printsupport/dialogs/qabstractprintdialog.h b/src/printsupport/dialogs/qabstractprintdialog.h
index 3cc89890fc..7f3f929d8a 100644
--- a/src/printsupport/dialogs/qabstractprintdialog.h
+++ b/src/printsupport/dialogs/qabstractprintdialog.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QABSTRACTPRINTDIALOG_H
#define QABSTRACTPRINTDIALOG_H
@@ -51,7 +15,6 @@ QT_BEGIN_NAMESPACE
class QAbstractPrintDialogPrivate;
class QPrinter;
-// ### QtPrintNG: merge this class with QPrintDialog
class Q_PRINTSUPPORT_EXPORT QAbstractPrintDialog : public QDialog
{
Q_DECLARE_PRIVATE(QAbstractPrintDialog)
@@ -67,13 +30,11 @@ public:
};
enum PrintDialogOption {
- None = 0x0000, // obsolete
PrintToFile = 0x0001,
PrintSelection = 0x0002,
PrintPageRange = 0x0004,
PrintShowPageSize = 0x0008,
PrintCollateCopies = 0x0010,
- DontUseSheet = 0x0020,
PrintCurrentPage = 0x0040
};
Q_ENUM(PrintDialogOption)
@@ -84,14 +45,6 @@ public:
explicit QAbstractPrintDialog(QPrinter *printer, QWidget *parent = nullptr);
~QAbstractPrintDialog();
- int exec() override = 0;
-
- // obsolete
- void addEnabledOption(PrintDialogOption option);
- void setEnabledOptions(PrintDialogOptions options);
- PrintDialogOptions enabledOptions() const;
- bool isOptionEnabled(PrintDialogOption option) const;
-
void setOptionTabs(const QList<QWidget*> &tabs);
void setPrintRange(PrintRange range);
diff --git a/src/printsupport/dialogs/qabstractprintdialog_p.h b/src/printsupport/dialogs/qabstractprintdialog_p.h
index b646b74f34..40f25d454a 100644
--- a/src/printsupport/dialogs/qabstractprintdialog_p.h
+++ b/src/printsupport/dialogs/qabstractprintdialog_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QABSTRACTPRINTDIALOG_P_H
#define QABSTRACTPRINTDIALOG_P_H
@@ -56,6 +20,8 @@
#include "private/qdialog_p.h"
#include "QtPrintSupport/qabstractprintdialog.h"
+#include <QtCore/qpointer.h>
+
QT_REQUIRE_CONFIG(printdialog);
QT_BEGIN_NAMESPACE
diff --git a/src/printsupport/dialogs/qpagesetupdialog.cpp b/src/printsupport/dialogs/qpagesetupdialog.cpp
index dc0457d20d..0bc80c1f6f 100644
--- a/src/printsupport/dialogs/qpagesetupdialog.cpp
+++ b/src/printsupport/dialogs/qpagesetupdialog.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qpagesetupdialog.h"
#include <private/qpagesetupdialog_p.h>
@@ -114,10 +78,8 @@ void QPageSetupDialogPrivate::setPrinter(QPrinter *newPrinter)
printer = new QPrinter;
ownsPrinter = true;
}
-#if 1 // Used to be excluded in Qt4 for Q_WS_X11
if (printer->outputFormat() != QPrinter::NativeFormat)
qWarning("QPageSetupDialog: Cannot be used on non-native printers");
-#endif
}
/*!
diff --git a/src/printsupport/dialogs/qpagesetupdialog.h b/src/printsupport/dialogs/qpagesetupdialog.h
index a7aaa03134..80d9c7a7fd 100644
--- a/src/printsupport/dialogs/qpagesetupdialog.h
+++ b/src/printsupport/dialogs/qpagesetupdialog.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPAGESETUPDIALOG_H
#define QPAGESETUPDIALOG_H
@@ -61,7 +25,7 @@ public:
explicit QPageSetupDialog(QWidget *parent = nullptr);
~QPageSetupDialog();
-#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
+#if defined(Q_OS_MAC) || defined(Q_OS_WIN) || defined(Q_QDOC)
void setVisible(bool visible) override;
#endif
int exec() override;
diff --git a/src/printsupport/dialogs/qpagesetupdialog_mac.mm b/src/printsupport/dialogs/qpagesetupdialog_mac.mm
index a3511fe7b6..046a1021af 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_mac.mm
+++ b/src/printsupport/dialogs/qpagesetupdialog_mac.mm
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <AppKit/AppKit.h>
@@ -47,6 +11,10 @@
#include <qpa/qplatformnativeinterface.h>
#include <QtPrintSupport/qprintengine.h>
+#include <QtPrintSupport/private/qprintengine_mac_p.h>
+
+#include <QtCore/private/qcore_mac_p.h>
+
QT_USE_NAMESPACE
@class QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate);
@@ -82,7 +50,7 @@ QT_USE_NAMESPACE
PMGetOrientation(format, &orientation);
QSizeF paperSize = QSizeF(paperRect.right - paperRect.left, paperRect.bottom - paperRect.top);
printer->printEngine()->setProperty(QPrintEngine::PPK_CustomPaperSize, paperSize);
- printer->printEngine()->setProperty(QPrintEngine::PPK_Orientation, orientation == kPMLandscape ? QPrinter::Landscape : QPrinter::Portrait);
+ printer->printEngine()->setProperty(QPrintEngine::PPK_Orientation, orientation == kPMLandscape ? QPageLayout::Landscape : QPageLayout::Portrait);
}
dialog->done((returnCode == NSModalResponseOK) ? QDialog::Accepted : QDialog::Rejected);
@@ -114,13 +82,7 @@ void QMacPageSetupDialogPrivate::openCocoaPageLayout(Qt::WindowModality modality
{
Q_Q(QPageSetupDialog);
- // get the NSPrintInfo from the print engine in the platform plugin
- void *voidp = 0;
- (void) QMetaObject::invokeMethod(qApp->platformNativeInterface(),
- "NSPrintInfoForPrintEngine",
- Q_RETURN_ARG(void *, voidp),
- Q_ARG(QPrintEngine *, printer->printEngine()));
- printInfo = static_cast<NSPrintInfo *>(voidp);
+ printInfo = static_cast<QMacPrintEngine *>(printer->printEngine())->printInfo();
[printInfo retain];
pageLayout = [NSPageLayout pageLayout];
diff --git a/src/printsupport/dialogs/qpagesetupdialog_p.h b/src/printsupport/dialogs/qpagesetupdialog_p.h
index a2b3f8363c..1b02f1e62d 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_p.h
+++ b/src/printsupport/dialogs/qpagesetupdialog_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPAGESETUPDIALOG_P_H
#define QPAGESETUPDIALOG_P_H
diff --git a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
index d9b4a84aa9..6c65eafc21 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
+++ b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qpagesetupdialog.h"
@@ -49,7 +13,7 @@
#include "qpainter.h"
#include "qprintdialog.h"
-#include "qtextcodec.h"
+#include "qstringconverter.h"
#include "qdialogbuttonbox.h"
#include <ui_qpagesetupwidget.h>
@@ -60,6 +24,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
// Disabled until we have support for papersources on unix
@@ -157,7 +123,7 @@ protected:
font.setPointSizeF(font.pointSizeF()*0.25);
p.setFont(font);
p.setPen(palette().color(QPalette::Dark));
- QString text(QLatin1String("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."));
+ QString text("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."_L1);
for (int i=0; i<3; ++i)
text += text;
@@ -249,9 +215,6 @@ QPageSetupWidget::QPageSetupWidget(QWidget *parent)
{
m_ui.setupUi(this);
- if (!QMetaType::hasRegisteredComparators<QPageSize>())
- QMetaType::registerEqualsComparator<QPageSize>();
-
QVBoxLayout *lay = new QVBoxLayout(m_ui.preview);
m_pagePreview = new QPagePreview(m_ui.preview);
m_pagePreview->setPagePreviewLayout(1, 1);
@@ -274,21 +237,21 @@ QPageSetupWidget::QPageSetupWidget(QWidget *parent)
initUnits();
initPagesPerSheet();
- connect(m_ui.unitCombo, QOverload<int>::of(&QComboBox::activated), this, &QPageSetupWidget::unitChanged);
+ connect(m_ui.unitCombo, &QComboBox::activated, this, &QPageSetupWidget::unitChanged);
- connect(m_ui.pageSizeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QPageSetupWidget::pageSizeChanged);
- connect(m_ui.pageWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &QPageSetupWidget::pageSizeChanged);
- connect(m_ui.pageHeight, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &QPageSetupWidget::pageSizeChanged);
+ connect(m_ui.pageSizeCombo, &QComboBox::currentIndexChanged, this, &QPageSetupWidget::pageSizeChanged);
+ connect(m_ui.pageWidth, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::pageSizeChanged);
+ connect(m_ui.pageHeight, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::pageSizeChanged);
- connect(m_ui.leftMargin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &QPageSetupWidget::leftMarginChanged);
- connect(m_ui.topMargin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &QPageSetupWidget::topMarginChanged);
- connect(m_ui.rightMargin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &QPageSetupWidget::rightMarginChanged);
- connect(m_ui.bottomMargin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &QPageSetupWidget::bottomMarginChanged);
+ connect(m_ui.leftMargin, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::leftMarginChanged);
+ connect(m_ui.topMargin, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::topMarginChanged);
+ connect(m_ui.rightMargin, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::rightMarginChanged);
+ connect(m_ui.bottomMargin, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::bottomMarginChanged);
connect(m_ui.portrait, &QRadioButton::clicked, this, &QPageSetupWidget::pageOrientationChanged);
connect(m_ui.landscape, &QRadioButton::clicked, this, &QPageSetupWidget::pageOrientationChanged);
- connect(m_ui.pagesPerSheetCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QPageSetupWidget::pagesPerSheetChanged);
+ connect(m_ui.pagesPerSheetCombo, &QComboBox::currentIndexChanged, this, &QPageSetupWidget::pagesPerSheetChanged);
}
// Init the Units combo box
@@ -301,7 +264,7 @@ void QPageSetupWidget::initUnits()
m_ui.unitCombo->addItem(tr("Didot (DD)"), QVariant::fromValue(QPageLayout::Didot));
m_ui.unitCombo->addItem(tr("Cicero (CC)"), QVariant::fromValue(QPageLayout::Cicero));
- // Initailly default to locale measurement system, mm if metric, in otherwise
+ // Initially default to locale measurement system, mm if metric, in otherwise
m_ui.unitCombo->setCurrentIndex(QLocale().measurementSystem() != QLocale::MetricSystem);
}
@@ -361,13 +324,21 @@ void QPageSetupWidget::initPageSizes()
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
if (ps) {
QPrintDevice printDevice = ps->createPrintDevice(m_printerName);
+ const QPageSize defaultSize = printDevice.defaultPageSize();
const auto pageSizes = printDevice.supportedPageSizes();
for (const QPageSize &pageSize : pageSizes)
m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize));
- if (m_ui.pageSizeCombo->count() > 0 && printDevice.supportsCustomPageSizes()) {
- m_ui.pageSizeCombo->addItem(tr("Custom"));
- m_realCustomPageSizeIndex = m_ui.pageSizeCombo->count() - 1;
+ if (m_ui.pageSizeCombo->count() > 0) {
+ if (printDevice.supportsCustomPageSizes()) {
+ m_ui.pageSizeCombo->addItem(tr("Custom"));
+ m_realCustomPageSizeIndex = m_ui.pageSizeCombo->count() - 1;
+ }
m_blockSignals = false;
+
+ // If the defaultSize is index 0, setCurrentIndex won't emit the currentIndexChanged
+ // signal; workaround the issue by initially setting the currentIndex to -1
+ m_ui.pageSizeCombo->setCurrentIndex(-1);
+ m_ui.pageSizeCombo->setCurrentIndex(m_ui.pageSizeCombo->findData(QVariant::fromValue(defaultSize)));
return;
}
}
@@ -403,12 +374,6 @@ void QPageSetupWidget::setPrinter(QPrinter *printer, QPrintDevice *printDevice,
// Initialize the layout to the current QPrinter layout
m_pageLayout = m_printer->pageLayout();
- if (printDevice) {
- const QPageSize pageSize = printDevice->defaultPageSize();
- const QMarginsF printable = printDevice->printableMargins(pageSize, m_pageLayout.orientation(), m_printer->resolution());
- m_pageLayout.setPageSize(pageSize, qt_convertMargins(printable, QPageLayout::Point, m_pageLayout.units()));
- }
-
// Assume if margins are Points then is by default, so set to locale default units
if (m_pageLayout.units() == QPageLayout::Point) {
if (QLocale().measurementSystem() == QLocale::MetricSystem)
@@ -530,11 +495,12 @@ void QPageSetupWidget::updateWidget()
void QPageSetupWidget::setupPrinter() const
{
m_printer->setPageLayout(m_pageLayout);
+ m_printer->setPageOrientation(m_pageLayout.orientation());
#if QT_CONFIG(cups)
- QCUPSSupport::PagesPerSheet pagesPerSheet = m_ui.pagesPerSheetCombo->currentData()
- .value<QCUPSSupport::PagesPerSheet>();
- QCUPSSupport::PagesPerSheetLayout pagesPerSheetLayout = m_ui.pagesPerSheetLayoutCombo->currentData()
- .value<QCUPSSupport::PagesPerSheetLayout>();
+ QCUPSSupport::PagesPerSheet pagesPerSheet = qvariant_cast<QCUPSSupport::PagesPerSheet>(m_ui.pagesPerSheetCombo->currentData()
+);
+ QCUPSSupport::PagesPerSheetLayout pagesPerSheetLayout = qvariant_cast<QCUPSSupport::PagesPerSheetLayout>(m_ui.pagesPerSheetLayoutCombo->currentData()
+);
QCUPSSupport::setPagesPerSheetLayout(m_printer, pagesPerSheet, pagesPerSheetLayout);
#endif
#ifdef PSD_ENABLE_PAPERSOURCE
@@ -585,15 +551,19 @@ void QPageSetupWidget::pageSizeChanged()
{
QPageSize pageSize;
if (m_ui.pageSizeCombo->currentIndex() != m_realCustomPageSizeIndex) {
- pageSize = m_ui.pageSizeCombo->currentData().value<QPageSize>();
+ pageSize = qvariant_cast<QPageSize>(m_ui.pageSizeCombo->currentData());
#if QT_CONFIG(cups)
if (m_pageSizePpdOption) {
- ppd_file_t *ppd = m_printDevice->property(PDPK_PpdFile).value<ppd_file_t*>();
- QTextCodec *cupsCodec = QTextCodec::codecForName(ppd->lang_encoding);
+ ppd_file_t *ppd = qvariant_cast<ppd_file_t*>(m_printDevice->property(PDPK_PpdFile));
+ QStringDecoder toUtf16(ppd->lang_encoding, QStringDecoder::Flag::Stateless);
+ if (!toUtf16.isValid()) {
+ qWarning() << "QPrinSupport: Cups uses unsupported encoding" << ppd->lang_encoding;
+ toUtf16 = QStringDecoder(QStringDecoder::Utf8);
+ }
for (int i = 0; i < m_pageSizePpdOption->num_choices; ++i) {
const ppd_choice_t *choice = &m_pageSizePpdOption->choices[i];
- if (cupsCodec->toUnicode(choice->text) == m_ui.pageSizeCombo->currentText()) {
+ if (toUtf16(choice->text) == m_ui.pageSizeCombo->currentText()) {
const auto values = QStringList{} << QString::fromLatin1(m_pageSizePpdOption->keyword)
<< QString::fromLatin1(choice->choice);
m_printDevice->setProperty(PDPK_PpdOption, values);
@@ -674,7 +644,7 @@ void QPageSetupWidget::unitChanged()
{
if (m_blockSignals)
return;
- m_units = m_ui.unitCombo->currentData().value<QPageLayout::Unit>();
+ m_units = qvariant_cast<QPageLayout::Unit>(m_ui.unitCombo->currentData());
m_pageLayout.setUnits(m_units);
updateWidget();
}
@@ -723,7 +693,7 @@ QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
}
QPageSetupDialog::QPageSetupDialog(QWidget *parent)
- : QDialog(*(new QUnixPageSetupDialogPrivate(0)), parent)
+ : QDialog(*(new QUnixPageSetupDialogPrivate(nullptr)), parent)
{
Q_D(QPageSetupDialog);
setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup"));
@@ -735,11 +705,17 @@ int QPageSetupDialog::exec()
Q_D(QPageSetupDialog);
int ret = QDialog::exec();
- if (ret == Accepted)
+ if (ret == Accepted) {
static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->setupPrinter();
+ static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->updateSavedValues();
+ } else {
+ static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->revertToSavedValues();
+ }
return ret;
}
QT_END_NAMESPACE
+#include "moc_qpagesetupdialog_unix_p.cpp"
+
#include "moc_qpagesetupdialog.cpp"
diff --git a/src/printsupport/dialogs/qpagesetupdialog_unix_p.h b/src/printsupport/dialogs/qpagesetupdialog_unix_p.h
index 7bfdaed740..0fe3a2e559 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_unix_p.h
+++ b/src/printsupport/dialogs/qpagesetupdialog_unix_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPAGESETUPDIALOG_UNIX_P_H
#define QPAGESETUPDIALOG_UNIX_P_H
diff --git a/src/printsupport/dialogs/qpagesetupdialog_win.cpp b/src/printsupport/dialogs/qpagesetupdialog_win.cpp
index 464381bbe4..1d2fdc98b7 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_win.cpp
+++ b/src/printsupport/dialogs/qpagesetupdialog_win.cpp
@@ -1,47 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qpagesetupdialog.h"
#include <qapplication.h>
-#include "../kernel/qprintengine_win_p.h"
+#include <private/qprintengine_win_p.h>
#include "qpagesetupdialog_p.h"
#include "qprinter.h"
#include <qpa/qplatformnativeinterface.h>
@@ -56,7 +20,7 @@ QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
}
QPageSetupDialog::QPageSetupDialog(QWidget *parent)
- : QDialog(*(new QPageSetupDialogPrivate(0)), parent)
+ : QDialog(*(new QPageSetupDialogPrivate(nullptr)), parent)
{
setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup"));
setAttribute(Qt::WA_DontShowOnScreen);
@@ -77,7 +41,7 @@ int QPageSetupDialog::exec()
psd.lStructSize = sizeof(PAGESETUPDLG);
// we need a temp DEVMODE struct if we don't have a global DEVMODE
- HGLOBAL hDevMode = 0;
+ HGLOBAL hDevMode = nullptr;
int devModeSize = 0;
if (!engine->globalDevMode()) {
devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra;
@@ -99,9 +63,10 @@ int QPageSetupDialog::exec()
parent = parent ? parent->window() : QApplication::activeWindow();
Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
- QWindow *parentWindow = parent ? parent->windowHandle() : 0;
- psd.hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0;
-
+ QWindow *parentWindow = parent ? parent->windowHandle() : nullptr;
+ psd.hwndOwner = parentWindow
+ ? HWND(QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow))
+ : nullptr;
psd.Flags = PSD_MARGINS;
QPageLayout layout = d->printer->pageLayout();
switch (layout.units()) {
@@ -134,17 +99,43 @@ int QPageSetupDialog::exec()
QDialog::setVisible(false);
if (result) {
engine->setGlobalDevMode(psd.hDevNames, psd.hDevMode);
- d->printer->setPageSize(QPageSize(QSizeF(psd.ptPaperSize.x / multiplier, psd.ptPaperSize.y / multiplier),
- layout.units() == QPageLayout::Inch ? QPageSize::Inch : QPageSize::Millimeter));
+ QPageSize pageSize;
+ // try to read orientation and paper size ID from the dialog's devmode struct
+ if (psd.hDevMode) {
+ DEVMODE *rDevmode = reinterpret_cast<DEVMODE*>(GlobalLock(psd.hDevMode));
+ if (rDevmode->dmFields & DM_ORIENTATION) {
+ layout.setOrientation(rDevmode->dmOrientation == DMORIENT_PORTRAIT
+ ? QPageLayout::Portrait : QPageLayout::Landscape);
+ }
+ if (rDevmode->dmFields & DM_PAPERSIZE)
+ pageSize = QPageSize::id(rDevmode->dmPaperSize);
+ GlobalUnlock(rDevmode);
+ }
+ // fall back to use our own matching, and assume that paper that's wider than long means landscape
+ if (!pageSize.isValid() || pageSize.id() == QPageSize::Custom) {
+ QSizeF unitSize(psd.ptPaperSize.x / multiplier, psd.ptPaperSize.y / multiplier);
+ if (unitSize.width() > unitSize.height()) {
+ layout.setOrientation(QPageLayout::Landscape);
+ unitSize.transpose();
+ } else {
+ layout.setOrientation(QPageLayout::Portrait);
+ }
+ pageSize = QPageSize(unitSize, layout.units() == QPageLayout::Inch
+ ? QPageSize::Inch : QPageSize::Millimeter);
+ }
+ layout.setPageSize(pageSize, layout.minimumMargins());
+
const QMarginsF margins(psd.rtMargin.left, psd.rtMargin.top, psd.rtMargin.right, psd.rtMargin.bottom);
- d->printer->setPageMargins(margins / multiplier, layout.units());
+ layout.setMargins(margins / multiplier, QPageLayout::OutOfBoundsPolicy::Clamp);
+ d->printer->setPageLayout(layout);
// copy from our temp DEVMODE struct
if (!engine->globalDevMode() && hDevMode) {
// Make sure memory is allocated
if (ep->ownsDevMode && ep->devMode)
free(ep->devMode);
- ep->devMode = (DEVMODE *) malloc(devModeSize);
+ ep->devMode = reinterpret_cast<DEVMODE *>(malloc(devModeSize));
+ QWin32PrintEnginePrivate::initializeDevMode(ep->devMode);
ep->ownsDevMode = true;
// Copy
diff --git a/src/printsupport/dialogs/qprintdialog.h b/src/printsupport/dialogs/qprintdialog.h
index bbb12202f0..fa05f42bea 100644
--- a/src/printsupport/dialogs/qprintdialog.h
+++ b/src/printsupport/dialogs/qprintdialog.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTDIALOG_H
#define QPRINTDIALOG_H
diff --git a/src/printsupport/dialogs/qprintdialog.qdoc b/src/printsupport/dialogs/qprintdialog.qdoc
index 90195db138..5fa4a021ae 100644
--- a/src/printsupport/dialogs/qprintdialog.qdoc
+++ b/src/printsupport/dialogs/qprintdialog.qdoc
@@ -1,27 +1,3 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
diff --git a/src/printsupport/dialogs/qprintdialog.qrc b/src/printsupport/dialogs/qprintdialog.qrc
deleted file mode 100644
index 5a579baa55..0000000000
--- a/src/printsupport/dialogs/qprintdialog.qrc
+++ /dev/null
@@ -1,38 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/qt-project.org/dialogs/qprintpreviewdialog">
-<file>images/fit-page-24.png</file>
-<file>images/fit-page-32.png</file>
-<file>images/fit-width-24.png</file>
-<file>images/fit-width-32.png</file>
-<file>images/go-first-24.png</file>
-<file>images/go-first-32.png</file>
-<file>images/go-last-24.png</file>
-<file>images/go-last-32.png</file>
-<file>images/go-next-24.png</file>
-<file>images/go-next-32.png</file>
-<file>images/go-previous-24.png</file>
-<file>images/go-previous-32.png</file>
-<file>images/layout-landscape-24.png</file>
-<file>images/layout-landscape-32.png</file>
-<file>images/layout-portrait-24.png</file>
-<file>images/layout-portrait-32.png</file>
-<file>images/page-setup-24.png</file>
-<file>images/page-setup-32.png</file>
-<file>images/print-24.png</file>
-<file>images/print-32.png</file>
-<file>images/view-page-multi-24.png</file>
-<file>images/view-page-multi-32.png</file>
-<file>images/view-page-one-24.png</file>
-<file>images/view-page-one-32.png</file>
-<file>images/view-page-sided-24.png</file>
-<file>images/view-page-sided-32.png</file>
-<file>images/zoom-in-24.png</file>
-<file>images/zoom-in-32.png</file>
-<file>images/zoom-out-24.png</file>
-<file>images/zoom-out-32.png</file>
-</qresource>
-<qresource prefix="/qt-project.org/dialogs/qprintdialog">
-<file>images/status-color.png</file>
-<file>images/status-gray-scale.png</file>
-</qresource>
-</RCC>
diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm
index ed2d0908c4..fa4fac1884 100644
--- a/src/printsupport/dialogs/qprintdialog_mac.mm
+++ b/src/printsupport/dialogs/qprintdialog_mac.mm
@@ -1,55 +1,24 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <AppKit/AppKit.h>
#include "qprintdialog.h"
#include "qabstractprintdialog_p.h"
+#include <QtCore/qtemporarydir.h>
#include <QtCore/private/qcore_mac_p.h>
#include <QtWidgets/private/qapplication_p.h>
#include <QtPrintSupport/qprinter.h>
#include <QtPrintSupport/qprintengine.h>
#include <qpa/qplatformprintdevice.h>
+#include <QtPrintSupport/private/qprintengine_mac_p.h>
+
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
extern qreal qt_pointMultiplier(QPageLayout::Unit unit);
class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
@@ -114,7 +83,7 @@ QT_USE_NAMESPACE
// (Apologies to the folks with more than INT_MAX pages)
if (dialog->fromPage() == 1 && dialog->toPage() == INT_MAX) {
dialog->setPrintRange(QPrintDialog::AllPages);
- dialog->setFromTo(0, 0);
+ printer->setPageRanges(QPageRanges());
} else {
dialog->setPrintRange(QPrintDialog::PageRange); // In a way a lie, but it shouldn't hurt.
// Carbon hands us back a very large number here even for ALL, set it to max
@@ -127,21 +96,36 @@ QT_USE_NAMESPACE
PMDestinationType dest;
PMSessionGetDestinationType(session, settings, &dest);
if (dest == kPMDestinationFile) {
- // QTBUG-38820
- // If user selected Print to File, leave OSX to generate the PDF,
- // otherwise setting PdfFormat would prevent us showing dialog again.
- // TODO Restore this when QTBUG-36112 is fixed.
- /*
QCFType<CFURLRef> file;
PMSessionCopyDestinationLocation(session, settings, &file);
UInt8 localFile[2048]; // Assuming there's a POSIX file system here.
CFURLGetFileSystemRepresentation(file, true, localFile, sizeof(localFile));
- printer->setOutputFileName(QString::fromUtf8(reinterpret_cast<const char *>(localFile)));
- */
- } else {
+ auto outputFile = QFileInfo(QString::fromUtf8(reinterpret_cast<const char *>(localFile)));
+ if (outputFile.suffix() == "pdf"_L1)
+ printer->setOutputFileName(outputFile.absoluteFilePath());
+ else
+ qWarning() << "Can not print to file type" << outputFile.suffix();
+ } else if (dest == kPMDestinationPreview) {
+ static QTemporaryDir printPreviews;
+ auto documentName = printer->docName();
+ if (documentName.isEmpty())
+ documentName = QGuiApplication::applicationDisplayName();
+ auto fileName = printPreviews.filePath(QString("%1.pdf"_L1).arg(documentName));
+ printer->setOutputFileName(fileName);
+ // Ideally we would have a callback when the PDF engine is done writing
+ // to the file, and open Preview in response to that. Lacking that, we
+ // use the quick and dirty assumption that the the print operation will
+ // happen synchronously after the dialog is accepted, so we can defer
+ // the opening of the file to the next runloop pass.
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:fileName.toNSString()]];
+ });
+ } else if (dest == kPMDestinationProcessPDF) {
+ qWarning("Printing workflows are not supported");
+ } else if (dest == kPMDestinationPrinter) {
PMPrinter macPrinter;
PMSessionGetCurrentPrinter(session, &macPrinter);
- QString printerId = QString::fromCFString(PMPrinterGetID(macPrinter));
+ QString printerId = QString::fromCFString(PMPrinterGetID(macPrinter)).trimmed();
if (printer->printerName() != printerId)
printer->setPrinterName(printerId);
}
@@ -186,7 +170,7 @@ QT_USE_NAMESPACE
}
if (pageSize.isValid() && !pageSize.isEquivalentTo(printer->pageLayout().pageSize()))
printer->setPageSize(pageSize);
- printer->setOrientation(orientation == kPMLandscape ? QPrinter::Landscape : QPrinter::Portrait);
+ printer->setPageOrientation(orientation == kPMLandscape ? QPageLayout::Landscape : QPageLayout::Portrait);
dialog->done((returnCode == NSModalResponseOK) ? QDialog::Accepted : QDialog::Rejected);
}
@@ -199,14 +183,18 @@ void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality)
{
Q_Q(QPrintDialog);
- // get the NSPrintInfo from the print engine in the platform plugin
- void *voidp = 0;
- (void) QMetaObject::invokeMethod(qApp->platformNativeInterface(),
- "NSPrintInfoForPrintEngine",
- Q_RETURN_ARG(void *, voidp),
- Q_ARG(QPrintEngine *, printer->printEngine()));
- printInfo = static_cast<NSPrintInfo *>(voidp);
- [printInfo retain];
+ if (printer->outputFormat() == QPrinter::NativeFormat) {
+ printInfo = static_cast<QMacPrintEngine *>(printer->printEngine())->printInfo();
+ [printInfo retain];
+ } else {
+ const QPageLayout pageLayout = printer->pageLayout();
+ // initialize the printInfo using the dictionary from the application-wide print info
+ const auto dictionary = [NSPrintInfo.sharedPrintInfo dictionary];
+ printInfo = [[NSPrintInfo alloc] initWithDictionary:dictionary];
+ printInfo.orientation = pageLayout.orientation() == QPageLayout::Landscape
+ ? NSPaperOrientationLandscape : NSPaperOrientationPortrait;
+ printInfo.paperSize = pageLayout.pageSize().size(QPageSize::Point).toCGSize();
+ }
// It seems the only way that PM lets you use all is if the minimum
// for the page range is 1. This _kind of_ makes sense if you think about
@@ -250,8 +238,8 @@ void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality)
int rval = [printPanel runModalWithPrintInfo:printInfo];
[delegate printPanelDidEnd:printPanel returnCode:rval contextInfo:q];
} else {
- Q_ASSERT(q->parentWidget());
- QWindow *parentWindow = q->parentWidget()->windowHandle();
+ Q_ASSERT(q->window());
+ QWindow *parentWindow = q->window()->windowHandle();
NSWindow *window = static_cast<NSWindow *>(qApp->platformNativeInterface()->nativeResourceForWindow("nswindow", parentWindow));
[printPanel beginSheetWithPrintInfo:printInfo
modalForWindow:window
@@ -269,43 +257,26 @@ void QPrintDialogPrivate::closeCocoaPrintPanel()
printPanel = 0;
}
-static bool warnIfNotNative(QPrinter *printer)
-{
- if (printer->outputFormat() != QPrinter::NativeFormat) {
- qWarning("QPrintDialog: Cannot be used on non-native printers");
- return false;
- }
- return true;
-}
-
-
QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent)
: QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent)
{
- Q_D(QPrintDialog);
- if (!warnIfNotNative(d->printer))
- return;
setAttribute(Qt::WA_DontShowOnScreen);
}
QPrintDialog::QPrintDialog(QWidget *parent)
: QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent)
{
- Q_D(QPrintDialog);
- if (!warnIfNotNative(d->printer))
- return;
setAttribute(Qt::WA_DontShowOnScreen);
}
QPrintDialog::~QPrintDialog()
{
+ hide();
}
int QPrintDialog::exec()
{
Q_D(QPrintDialog);
- if (!warnIfNotNative(d->printer))
- return QDialog::Rejected;
QDialog::setVisible(true);
diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp
index 5390a8b2f2..aab5e2c7f0 100644
--- a/src/printsupport/dialogs/qprintdialog_unix.cpp
+++ b/src/printsupport/dialogs/qprintdialog_unix.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformdefs.h"
#include <QtPrintSupport/private/qtprintsupportglobal_p.h>
@@ -51,10 +15,10 @@
#include <QtCore/qdebug.h>
#include <QtCore/qdir.h>
#include <QtCore/qglobal.h>
-#include <QtCore/qtextcodec.h>
+#include <QtCore/qstringconverter.h>
#include <QtGui/qevent.h>
#if QT_CONFIG(filesystemmodel)
-#include <QtWidgets/qfilesystemmodel.h>
+#include <QtGui/qfilesystemmodel.h>
#endif
#include <QtWidgets/qstyleditemdelegate.h>
#include <QtWidgets/qformlayout.h>
@@ -67,6 +31,10 @@
#include <QtWidgets/qdialogbuttonbox.h>
+#if QT_CONFIG(regularexpression)
+#include <qregularexpression.h>
+#endif
+
#if QT_CONFIG(completer)
#include <private/qcompleter_p.h>
#endif
@@ -115,13 +83,15 @@ Print dialog class declarations
Layout in qprintpropertieswidget.ui
*/
-static void initResources()
+static void _q_pdu_initResources()
{
Q_INIT_RESOURCE(qprintdialog);
}
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
class QPrintPropertiesDialog : public QDialog
{
Q_OBJECT
@@ -159,8 +129,9 @@ private:
bool anyAdvancedOptionConflict() const;
QPrintDevice *m_currentPrintDevice;
- QTextCodec *m_cupsCodec = nullptr;
- QVector<QComboBox*> m_advancedOptionsCombos;
+
+ QStringDecoder toUnicode;
+ QList<QComboBox*> m_advancedOptionsCombos;
#endif
};
@@ -203,7 +174,7 @@ public:
QUnixPrintWidget * const parent;
QPrintPropertiesDialog *propertiesDialog;
Ui::QPrintWidget widget;
- QAbstractPrintDialog * q;
+ QPrintDialog * q;
QPrinter *printer;
QPrintDevice m_currentPrintDevice;
@@ -307,7 +278,7 @@ QPrintPropertiesDialog::QPrintPropertiesDialog(QPrinter *printer, QPrintDevice *
});
#else
- Q_UNUSED(currentPrintDevice)
+ Q_UNUSED(currentPrintDevice);
widget.tabs->setTabEnabled(advancedTabIndex, false);
#endif
}
@@ -351,7 +322,7 @@ void QPrintPropertiesDialog::reject()
void QPrintPropertiesDialog::accept()
{
-#if QT_CONFIG(cups)
+#if QT_CONFIG(cups) && QT_CONFIG(messagebox)
if (widget.pageSetup->hasPpdConflict()) {
widget.tabs->setCurrentWidget(widget.tabPage);
const QMessageBox::StandardButton answer = QMessageBox::warning(this, tr("Page Setup Conflicts"),
@@ -398,12 +369,12 @@ static const char *ppdOriginallySelectedChoiceProperty = "_q_ppd_originally_sele
// Used to store the warning label pointer for each QComboBox that represents an advanced option
static const char *warningLabelProperty = "_q_warning_label";
-static bool isBlacklistedGroup(const ppd_group_t *group) Q_DECL_NOTHROW
+static bool isBlacklistedGroup(const ppd_group_t *group) noexcept
{
return qstrcmp(group->name, "InstallableOptions") == 0;
};
-static bool isBlacklistedOption(const char *keyword) Q_DECL_NOTHROW
+static bool isBlacklistedOption(const char *keyword) noexcept
{
// We already let the user set these options elsewhere
const char *cupsOptionBlacklist[] = {
@@ -426,10 +397,14 @@ bool QPrintPropertiesDialog::createAdvancedOptionsWidget()
{
bool anyWidgetCreated = false;
- ppd_file_t *ppd = m_currentPrintDevice->property(PDPK_PpdFile).value<ppd_file_t*>();
+ ppd_file_t *ppd = qvariant_cast<ppd_file_t*>(m_currentPrintDevice->property(PDPK_PpdFile));
if (ppd) {
- m_cupsCodec = QTextCodec::codecForName(ppd->lang_encoding);
+ toUnicode = QStringDecoder(ppd->lang_encoding, QStringDecoder::Flag::Stateless);
+ if (!toUnicode.isValid()) {
+ qWarning() << "QPrinSupport: Cups uses unsupported encoding" << ppd->lang_encoding;
+ toUnicode = QStringDecoder(QStringDecoder::Utf8, QStringDecoder::Flag::Stateless);
+ }
QWidget *holdingWidget = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(holdingWidget);
@@ -466,7 +441,7 @@ bool QPrintPropertiesDialog::createAdvancedOptionsWidget()
if (choiceIsInstallableConflict && static_cast<int>(choice->marked) == 1) {
markedChoiceNotAvailable = true;
} else if (!choiceIsInstallableConflict) {
- choicesCb->addItem(m_cupsCodec->toUnicode(choice->text), i);
+ choicesCb->addItem(toUnicode(choice->text), i);
if (static_cast<int>(choice->marked) == 1) {
choicesCb->setCurrentIndex(choicesCb->count() - 1);
choicesCb->setProperty(ppdOriginallySelectedChoiceProperty, QVariant(i));
@@ -487,7 +462,7 @@ bool QPrintPropertiesDialog::createAdvancedOptionsWidget()
if (choicesCb->count() > 1) {
- connect(choicesCb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, setPpdOptionFromCombo);
+ connect(choicesCb, &QComboBox::currentIndexChanged, this, setPpdOptionFromCombo);
// We need an extra label at the end to show the conflict warning
QWidget *choicesCbWithLabel = new QWidget();
@@ -497,7 +472,7 @@ bool QPrintPropertiesDialog::createAdvancedOptionsWidget()
choicesCbWithLabelLayout->addWidget(choicesCb);
choicesCbWithLabelLayout->addWidget(warningLabel);
- QLabel *optionLabel = new QLabel(m_cupsCodec->toUnicode(option->text));
+ QLabel *optionLabel = new QLabel(toUnicode(option->text));
groupLayout->addRow(optionLabel, choicesCbWithLabel);
anyWidgetCreated = true;
choicesCb->setProperty(ppdOptionProperty, QVariant::fromValue(option));
@@ -510,7 +485,7 @@ bool QPrintPropertiesDialog::createAdvancedOptionsWidget()
}
if (groupLayout->rowCount() > 0) {
- QGroupBox *groupBox = new QGroupBox(m_cupsCodec->toUnicode(group->text));
+ QGroupBox *groupBox = new QGroupBox(toUnicode(group->text));
groupBox->setLayout(groupLayout);
layout->addWidget(groupBox);
} else {
@@ -523,16 +498,13 @@ bool QPrintPropertiesDialog::createAdvancedOptionsWidget()
widget.scrollArea->setWidget(holdingWidget);
}
- if (!m_cupsCodec)
- m_cupsCodec = QTextCodec::codecForLocale();
-
return anyWidgetCreated;
}
void QPrintPropertiesDialog::setPrinterAdvancedCupsOptions() const
{
for (const QComboBox *choicesCb : m_advancedOptionsCombos) {
- const ppd_option_t *option = choicesCb->property(ppdOptionProperty).value<const ppd_option_t *>();
+ const ppd_option_t *option = qvariant_cast<const ppd_option_t *>(choicesCb->property(ppdOptionProperty));
// We can't use choicesCb->currentIndex() to know the index of the option in the choices[] array
// because some of them may not be present in the list because they conflict with the
@@ -551,7 +523,7 @@ void QPrintPropertiesDialog::setPrinterAdvancedCupsOptions() const
void QPrintPropertiesDialog::revertAdvancedOptionsToSavedValues() const
{
for (QComboBox *choicesCb : m_advancedOptionsCombos) {
- const int originallySelectedChoice = choicesCb->property(ppdOriginallySelectedChoiceProperty).value<int>();
+ const int originallySelectedChoice = qvariant_cast<int>(choicesCb->property(ppdOriginallySelectedChoiceProperty));
const int newComboIndexToSelect = choicesCb->findData(originallySelectedChoice);
choicesCb->setCurrentIndex(newComboIndexToSelect);
// The currentIndexChanged lambda takes care of resetting the ppd option
@@ -580,8 +552,8 @@ bool QPrintPropertiesDialog::anyAdvancedOptionConflict() const
bool anyConflicted = false;
for (const QComboBox *choicesCb : m_advancedOptionsCombos) {
- const ppd_option_t *option = choicesCb->property(ppdOptionProperty).value<const ppd_option_t *>();
- QLabel *warningLabel = choicesCb->property(warningLabelProperty).value<QLabel *>();
+ const ppd_option_t *option = qvariant_cast<const ppd_option_t *>(choicesCb->property(ppdOptionProperty));
+ QLabel *warningLabel = qvariant_cast<QLabel *>(choicesCb->property(warningLabelProperty));
if (option->conflicted) {
anyConflicted = true;
const int pixmap_size = choicesCb->sizeHint().height() * .75;
@@ -612,7 +584,7 @@ QPrintDialogPrivate::QPrintDialogPrivate()
: top(nullptr), bottom(nullptr), buttons(nullptr), collapseButton(nullptr),
explicitDuplexMode(QPrint::DuplexAuto)
{
- initResources();
+ _q_pdu_initResources();
}
QPrintDialogPrivate::~QPrintDialogPrivate()
@@ -627,9 +599,9 @@ void QPrintDialogPrivate::init()
bottom = new QWidget(q);
options.setupUi(bottom);
options.color->setIconSize(QSize(32, 32));
- options.color->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-color.png")));
+ options.color->setIcon(QIcon(":/qt-project.org/dialogs/qprintdialog/images/status-color.png"_L1));
options.grayscale->setIconSize(QSize(32, 32));
- options.grayscale->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png")));
+ options.grayscale->setIcon(QIcon(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png"_L1));
#if QT_CONFIG(cups)
// Add Page Set widget if CUPS is available
@@ -637,8 +609,10 @@ void QPrintDialogPrivate::init()
options.pageSetCombo->addItem(tr("Odd Pages"), QVariant::fromValue(QCUPSSupport::OddPages));
options.pageSetCombo->addItem(tr("Even Pages"), QVariant::fromValue(QCUPSSupport::EvenPages));
#else
- for (int i = options.pagesLayout->count() - 1; i >= 0; --i)
- delete options.pagesLayout->itemAt(i)->widget();
+ delete options.pagesRadioButton;
+ delete options.pagesLineEdit;
+ options.pagesRadioButton = nullptr;
+ options.pagesLineEdit = nullptr;
#endif
top->d->setOptionsPane(this);
@@ -700,13 +674,14 @@ void QPrintDialogPrivate::selectPrinter(const QPrinter::OutputFormat outputForma
else
options.grayscale->setChecked(true);
- // keep duplex value explicitly set by user, if any, and selected printer supports it;
- // use device default otherwise
+ // duplex priorities to be as follows:
+ // 1) a user-selected duplex value in the dialog has highest priority
+ // 2) duplex value set in the QPrinter
QPrint::DuplexMode duplex;
if (explicitDuplexMode != QPrint::DuplexAuto && supportedDuplexMode.contains(explicitDuplexMode))
duplex = explicitDuplexMode;
else
- duplex = top->d->m_currentPrintDevice.defaultDuplexMode();
+ duplex = static_cast<QPrint::DuplexMode>(p->duplex());
switch (duplex) {
case QPrint::DuplexNone:
options.noDuplex->setChecked(true); break;
@@ -728,91 +703,17 @@ void QPrintDialogPrivate::selectPrinter(const QPrinter::OutputFormat outputForma
options.pageSetCombo->setEnabled(true);
#if QT_CONFIG(cups)
+ // Disable complex page ranges widget when printing to pdf
+ // It doesn't work since it relies on cups to do the heavy lifting and cups
+ // is not used when printing to PDF
+ options.pagesRadioButton->setEnabled(outputFormat != QPrinter::PdfFormat);
+
// Disable color options on main dialog if not printing to file, it will be handled by CUPS advanced dialog
options.colorMode->setVisible(outputFormat == QPrinter::PdfFormat);
#endif
}
#if QT_CONFIG(cups)
-static std::vector<std::pair<int, int>> pageRangesFromString(const QString &pagesString) Q_DECL_NOTHROW
-{
- std::vector<std::pair<int, int>> result;
- const QStringList items = pagesString.split(',');
- for (const QString item : items) {
- if (item.isEmpty())
- return {};
-
- if (item.contains(QLatin1Char('-'))) {
- const QStringList rangeItems = item.split('-');
- if (rangeItems.count() != 2)
- return {};
-
- bool ok;
- const int number1 = rangeItems[0].toInt(&ok);
- if (!ok)
- return {};
-
- const int number2 = rangeItems[1].toInt(&ok);
- if (!ok)
- return {};
-
- if (number1 < 1 || number2 < 1 || number2 < number1)
- return {};
-
- result.push_back(std::make_pair(number1, number2));
-
- } else {
- bool ok;
- const int number = item.toInt(&ok);
- if (!ok)
- return {};
-
- if (number < 1)
- return {};
-
- result.push_back(std::make_pair(number, number));
- }
- }
-
- // check no range intersects with the next
- std::sort(result.begin(), result.end(),
- [](const std::pair<int, int> &it1, const std::pair<int, int> &it2) { return it1.first < it2.first; });
- int previousSecond = -1;
- for (auto pair : result) {
- if (pair.first <= previousSecond)
- return {};
-
- previousSecond = pair.second;
- }
-
- return result;
-}
-
-static QString stringFromPageRanges(const std::vector<std::pair<int, int>> &pageRanges) Q_DECL_NOTHROW
-{
- QString result;
-
- for (auto pair : pageRanges) {
- if (!result.isEmpty())
- result += QLatin1Char(',');
-
- if (pair.first == pair.second)
- result += QString::number(pair.first);
- else
- result += QStringLiteral("%1-%2").arg(pair.first).arg(pair.second);
- }
-
- return result;
-}
-
-static bool isValidPagesString(const QString &pagesString) Q_DECL_NOTHROW
-{
- if (pagesString.isEmpty())
- return false;
-
- auto pagesRanges = pageRangesFromString(pagesString);
- return !pagesRanges.empty();
-}
void QPrintDialogPrivate::updatePpdDuplexOption(QRadioButton *radio)
{
@@ -862,41 +763,42 @@ void QPrintDialogPrivate::setupPrinter()
// print range
if (options.printAll->isChecked()) {
p->setPrintRange(QPrinter::AllPages);
- p->setFromTo(0,0);
+ p->setPageRanges(QPageRanges());
} else if (options.printSelection->isChecked()) {
p->setPrintRange(QPrinter::Selection);
- p->setFromTo(0,0);
+ p->setPageRanges(QPageRanges());
} else if (options.printCurrentPage->isChecked()) {
p->setPrintRange(QPrinter::CurrentPage);
- p->setFromTo(0,0);
+ p->setPageRanges(QPageRanges());
} else if (options.printRange->isChecked()) {
- if (q->isOptionEnabled(QPrintDialog::PrintPageRange)) {
+ if (q->testOption(QPrintDialog::PrintPageRange)) {
p->setPrintRange(QPrinter::PageRange);
p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value()));
} else {
// This case happens when CUPS server-side page range is enabled
// Setting the range to the printer occurs below
p->setPrintRange(QPrinter::AllPages);
- p->setFromTo(0,0);
+ p->setPageRanges(QPageRanges());
}
}
#if QT_CONFIG(cups)
if (options.pagesRadioButton->isChecked()) {
- auto pageRanges = pageRangesFromString(options.pagesLineEdit->text());
-
- p->setPrintRange(QPrinter::AllPages);
- p->setFromTo(0, 0);
+ const QPageRanges ranges = QPageRanges::fromString(options.pagesLineEdit->text());
+ if (!ranges.isEmpty()) {
+ p->setPrintRange(QPrinter::PageRange);
+ p->setPageRanges(ranges);
+ }
// server-side page filtering
- QCUPSSupport::setPageRange(p, stringFromPageRanges(pageRanges));
+ QCUPSSupport::setPageRange(p, ranges.toString());
}
// page set
if (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange) {
//If the application is selecting pages and the first page number is even then need to adjust the odd-even accordingly
- QCUPSSupport::PageSet pageSet = options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()).value<QCUPSSupport::PageSet>();
- if (q->isOptionEnabled(QPrintDialog::PrintPageRange)
+ QCUPSSupport::PageSet pageSet = qvariant_cast<QCUPSSupport::PageSet>(options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()));
+ if (q->testOption(QPrintDialog::PrintPageRange)
&& p->printRange() == QPrinter::PageRange
&& (q->fromPage() % 2 == 0)) {
@@ -916,7 +818,7 @@ void QPrintDialogPrivate::setupPrinter()
// server-side page range, since we set the page range on the printer to 0-0/AllPages above,
// we need to take the values directly from the widget as q->fromPage() will return 0
- if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && options.printRange->isChecked())
+ if (!q->testOption(QPrintDialog::PrintPageRange) && options.printRange->isChecked())
QCUPSSupport::setPageRange(p, options.from->value(), qMax(options.from->value(), options.to->value()));
}
#endif
@@ -965,19 +867,19 @@ void QPrintDialogPrivate::_q_checkFields()
void QPrintDialogPrivate::updateWidgets()
{
Q_Q(QPrintDialog);
- options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) ||
- q->isOptionEnabled(QPrintDialog::PrintSelection) ||
- q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
+ options.gbPrintRange->setVisible(q->testOption(QPrintDialog::PrintPageRange) ||
+ q->testOption(QPrintDialog::PrintSelection) ||
+ q->testOption(QPrintDialog::PrintCurrentPage));
- options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange));
- options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection));
- options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
- options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies));
+ options.printRange->setEnabled(q->testOption(QPrintDialog::PrintPageRange));
+ options.printSelection->setVisible(q->testOption(QPrintDialog::PrintSelection));
+ options.printCurrentPage->setVisible(q->testOption(QPrintDialog::PrintCurrentPage));
+ options.collate->setVisible(q->testOption(QPrintDialog::PrintCollateCopies));
#if QT_CONFIG(cups)
// Don't display Page Set if only Selection or Current Page are enabled
- if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)
- && (q->isOptionEnabled(QPrintDialog::PrintSelection) || q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) {
+ if (!q->testOption(QPrintDialog::PrintPageRange)
+ && (q->testOption(QPrintDialog::PrintSelection) || q->testOption(QPrintDialog::PrintCurrentPage))) {
options.pageSetCombo->setVisible(false);
options.pageSetLabel->setVisible(false);
} else {
@@ -985,7 +887,7 @@ void QPrintDialogPrivate::updateWidgets()
options.pageSetLabel->setVisible(true);
}
- if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)) {
+ if (!q->testOption(QPrintDialog::PrintPageRange)) {
// If we can do CUPS server side pages selection,
// display the page range widgets
options.gbPrintRange->setVisible(true);
@@ -1007,7 +909,7 @@ void QPrintDialogPrivate::updateWidgets()
options.pageSetCombo->setEnabled(true);
break;
case QPrintDialog::CurrentPage:
- if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage)) {
+ if (q->testOption(QPrintDialog::PrintCurrentPage)) {
options.printCurrentPage->setChecked(true);
options.pageSetCombo->setEnabled(false);
}
@@ -1082,14 +984,14 @@ void QPrintDialog::setVisible(bool visible)
int QPrintDialog::exec()
{
- return QDialog::exec();
+ return QAbstractPrintDialog::exec();
}
void QPrintDialog::accept()
{
Q_D(QPrintDialog);
-#if QT_CONFIG(cups)
- if (d->options.pagesRadioButton->isChecked() && !isValidPagesString(d->options.pagesLineEdit->text())) {
+#if QT_CONFIG(cups) && QT_CONFIG(messagebox)
+ if (d->options.pagesRadioButton->isChecked() && printer()->pageRanges().isEmpty()) {
QMessageBox::critical(this, tr("Invalid Pages Definition"),
tr("%1 does not follow the correct syntax. Please use ',' to separate "
"ranges and pages, '-' to define ranges and make sure ranges do "
@@ -1133,7 +1035,7 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter *
{
q = nullptr;
if (parent)
- q = qobject_cast<QAbstractPrintDialog*> (parent->parent());
+ q = qobject_cast<QPrintDialog*> (parent->parent());
widget.setupUi(parent);
@@ -1171,12 +1073,14 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter *
void QUnixPrintWidgetPrivate::updateWidget()
{
- const bool printToFile = q == 0 || q->isOptionEnabled(QPrintDialog::PrintToFile);
+ const bool printToFile = q == nullptr || q->testOption(QPrintDialog::PrintToFile);
if (printToFile && !filePrintersAdded) {
if (widget.printers->count())
widget.printers->insertSeparator(widget.printers->count());
widget.printers->addItem(QPrintDialog::tr("Print to File (PDF)"));
filePrintersAdded = true;
+ if (widget.printers->count() == 1)
+ _q_printerChanged(0);
}
if (!printToFile && filePrintersAdded) {
widget.printers->removeItem(widget.printers->count()-1);
@@ -1198,7 +1102,8 @@ void QUnixPrintWidgetPrivate::updateWidget()
widget.lOutput->setVisible(printToFile);
widget.fileBrowser->setVisible(printToFile);
- widget.properties->setVisible(q->isOptionEnabled(QAbstractPrintDialog::PrintShowPageSize));
+ if (q)
+ widget.properties->setVisible(q->testOption(QAbstractPrintDialog::PrintShowPageSize));
}
QUnixPrintWidgetPrivate::~QUnixPrintWidgetPrivate()
@@ -1233,10 +1138,10 @@ void QUnixPrintWidgetPrivate::_q_printerChanged(int index)
QString filename = widget.filename->text();
widget.filename->setText(filename);
widget.lOutput->setEnabled(true);
- if (optionsPane)
- optionsPane->selectPrinter(QPrinter::PdfFormat);
printer->setOutputFormat(QPrinter::PdfFormat);
m_currentPrintDevice = QPrintDevice();
+ if (optionsPane)
+ optionsPane->selectPrinter(QPrinter::PdfFormat);
return;
}
}
@@ -1318,10 +1223,10 @@ bool QUnixPrintWidgetPrivate::checkFields()
#if QT_CONFIG(cups)
if (propertiesDialog) {
- QCUPSSupport::PagesPerSheet pagesPerSheet = propertiesDialog->widget.pageSetup->m_ui.pagesPerSheetCombo
- ->currentData().value<QCUPSSupport::PagesPerSheet>();
+ QCUPSSupport::PagesPerSheet pagesPerSheet = qvariant_cast<QCUPSSupport::PagesPerSheet>(propertiesDialog->widget.pageSetup->m_ui.pagesPerSheetCombo
+ ->currentData());
- QCUPSSupport::PageSet pageSet = optionsPane->options.pageSetCombo->currentData().value<QCUPSSupport::PageSet>();
+ QCUPSSupport::PageSet pageSet = qvariant_cast<QCUPSSupport::PageSet>(optionsPane->options.pageSetCombo->currentData());
if (pagesPerSheet != QCUPSSupport::OnePagePerSheet
@@ -1345,7 +1250,7 @@ void QUnixPrintWidgetPrivate::setupPrinterProperties()
QPrinter::OutputFormat outputFormat;
QString printerName;
- if (q->isOptionEnabled(QPrintDialog::PrintToFile)
+ if (q->testOption(QPrintDialog::PrintToFile)
&& (widget.printers->currentIndex() == widget.printers->count() - 1)) {// PDF
outputFormat = QPrinter::PdfFormat;
} else {
@@ -1417,22 +1322,25 @@ QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent)
if (printer->outputFileName().isEmpty()) {
QString home = QDir::homePath();
QString cur = QDir::currentPath();
- if (!home.endsWith(QLatin1Char('/')))
- home += QLatin1Char('/');
+ if (!home.endsWith(u'/'))
+ home += u'/';
if (!cur.startsWith(home))
cur = home;
- else if (!cur.endsWith(QLatin1Char('/')))
- cur += QLatin1Char('/');
- if (QGuiApplication::platformName() == QStringLiteral("xcb")) {
+ else if (!cur.endsWith(u'/'))
+ cur += u'/';
+ if (QGuiApplication::platformName() == "xcb"_L1) {
if (printer->docName().isEmpty()) {
- cur += QStringLiteral("print.pdf");
+ cur += "print.pdf"_L1;
} else {
- const QRegExp re(QStringLiteral("(.*)\\.\\S+"));
- if (re.exactMatch(printer->docName()))
- cur += re.cap(1);
+#if QT_CONFIG(regularexpression)
+ const QRegularExpression re(QStringLiteral("(.*)\\.\\S+"));
+ auto match = re.match(printer->docName());
+ if (match.hasMatch())
+ cur += match.captured(1);
else
+#endif
cur += printer->docName();
- cur += QStringLiteral(".pdf");
+ cur += ".pdf"_L1;
}
} // xcb
diff --git a/src/printsupport/dialogs/qprintdialog_win.cpp b/src/printsupport/dialogs/qprintdialog_win.cpp
index 11f2fa3259..6d8c2d0f4d 100644
--- a/src/printsupport/dialogs/qprintdialog_win.cpp
+++ b/src/printsupport/dialogs/qprintdialog_win.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtPrintSupport/qtprintsupportglobal.h>
@@ -47,7 +11,7 @@
#include <private/qapplication_p.h>
#include "qabstractprintdialog_p.h"
-#include "../kernel/qprintengine_win_p.h"
+#include <private/qprintengine_win_p.h>
#include "../kernel/qprinter_p.h"
#if !defined(PD_NOCURRENTPAGE)
@@ -59,6 +23,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
//extern void qt_win_eatMouseMove();
class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
@@ -76,7 +42,7 @@ public:
QWin32PrintEnginePrivate *ep;
};
-static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent,
+static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWindow *parentWindow,
QPrintDialog *pdlg,
QPrintDialogPrivate *d, HGLOBAL *tempDevNames)
{
@@ -98,21 +64,21 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent,
pd->Flags = PD_RETURNDC;
pd->Flags |= PD_USEDEVMODECOPIESANDCOLLATE;
- if (!pdlg->isOptionEnabled(QPrintDialog::PrintSelection))
+ if (!pdlg->testOption(QPrintDialog::PrintSelection))
pd->Flags |= PD_NOSELECTION;
- if (pdlg->isOptionEnabled(QPrintDialog::PrintPageRange)) {
+ if (pdlg->testOption(QPrintDialog::PrintPageRange)) {
pd->nMinPage = pdlg->minPage();
pd->nMaxPage = pdlg->maxPage();
}
- if(!pdlg->isOptionEnabled(QPrintDialog::PrintToFile))
+ if (!pdlg->testOption(QPrintDialog::PrintToFile))
pd->Flags |= PD_DISABLEPRINTTOFILE;
- if (pdlg->isOptionEnabled(QPrintDialog::PrintSelection) && pdlg->printRange() == QPrintDialog::Selection)
+ if (pdlg->testOption(QPrintDialog::PrintSelection) && pdlg->printRange() == QPrintDialog::Selection)
pd->Flags |= PD_SELECTION;
- else if (pdlg->isOptionEnabled(QPrintDialog::PrintPageRange) && pdlg->printRange() == QPrintDialog::PageRange)
+ else if (pdlg->testOption(QPrintDialog::PrintPageRange) && pdlg->printRange() == QPrintDialog::PageRange)
pd->Flags |= PD_PAGENUMS;
- else if (pdlg->isOptionEnabled(QPrintDialog::PrintCurrentPage) && pdlg->printRange() == QPrintDialog::CurrentPage)
+ else if (pdlg->testOption(QPrintDialog::PrintCurrentPage) && pdlg->printRange() == QPrintDialog::CurrentPage)
pd->Flags |= PD_CURRENTPAGE;
else
pd->Flags |= PD_ALLPAGES;
@@ -123,7 +89,7 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent,
pd->Flags |= PD_NOPAGENUMS;
// Disable Current Page option if not required as default is Enabled
- if (!pdlg->isOptionEnabled(QPrintDialog::PrintCurrentPage))
+ if (!pdlg->testOption(QPrintDialog::PrintCurrentPage))
pd->Flags |= PD_NOCURRENTPAGE;
// Default to showing the General tab first
@@ -135,9 +101,12 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent,
if (d->ep->printToFile)
pd->Flags |= PD_PRINTTOFILE;
- Q_ASSERT(parent);
- QWindow *parentWindow = parent->windowHandle();
- pd->hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0;
+
+ WId wId = parentWindow ? parentWindow->winId() : 0;
+ //QTBUG-118899 PrintDlg needs valid window handle in hwndOwner
+ //So in case there is no valid handle in the application,
+ //use the desktop as valid handle.
+ pd->hwndOwner = wId != 0 ? HWND(wId) : GetDesktopWindow();
pd->lpPageRanges[0].nFromPage = qMax(pdlg->fromPage(), pdlg->minPage());
pd->lpPageRanges[0].nToPage = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1;
pd->nCopies = d->printer->copyCount();
@@ -147,16 +116,16 @@ static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPri
{
if (pd->Flags & PD_SELECTION) {
pdlg->setPrintRange(QPrintDialog::Selection);
- pdlg->setFromTo(0, 0);
+ pdlg->printer()->setPageRanges(QPageRanges());
} else if (pd->Flags & PD_PAGENUMS) {
pdlg->setPrintRange(QPrintDialog::PageRange);
pdlg->setFromTo(pd->lpPageRanges[0].nFromPage, pd->lpPageRanges[0].nToPage);
} else if (pd->Flags & PD_CURRENTPAGE) {
pdlg->setPrintRange(QPrintDialog::CurrentPage);
- pdlg->setFromTo(0, 0);
+ pdlg->printer()->setPageRanges(QPageRanges());
} else { // PD_ALLPAGES
pdlg->setPrintRange(QPrintDialog::AllPages);
- pdlg->setFromTo(0, 0);
+ pdlg->printer()->setPageRanges(QPageRanges());
}
d->ep->printToFile = (pd->Flags & PD_PRINTTOFILE) != 0;
@@ -164,8 +133,8 @@ static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPri
d->engine->setGlobalDevMode(pd->hDevNames, pd->hDevMode);
if (d->ep->printToFile && d->ep->fileName.isEmpty())
- d->ep->fileName = QLatin1String("FILE:");
- else if (!d->ep->printToFile && d->ep->fileName == QLatin1String("FILE:"))
+ d->ep->fileName = "FILE:"_L1;
+ else if (!d->ep->printToFile && d->ep->fileName == "FILE:"_L1)
d->ep->fileName.clear();
}
@@ -216,15 +185,20 @@ int QPrintDialog::exec()
int QPrintDialogPrivate::openWindowsPrintDialogModally()
{
Q_Q(QPrintDialog);
- QWidget *parent = q->parentWidget();
- if (parent)
- parent = parent->window();
- else
- parent = QApplication::activeWindow();
-
- // If there is no window, fall back to the print dialog itself
- if (parent == 0)
- parent = q;
+ QWindow *parentWindow = q->windowHandle() ? q->windowHandle()->transientParent() : nullptr;
+ if (!parentWindow) {
+ QWidget *parent = q->parentWidget();
+ if (parent)
+ parent = parent->window();
+ else
+ parent = QApplication::activeWindow();
+
+ // If there is no window, fall back to the print dialog itself
+ if (!parent)
+ parent = q;
+
+ parentWindow = parent->windowHandle();
+ }
q->QDialog::setVisible(true);
@@ -239,7 +213,7 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally()
memset(&pd, 0, sizeof(PRINTDLGEX));
pd.lStructSize = sizeof(PRINTDLGEX);
pd.lpPageRanges = &pageRange;
- qt_win_setup_PRINTDLGEX(&pd, parent, q, this, tempDevNames);
+ qt_win_setup_PRINTDLGEX(&pd, parentWindow, q, this, tempDevNames);
do {
done = true;
@@ -261,9 +235,9 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally()
}
if (!done) {
- QMessageBox::warning(0, QPrintDialog::tr("Print"),
- QPrintDialog::tr("The 'From' value cannot be greater than the 'To' value."),
- QPrintDialog::tr("OK"));
+ QMessageBox::warning(nullptr,
+ QPrintDialog::tr("Print"),
+ QPrintDialog::tr("The 'From' value cannot be greater than the 'To' value."));
}
} while (!done);
diff --git a/src/printsupport/dialogs/qprintpreviewdialog.cpp b/src/printsupport/dialogs/qprintpreviewdialog.cpp
index 418bc47a59..2028287b55 100644
--- a/src/printsupport/dialogs/qprintpreviewdialog.cpp
+++ b/src/printsupport/dialogs/qprintpreviewdialog.cpp
@@ -1,48 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qprintpreviewdialog.h"
#include "qprintpreviewwidget.h"
#include <private/qprinter_p.h>
#include "qprintdialog.h"
-#include <QtWidgets/qaction.h>
+#include <QtGui/qaction.h>
+#include <QtGui/qactiongroup.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qcombobox.h>
#include <QtWidgets/qlineedit.h>
@@ -63,7 +28,9 @@
#include <QtWidgets/qformlayout.h>
#include <QtWidgets/qlabel.h>
-static void initResources()
+#include <QtCore/qpointer.h>
+
+static void _q_ppd_initResources()
{
static bool resourcesInitialized = false;
if (!resourcesInitialized) {
@@ -74,6 +41,8 @@ static void initResources()
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
namespace {
class QPrintPreviewMainWindow : public QMainWindow
{
@@ -93,13 +62,13 @@ public:
State validate(QString &input, int &pos) const override
{
bool replacePercent = false;
- if (input.endsWith(QLatin1Char('%'))) {
- input = input.left(input.length() - 1);
+ if (input.endsWith(u'%')) {
+ input = input.left(input.size() - 1);
replacePercent = true;
}
State state = QDoubleValidator::validate(input, pos);
if (replacePercent)
- input += QLatin1Char('%');
+ input += u'%';
const int num_size = 4;
if (state == Intermediate) {
int i = input.indexOf(QLocale::system().decimalPoint());
@@ -152,8 +121,8 @@ class QPrintPreviewDialogPrivate : public QDialogPrivate
Q_DECLARE_PUBLIC(QPrintPreviewDialog)
public:
QPrintPreviewDialogPrivate()
- : printDialog(nullptr), ownPrinter(false),
- initialized(false) {}
+ : printDialog(nullptr), pageSetupDialog(nullptr),
+ ownPrinter(false), initialized(false) {}
// private slots
void _q_fit(QAction *action);
@@ -178,6 +147,7 @@ public:
void updateZoomFactor();
QPrintDialog *printDialog;
+ QPageSetupDialog *pageSetupDialog;
QPrintPreviewWidget *preview;
QPrinter *printer;
bool ownPrinter;
@@ -224,7 +194,7 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
{
Q_Q(QPrintPreviewDialog);
- initResources();
+ _q_ppd_initResources();
if (_printer) {
preview = new QPrintPreviewWidget(_printer, q);
@@ -331,12 +301,12 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
QVBoxLayout *topLayout = new QVBoxLayout;
topLayout->addWidget(mw);
- topLayout->setMargin(0);
+ topLayout->setContentsMargins(0, 0, 0, 0);
q->setLayout(topLayout);
QString caption = QCoreApplication::translate("QPrintPreviewDialog", "Print Preview");
if (!printer->docName().isEmpty())
- caption += QLatin1String(": ") + printer->docName();
+ caption += ": "_L1 + printer->docName();
q->setWindowTitle(caption);
if (!printer->isValid()
@@ -348,12 +318,12 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
preview->setFocus();
}
-static inline void qt_setupActionIcon(QAction *action, QLatin1String name)
+static inline void qt_setupActionIcon(QAction *action, QLatin1StringView name)
{
- QLatin1String imagePrefix(":/qt-project.org/dialogs/qprintpreviewdialog/images/");
- QIcon icon;
- icon.addFile(imagePrefix + name + QLatin1String("-24.png"), QSize(24, 24));
- icon.addFile(imagePrefix + name + QLatin1String("-32.png"), QSize(32, 32));
+ const auto imagePrefix = ":/qt-project.org/dialogs/qprintpreviewdialog/images/"_L1;
+ QIcon icon = QIcon::fromTheme(name);
+ icon.addFile(imagePrefix + name + "-24.png"_L1, QSize(24, 24));
+ icon.addFile(imagePrefix + name + "-32.png"_L1, QSize(32, 32));
action->setIcon(icon);
}
@@ -368,30 +338,30 @@ void QPrintPreviewDialogPrivate::setupActions()
prevPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Previous page"));
firstPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "First page"));
lastPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Last page"));
- qt_setupActionIcon(nextPageAction, QLatin1String("go-next"));
- qt_setupActionIcon(prevPageAction, QLatin1String("go-previous"));
- qt_setupActionIcon(firstPageAction, QLatin1String("go-first"));
- qt_setupActionIcon(lastPageAction, QLatin1String("go-last"));
+ qt_setupActionIcon(nextPageAction, "go-next"_L1);
+ qt_setupActionIcon(prevPageAction, "go-previous"_L1);
+ qt_setupActionIcon(firstPageAction, "go-first"_L1);
+ qt_setupActionIcon(lastPageAction, "go-last"_L1);
QObject::connect(navGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_navigate(QAction*)));
fitGroup = new QActionGroup(q);
fitWidthAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit width"));
fitPageAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit page"));
- fitWidthAction->setObjectName(QLatin1String("fitWidthAction"));
- fitPageAction->setObjectName(QLatin1String("fitPageAction"));
+ fitWidthAction->setObjectName("fitWidthAction"_L1);
+ fitPageAction->setObjectName("fitPageAction"_L1);
fitWidthAction->setCheckable(true);
fitPageAction->setCheckable(true);
- qt_setupActionIcon(fitWidthAction, QLatin1String("fit-width"));
- qt_setupActionIcon(fitPageAction, QLatin1String("fit-page"));
+ qt_setupActionIcon(fitWidthAction, "zoom-fit-width"_L1);
+ qt_setupActionIcon(fitPageAction, "zoom-fit-page"_L1);
QObject::connect(fitGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_fit(QAction*)));
// Zoom
zoomGroup = new QActionGroup(q);
zoomInAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom in"));
zoomOutAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom out"));
- qt_setupActionIcon(zoomInAction, QLatin1String("zoom-in"));
- qt_setupActionIcon(zoomOutAction, QLatin1String("zoom-out"));
+ qt_setupActionIcon(zoomInAction, "zoom-in"_L1);
+ qt_setupActionIcon(zoomOutAction, "zoom-out"_L1);
// Portrait/Landscape
orientationGroup = new QActionGroup(q);
@@ -399,8 +369,8 @@ void QPrintPreviewDialogPrivate::setupActions()
landscapeAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Landscape"));
portraitAction->setCheckable(true);
landscapeAction->setCheckable(true);
- qt_setupActionIcon(portraitAction, QLatin1String("layout-portrait"));
- qt_setupActionIcon(landscapeAction, QLatin1String("layout-landscape"));
+ qt_setupActionIcon(portraitAction, "layout-portrait"_L1);
+ qt_setupActionIcon(landscapeAction, "layout-landscape"_L1);
QObject::connect(portraitAction, SIGNAL(triggered(bool)), preview, SLOT(setPortraitOrientation()));
QObject::connect(landscapeAction, SIGNAL(triggered(bool)), preview, SLOT(setLandscapeOrientation()));
@@ -409,12 +379,12 @@ void QPrintPreviewDialogPrivate::setupActions()
singleModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show single page"));
facingModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show facing pages"));
overviewModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show overview of all pages"));
- qt_setupActionIcon(singleModeAction, QLatin1String("view-page-one"));
- qt_setupActionIcon(facingModeAction, QLatin1String("view-page-sided"));
- qt_setupActionIcon(overviewModeAction, QLatin1String("view-page-multi"));
- singleModeAction->setObjectName(QLatin1String("singleModeAction"));
- facingModeAction->setObjectName(QLatin1String("facingModeAction"));
- overviewModeAction->setObjectName(QLatin1String("overviewModeAction"));
+ qt_setupActionIcon(singleModeAction, "view-pages-single"_L1);
+ qt_setupActionIcon(facingModeAction, "view-pages-facing"_L1);
+ qt_setupActionIcon(overviewModeAction, "view-pages-overview"_L1);
+ singleModeAction->setObjectName("singleModeAction"_L1);
+ facingModeAction->setObjectName("facingModeAction"_L1);
+ overviewModeAction->setObjectName("overviewModeAction"_L1);
singleModeAction->setCheckable(true);
facingModeAction->setCheckable(true);
@@ -425,15 +395,15 @@ void QPrintPreviewDialogPrivate::setupActions()
printerGroup = new QActionGroup(q);
printAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Print"));
pageSetupAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Page setup"));
- qt_setupActionIcon(printAction, QLatin1String("print"));
- qt_setupActionIcon(pageSetupAction, QLatin1String("page-setup"));
+ qt_setupActionIcon(printAction, "printer"_L1);
+ qt_setupActionIcon(pageSetupAction, "page-setup"_L1);
QObject::connect(printAction, SIGNAL(triggered(bool)), q, SLOT(_q_print()));
QObject::connect(pageSetupAction, SIGNAL(triggered(bool)), q, SLOT(_q_pageSetup()));
// Initial state:
fitPageAction->setChecked(true);
singleModeAction->setChecked(true);
- if (preview->orientation() == QPrinter::Portrait)
+ if (preview->orientation() == QPageLayout::Portrait)
portraitAction->setChecked(true);
else
landscapeAction->setChecked(true);
@@ -482,9 +452,9 @@ void QPrintPreviewDialogPrivate::updatePageNumLabel()
Q_Q(QPrintPreviewDialog);
int numPages = preview->pageCount();
- int maxChars = QString::number(numPages).length();
+ int maxChars = QString::number(numPages).size();
pageNumLabel->setText(QString::fromLatin1("/ %1").arg(numPages));
- int cyphersWidth = q->fontMetrics().horizontalAdvance(QString().fill(QLatin1Char('8'), maxChars));
+ int cyphersWidth = q->fontMetrics().horizontalAdvance(QString().fill(u'8', maxChars));
int maxWidth = pageNumEdit->minimumSizeHint().width() + cyphersWidth;
pageNumEdit->setMinimumWidth(maxWidth);
pageNumEdit->setMaximumWidth(maxWidth);
@@ -494,7 +464,7 @@ void QPrintPreviewDialogPrivate::updatePageNumLabel()
void QPrintPreviewDialogPrivate::updateZoomFactor()
{
- zoomFactor->lineEdit()->setText(QString().sprintf("%.1f%%", preview->zoomFactor()*100));
+ zoomFactor->lineEdit()->setText(QString::asprintf("%.1f%%", preview->zoomFactor()*100));
}
void QPrintPreviewDialogPrivate::_q_fit(QAction* action)
@@ -572,11 +542,10 @@ void QPrintPreviewDialogPrivate::_q_print()
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
if (printer->outputFormat() != QPrinter::NativeFormat) {
QString title = QCoreApplication::translate("QPrintPreviewDialog", "Export to PDF");
- QString suffix = QLatin1String(".pdf");
+ QString suffix = ".pdf"_L1;
QString fileName;
#if QT_CONFIG(filedialog)
- fileName = QFileDialog::getSaveFileName(q, title, printer->outputFileName(),
- QLatin1Char('*') + suffix);
+ fileName = QFileDialog::getSaveFileName(q, title, printer->outputFileName(), u'*' + suffix);
#endif
if (!fileName.isEmpty()) {
if (QFileInfo(fileName).suffix().isEmpty())
@@ -602,10 +571,12 @@ void QPrintPreviewDialogPrivate::_q_pageSetup()
{
Q_Q(QPrintPreviewDialog);
- QPageSetupDialog pageSetup(printer, q);
- if (pageSetup.exec() == QDialog::Accepted) {
+ if (!pageSetupDialog)
+ pageSetupDialog = new QPageSetupDialog(printer, q);
+
+ if (pageSetupDialog->exec() == QDialog::Accepted) {
// update possible orientation changes
- if (preview->orientation() == QPrinter::Portrait) {
+ if (preview->orientation() == QPageLayout::Portrait) {
portraitAction->setChecked(true);
preview->setPortraitOrientation();
}else {
@@ -626,7 +597,7 @@ void QPrintPreviewDialogPrivate::_q_zoomFactorChanged()
{
QString text = zoomFactor->lineEdit()->text();
bool ok;
- qreal factor = text.remove(QLatin1Char('%')).toFloat(&ok);
+ qreal factor = text.remove(u'%').toFloat(&ok);
factor = qMax(qreal(1.0), qMin(qreal(1000.0), factor));
if (ok) {
preview->setZoomFactor(factor/100.0);
@@ -713,6 +684,7 @@ QPrintPreviewDialog::~QPrintPreviewDialog()
if (d->ownPrinter)
delete d->printer;
delete d->printDialog;
+ delete d->pageSetupDialog;
}
/*!
diff --git a/src/printsupport/dialogs/qprintpreviewdialog.h b/src/printsupport/dialogs/qprintpreviewdialog.h
index 53fede7e83..5c0cb8de98 100644
--- a/src/printsupport/dialogs/qprintpreviewdialog.h
+++ b/src/printsupport/dialogs/qprintpreviewdialog.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTPREVIEWDIALOG_H
#define QPRINTPREVIEWDIALOG_H
diff --git a/src/printsupport/dialogs/qprintsettingsoutput.ui b/src/printsupport/dialogs/qprintsettingsoutput.ui
index 290111a98c..360634aaa7 100644
--- a/src/printsupport/dialogs/qprintsettingsoutput.ui
+++ b/src/printsupport/dialogs/qprintsettingsoutput.ui
@@ -351,13 +351,13 @@
<item row="0" column="0">
<widget class="QGroupBox" name="duplex">
<property name="title">
- <string>Duplex Printing</string>
+ <string>Double Sided Printing</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="noDuplex">
<property name="text">
- <string>None</string>
+ <string>Off</string>
</property>
<property name="checked">
<bool>true</bool>
@@ -367,14 +367,14 @@
<item>
<widget class="QRadioButton" name="duplexLong">
<property name="text">
- <string>Long side</string>
+ <string>Long side binding</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="duplexShort">
<property name="text">
- <string>Short side</string>
+ <string>Short side binding</string>
</property>
</widget>
</item>
diff --git a/src/printsupport/doc/qtprintsupport.qdocconf b/src/printsupport/doc/qtprintsupport.qdocconf
index fbb6f8d1a9..f1b541bafb 100644
--- a/src/printsupport/doc/qtprintsupport.qdocconf
+++ b/src/printsupport/doc/qtprintsupport.qdocconf
@@ -1,4 +1,5 @@
include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf)
+include($QT_INSTALL_DOCS/config/exampleurl-qtbase.qdocconf)
project = QtPrintSupport
description = Qt Print Support Reference Documentation
@@ -14,10 +15,6 @@ qhp.QtPrintSupport.virtualFolder = qtprintsupport
qhp.QtPrintSupport.indexTitle = Qt Print Support
qhp.QtPrintSupport.indexRoot =
-qhp.QtPrintSupport.filterAttributes = qtprintsupport $QT_VERSION qtrefdoc
-qhp.QtPrintSupport.customFilters.Qt.name = QtPrintSupport $QT_VERSION
-qhp.QtPrintSupport.customFilters.Qt.filterAttributes = qtprintsupport $QT_VERSION
-
qhp.QtPrintSupport.subprojects = classes
qhp.QtPrintSupport.subprojects.classes.title = C++ Classes
qhp.QtPrintSupport.subprojects.classes.indexTitle = Qt Print Support C++ Classes
@@ -26,14 +23,15 @@ qhp.QtPrintSupport.subprojects.classes.sortPages = true
tagfile = ../../../doc/qtprintsupport/qtprintsupport.tags
-depends += qtcore qtgui qtwidgets qtdoc qmake
+depends += qtcore qtgui qtwidgets qtdoc qmake qtcmake
headerdirs += ..
sourcedirs += ..
-exampledirs += ../ \
- snippets
+exampledirs += . \
+ snippets \
+ ..
excludedirs += ../../../examples/widgets/doc
@@ -42,3 +40,6 @@ imagedirs += images \
navigation.landingpage = "Qt Print Support"
navigation.cppclassespage = "Qt Print Support C++ Classes"
+
+# Enforce zero documentation warnings
+warninglimit = 0
diff --git a/src/printsupport/doc/snippets/CMakeLists.txt b/src/printsupport/doc/snippets/CMakeLists.txt
new file mode 100644
index 0000000000..bedcdbb662
--- /dev/null
+++ b/src/printsupport/doc/snippets/CMakeLists.txt
@@ -0,0 +1,7 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#! [cmake_use]
+find_package(Qt6 REQUIRED COMPONENTS PrintSupport)
+target_link_libraries(mytarget PRIVATE Qt6::PrintSupport)
+#! [cmake_use]
diff --git a/src/printsupport/doc/snippets/code/doc_src_qtprintsupport.cpp b/src/printsupport/doc/snippets/code/doc_src_qtprintsupport.cpp
deleted file mode 100644
index dcf8c3b5d2..0000000000
--- a/src/printsupport/doc/snippets/code/doc_src_qtprintsupport.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [1]
-#include <QtPrintSupport>
-//! [1]
diff --git a/src/printsupport/doc/snippets/code/doc_src_qtprintsupport.pro b/src/printsupport/doc/snippets/code/doc_src_qtprintsupport.pro
deleted file mode 100644
index 39dd838120..0000000000
--- a/src/printsupport/doc/snippets/code/doc_src_qtprintsupport.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-#! [0]
-QT += printsupport
-#! [0]
diff --git a/src/printsupport/doc/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp b/src/printsupport/doc/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp
index 65349df18c..dcd51d4766 100644
--- a/src/printsupport/doc/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp
+++ b/src/printsupport/doc/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//! [0]
QPrintDialog printDialog(printer, parent);
diff --git a/src/printsupport/doc/snippets/printing-qprinter/errors.cpp b/src/printsupport/doc/snippets/printing-qprinter/errors.cpp
index 40acf9293c..565d0c4a4b 100644
--- a/src/printsupport/doc/snippets/printing-qprinter/errors.cpp
+++ b/src/printsupport/doc/snippets/printing-qprinter/errors.cpp
@@ -1,54 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtGui>
+#include <QtWidgets>
+#include <QtPrintSupport/qtprintsupportglobal.h>
+#if QT_CONFIG(printdialog)
+#include <QPrinter>
+#endif
int main(int argc, char **argv)
{
diff --git a/src/printsupport/doc/snippets/printing-qprinter/object.cpp b/src/printsupport/doc/snippets/printing-qprinter/object.cpp
index c4987af4a6..4d1dac176c 100644
--- a/src/printsupport/doc/snippets/printing-qprinter/object.cpp
+++ b/src/printsupport/doc/snippets/printing-qprinter/object.cpp
@@ -1,56 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtGui>
#include "object.h"
+#include <QtWidgets>
+#include <QtPrintSupport/qtprintsupportglobal.h>
+#if QT_CONFIG(printdialog)
+#include <QPrinter>
+#endif
+
Object::Object(QObject *parent)
: QObject(parent)
{
diff --git a/src/printsupport/doc/snippets/snippets.pro b/src/printsupport/doc/snippets/snippets.pro
new file mode 100644
index 0000000000..ea1f634ac1
--- /dev/null
+++ b/src/printsupport/doc/snippets/snippets.pro
@@ -0,0 +1,3 @@
+#! [qmake_use]
+QT += printsupport
+#! [qmake_use]
diff --git a/src/printsupport/doc/snippets/widgetprinting.cpp b/src/printsupport/doc/snippets/widgetprinting.cpp
index 6e0256cb92..cdcc66ea63 100644
--- a/src/printsupport/doc/snippets/widgetprinting.cpp
+++ b/src/printsupport/doc/snippets/widgetprinting.cpp
@@ -1,54 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QtGui>
#include <QtWidgets>
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printdialog)
@@ -61,11 +13,12 @@ class Window : public QWidget
Q_OBJECT
public:
- Window() {
+ Window()
+ {
myWidget = new QPushButton("Print Me");
- connect(myWidget, SIGNAL(clicked()), this, SLOT(print()));
+ connect(myWidget, &QPushButton::clicked, this, &Window::print);
myWidget2 = new QPushButton("Print Document");
- connect(myWidget2, SIGNAL(clicked()), this, SLOT(printFile()));
+ connect(myWidget2, &QPushButton::clicked, this, &Window::printFile);
editor = new QTextEdit(this);
QVBoxLayout *layout = new QVBoxLayout;
@@ -76,8 +29,9 @@ public:
}
private slots:
- void print() {
- #if !defined(QT_NO_PRINTER)
+ void print()
+ {
+ #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFileName("test.pdf");
@@ -85,21 +39,25 @@ private slots:
//! [0]
QPainter painter;
painter.begin(&printer);
- double xscale = printer.pageRect().width()/double(myWidget->width());
- double yscale = printer.pageRect().height()/double(myWidget->height());
+ const auto pageLayout = printer.pageLayout();
+ const auto pageRect = pageLayout.paintRectPixels(printer.resolution());
+ const auto paperRect = pageLayout.fullRectPixels(printer.resolution());
+ double xscale = pageRect.width() / double(myWidget->width());
+ double yscale = pageRect.height() / double(myWidget->height());
double scale = qMin(xscale, yscale);
- painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
- printer.paperRect().y() + printer.pageRect().height()/2);
+ painter.translate(pageRect.x() + paperRect.width() / 2.,
+ pageRect.y() + paperRect.height() / 2.);
painter.scale(scale, scale);
- painter.translate(-width()/2, -height()/2);
+ painter.translate(-myWidget->width() / 2., -myWidget->height() / 2.);
myWidget->render(&painter);
//! [0]
#endif
}
- void printFile() {
- #if QT_CONFIG(printdialog)
+ void printFile()
+ {
+ #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
//! [1]
QPrinter printer;
@@ -107,9 +65,8 @@ private slots:
dialog.setWindowTitle(tr("Print Document"));
if (editor->textCursor().hasSelection())
dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
- if (dialog.exec() != QDialog::Accepted) {
+ if (dialog.exec() != QDialog::Accepted)
return;
- }
//! [1]
editor->print(&printer);
#endif
diff --git a/src/printsupport/doc/src/dontdocument.qdoc b/src/printsupport/doc/src/dontdocument.qdoc
new file mode 100644
index 0000000000..e0e7499ba5
--- /dev/null
+++ b/src/printsupport/doc/src/dontdocument.qdoc
@@ -0,0 +1,6 @@
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \dontdocument (QMetaTypeId QPlatformPrintDevice QPlatformPrinterSupportPlugin)
+*/
diff --git a/src/printsupport/doc/src/qt6-changes.qdoc b/src/printsupport/doc/src/qt6-changes.qdoc
new file mode 100644
index 0000000000..958301c9c7
--- /dev/null
+++ b/src/printsupport/doc/src/qt6-changes.qdoc
@@ -0,0 +1,28 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page printsupport-changes-qt6.html
+ \title Changes to Qt Print Support
+ \ingroup changes-qt-5-to-6
+ \brief General API consolidation.
+
+ Qt 6 is a result of the conscious effort to make the framework more
+ efficient and easy to use.
+
+ We try to maintain binary and source compatibility for all the public
+ APIs in each release. But some changes were inevitable in an effort to
+ make Qt a better framework.
+
+ In this topic we summarize those changes in Qt Print Support, and provide
+ guidance to handle them.
+
+ \section1 General API consolidation
+
+ The various enums and types for \l{QPageSize}{page sizes},
+ margins, and orientation have been consolidated. QPrinter APIs to set
+ paper sizes and margins explicitly have been removed; use
+ QPagedPaintDevice::setPageLayout(), QPagedPaintDevice::setPageSize(),
+ QPagedPaintDevice::setPageOrientation(), and
+ QPagedPaintDevice::setPageMargins() instead.
+*/
diff --git a/src/printsupport/doc/src/qtprintsupport-index.qdoc b/src/printsupport/doc/src/qtprintsupport-index.qdoc
index a8a0f0cb20..9d3c83b970 100644
--- a/src/printsupport/doc/src/qtprintsupport-index.qdoc
+++ b/src/printsupport/doc/src/qtprintsupport-index.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qtprintsupport-index.html
@@ -32,11 +8,13 @@
\ingroup qt-graphics
- Qt provides extensive cross-platform support for printing. Using the printing
- systems on each platform, Qt applications can print to attached printers and
- across networks to remote printers. Qt's printing system also supports
- PDF file generation, providing the foundation for basic report
- generation facilities.
+ The Qt Print Support module provides extensive cross-platform support for
+ printing. Using the printing systems on each platform, Qt applications can
+ print to attached printers and across networks to remote printers. The
+ printing system also supports PDF file generation, providing the foundation
+ for basic report generation facilities.
+
+ Qt Print Support is not available on iOS.
\tableofcontents
@@ -49,7 +27,7 @@
\section1 Paint Devices and Printing
- In Qt, printers are represented by QPrinter, a paint device that provides
+ Printers are represented by QPrinter, a paint device that provides
functionality specific to printing, such as support for multiple pages and
double-sided output. As a result, printing involves using a QPainter to paint
onto a series of pages in the same way that you would paint onto a custom
@@ -59,18 +37,18 @@
Although QPrinter objects can be constructed and set up without requiring user
input, printing is often performed as a result of a request by the user;
- for example, when the user selects the \uicontrol{File|Print...} menu item in a GUI
- application. In such cases, a newly-constructed QPrinter object is supplied to
- a QPrintDialog, allowing the user to specify the printer to use, paper size, and
- other printing properties.
+ for example, when the user selects the \uicontrol{File|Print...} menu item in
+ a GUI application. In such cases, a newly-constructed QPrinter object is
+ supplied to a QPrintDialog, allowing the user to specify the printer to use,
+ paper size, and other printing properties.
\snippet widgetprinting.cpp 1
- It is also possible to set certain default properties by modifying the QPrinter
- before it is supplied to the print dialog. For example, applications that
- generate batches of reports for printing may set up the QPrinter to
- \l{QPrinter::setOutputFileName()}{write to a local file} by default rather than
- to a printer.
+ It is also possible to set certain default properties by modifying the
+ QPrinter before it is supplied to the print dialog. For example, applications
+ that generate batches of reports for printing may set up the QPrinter to
+ \l{QPrinter::setOutputFileName()}{write to a local file} by default rather
+ than to a printer.
\section2 Painting onto a Page
@@ -122,16 +100,16 @@
The paint system automatically uses the correct device metrics when painting
text but, if you need to position text using information obtained from
font metrics, you need to ensure that the print device is specified when
- you construct QFontMetrics and QFontMetricsF objects, or ensure that each QFont
- used is constructed using the form of the constructor that accepts a
+ you construct QFontMetrics and QFontMetricsF objects, or ensure that each
+ QFont used is constructed using the form of the constructor that accepts a
QPaintDevice argument.
\section1 Printing Widgets
To print a widget, you can use the QWidget::render() function. As mentioned,
the printer's resolution is usually higher than the screen resolution, so you
- will have to scale the painter. You may also want to position the widget on the
- page. The following code sample shows how this may look.
+ will have to scale the painter. You may also want to position the widget on
+ the page. The following code sample shows how this may look.
\snippet widgetprinting.cpp 0
@@ -144,9 +122,9 @@
and QGraphicsScene. As a result, it is these content handling classes that
usually provide printing functionality, either via a function that can be used
to perform the complete task, or via a function that accepts an existing
- QPainter object. Some widgets provide convenience functions to expose underlying
- printing features, avoiding the need to obtain the content handler just to call
- a single function.
+ QPainter object. Some widgets provide convenience functions to expose
+ underlying printing features, avoiding the need to obtain the content handler
+ just to call a single function.
The following table shows which class and function are responsible for
printing from a selection of different widgets. For widgets that do not expose
@@ -162,16 +140,28 @@
\row \li QTextLine \li QTextLine::draw() \li QPainter
\endtable
- QTextEdit requires a QPrinter rather than a QPainter because it uses information
- about the configured page dimensions in order to insert page breaks at the most
- appropriate places in printed documents.
+ QTextEdit requires a QPrinter rather than a QPainter because it uses
+ information about the configured page dimensions in order to insert page
+ breaks at the most appropriate places in printed documents.
+
+ \include module-use.qdocinc using qt module
+ \snippet snippets/CMakeLists.txt cmake_use
+
+ See also the \l {Build with CMake} overview.
+
+ \include module-use.qdocinc building with qmake
+ \snippet snippets.pro qmake_use
+
+ \section1 Module Evolution
+ \l{Changes to Qt Print Support} lists important changes in the module API
+ and functionality that were done for the Qt 6 series of Qt.
\section1 Licenses and Trademarks
- The Qt Print Support module is available under commercial licenses from \l{The Qt Company}.
- In addition, it is available under free software licenses. Since Qt 5.4,
- these free software licenses are
- \l{GNU Lesser General Public License, version 3}, or
+ The Qt Print Support module is available under commercial licenses from
+ \l{The Qt Company}.
+ In addition, it is available under free software licenses:
+ The \l{GNU Lesser General Public License, version 3}, or
the \l{GNU General Public License, version 2}.
See \l{Qt Licensing} for further details.
diff --git a/src/printsupport/doc/src/qtprintsupport-module.qdoc b/src/printsupport/doc/src/qtprintsupport-module.qdoc
index 0e851e593c..7c98417948 100644
--- a/src/printsupport/doc/src/qtprintsupport-module.qdoc
+++ b/src/printsupport/doc/src/qtprintsupport-module.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\module QtPrintSupport
@@ -31,17 +7,10 @@
\brief The Qt PrintSupport module provides classes to make printing easier and portable.
\ingroup modules
+ \qtcmakepackage PrintSupport
\qtvariable printsupport
- To include the definitions of the module's classes, use the
- following directive:
+ The \l{Qt Print Support} page contains information about using the module.
- \snippet code/doc_src_qtprintsupport.cpp 1
-
- \if !defined(qtforpython)
- To link against the module, add this line to your \l qmake \c
- .pro file:
-
- \snippet code/doc_src_qtprintsupport.pro 0
- \endif
+ Qt Print Support is not available on iOS.
*/
diff --git a/src/printsupport/kernel/kernel.pri b/src/printsupport/kernel/kernel.pri
deleted file mode 100644
index ea7b4b9780..0000000000
--- a/src/printsupport/kernel/kernel.pri
+++ /dev/null
@@ -1,42 +0,0 @@
-HEADERS += \
- $$PWD/qpaintengine_alpha_p.h \
- $$PWD/qprint_p.h \
- $$PWD/qprintdevice_p.h \
- $$PWD/qprintengine.h \
- $$PWD/qprinter.h \
- $$PWD/qprinter_p.h \
- $$PWD/qprinterinfo.h \
- $$PWD/qprinterinfo_p.h \
- $$PWD/qplatformprintdevice.h \
- $$PWD/qplatformprintplugin.h \
- $$PWD/qplatformprintersupport.h \
- $$PWD/qtprintsupportglobal_p.h \
- $$PWD/qtprintsupportglobal.h
-
-SOURCES += \
- $$PWD/qpaintengine_alpha.cpp \
- $$PWD/qprintdevice.cpp \
- $$PWD/qprintengine_pdf.cpp \
- $$PWD/qprinter.cpp \
- $$PWD/qprinterinfo.cpp \
- $$PWD/qplatformprintdevice.cpp \
- $$PWD/qplatformprintplugin.cpp \
- $$PWD/qplatformprintersupport.cpp
-
-qtConfig(printpreviewwidget) {
- HEADERS += $$PWD/qpaintengine_preview_p.h
- SOURCES += $$PWD/qpaintengine_preview.cpp
-}
-
-win32 {
- HEADERS += \
- $$PWD/qprintengine_win_p.h
- SOURCES += \
- $$PWD/qprintengine_win.cpp
- !winrt: LIBS_PRIVATE += -lwinspool -lcomdlg32 -lgdi32 -luser32
-}
-
-unix:!darwin:qtConfig(cups) {
- SOURCES += $$PWD/qcups.cpp
- HEADERS += $$PWD/qcups_p.h
-}
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp
index 8505e8356c..231b816499 100644
--- a/src/printsupport/kernel/qcups.cpp
+++ b/src/printsupport/kernel/qcups.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcups_p.h"
@@ -44,12 +8,24 @@
QT_BEGIN_NAMESPACE
-static QStringList cupsOptionsList(QPrinter *printer) Q_DECL_NOTHROW
+using namespace Qt::StringLiterals;
+
+QT_IMPL_METATYPE_EXTERN_TAGGED(QCUPSSupport::JobHoldUntil,
+ QCUPSSupport__JobHoldUntil)
+QT_IMPL_METATYPE_EXTERN_TAGGED(QCUPSSupport::BannerPage,
+ QCUPSSupport__BannerPage)
+QT_IMPL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PageSet, QCUPSSupport__PageSet)
+QT_IMPL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PagesPerSheetLayout,
+ QCUPSSupport__PagesPerSheetLayout)
+QT_IMPL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PagesPerSheet,
+ QCUPSSupport__PagesPerSheet)
+
+static QStringList cupsOptionsList(QPrinter *printer) noexcept
{
return printer->printEngine()->property(PPK_CupsOptions).toStringList();
}
-void setCupsOptions(QPrinter *printer, const QStringList &cupsOptions) Q_DECL_NOTHROW
+void setCupsOptions(QPrinter *printer, const QStringList &cupsOptions) noexcept
{
printer->printEngine()->setProperty(PPK_CupsOptions, QVariant(cupsOptions));
}
@@ -83,7 +59,7 @@ void QCUPSSupport::clearCupsOptions(QPrinter *printer)
setCupsOptions(printer, QStringList());
}
-static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold, const QTime holdUntilTime)
+static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold, QTime holdUntilTime)
{
switch (jobHold) {
case QCUPSSupport::Indefinite:
@@ -106,37 +82,36 @@ static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold,
if (holdUntilTime < localDateTime.time())
localDateTime = localDateTime.addDays(1);
localDateTime.setTime(holdUntilTime);
- return localDateTime.toUTC().time().toString(QStringViewLiteral("HH:mm"));
+ return localDateTime.toUTC().time().toString(u"HH:mm");
}
// else fall through:
Q_FALLTHROUGH();
case QCUPSSupport::NoHold:
return QString();
}
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
QCUPSSupport::JobHoldUntilWithTime QCUPSSupport::parseJobHoldUntil(const QString &jobHoldUntil)
{
- if (jobHoldUntil == QLatin1String("indefinite")) {
+ if (jobHoldUntil == "indefinite"_L1) {
return { QCUPSSupport::Indefinite, QTime() };
- } else if (jobHoldUntil == QLatin1String("day-time")) {
+ } else if (jobHoldUntil == "day-time"_L1) {
return { QCUPSSupport::DayTime, QTime() };
- } else if (jobHoldUntil == QLatin1String("night")) {
+ } else if (jobHoldUntil == "night"_L1) {
return { QCUPSSupport::Night, QTime() };
- } else if (jobHoldUntil == QLatin1String("second-shift")) {
+ } else if (jobHoldUntil == "second-shift"_L1) {
return { QCUPSSupport::SecondShift, QTime() };
- } else if (jobHoldUntil == QLatin1String("third-shift")) {
+ } else if (jobHoldUntil == "third-shift"_L1) {
return { QCUPSSupport::ThirdShift, QTime() };
- } else if (jobHoldUntil == QLatin1String("weekend")) {
+ } else if (jobHoldUntil == "weekend"_L1) {
return { QCUPSSupport::Weekend, QTime() };
}
- QTime parsedTime = QTime::fromString(jobHoldUntil, QStringLiteral("h:m:s"));
+ QTime parsedTime = QTime::fromString(jobHoldUntil, u"h:m:s");
if (!parsedTime.isValid())
- parsedTime = QTime::fromString(jobHoldUntil, QStringLiteral("h:m"));
+ parsedTime = QTime::fromString(jobHoldUntil, u"h:m");
if (parsedTime.isValid()) {
// CUPS time is in UTC, user expects local time, so get the equivalent
QDateTime dateTimeUtc = QDateTime::currentDateTimeUtc();
@@ -149,7 +124,7 @@ QCUPSSupport::JobHoldUntilWithTime QCUPSSupport::parseJobHoldUntil(const QString
ppd_option_t *QCUPSSupport::findPpdOption(const char *optionName, QPrintDevice *printDevice)
{
- ppd_file_t *ppd = printDevice->property(PDPK_PpdFile).value<ppd_file_t*>();
+ ppd_file_t *ppd = qvariant_cast<ppd_file_t*>(printDevice->property(PDPK_PpdFile));
if (ppd) {
for (int i = 0; i < ppd->num_groups; ++i) {
@@ -167,7 +142,7 @@ ppd_option_t *QCUPSSupport::findPpdOption(const char *optionName, QPrintDevice *
return nullptr;
}
-void QCUPSSupport::setJobHold(QPrinter *printer, const JobHoldUntil jobHold, const QTime &holdUntilTime)
+void QCUPSSupport::setJobHold(QPrinter *printer, const JobHoldUntil jobHold, QTime holdUntilTime)
{
const QString jobHoldUntilArgument = jobHoldToString(jobHold, holdUntilTime);
if (!jobHoldUntilArgument.isEmpty()) {
@@ -200,19 +175,18 @@ static inline QString bannerPageToString(const QCUPSSupport::BannerPage bannerPa
case QCUPSSupport::Secret: return QStringLiteral("secret");
case QCUPSSupport::TopSecret: return QStringLiteral("topsecret");
}
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
static inline QCUPSSupport::BannerPage stringToBannerPage(const QString &bannerPage)
{
- if (bannerPage == QLatin1String("none")) return QCUPSSupport::NoBanner;
- else if (bannerPage == QLatin1String("standard")) return QCUPSSupport::Standard;
- else if (bannerPage == QLatin1String("unclassified")) return QCUPSSupport::Unclassified;
- else if (bannerPage == QLatin1String("confidential")) return QCUPSSupport::Confidential;
- else if (bannerPage == QLatin1String("classified")) return QCUPSSupport::Classified;
- else if (bannerPage == QLatin1String("secret")) return QCUPSSupport::Secret;
- else if (bannerPage == QLatin1String("topsecret")) return QCUPSSupport::TopSecret;
+ if (bannerPage == "none"_L1) return QCUPSSupport::NoBanner;
+ else if (bannerPage == "standard"_L1) return QCUPSSupport::Standard;
+ else if (bannerPage == "unclassified"_L1) return QCUPSSupport::Unclassified;
+ else if (bannerPage == "confidential"_L1) return QCUPSSupport::Confidential;
+ else if (bannerPage == "classified"_L1) return QCUPSSupport::Classified;
+ else if (bannerPage == "secret"_L1) return QCUPSSupport::Secret;
+ else if (bannerPage == "topsecret"_L1) return QCUPSSupport::TopSecret;
return QCUPSSupport::NoBanner;
}
@@ -221,8 +195,8 @@ QCUPSSupport::JobSheets QCUPSSupport::parseJobSheets(const QString &jobSheets)
{
JobSheets result;
- const QStringList parts = jobSheets.split(QLatin1Char(','));
- if (parts.count() == 2) {
+ const QStringList parts = jobSheets.split(u',');
+ if (parts.size() == 2) {
result.startBannerPage = stringToBannerPage(parts[0]);
result.endBannerPage = stringToBannerPage(parts[1]);
}
@@ -235,7 +209,7 @@ void QCUPSSupport::setBannerPages(QPrinter *printer, const BannerPage startBanne
const QString startBanner = bannerPageToString(startBannerPage);
const QString endBanner = bannerPageToString(endBannerPage);
- setCupsOption(printer, QStringLiteral("job-sheets"), startBanner + QLatin1Char(',') + endBanner);
+ setCupsOption(printer, QStringLiteral("job-sheets"), startBanner + u',' + endBanner);
}
void QCUPSSupport::setPageSet(QPrinter *printer, const PageSet pageSet)
@@ -265,8 +239,8 @@ void QCUPSSupport::setPagesPerSheetLayout(QPrinter *printer, const PagesPerShee
// WARNING: and it is the last one (before the "\0")!
static const char pagesPerSheetData[][2] = { "1", "2", "4", "6", "9", {'1', '6'}, "\0" };
static const char pageLayoutData[][5] = {"lrtb", "lrbt", "rlbt", "rltb", "btlr", "btrl", "tblr", "tbrl"};
- setCupsOption(printer, QStringLiteral("number-up"), QLatin1String(pagesPerSheetData[pagesPerSheet]));
- setCupsOption(printer, QStringLiteral("number-up-layout"), QLatin1String(pageLayoutData[pagesPerSheetLayout]));
+ setCupsOption(printer, QStringLiteral("number-up"), QLatin1StringView(pagesPerSheetData[pagesPerSheet]));
+ setCupsOption(printer, QStringLiteral("number-up-layout"), QLatin1StringView(pageLayoutData[pagesPerSheetLayout]));
}
void QCUPSSupport::setPageRange(QPrinter *printer, int pageFrom, int pageTo)
diff --git a/src/printsupport/kernel/qcups_p.h b/src/printsupport/kernel/qcups_p.h
index 57ec281383..4570935ba1 100644
--- a/src/printsupport/kernel/qcups_p.h
+++ b/src/printsupport/kernel/qcups_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCUPS_P_H
#define QCUPS_P_H
@@ -137,7 +101,7 @@ public:
static void clearCupsOption(QPrinter *printer, const QString &option);
static void clearCupsOptions(QPrinter *printer);
- static void setJobHold(QPrinter *printer, const JobHoldUntil jobHold = NoHold, const QTime &holdUntilTime = QTime());
+ static void setJobHold(QPrinter *printer, const JobHoldUntil jobHold = NoHold, QTime holdUntilTime = QTime());
static void setJobBilling(QPrinter *printer, const QString &jobBilling = QString());
static void setJobPriority(QPrinter *printer, int priority = 50);
static void setBannerPages(QPrinter *printer, const BannerPage startBannerPage, const BannerPage endBannerPage);
@@ -159,7 +123,7 @@ public:
struct JobHoldUntilWithTime
{
- JobHoldUntilWithTime(JobHoldUntil jh = NoHold, const QTime &t = QTime())
+ JobHoldUntilWithTime(JobHoldUntil jh = NoHold, QTime t = QTime())
: jobHold(jh), time(t) {}
JobHoldUntil jobHold;
@@ -177,10 +141,14 @@ Q_DECLARE_TYPEINFO(QCUPSSupport::PagesPerSheet, Q_PRIMITIVE_TYPE);
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QCUPSSupport::JobHoldUntil)
-Q_DECLARE_METATYPE(QCUPSSupport::BannerPage)
-Q_DECLARE_METATYPE(QCUPSSupport::PageSet)
-Q_DECLARE_METATYPE(QCUPSSupport::PagesPerSheetLayout)
-Q_DECLARE_METATYPE(QCUPSSupport::PagesPerSheet)
+QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::JobHoldUntil,
+ QCUPSSupport__JobHoldUntil, Q_PRINTSUPPORT_EXPORT)
+QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::BannerPage,
+ QCUPSSupport__BannerPage, Q_PRINTSUPPORT_EXPORT)
+QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PageSet, QCUPSSupport__PageSet, Q_PRINTSUPPORT_EXPORT)
+QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PagesPerSheetLayout,
+ QCUPSSupport__PagesPerSheetLayout, Q_PRINTSUPPORT_EXPORT)
+QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PagesPerSheet,
+ QCUPSSupport__PagesPerSheet, Q_PRINTSUPPORT_EXPORT)
#endif
diff --git a/src/printsupport/kernel/qpaintengine_alpha.cpp b/src/printsupport/kernel/qpaintengine_alpha.cpp
index 410051df2a..4c34457570 100644
--- a/src/printsupport/kernel/qpaintengine_alpha.cpp
+++ b/src/printsupport/kernel/qpaintengine_alpha.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qtprintsupportglobal.h>
@@ -377,16 +341,16 @@ void QAlphaPaintEngine::cleanUp()
delete d->m_picpainter;
delete d->m_pic;
- d->m_picpainter = 0;
- d->m_pic = 0;
- d->m_picengine = 0;
+ d->m_picpainter = nullptr;
+ d->m_pic = nullptr;
+ d->m_picengine = nullptr;
}
QAlphaPaintEnginePrivate::QAlphaPaintEnginePrivate()
: m_pass(0),
- m_pic(0),
- m_picengine(0),
- m_picpainter(0),
+ m_pic(nullptr),
+ m_picengine(nullptr),
+ m_picpainter(nullptr),
m_numberOfCachedRects(0),
m_hasalpha(false),
m_alphaPen(false),
@@ -407,13 +371,11 @@ QAlphaPaintEnginePrivate::~QAlphaPaintEnginePrivate()
QRectF QAlphaPaintEnginePrivate::addPenWidth(const QPainterPath &path)
{
- Q_Q(QAlphaPaintEngine);
-
QPainterPath tmp = path;
if (m_pen.style() == Qt::NoPen)
return (path.controlPointRect() * m_transform).boundingRect();
- bool cosmetic = qt_pen_is_cosmetic(m_pen, q->state->renderHints());
+ bool cosmetic = m_pen.isCosmetic();
if (cosmetic)
tmp = path * m_transform;
@@ -439,9 +401,9 @@ void QAlphaPaintEnginePrivate::addAlphaRect(const QRectF &rect)
bool QAlphaPaintEnginePrivate::canSeeTroughBackground(bool somethingInRectHasAlpha, const QRectF &rect) const
{
if (somethingInRectHasAlpha) {
- if (m_dirtyRects.count() != m_numberOfCachedRects) {
- m_cachedDirtyRgn.setRects(m_dirtyRects.constData(), m_dirtyRects.count());
- m_numberOfCachedRects = m_dirtyRects.count();
+ if (m_dirtyRects.size() != m_numberOfCachedRects) {
+ m_cachedDirtyRgn.setRects(m_dirtyRects.constData(), m_dirtyRects.size());
+ m_numberOfCachedRects = m_dirtyRects.size();
}
return m_cachedDirtyRgn.intersects(rect.toAlignedRect());
}
diff --git a/src/printsupport/kernel/qpaintengine_alpha_p.h b/src/printsupport/kernel/qpaintengine_alpha_p.h
index efae442690..221194d4ad 100644
--- a/src/printsupport/kernel/qpaintengine_alpha_p.h
+++ b/src/printsupport/kernel/qpaintengine_alpha_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPAINTENGINE_ALPHA_P_H
#define QPAINTENGINE_ALPHA_P_H
@@ -81,7 +45,7 @@ public:
void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) override;
protected:
- QAlphaPaintEngine(QAlphaPaintEnginePrivate &data, PaintEngineFeatures devcaps = 0);
+ QAlphaPaintEngine(QAlphaPaintEnginePrivate &data, PaintEngineFeatures devcaps = { });
QRegion alphaClipping() const;
bool continueCall() const;
void flushAndInit(bool init = true);
@@ -107,7 +71,7 @@ public:
QRegion m_cliprgn;
mutable QRegion m_cachedDirtyRgn;
mutable int m_numberOfCachedRects;
- QVector<QRect> m_dirtyRects;
+ QList<QRect> m_dirtyRects;
bool m_hasalpha;
bool m_alphaPen;
diff --git a/src/printsupport/kernel/qpaintengine_preview.cpp b/src/printsupport/kernel/qpaintengine_preview.cpp
index 7179249677..7e3a9f8c60 100644
--- a/src/printsupport/kernel/qpaintengine_preview.cpp
+++ b/src/printsupport/kernel/qpaintengine_preview.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <private/qpaintengine_preview_p.h>
#include <private/qpainter_p.h>
diff --git a/src/printsupport/kernel/qpaintengine_preview_p.h b/src/printsupport/kernel/qpaintengine_preview_p.h
index 9203e40235..87692a0b92 100644
--- a/src/printsupport/kernel/qpaintengine_preview_p.h
+++ b/src/printsupport/kernel/qpaintengine_preview_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPAINTENGINE_PREVIEW_P_H
#define QPAINTENGINE_PREVIEW_P_H
diff --git a/src/printsupport/kernel/qplatformprintdevice.cpp b/src/printsupport/kernel/qplatformprintdevice.cpp
index 69d984cb0c..a2ee51f887 100644
--- a/src/printsupport/kernel/qplatformprintdevice.cpp
+++ b/src/printsupport/kernel/qplatformprintdevice.cpp
@@ -1,49 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 John Layt <jlayt@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPrintSupport module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformprintdevice.h"
#include "qprintdevice_p.h"
-#if QT_CONFIG(printdialog)
-#include "qprintdialog.h"
-#endif
+#include <QtCore/qcoreapplication.h>
#include <QtGui/qpagelayout.h>
QT_BEGIN_NAMESPACE
@@ -113,6 +75,10 @@ bool QPlatformPrintDevice::isValidPageLayout(const QPageLayout &layout, int reso
if (!supportedPageSize(layout.pageSize()).isValid())
return false;
+ // In fullpage mode, margins outside the printable area are valid
+ if (layout.mode() == QPageLayout::FullPageMode)
+ return true;
+
// Check the margins are valid
QMarginsF pointMargins = layout.margins(QPageLayout::Point);
QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution);
@@ -165,7 +131,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
// map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
if (pageSize.id() != QPageSize::Custom) {
- for (const QPageSize &ps : m_pageSizes) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.id() == pageSize.id() && ps.name() == pageSize.name())
return ps;
}
@@ -173,7 +139,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// Next try match on id only if not custom
if (pageSize.id() != QPageSize::Custom) {
- for (const QPageSize &ps : m_pageSizes) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.id() == pageSize.id())
return ps;
}
@@ -188,7 +154,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSize
if (!m_havePageSizes)
loadPageSizes();
- for (const QPageSize &ps : m_pageSizes) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.id() == pageSizeId)
return ps;
}
@@ -202,7 +168,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QString &pageName) const
if (!m_havePageSizes)
loadPageSizes();
- for (const QPageSize &ps : m_pageSizes) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.name() == pageName)
return ps;
}
@@ -235,7 +201,7 @@ QPageSize QPlatformPrintDevice::supportedPageSizeMatch(const QPageSize &pageSize
return pageSize;
// Try to find a supported page size based on point size
- for (const QPageSize &ps : m_pageSizes) {
+ for (const QPageSize &ps : std::as_const(m_pageSizes)) {
if (ps.sizePoints() == pageSize.sizePoints())
return ps;
}
@@ -261,9 +227,9 @@ QMarginsF QPlatformPrintDevice::printableMargins(const QPageSize &pageSize,
QPageLayout::Orientation orientation,
int resolution) const
{
- Q_UNUSED(pageSize)
- Q_UNUSED(orientation)
- Q_UNUSED(resolution)
+ Q_UNUSED(pageSize);
+ Q_UNUSED(orientation);
+ Q_UNUSED(resolution);
return QMarginsF(0, 0, 0, 0);
}
@@ -291,16 +257,12 @@ QPrint::InputSlot QPlatformPrintDevice::defaultInputSlot() const
{
QPrint::InputSlot input;
input.key = QByteArrayLiteral("Auto");
-#if QT_CONFIG(printdialog)
- input.name = QPrintDialog::tr("Automatic");
-#else
- input.name = QString::fromLatin1("Automatic");
-#endif
+ input.name = QCoreApplication::translate("Print Device Input Slot", "Automatic");
input.id = QPrint::Auto;
return input;
}
-QVector<QPrint::InputSlot> QPlatformPrintDevice::supportedInputSlots() const
+QList<QPrint::InputSlot> QPlatformPrintDevice::supportedInputSlots() const
{
if (!m_haveInputSlots)
loadInputSlots();
@@ -315,16 +277,12 @@ QPrint::OutputBin QPlatformPrintDevice::defaultOutputBin() const
{
QPrint::OutputBin output;
output.key = QByteArrayLiteral("Auto");
-#if QT_CONFIG(printdialog)
- output.name = QPrintDialog::tr("Automatic");
-#else
- output.name = QString::fromLatin1("Automatic");
-#endif
+ output.name = QCoreApplication::translate("Print Device Output Bin", "Automatic");
output.id = QPrint::AutoOutputBin;
return output;
}
-QVector<QPrint::OutputBin> QPlatformPrintDevice::supportedOutputBins() const
+QList<QPrint::OutputBin> QPlatformPrintDevice::supportedOutputBins() const
{
if (!m_haveOutputBins)
loadOutputBins();
@@ -340,7 +298,7 @@ QPrint::DuplexMode QPlatformPrintDevice::defaultDuplexMode() const
return QPrint::DuplexNone;
}
-QVector<QPrint::DuplexMode> QPlatformPrintDevice::supportedDuplexModes() const
+QList<QPrint::DuplexMode> QPlatformPrintDevice::supportedDuplexModes() const
{
if (!m_haveDuplexModes)
loadDuplexModes();
@@ -356,7 +314,7 @@ QPrint::ColorMode QPlatformPrintDevice::defaultColorMode() const
return QPrint::GrayScale;
}
-QVector<QPrint::ColorMode> QPlatformPrintDevice::supportedColorModes() const
+QList<QPrint::ColorMode> QPlatformPrintDevice::supportedColorModes() const
{
if (!m_haveColorModes)
loadColorModes();
@@ -371,23 +329,23 @@ void QPlatformPrintDevice::loadMimeTypes() const
QVariant QPlatformPrintDevice::property(QPrintDevice::PrintDevicePropertyKey key) const
{
- Q_UNUSED(key)
+ Q_UNUSED(key);
return QVariant();
}
bool QPlatformPrintDevice::setProperty(QPrintDevice::PrintDevicePropertyKey key, const QVariant &value)
{
- Q_UNUSED(key)
- Q_UNUSED(value)
+ Q_UNUSED(key);
+ Q_UNUSED(value);
return false;
}
bool QPlatformPrintDevice::isFeatureAvailable(QPrintDevice::PrintDevicePropertyKey key, const QVariant &params) const
{
- Q_UNUSED(key)
- Q_UNUSED(params)
+ Q_UNUSED(key);
+ Q_UNUSED(params);
return false;
}
diff --git a/src/printsupport/kernel/qplatformprintdevice.h b/src/printsupport/kernel/qplatformprintdevice.h
index 64723db92e..a8d9c10f7f 100644
--- a/src/printsupport/kernel/qplatformprintdevice.h
+++ b/src/printsupport/kernel/qplatformprintdevice.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 John Layt <jlayt@kde.org>
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPrintSupport module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMPRINTDEVICE_H
#define QPLATFORMPRINTDEVICE_H
@@ -56,8 +20,8 @@
#include <private/qprint_p.h>
#include <private/qprintdevice_p.h>
+#include <QtCore/qlist.h>
#include <QtCore/qvariant.h>
-#include <QtCore/qvector.h>
#if QT_CONFIG(mimetype)
#include <QtCore/qmimetype.h>
#endif
@@ -112,16 +76,16 @@ public:
virtual QList<int> supportedResolutions() const;
virtual QPrint::InputSlot defaultInputSlot() const;
- virtual QVector<QPrint::InputSlot> supportedInputSlots() const;
+ virtual QList<QPrint::InputSlot> supportedInputSlots() const;
virtual QPrint::OutputBin defaultOutputBin() const;
- virtual QVector<QPrint::OutputBin> supportedOutputBins() const;
+ virtual QList<QPrint::OutputBin> supportedOutputBins() const;
virtual QPrint::DuplexMode defaultDuplexMode() const;
- virtual QVector<QPrint::DuplexMode> supportedDuplexModes() const;
+ virtual QList<QPrint::DuplexMode> supportedDuplexModes() const;
virtual QPrint::ColorMode defaultColorMode() const;
- virtual QVector<QPrint::ColorMode> supportedColorModes() const;
+ virtual QList<QPrint::ColorMode> supportedColorModes() const;
virtual QVariant property(QPrintDevice::PrintDevicePropertyKey key) const;
virtual bool setProperty(QPrintDevice::PrintDevicePropertyKey key, const QVariant &value);
@@ -169,16 +133,16 @@ protected:
mutable QList<int> m_resolutions;
mutable bool m_haveInputSlots;
- mutable QVector<QPrint::InputSlot> m_inputSlots;
+ mutable QList<QPrint::InputSlot> m_inputSlots;
mutable bool m_haveOutputBins;
- mutable QVector<QPrint::OutputBin> m_outputBins;
+ mutable QList<QPrint::OutputBin> m_outputBins;
mutable bool m_haveDuplexModes;
- mutable QVector<QPrint::DuplexMode> m_duplexModes;
+ mutable QList<QPrint::DuplexMode> m_duplexModes;
mutable bool m_haveColorModes;
- mutable QVector<QPrint::ColorMode> m_colorModes;
+ mutable QList<QPrint::ColorMode> m_colorModes;
#if QT_CONFIG(mimetype)
mutable bool m_haveMimeTypes;
diff --git a/src/printsupport/kernel/qplatformprintersupport.cpp b/src/printsupport/kernel/qplatformprintersupport.cpp
index a25dc6d45c..f900de62c4 100644
--- a/src/printsupport/kernel/qplatformprintersupport.cpp
+++ b/src/printsupport/kernel/qplatformprintersupport.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformprintersupport.h"
#include "qplatformprintdevice.h"
@@ -85,7 +49,7 @@ QPrintDevice QPlatformPrinterSupport::createPrintDevice(QPlatformPrintDevice *de
QPrintDevice QPlatformPrinterSupport::createPrintDevice(const QString &id)
{
- Q_UNUSED(id)
+ Q_UNUSED(id);
return QPrintDevice();
}
@@ -101,9 +65,9 @@ QString QPlatformPrinterSupport::defaultPrintDeviceId() const
QPageSize QPlatformPrinterSupport::createPageSize(const QString &id, QSize size, const QString &localizedName)
{
- Q_UNUSED(id)
- Q_UNUSED(size)
- Q_UNUSED(localizedName)
+ Q_UNUSED(id);
+ Q_UNUSED(size);
+ Q_UNUSED(localizedName);
return QPageSize();
}
diff --git a/src/printsupport/kernel/qplatformprintersupport.h b/src/printsupport/kernel/qplatformprintersupport.h
index 413c1067c2..0aba2eab59 100644
--- a/src/printsupport/kernel/qplatformprintersupport.h
+++ b/src/printsupport/kernel/qplatformprintersupport.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMPRINTERSUPPORT_H
#define QPLATFORMPRINTERSUPPORT_H
diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp
index 9a7656f7d6..c48e5f65bf 100644
--- a/src/printsupport/kernel/qplatformprintplugin.cpp
+++ b/src/printsupport/kernel/qplatformprintplugin.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformprintplugin.h"
#include "qplatformprintersupport.h"
@@ -46,10 +10,18 @@
#ifndef QT_NO_PRINTER
+#if defined(Q_OS_MACOS)
+Q_IMPORT_PLUGIN(QCocoaPrinterSupportPlugin)
+#elif defined(Q_OS_WIN)
+Q_IMPORT_PLUGIN(QWindowsPrinterSupportPlugin)
+#endif
+
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
- (QPlatformPrinterSupportFactoryInterface_iid, QLatin1String("/printsupport"), Qt::CaseInsensitive))
+ (QPlatformPrinterSupportFactoryInterface_iid, "/printsupport"_L1, Qt::CaseInsensitive))
QPlatformPrinterSupportPlugin::QPlatformPrinterSupportPlugin(QObject *parent)
: QObject(parent)
@@ -99,4 +71,6 @@ QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get()
QT_END_NAMESPACE
+#include "moc_qplatformprintplugin.cpp"
+
#endif
diff --git a/src/printsupport/kernel/qplatformprintplugin.h b/src/printsupport/kernel/qplatformprintplugin.h
index 30e8f7938a..0e7ec9cd9f 100644
--- a/src/printsupport/kernel/qplatformprintplugin.h
+++ b/src/printsupport/kernel/qplatformprintplugin.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMPRINTPLUGIN_H
#define QPLATFORMPRINTPLUGIN_H
@@ -66,7 +30,7 @@ class Q_PRINTSUPPORT_EXPORT QPlatformPrinterSupportPlugin : public QObject
{
Q_OBJECT
public:
- explicit QPlatformPrinterSupportPlugin(QObject *parent = 0);
+ explicit QPlatformPrinterSupportPlugin(QObject *parent = nullptr);
~QPlatformPrinterSupportPlugin();
virtual QPlatformPrinterSupport *create(const QString &key) = 0;
diff --git a/src/printsupport/kernel/qprint.cpp b/src/printsupport/kernel/qprint.cpp
new file mode 100644
index 0000000000..755da40a08
--- /dev/null
+++ b/src/printsupport/kernel/qprint.cpp
@@ -0,0 +1,159 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qprint_p.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+// Note: PPD standard does not define a standard set of InputSlot keywords,
+// it is a free form text field left to the PPD writer to decide,
+// but it does suggest some names for consistency with the Windows enum.
+static const InputSlotMap inputSlotMap[] = {
+ { QPrint::Upper, DMBIN_UPPER, "Upper" },
+ { QPrint::Lower, DMBIN_LOWER, "Lower" },
+ { QPrint::Middle, DMBIN_MIDDLE, "Middle" },
+ { QPrint::Manual, DMBIN_MANUAL, "Manual" },
+ { QPrint::Envelope, DMBIN_ENVELOPE, "Envelope" },
+ { QPrint::EnvelopeManual, DMBIN_ENVMANUAL, "EnvelopeManual" },
+ { QPrint::Auto, DMBIN_AUTO, "Auto" },
+ { QPrint::Tractor, DMBIN_TRACTOR, "Tractor" },
+ { QPrint::SmallFormat, DMBIN_SMALLFMT, "AnySmallFormat" },
+ { QPrint::LargeFormat, DMBIN_LARGEFMT, "AnyLargeFormat" },
+ { QPrint::LargeCapacity, DMBIN_LARGECAPACITY, "LargeCapacity" },
+ { QPrint::Cassette, DMBIN_CASSETTE, "Cassette" },
+ { QPrint::FormSource, DMBIN_FORMSOURCE, "FormSource" },
+ { QPrint::Manual, DMBIN_MANUAL, "ManualFeed" },
+ { QPrint::OnlyOne, DMBIN_ONLYONE, "OnlyOne" }, // = QPrint::Upper
+ { QPrint::CustomInputSlot, DMBIN_USER, "" } // Must always be last row
+};
+
+static const OutputBinMap outputBinMap[] = {
+ { QPrint::AutoOutputBin, "" }, // Not a PPD defined value, internal use only
+ { QPrint::UpperBin, "Upper" },
+ { QPrint::LowerBin, "Lower" },
+ { QPrint::RearBin, "Rear" },
+ { QPrint::CustomOutputBin, "" } // Must always be last row
+};
+
+namespace QPrintUtils {
+
+QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key)
+{
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].key == key)
+ return inputSlotMap[i].id;
+ }
+ return QPrint::CustomInputSlot;
+}
+
+QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id)
+{
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].id == id)
+ return QByteArray(inputSlotMap[i].key);
+ }
+ return QByteArray();
+}
+
+int inputSlotIdToWindowsId(QPrint::InputSlotId id)
+{
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].id == id)
+ return inputSlotMap[i].windowsId;
+ }
+ return 0;
+}
+
+QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key)
+{
+ for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
+ if (outputBinMap[i].key == key)
+ return outputBinMap[i].id;
+ }
+ return QPrint::CustomOutputBin;
+}
+
+QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id)
+{
+ for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
+ if (outputBinMap[i].id == id)
+ return QByteArray(outputBinMap[i].key);
+ }
+ return QByteArray();
+}
+
+QPrint::InputSlot paperBinToInputSlot(int windowsId, const QString &name)
+{
+ QPrint::InputSlot slot;
+ slot.name = name;
+ int i;
+ for (i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].windowsId == windowsId) {
+ slot.key = inputSlotMap[i].key;
+ slot.id = inputSlotMap[i].id;
+ slot.windowsId = inputSlotMap[i].windowsId;
+ return slot;
+ }
+ }
+ slot.key = inputSlotMap[i].key;
+ slot.id = inputSlotMap[i].id;
+ slot.windowsId = windowsId;
+ return slot;
+}
+
+#if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
+
+// PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
+// May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
+// but where would it live? Not in base module as don't want to link to CUPS.
+// May have to have two copies in plugins to keep in sync.
+
+QPrint::InputSlot ppdChoiceToInputSlot(const ppd_choice_t &choice)
+{
+ QPrint::InputSlot input;
+ input.key = choice.choice;
+ input.name = QString::fromUtf8(choice.text);
+ input.id = inputSlotKeyToInputSlotId(input.key);
+ input.windowsId = inputSlotMap[input.id].windowsId;
+ return input;
+}
+
+QPrint::OutputBin ppdChoiceToOutputBin(const ppd_choice_t &choice)
+{
+ QPrint::OutputBin output;
+ output.key = choice.choice;
+ output.name = QString::fromUtf8(choice.text);
+ output.id = outputBinKeyToOutputBinId(output.key);
+ return output;
+}
+
+int parsePpdResolution(const QByteArray &value)
+{
+ if (value.isEmpty())
+ return -1;
+ // value can be in form 600dpi or 600x600dpi
+ QByteArray result = value.split('x').at(0);
+ if (result.endsWith("dpi"))
+ result.chop(3);
+ return result.toInt();
+}
+
+QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice)
+{
+ if (choice == "DuplexTumble")
+ return QPrint::DuplexShortSide;
+ else if (choice == "DuplexNoTumble")
+ return QPrint::DuplexLongSide;
+ else // None or SimplexTumble or SimplexNoTumble
+ return QPrint::DuplexNone;
+}
+
+#endif // Mac and CUPS PPD Utilities
+
+}
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qprint_p.h b/src/printsupport/kernel/qprint_p.h
index 4956775461..0a94aa8db3 100644
--- a/src/printsupport/kernel/qprint_p.h
+++ b/src/printsupport/kernel/qprint_p.h
@@ -1,41 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 John Layt <jlayt@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPrintSupport module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINT_P_H
#define QPRINT_P_H
@@ -59,6 +24,7 @@
#if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
#include <cups/ppd.h> // Use for type defs only, don't want to actually link in main module
+// ### QT_DECL_METATYPE_EXTERN_TAGGED once there's a qprint.cpp TU
Q_DECLARE_METATYPE(ppd_file_t *)
#endif
@@ -102,6 +68,7 @@ namespace QPrint {
DuplexShortSide
};
+ // Note: Keep in sync with QPrinter::ColorMode
enum ColorMode {
GrayScale,
Color
@@ -159,142 +126,32 @@ struct InputSlotMap {
const char *key;
};
-// Note: PPD standard does not define a standard set of InputSlot keywords,
-// it is a free form text field left to the PPD writer to decide,
-// but it does suggest some names for consistency with the Windows enum.
-static const InputSlotMap inputSlotMap[] = {
- { QPrint::Upper, DMBIN_UPPER, "Upper" },
- { QPrint::Lower, DMBIN_LOWER, "Lower" },
- { QPrint::Middle, DMBIN_MIDDLE, "Middle" },
- { QPrint::Manual, DMBIN_MANUAL, "Manual" },
- { QPrint::Envelope, DMBIN_ENVELOPE, "Envelope" },
- { QPrint::EnvelopeManual, DMBIN_ENVMANUAL, "EnvelopeManual" },
- { QPrint::Auto, DMBIN_AUTO, "Auto" },
- { QPrint::Tractor, DMBIN_TRACTOR, "Tractor" },
- { QPrint::SmallFormat, DMBIN_SMALLFMT, "AnySmallFormat" },
- { QPrint::LargeFormat, DMBIN_LARGEFMT, "AnyLargeFormat" },
- { QPrint::LargeCapacity, DMBIN_LARGECAPACITY, "LargeCapacity" },
- { QPrint::Cassette, DMBIN_CASSETTE, "Cassette" },
- { QPrint::FormSource, DMBIN_FORMSOURCE, "FormSource" },
- { QPrint::Manual, DMBIN_MANUAL, "ManualFeed" },
- { QPrint::OnlyOne, DMBIN_ONLYONE, "OnlyOne" }, // = QPrint::Upper
- { QPrint::CustomInputSlot, DMBIN_USER, "" } // Must always be last row
-};
-
struct OutputBinMap {
QPrint::OutputBinId id;
const char *key;
};
-static const OutputBinMap outputBinMap[] = {
- { QPrint::AutoOutputBin, "" }, // Not a PPD defined value, internal use only
- { QPrint::UpperBin, "Upper" },
- { QPrint::LowerBin, "Lower" },
- { QPrint::RearBin, "Rear" },
- { QPrint::CustomOutputBin, "" } // Must always be last row
-};
-
// Print utilities shared by print plugins
-class QPrintUtils
-{
-
-public:
-
- static QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key)
- {
- for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
- if (inputSlotMap[i].key == key)
- return inputSlotMap[i].id;
- }
- return QPrint::CustomInputSlot;
- }
-
- static QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id)
- {
- for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
- if (inputSlotMap[i].id == id)
- return QByteArray(inputSlotMap[i].key);
- }
- return QByteArray();
- }
-
- static int inputSlotIdToWindowsId(QPrint::InputSlotId id)
- {
- for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
- if (inputSlotMap[i].id == id)
- return inputSlotMap[i].windowsId;
- }
- return 0;
- }
-
- static QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key)
- {
- for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
- if (outputBinMap[i].key == key)
- return outputBinMap[i].id;
- }
- return QPrint::CustomOutputBin;
- }
-
- static QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id)
- {
- for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
- if (outputBinMap[i].id == id)
- return QByteArray(outputBinMap[i].key);
- }
- return QByteArray();
- }
-
-#if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
-
- // PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
- // May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
- // but where would it live? Not in base module as don't want to link to CUPS.
- // May have to have two copies in plugins to keep in sync.
-
- static QPrint::InputSlot ppdChoiceToInputSlot(const ppd_choice_t &choice)
- {
- QPrint::InputSlot input;
- input.key = choice.choice;
- input.name = QString::fromUtf8(choice.text);
- input.id = inputSlotKeyToInputSlotId(input.key);
- input.windowsId = inputSlotMap[input.id].windowsId;
- return input;
- }
-
- static QPrint::OutputBin ppdChoiceToOutputBin(const ppd_choice_t &choice)
- {
- QPrint::OutputBin output;
- output.key = choice.choice;
- output.name = QString::fromUtf8(choice.text);
- output.id = outputBinKeyToOutputBinId(output.key);
- return output;
- }
-
- static int parsePpdResolution(const QByteArray &value)
- {
- if (value.isEmpty())
- return -1;
- // value can be in form 600dpi or 600x600dpi
- QByteArray result = value.split('x').at(0);
- if (result.endsWith("dpi"))
- result.chop(3);
- return result.toInt();
- }
-
- static QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice)
- {
- if (choice == "DuplexTumble")
- return QPrint::DuplexShortSide;
- else if (choice == "DuplexNoTumble")
- return QPrint::DuplexLongSide;
- else // None or SimplexTumble or SimplexNoTumble
- return QPrint::DuplexNone;
- }
-
-#endif // Mac and CUPS PPD Utilities
-
+namespace QPrintUtils {
+
+Q_PRINTSUPPORT_EXPORT QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key);
+Q_PRINTSUPPORT_EXPORT QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id);
+Q_PRINTSUPPORT_EXPORT int inputSlotIdToWindowsId(QPrint::InputSlotId id);
+Q_PRINTSUPPORT_EXPORT QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key);
+Q_PRINTSUPPORT_EXPORT QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id);
+Q_PRINTSUPPORT_EXPORT QPrint::InputSlot paperBinToInputSlot(int windowsId, const QString &name);
+
+# if (defined Q_OS_MACOS) || (defined Q_OS_UNIX && QT_CONFIG(cups))
+// PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
+// May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
+// but where would it live? Not in base module as don't want to link to CUPS.
+// May have to have two copies in plugins to keep in sync.
+Q_PRINTSUPPORT_EXPORT QPrint::InputSlot ppdChoiceToInputSlot(const ppd_choice_t &choice);
+Q_PRINTSUPPORT_EXPORT QPrint::OutputBin ppdChoiceToOutputBin(const ppd_choice_t &choice);
+Q_PRINTSUPPORT_EXPORT int parsePpdResolution(const QByteArray &value);
+Q_PRINTSUPPORT_EXPORT QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice);
+# endif // Mac and CUPS PPD Utilities
};
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprintdevice.cpp b/src/printsupport/kernel/qprintdevice.cpp
index 7fca3e45bf..acf6d0f329 100644
--- a/src/printsupport/kernel/qprintdevice.cpp
+++ b/src/printsupport/kernel/qprintdevice.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 John Layt <jlayt@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPrintSupport module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qprintdevice_p.h"
#include "qplatformprintdevice.h"
@@ -210,9 +174,9 @@ QPrint::InputSlot QPrintDevice::defaultInputSlot() const
return isValid() ? d->defaultInputSlot() : QPrint::InputSlot();
}
-QVector<QPrint::InputSlot> QPrintDevice::supportedInputSlots() const
+QList<QPrint::InputSlot> QPrintDevice::supportedInputSlots() const
{
- return isValid() ? d->supportedInputSlots() : QVector<QPrint::InputSlot>{};
+ return isValid() ? d->supportedInputSlots() : QList<QPrint::InputSlot>{};
}
QPrint::OutputBin QPrintDevice::defaultOutputBin() const
@@ -220,9 +184,9 @@ QPrint::OutputBin QPrintDevice::defaultOutputBin() const
return isValid() ? d->defaultOutputBin() : QPrint::OutputBin();
}
-QVector<QPrint::OutputBin> QPrintDevice::supportedOutputBins() const
+QList<QPrint::OutputBin> QPrintDevice::supportedOutputBins() const
{
- return isValid() ? d->supportedOutputBins() : QVector<QPrint::OutputBin>{};
+ return isValid() ? d->supportedOutputBins() : QList<QPrint::OutputBin>{};
}
QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const
@@ -230,9 +194,9 @@ QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const
return isValid() ? d->defaultDuplexMode() : QPrint::DuplexNone;
}
-QVector<QPrint::DuplexMode> QPrintDevice::supportedDuplexModes() const
+QList<QPrint::DuplexMode> QPrintDevice::supportedDuplexModes() const
{
- return isValid() ? d->supportedDuplexModes() : QVector<QPrint::DuplexMode>{};
+ return isValid() ? d->supportedDuplexModes() : QList<QPrint::DuplexMode>{};
}
QPrint::ColorMode QPrintDevice::defaultColorMode() const
@@ -240,9 +204,9 @@ QPrint::ColorMode QPrintDevice::defaultColorMode() const
return isValid() ? d->defaultColorMode() : QPrint::GrayScale;
}
-QVector<QPrint::ColorMode> QPrintDevice::supportedColorModes() const
+QList<QPrint::ColorMode> QPrintDevice::supportedColorModes() const
{
- return isValid() ? d->supportedColorModes() : QVector<QPrint::ColorMode>{};
+ return isValid() ? d->supportedColorModes() : QList<QPrint::ColorMode>{};
}
QVariant QPrintDevice::property(PrintDevicePropertyKey key) const
diff --git a/src/printsupport/kernel/qprintdevice_p.h b/src/printsupport/kernel/qprintdevice_p.h
index a2b18f08cf..ec4b9c59fc 100644
--- a/src/printsupport/kernel/qprintdevice_p.h
+++ b/src/printsupport/kernel/qprintdevice_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 John Layt <jlayt@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPrintSupport module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTDEVICE_H
#define QPRINTDEVICE_H
@@ -76,9 +40,7 @@ public:
~QPrintDevice();
QPrintDevice &operator=(const QPrintDevice &other);
- #ifdef Q_COMPILER_RVALUE_REFS
QPrintDevice &operator=(QPrintDevice &&other) { swap(other); return *this; }
-#endif
void swap(QPrintDevice &other) { d.swap(other.d); }
@@ -120,16 +82,16 @@ public:
QList<int> supportedResolutions() const;
QPrint::InputSlot defaultInputSlot() const;
- QVector<QPrint::InputSlot> supportedInputSlots() const;
+ QList<QPrint::InputSlot> supportedInputSlots() const;
QPrint::OutputBin defaultOutputBin() const;
- QVector<QPrint::OutputBin> supportedOutputBins() const;
+ QList<QPrint::OutputBin> supportedOutputBins() const;
QPrint::DuplexMode defaultDuplexMode() const;
- QVector<QPrint::DuplexMode> supportedDuplexModes() const;
+ QList<QPrint::DuplexMode> supportedDuplexModes() const;
QPrint::ColorMode defaultColorMode() const;
- QVector<QPrint::ColorMode> supportedColorModes() const;
+ QList<QPrint::ColorMode> supportedColorModes() const;
enum PrintDevicePropertyKey {
PDPK_CustomBase = 0xff00
diff --git a/src/printsupport/kernel/qprintengine.h b/src/printsupport/kernel/qprintengine.h
index 698f7548cf..65d9ed9a06 100644
--- a/src/printsupport/kernel/qprintengine.h
+++ b/src/printsupport/kernel/qprintengine.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTENGINE_H
#define QPRINTENGINE_H
@@ -44,6 +8,7 @@
#include <QtCore/qvariant.h>
#include <QtPrintSupport/qprinter.h>
+// ### move to qmargins.h
Q_DECLARE_METATYPE(QMarginsF)
QT_BEGIN_NAMESPACE
diff --git a/src/printsupport/kernel/qprintengine_pdf.cpp b/src/printsupport/kernel/qprintengine_pdf.cpp
index 3c24e5ac69..3e50247186 100644
--- a/src/printsupport/kernel/qprintengine_pdf.cpp
+++ b/src/printsupport/kernel/qprintengine_pdf.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qprintengine_pdf_p.h"
@@ -140,7 +104,14 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
d->collate = value.toBool();
break;
case PPK_ColorMode:
- d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale);
+ switch (QPrinter::ColorMode(value.toInt())) {
+ case QPrinter::GrayScale:
+ d->colorModel = QPdfEngine::ColorModel::Grayscale;
+ break;
+ case QPrinter::Color:
+ d->colorModel = QPdfEngine::ColorModel::Auto;
+ break;
+ }
break;
case PPK_Creator:
d->creator = value.toString();
@@ -213,23 +184,24 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
Q_ASSERT(margins.size() == 4);
d->m_pageLayout.setUnits(QPageLayout::Point);
d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
- margins.at(2).toReal(), margins.at(3).toReal()));
+ margins.at(2).toReal(), margins.at(3).toReal()),
+ QPageLayout::OutOfBoundsPolicy::Clamp);
break;
}
case PPK_QPageSize: {
- QPageSize pageSize = value.value<QPageSize>();
+ QPageSize pageSize = qvariant_cast<QPageSize>(value);
if (pageSize.isValid())
d->m_pageLayout.setPageSize(pageSize);
break;
}
case PPK_QPageMargins: {
- QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
+ QPair<QMarginsF, QPageLayout::Unit> pair = qvariant_cast<QPair<QMarginsF, QPageLayout::Unit> >(value);
d->m_pageLayout.setUnits(pair.second);
- d->m_pageLayout.setMargins(pair.first);
+ d->m_pageLayout.setMargins(pair.first, QPageLayout::OutOfBoundsPolicy::Clamp);
break;
}
case PPK_QPageLayout: {
- QPageLayout pageLayout = value.value<QPageLayout>();
+ QPageLayout pageLayout = qvariant_cast<QPageLayout>(value);
if (pageLayout.isValid())
d->m_pageLayout = pageLayout;
break;
@@ -257,7 +229,7 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
ret = d->collate;
break;
case PPK_ColorMode:
- ret = d->grayscale ? QPrinter::GrayScale : QPrinter::Color;
+ ret = d->printerColorMode();
break;
case PPK_Creator:
ret = d->creator;
@@ -403,6 +375,22 @@ QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate()
{
}
+QPrinter::ColorMode QPdfPrintEnginePrivate::printerColorMode() const
+{
+ switch (colorModel) {
+ case QPdfEngine::ColorModel::RGB:
+ case QPdfEngine::ColorModel::CMYK:
+ case QPdfEngine::ColorModel::Auto:
+ return QPrinter::Color;
+ case QPdfEngine::ColorModel::Grayscale:
+ return QPrinter::GrayScale;
+ }
+
+ Q_UNREACHABLE();
+ return QPrinter::Color;
+}
+
+
QT_END_NAMESPACE
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprintengine_pdf_p.h b/src/printsupport/kernel/qprintengine_pdf_p.h
index e7ae21f260..dbf50080a4 100644
--- a/src/printsupport/kernel/qprintengine_pdf_p.h
+++ b/src/printsupport/kernel/qprintengine_pdf_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTENGINE_PDF_P_H
#define QPRINTENGINE_PDF_P_H
@@ -54,13 +18,11 @@
#include "QtPrintSupport/qprintengine.h"
#ifndef QT_NO_PRINTER
+#include "QtCore/qdatastream.h"
#include "QtCore/qmap.h"
-#include "QtGui/qmatrix.h"
#include "QtCore/qstring.h"
-#include "QtCore/qvector.h"
#include "QtGui/qpaintengine.h"
#include "QtGui/qpainterpath.h"
-#include "QtCore/qdatastream.h"
#include "private/qfontengine_p.h"
#include "private/qpdf_p.h"
@@ -117,6 +79,8 @@ public:
QPdfPrintEnginePrivate(QPrinter::PrinterMode m);
~QPdfPrintEnginePrivate();
+ QPrinter::ColorMode printerColorMode() const;
+
virtual bool openPrintDevice();
virtual void closePrintDevice();
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
index 829a13863b..10c4c681ba 100644
--- a/src/printsupport/kernel/qprinter.cpp
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qprinter.h"
#include "qprinter_p.h"
@@ -61,6 +25,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
#define ABORT_IF_ACTIVE(location) \
if (d->printEngine->printerState() == QPrinter::Active) { \
qWarning("%s: Cannot be changed while printer is active", location); \
@@ -76,43 +42,6 @@ QT_BEGIN_NAMESPACE
extern qreal qt_pixelMultiplier(int resolution);
extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
-/// return the multiplier of converting from the unit value to postscript-points.
-Q_PRINTSUPPORT_EXPORT double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
-{
- switch(unit) {
- case QPrinter::Millimeter:
- return 2.83464566929;
- case QPrinter::Point:
- return 1.0;
- case QPrinter::Inch:
- return 72.0;
- case QPrinter::Pica:
- return 12;
- case QPrinter::Didot:
- return 1.065826771;
- case QPrinter::Cicero:
- return 12.789921252;
- case QPrinter::DevicePixel:
- return 72.0/resolution;
- }
- return 1.0;
-}
-
-// not static: it's needed in qpagesetupdialog_unix.cpp
-Q_PRINTSUPPORT_EXPORT QSizeF qt_printerPaperSize(QPrinter::Orientation orientation,
- QPrinter::PaperSize paperSize,
- QPrinter::Unit unit,
- int resolution)
-{
- QPageSize pageSize = QPageSize(QPageSize::PageSizeId(paperSize));
- QSizeF sizef;
- if (unit == QPrinter::DevicePixel)
- sizef = pageSize.size(QPageSize::Point) * qt_multiplierForUnit(unit, resolution);
- else
- sizef = pageSize.size(QPageSize::Unit(unit));
- return orientation == QPrinter::Landscape ? sizef.transposed() : sizef;
-}
-
QPrinterInfo QPrinterPrivate::findValidPrinter(const QPrinterInfo &printer)
{
// Try find a valid printer to use, either the one given, the default or the first available
@@ -200,6 +129,11 @@ QList<const QPicture *> QPrinterPrivate::previewPages() const
return QList<const QPicture *>();
}
+bool QPrinterPrivate::previewMode() const
+{
+ return (previewEngine != nullptr) && (previewEngine == printEngine);
+}
+
void QPrinterPrivate::setPreviewMode(bool enable)
{
Q_Q(QPrinter);
@@ -294,7 +228,7 @@ public:
{
QPrinterPrivate *pd = QPrinterPrivate::get(m_printer);
- return pd->printEngine->property(QPrintEngine::PPK_QPageLayout).value<QPageLayout>();
+ return qvariant_cast<QPageLayout>(pd->printEngine->property(QPrintEngine::PPK_QPageLayout));
}
QPrinter *m_printer;
@@ -335,9 +269,8 @@ public:
The most important parameters are:
\list
- \li setOrientation() tells QPrinter which page orientation to use.
- \li setPaperSize() tells QPrinter what paper size to expect from the
- printer.
+ \li setPageLayout() tells QPrinter which page orientation to use, and
+ what size to expect from the printer.
\li setResolution() tells QPrinter what resolution you wish the
printer to provide, in dots per inch (DPI).
\li setFullPage() tells QPrinter whether you want to deal with the
@@ -420,22 +353,6 @@ public:
*/
/*!
- \enum QPrinter::Orientation
-
- This enum type (not to be confused with \c Orientation) is used
- to specify each page's orientation.
-
- \value Portrait the page's height is greater than its width.
-
- \value Landscape the page's width is greater than its height.
-
- This type interacts with \l QPrinter::PaperSize and
- QPrinter::setFullPage() to determine the final size of the page
- available to the application.
-*/
-
-
-/*!
\enum QPrinter::PrintRange
Used to specify the print range selection option.
@@ -449,31 +366,6 @@ public:
*/
/*!
- \typedef QPrinter::PaperSize
- \since 4.4
-
- typdef for the enum QPagedPaintDevice::PageSize.
-
- This enum type specifies what paper size QPrinter should use.
- QPrinter does not check that the paper size is available; it just
- uses this information, together with QPrinter::Orientation and
- QPrinter::setFullPage(), to determine the printable area.
-
- The defined sizes (with setFullPage(true)) are found in QPagedPaintDevice.
-
- With setFullPage(false) (the default), the metrics will be a bit
- smaller; how much depends on the printer in use.
-
- Due to historic reasons QPageSize::Executive is not the same as the standard
- Postscript and Windows Executive size, use QPageSize::ExecutiveStandard instead.
-
- The Postscript standard size QPageSize::Folio is different to the Windows
- DMPAPER_FOLIO size, use the Postscript standard size QPageSize::FanFoldGermanLegal
- if needed.
-*/
-
-
-/*!
\enum QPrinter::PageOrder
This enum type is used by QPrinter to tell the application program
@@ -544,7 +436,7 @@ public:
Note the difference between Point and DevicePixel. The Point unit is
defined to be 1/72th of an inch, while the DevicePixel unit is
- resolution dependant and is based on the actual pixels, or dots, on
+ resolution dependent and is based on the actual pixels, or dots, on
the printer.
*/
@@ -828,7 +720,7 @@ void QPrinter::setOutputFileName(const QString &fileName)
ABORT_IF_ACTIVE("QPrinter::setOutputFileName");
QFileInfo fi(fileName);
- if (!fi.suffix().compare(QLatin1String("pdf"), Qt::CaseInsensitive))
+ if (!fi.suffix().compare("pdf"_L1, Qt::CaseInsensitive))
setOutputFormat(QPrinter::PdfFormat);
else if (fileName.isEmpty())
setOutputFormat(QPrinter::NativeFormat);
@@ -931,294 +823,6 @@ void QPrinter::setCreator(const QString &creator)
d->setProperty(QPrintEngine::PPK_Creator, creator);
}
-// Defined in QPagedPaintDevice but non-virtual, add QPrinter specific doc here
-#ifdef Q_CLANG_QDOC
-/*!
- \fn bool QPrinter::setPageLayout(const QPageLayout &newLayout)
- \since 5.3
-
- Sets the page layout to \a newLayout.
-
- If the \a newLayout is not valid for the current printer then the page
- layout will not be changed. For example, if the page size is not supported
- by the printer, or if the margins fall outside the printable area.
-
- Returns true if the page layout was successfully set to \a newLayout.
-
- \sa pageLayout(), setPageSize(), setPageOrientation(), setPageMargins()
-*/
-
-/*!
- \fn bool QPrinter::setPageSize(const QPageSize &pageSize)
- \since 5.3
-
- Sets the page size to \a pageSize.
-
- If the \a pageSize is not valid for the current printer then the page
- size will not be changed.
-
- Changing the page size may affect the current page margins if they fall
- outside the printable margins for the new page size on the current printer.
-
- To obtain the current QPageSize use pageLayout().pageSize().
-
- Returns true if the page size was successfully set to \a pageSize.
-
- \sa pageLayout(), setPageLayout()
-*/
-
-/*!
- \fn bool QPrinter::setPageOrientation(QPageLayout::Orientation orientation)
- \since 5.3
-
- Sets the page \a orientation to QPageLayout::Portrait or QPageLayout::Landscape.
-
- The printer driver reads this setting and prints the page using the
- specified orientation.
-
- On Windows and Mac, this option can be changed while printing and will
- take effect from the next call to newPage().
-
- To obtain the current QPageLayout::Orientation use pageLayout().pageOrientation().
-
- Returns true if the page orientation was successfully set to \a orientation.
-
- \sa pageLayout(), setPageLayout()
-*/
-
-/*!
- \fn bool QPrinter::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)
- \since 5.3
-
- Set the page margins to \a margins in the given \a units. If \a units are
- not provided then the current units are used.
-
- If in Full Page mode then no check is performed on the \a margins set,
- otherwise the \a margins must fall within the printable area for the page
- size on the current printer.
-
- To obtain the current page margins use pageLayout().pageMargins().
-
- Returns \c true if the page margins was successfully set to \a margins.
-
- \sa pageLayout(), setPageLayout()
-*/
-
-/*!
- \fn bool QPrinter::setPageMargins(const QMarginsF &margins)
-
- Set the page margins to \a margins using the current units.
- Returns \c true if the page margins were set successfully.
-
- \sa pageLayout(), setPageLayout()
-*/
-/*!
- \fn QPageLayout QPrinter::pageLayout() const
- \since 5.3
-
- Returns the current page layout. Use this method to access the current
- QPageSize, QPageLayout::Orientation, QMarginsF, fullPageRect() and paintRect().
-
- Note that you cannot use the setters on the returned object, you must either
- call the QPrinter methods or setPageLayout().
-
- \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins()
-*/
-#endif
-
-/*!
- \obsolete Use pageLayout().pageOrientation() instead.
-
- Returns the orientation setting. This is driver-dependent, but is usually
- QPrinter::Portrait.
-
- \sa pageLayout()
-*/
-QPrinter::Orientation QPrinter::orientation() const
-{
- return QPrinter::Orientation(pageLayout().orientation());
-}
-
-
-/*!
- \obsolete Use setPageOrientation() instead.
-
- Sets the print orientation to \a orientation.
-
- The orientation can be either QPrinter::Portrait or
- QPrinter::Landscape.
-
- The printer driver reads this setting and prints using the
- specified orientation.
-
- On Windows and Mac, this option can be changed while printing and will
- take effect from the next call to newPage().
-
- \sa setPageOrientation()
-*/
-
-void QPrinter::setOrientation(Orientation orientation)
-{
- setPageOrientation(QPageLayout::Orientation(orientation));
-}
-
-/*!
- \since 4.4
-
- \obsolete Use pageLayout().pageSize().id() instead.
-
- Returns the printer paper size. The default value is driver-dependent.
-
- \sa pageLayout()
-*/
-
-QPrinter::PaperSize QPrinter::paperSize() const
-{
- return pageSize();
-}
-
-/*!
- \since 4.4
-
- \obsolete Use setPageSize(QPageSize) instead.
-
- Sets the printer paper size to \a newPaperSize if that size is
- supported. The result is undefined if \a newPaperSize is not
- supported.
-
- The default paper size is driver-dependent.
-
- This function is useful mostly for setting a default value that
- the user can override in the print dialog.
-
- \sa setPageSize()
-*/
-void QPrinter::setPaperSize(PaperSize newPaperSize)
-{
- setPageSize(QPageSize(QPageSize::PageSizeId(newPaperSize)));
-}
-
-/*!
- \obsolete Use pageLayout().pageSize().id() instead.
-
- Returns the printer page size. The default value is driver-dependent.
-
- \sa pageLayout()
-*/
-QPrinter::PageSize QPrinter::pageSize() const
-{
- return QPrinter::PaperSize(pageLayout().pageSize().id());
-}
-
-
-/*!
- \obsolete Use setPageSize(QPageSize) instead.
-
- Sets the printer page size based on \a newPageSize.
-
- \sa setPageSize()
-*/
-
-void QPrinter::setPageSize(PageSize newPageSize)
-{
- setPageSize(QPageSize(QPageSize::PageSizeId(newPageSize)));
-}
-
-/*!
- \since 4.4
-
- \obsolete Use setPageSize(QPageSize) instead.
-
- Sets the paper size based on \a paperSize in \a unit.
-
- Note that the paper size is defined in a portrait layout, regardless of
- what the current printer orientation is set to.
-
- \sa setPageSize()
-*/
-
-void QPrinter::setPaperSize(const QSizeF &paperSize, QPrinter::Unit unit)
-{
- if (unit == QPrinter::DevicePixel)
- setPageSize(QPageSize(paperSize * qt_pixelMultiplier(resolution()), QPageSize::Point));
- else
- setPageSize(QPageSize(paperSize, QPageSize::Unit(unit)));
-}
-
-/*!
- \reimp
-
- \obsolete Use setPageSize(QPageSize) instead.
-
- Use setPageSize(QPageSize) instead.
-
- Note that the page size is defined in a portrait layout, regardless of
- what the current printer orientation is set to.
-
- \sa setPageSize()
-*/
-void QPrinter::setPageSizeMM(const QSizeF &size)
-{
- setPageSize(QPageSize(size, QPageSize::Millimeter));
-}
-
-/*!
- \since 4.4
-
- \obsolete Use pageLayout().pageSize().size() or
- pageLayout().fullPageSize() instead.
-
- Returns the paper size in \a unit.
-
- Note that the returned size reflects the current paper orientation.
-
- \sa pageLayout()
-*/
-
-QSizeF QPrinter::paperSize(Unit unit) const
-{
- if (unit == QPrinter::DevicePixel)
- return pageLayout().fullRectPixels(resolution()).size();
- else
- return pageLayout().fullRect(QPageLayout::Unit(unit)).size();
-}
-
-/*!
- \since 5.1
-
- \obsolete Use setPageSize(QPageSize) instead.
-
- Sets the paper used by the printer to \a paperName.
-
- \sa setPageSize()
-*/
-
-void QPrinter::setPaperName(const QString &paperName)
-{
- Q_D(QPrinter);
- if (d->paintEngine->type() != QPaintEngine::Pdf)
- ABORT_IF_ACTIVE("QPrinter::setPaperName");
- d->setProperty(QPrintEngine::PPK_PaperName, paperName);
-}
-
-/*!
- \since 5.1
-
- \obsolete Use pageLayout().pageSize().name() instead.
-
- Returns the paper name of the paper set on the printer.
-
- The default value for this is driver-dependent.
-
- \sa pageLayout()
-*/
-
-QString QPrinter::paperName() const
-{
- Q_D(const QPrinter);
- return d->printEngine->property(QPrintEngine::PPK_PaperName).toString();
-}
-
/*!
Sets the page order to \a pageOrder.
@@ -1281,73 +885,6 @@ QPrinter::ColorMode QPrinter::colorMode() const
return QPrinter::ColorMode(d->printEngine->property(QPrintEngine::PPK_ColorMode).toInt());
}
-
-/*!
- \obsolete
- Returns the number of copies to be printed. The default value is 1.
-
- On Windows, \macos and X11 systems that support CUPS, this will always
- return 1 as these operating systems can internally handle the number
- of copies.
-
- On X11, this value will return the number of times the application is
- required to print in order to match the number specified in the printer setup
- dialog. This has been done since some printer drivers are not capable of
- buffering up the copies and in those cases the application must make an
- explicit call to the print code for each copy.
-
- Use copyCount() in conjunction with supportsMultipleCopies() instead.
-
- \sa setNumCopies(), actualNumCopies()
-*/
-
-int QPrinter::numCopies() const
-{
- Q_D(const QPrinter);
- return d->printEngine->property(QPrintEngine::PPK_NumberOfCopies).toInt();
-}
-
-
-/*!
- \obsolete
- \since 4.6
-
- Returns the number of copies that will be printed. The default
- value is 1.
-
- This function always returns the actual value specified in the print
- dialog or using setNumCopies().
-
- Use copyCount() instead.
-
- \sa setNumCopies(), numCopies()
-*/
-int QPrinter::actualNumCopies() const
-{
- return copyCount();
-}
-
-
-
-/*!
- \obsolete
- Sets the number of copies to be printed to \a numCopies.
-
- The printer driver reads this setting and prints the specified
- number of copies.
-
- Use setCopyCount() instead.
-
- \sa numCopies()
-*/
-
-void QPrinter::setNumCopies(int numCopies)
-{
- Q_D(QPrinter);
- ABORT_IF_ACTIVE("QPrinter::setNumCopies");
- d->setProperty(QPrintEngine::PPK_NumberOfCopies, numCopies);
-}
-
/*!
\since 4.7
@@ -1450,12 +987,12 @@ void QPrinter::setCollateCopies(bool collate)
coordinate system coincides with the top-left corner of the paper
itself. In this case, the
\l{QPaintDevice::PaintDeviceMetric}{device metrics} will report
- the exact same dimensions as indicated by \l{PaperSize}. It may not
+ the exact same dimensions as indicated by \{QPageSize}. It may not
be possible to print on the entire physical page because of the
printer's margins, so the application must account for the margins
itself.
- \sa fullPage(), pageLayout(), setPageSize(), width(), height()
+ \sa fullPage(), QPagedPaintDevice::pageLayout(), QPagedPaintDevice::setPageSize()
*/
void QPrinter::setFullPage(bool fp)
@@ -1473,7 +1010,7 @@ void QPrinter::setFullPage(bool fp)
See setFullPage() for details and caveats.
- \sa setFullPage(), pageLayout()
+ \sa setFullPage(), QPagedPaintDevice::pageLayout()
*/
bool QPrinter::fullPage() const
@@ -1493,7 +1030,7 @@ bool QPrinter::fullPage() const
This function must be called before QPainter::begin() to have an effect on
all platforms.
- \sa resolution(), setPaperSize()
+ \sa resolution(), QPagedPaintDevice::setPageSize()
*/
void QPrinter::setResolution(int dpi)
@@ -1588,35 +1125,6 @@ bool QPrinter::fontEmbeddingEnabled() const
*/
/*!
- \since 4.2
-
- \obsolete Use setDuplex() instead.
-
- Enables double sided printing if \a doubleSided is true; otherwise disables it.
-
- \sa setDuplex()
-*/
-void QPrinter::setDoubleSidedPrinting(bool doubleSided)
-{
- setDuplex(doubleSided ? DuplexAuto : DuplexNone);
-}
-
-
-/*!
- \since 4.2
-
- \obsolete Use duplex() instead.
-
- Returns \c true if double side printing is enabled.
-
- \sa duplex()
-*/
-bool QPrinter::doubleSidedPrinting() const
-{
- return duplex() != DuplexNone;
-}
-
-/*!
\since 4.4
Enables double sided printing based on the \a duplex mode.
@@ -1649,7 +1157,7 @@ QPrinter::DuplexMode QPrinter::duplex() const
than the paperRect() since the page normally has margins between
its borders and the paper.
- \sa paperSize()
+ \sa QPagedPaintDevice::pageLayout()
*/
QRectF QPrinter::pageRect(Unit unit) const
{
@@ -1677,104 +1185,6 @@ QRectF QPrinter::paperRect(Unit unit) const
}
/*!
- \obsolete Use pageLayout().paintRectPixels(resolution()) instead.
-
- Returns the page's rectangle; this is usually smaller than the
- paperRect() since the page normally has margins between its
- borders and the paper.
-
- The unit of the returned rectangle is DevicePixel.
-
- \sa pageLayout()
-*/
-QRect QPrinter::pageRect() const
-{
- Q_D(const QPrinter);
- return d->printEngine->property(QPrintEngine::PPK_PageRect).toRect();
-}
-
-/*!
- \obsolete Use pageLayout().fullRectPixels(resolution()) instead.
-
- Returns the paper's rectangle; this is usually larger than the
- pageRect().
-
- The unit of the returned rectangle is DevicePixel.
-
- \sa pageLayout()
-*/
-QRect QPrinter::paperRect() const
-{
- Q_D(const QPrinter);
- return d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect();
-}
-
-/*!
- \since 4.4
-
- \obsolete Use setPageMargins(QMarginsF, QPageLayout::Unit) instead.
-
- This function sets the \a left, \a top, \a right and \a bottom
- page margins for this printer. The unit of the margins are
- specified with the \a unit parameter.
-
- \sa setPageMargins()
-*/
-void QPrinter::setPageMargins(qreal left, qreal top, qreal right, qreal bottom, QPrinter::Unit unit)
-{
- if (unit == QPrinter::DevicePixel) {
- QMarginsF margins = QMarginsF(left, top, right, bottom);
- margins *= qt_pixelMultiplier(resolution());
- margins = qt_convertMargins(margins, QPageLayout::Point, pageLayout().units());
- setPageMargins(margins, pageLayout().units());
- } else {
- setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Unit(unit));
- }
-}
-
-/*!
- \reimp
-
- \obsolete Use setPageMargins(QMarginsF, QPageLayout::Unit) instead.
-
- \sa setPageMargins()
- */
-void QPrinter::setMargins(const Margins &m)
-{
- setPageMargins(QMarginsF(m.left, m.top, m.right, m.bottom), QPageLayout::Millimeter);
-}
-
-/*!
- \since 4.4
-
- \obsolete Use pageLayout().pageMargins() instead.
-
- Returns the page margins for this printer in \a left, \a top, \a
- right, \a bottom. The unit of the returned margins are specified
- with the \a unit parameter.
-
- \sa pageLayout(), setPageMargins()
-*/
-void QPrinter::getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, QPrinter::Unit unit) const
-{
- QMarginsF margins;
- if (unit == QPrinter::DevicePixel) {
- QMargins tmp = pageLayout().marginsPixels(resolution());
- margins = QMarginsF(tmp.left(), tmp.top(), tmp.right(), tmp.bottom());
- } else {
- margins = pageLayout().margins(QPageLayout::Unit(unit));
- }
- if (left)
- *left = margins.left();
- if (right)
- *right = margins.right();
- if (top)
- *top = margins.top();
- if (bottom)
- *bottom = margins.bottom();
-}
-
-/*!
\internal
Returns the metric for the given \a id.
@@ -1806,34 +1216,6 @@ QPrintEngine *QPrinter::printEngine() const
}
/*!
- \obsolete Use QPageSize::id(windowsId) and setPageLayout(QPageSize) instead.
-
- Sets the page size to be used by the printer under Windows to \a
- pageSize.
-
- \sa pageLayout()
-*/
-void QPrinter::setWinPageSize(int pageSize)
-{
- Q_D(QPrinter);
- ABORT_IF_ACTIVE("QPrinter::setWinPageSize");
- d->setProperty(QPrintEngine::PPK_WindowsPageSize, pageSize);
-}
-
-/*!
- \obsolete Use pageLayout.pageSize().windowsId() instead.
-
- Returns the page size used by the printer under Windows.
-
- \sa pageLayout()
-*/
-int QPrinter::winPageSize() const
-{
- Q_D(const QPrinter);
- return d->printEngine->property(QPrintEngine::PPK_WindowsPageSize).toInt();
-}
-
-/*!
Returns a list of the resolutions (a list of dots-per-inch
integers) that the printer says it supports.
@@ -1848,7 +1230,7 @@ QList<int> QPrinter::supportedResolutions() const
= d->printEngine->property(QPrintEngine::PPK_SupportedResolutions).toList();
QList<int> intlist;
intlist.reserve(varlist.size());
- for (auto var : varlist)
+ for (const auto &var : varlist)
intlist << var.toInt();
return intlist;
}
@@ -1895,7 +1277,7 @@ QPrinter::PrinterState QPrinter::printerState() const
return d->printEngine->printerState();
}
-#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
/*!
Returns the supported paper sizes for this printer.
@@ -1981,12 +1363,12 @@ void QPrinter::setPrinterSelectionOption(const QString &option)
\note If fromPage() and toPage() both return 0, this indicates that
\e{the whole document will be printed}.
- \sa setFromTo(), toPage()
+ \sa setFromTo(), toPage(), pageRanges()
*/
int QPrinter::fromPage() const
{
- return d->fromPage;
+ return d->pageRanges.firstPage();
}
/*!
@@ -2005,12 +1387,12 @@ int QPrinter::fromPage() const
The programmer is responsible for reading this setting and
printing accordingly.
- \sa setFromTo(), fromPage()
+ \sa setFromTo(), fromPage(), pageRanges()
*/
int QPrinter::toPage() const
{
- return d->toPage;
+ return d->pageRanges.lastPage();
}
/*!
@@ -2027,17 +1409,14 @@ int QPrinter::toPage() const
This function is mostly used to set a default value that the user can
override in the print dialog when you call setup().
- \sa fromPage(), toPage()
+ \sa fromPage(), toPage(), pageRanges()
*/
void QPrinter::setFromTo(int from, int to)
{
- if (from > to) {
- qWarning("QPrinter::setFromTo: 'from' must be less than or equal to 'to'");
- from = to;
- }
- d->fromPage = from;
- d->toPage = to;
+ d->pageRanges.clear();
+ if (from && to)
+ d->pageRanges.addRange(from, to);
}
/*!
@@ -2117,7 +1496,7 @@ QPrinter::PrintRange QPrinter::printRange() const
\value PPK_NumberOfCopies Obsolete. An integer specifying the number of
copies. Use PPK_CopyCount instead.
- \value PPK_Orientation Specifies a QPrinter::Orientation value.
+ \value PPK_Orientation Specifies a QPageLayout::Orientation value.
\value PPK_OutputFileName The output file name as a string. An
empty file name indicates that the printer should not print to a file.
@@ -2224,8 +1603,4 @@ QPrinter::PrintRange QPrinter::printRange() const
QT_END_NAMESPACE
-#elif defined(Q_OS_WINRT)
-QT_BEGIN_NAMESPACE
-bool Q_PRINTSUPPORT_EXPORT qt_winrt_export_lib_creation_variable;
-QT_END_NAMESPACE
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprinter.h b/src/printsupport/kernel/qprinter.h
index 28dca78a63..c60f0eea1f 100644
--- a/src/printsupport/kernel/qprinter.h
+++ b/src/printsupport/kernel/qprinter.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTER_H
#define QPRINTER_H
@@ -44,7 +8,6 @@
#include <QtCore/qstring.h>
#include <QtCore/qscopedpointer.h>
#include <QtGui/qpagedpaintdevice.h>
-#include <QtGui/qpagelayout.h>
QT_BEGIN_NAMESPACE
@@ -60,7 +23,6 @@ class QPaintEngine;
class QPrintEngine;
class QPrinterInfo;
class QPageSize;
-class QPageMargins;
class Q_PRINTSUPPORT_EXPORT QPrinter : public QPagedPaintDevice
{
@@ -74,11 +36,6 @@ public:
int devType() const override;
- enum Orientation { Portrait, Landscape };
-
- // ### Qt6 Remove in favor of QPage::PageSize
- typedef PageSize PaperSize;
-
enum PageOrder { FirstPageFirst,
LastPageFirst };
@@ -154,36 +111,6 @@ public:
void setCreator(const QString &);
QString creator() const;
-#ifdef Q_CLANG_QDOC
- // ### Qt6 Remove when these are made virtual in QPagedPaintDevice
- bool setPageLayout(const QPageLayout &pageLayout);
- bool setPageSize(const QPageSize &pageSize);
- bool setPageOrientation(QPageLayout::Orientation orientation);
- bool setPageMargins(const QMarginsF &margins);
- bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units);
- QPageLayout pageLayout() const;
-#else
- using QPagedPaintDevice::setPageSize;
- using QPagedPaintDevice::setPageMargins;
-#endif
-
- void setOrientation(Orientation);
- Orientation orientation() const;
-
- void setPageSize(PageSize) override;
- PageSize pageSize() const;
-
- void setPageSizeMM(const QSizeF &size) override;
-
- void setPaperSize(PaperSize);
- PaperSize paperSize() const;
-
- void setPaperSize(const QSizeF &paperSize, Unit unit);
- QSizeF paperSize(Unit unit) const;
-
- void setPaperName(const QString &paperName);
- QString paperName() const;
-
void setPageOrder(PageOrder);
PageOrder pageOrder() const;
@@ -199,11 +126,6 @@ public:
void setFullPage(bool);
bool fullPage() const;
- void setNumCopies(int);
- int numCopies() const;
-
- int actualNumCopies() const;
-
void setCopyCount(int);
int copyCount() const;
bool supportsMultipleCopies() const;
@@ -216,21 +138,13 @@ public:
QList<int> supportedResolutions() const;
-#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
QList<PaperSource> supportedPaperSources() const;
#endif
void setFontEmbeddingEnabled(bool enable);
bool fontEmbeddingEnabled() const;
- void setDoubleSidedPrinting(bool enable);
- bool doubleSidedPrinting() const;
-
- void setWinPageSize(int winPageSize);
- int winPageSize() const;
-
- QRect paperRect() const;
- QRect pageRect() const;
QRectF paperRect(Unit) const;
QRectF pageRect(Unit) const;
@@ -252,11 +166,6 @@ public:
void setPrintRange(PrintRange range);
PrintRange printRange() const;
- void setMargins(const Margins &m) override;
-
- void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit);
- void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const;
-
protected:
int metric(PaintDeviceMetric) const override;
void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
diff --git a/src/printsupport/kernel/qprinter_p.h b/src/printsupport/kernel/qprinter_p.h
index 37c9702c17..77dd5fb4bc 100644
--- a/src/printsupport/kernel/qprinter_p.h
+++ b/src/printsupport/kernel/qprinter_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTER_P_H
#define QPRINTER_P_H
@@ -76,12 +40,12 @@ class Q_PRINTSUPPORT_EXPORT QPrinterPrivate
public:
QPrinterPrivate(QPrinter *printer)
: pdfVersion(QPrinter::PdfVersion_1_4),
- printEngine(0),
- paintEngine(0),
- realPrintEngine(0),
- realPaintEngine(0),
+ printEngine(nullptr),
+ paintEngine(nullptr),
+ realPrintEngine(nullptr),
+ realPaintEngine(nullptr),
#if QT_CONFIG(printpreviewwidget)
- previewEngine(0),
+ previewEngine(nullptr),
#endif
q_ptr(printer),
printRange(QPrinter::AllPages),
@@ -106,6 +70,7 @@ public:
#if QT_CONFIG(printpreviewwidget)
QList<const QPicture *> previewPages() const;
void setPreviewMode(bool);
+ bool previewMode() const;
#endif
void setProperty(QPrintEngine::PrintEnginePropertyKey key, const QVariant &value);
diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp
index 4b092dee64..59078b4df4 100644
--- a/src/printsupport/kernel/qprinterinfo.cpp
+++ b/src/printsupport/kernel/qprinterinfo.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qprinterinfo.h"
#include "qprinterinfo_p.h"
@@ -57,7 +21,7 @@ class QPrinterInfoPrivateDeleter
public:
static inline void cleanup(QPrinterInfoPrivate *d)
{
- if (d != shared_null)
+ if (d != &*shared_null)
delete d;
}
};
@@ -106,7 +70,7 @@ QPrinterInfo::QPrinterInfo()
Constructs a copy of \a other.
*/
QPrinterInfo::QPrinterInfo(const QPrinterInfo &other)
- : d_ptr((other.d_ptr.data() == shared_null) ? shared_null : new QPrinterInfoPrivate(*other.d_ptr))
+ : d_ptr((other.d_ptr.data() == shared_null) ? &*shared_null : new QPrinterInfoPrivate(*other.d_ptr))
{
}
@@ -313,51 +277,6 @@ QPageSize QPrinterInfo::maximumPhysicalPageSize() const
return QPageSize(d->m_printDevice.maximumPhysicalPageSize(), QString(), QPageSize::ExactMatch);
}
-#if QT_DEPRECATED_SINCE(5,3)
-/*!
- \obsolete Use supportedPageSizes() instead.
-
- Returns a list of supported paper sizes by the printer.
-
- Not all printer drivers support this query, so the list may be empty.
-
- \since 4.4
-*/
-
-QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
-{
- Q_D(const QPrinterInfo);
- QList<QPrinter::PaperSize> list;
- const QList<QPageSize> supportedPageSizes = d->m_printDevice.supportedPageSizes();
- list.reserve(supportedPageSizes.size());
- for (const QPageSize &pageSize : supportedPageSizes)
- list.append(QPrinter::PaperSize(pageSize.id()));
- return list;
-}
-
-/*!
- \obsolete Use supportedPageSizes() instead.
-
- Returns a list of all the paper names supported by the driver with the
- corresponding size in millimeters.
-
- Not all printer drivers support this query, so the list may be empty.
-
- \since 5.1
-*/
-
-QList<QPair<QString, QSizeF> > QPrinterInfo::supportedSizesWithNames() const
-{
- Q_D(const QPrinterInfo);
- QList<QPair<QString, QSizeF> > list;
- const QList<QPageSize> supportedPageSizes = d->m_printDevice.supportedPageSizes();
- list.reserve(supportedPageSizes.size());
- for (const QPageSize &pageSize : supportedPageSizes)
- list.append(qMakePair(pageSize.name(), pageSize.size(QPageSize::Millimeter)));
- return list;
-}
-#endif // QT_DEPRECATED_SINCE(5,3)
-
/*!
Returns a list of resolutions supported by this printer.
@@ -400,6 +319,35 @@ QList<QPrinter::DuplexMode> QPrinterInfo::supportedDuplexModes() const
}
/*!
+ Returns the default color mode of this printer.
+
+ \since 5.13
+*/
+
+QPrinter::ColorMode QPrinterInfo::defaultColorMode() const
+{
+ Q_D(const QPrinterInfo);
+ return QPrinter::ColorMode(d->m_printDevice.defaultColorMode());
+}
+
+/*!
+ Returns the supported color modes of this printer.
+
+ \since 5.13
+*/
+
+QList<QPrinter::ColorMode> QPrinterInfo::supportedColorModes() const
+{
+ Q_D(const QPrinterInfo);
+ QList<QPrinter::ColorMode> list;
+ const auto supportedColorModes = d->m_printDevice.supportedColorModes();
+ list.reserve(supportedColorModes.size());
+ for (QPrint::ColorMode mode : supportedColorModes)
+ list << QPrinter::ColorMode(mode);
+ return list;
+}
+
+/*!
Returns a list of all the available Printer Names on this system.
It is recommended to use this instead of availablePrinters() as
diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h
index 8bac395ab3..f1b16e7ccb 100644
--- a/src/printsupport/kernel/qprinterinfo.h
+++ b/src/printsupport/kernel/qprinterinfo.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTERINFO_H
#define QPRINTERINFO_H
@@ -44,7 +8,6 @@
#include <QtPrintSupport/qprinter.h>
#include <QtCore/QList>
-#include <QtCore/QPair>
#include <QtGui/qpagesize.h>
QT_BEGIN_NAMESPACE
@@ -83,16 +46,14 @@ public:
QPageSize minimumPhysicalPageSize() const;
QPageSize maximumPhysicalPageSize() const;
-#if QT_DEPRECATED_SINCE(5,3)
- QT_DEPRECATED QList<QPrinter::PaperSize> supportedPaperSizes() const;
- QT_DEPRECATED QList<QPair<QString, QSizeF> > supportedSizesWithNames() const;
-#endif // QT_DEPRECATED_SINCE(5,3)
-
QList<int> supportedResolutions() const;
QPrinter::DuplexMode defaultDuplexMode() const;
QList<QPrinter::DuplexMode> supportedDuplexModes() const;
+ QPrinter::ColorMode defaultColorMode() const;
+ QList<QPrinter::ColorMode> supportedColorModes() const;
+
static QStringList availablePrinterNames();
static QList<QPrinterInfo> availablePrinters();
diff --git a/src/printsupport/kernel/qprinterinfo_p.h b/src/printsupport/kernel/qprinterinfo_p.h
index 727457a959..ef6a814468 100644
--- a/src/printsupport/kernel/qprinterinfo_p.h
+++ b/src/printsupport/kernel/qprinterinfo_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTERINFO_P_H
#define QPRINTERINFO_P_H
diff --git a/src/printsupport/kernel/qtprintsupportglobal.h b/src/printsupport/kernel/qtprintsupportglobal.h
index 67779af5a2..95f52d18f5 100644
--- a/src/printsupport/kernel/qtprintsupportglobal.h
+++ b/src/printsupport/kernel/qtprintsupportglobal.h
@@ -1,60 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTPRINTSUPPORTGLOBAL_H
#define QTPRINTSUPPORTGLOBAL_H
#include <QtWidgets/qtwidgetsglobal.h>
#include <QtPrintSupport/qtprintsupport-config.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_PRINTSUPPORT_LIB)
-# define Q_PRINTSUPPORT_EXPORT Q_DECL_EXPORT
-# else
-# define Q_PRINTSUPPORT_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_PRINTSUPPORT_EXPORT
-#endif
-
-QT_END_NAMESPACE
+#include <QtPrintSupport/qtprintsupportexports.h>
#endif // QTPRINTSUPPORTGLOBAL_H
diff --git a/src/printsupport/kernel/qtprintsupportglobal_p.h b/src/printsupport/kernel/qtprintsupportglobal_p.h
index 0623a08f1c..53afe86e56 100644
--- a/src/printsupport/kernel/qtprintsupportglobal_p.h
+++ b/src/printsupport/kernel/qtprintsupportglobal_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPrintSupport module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTPRINTSUPPORTGLOBAL_P_H
#define QTPRINTSUPPORTGLOBAL_P_H
diff --git a/src/printsupport/platform/macos/cocoa.json b/src/printsupport/platform/macos/cocoa.json
new file mode 100644
index 0000000000..85c38c42be
--- /dev/null
+++ b/src/printsupport/platform/macos/cocoa.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "cocoaprintersupport" ]
+}
diff --git a/src/printsupport/platform/macos/qcocoaprintdevice.mm b/src/printsupport/platform/macos/qcocoaprintdevice.mm
new file mode 100644
index 0000000000..867e5225db
--- /dev/null
+++ b/src/printsupport/platform/macos/qcocoaprintdevice.mm
@@ -0,0 +1,459 @@
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <ApplicationServices/ApplicationServices.h>
+
+#include "qcocoaprintdevice_p.h"
+
+#if QT_CONFIG(mimetype)
+#include <QtCore/qmimedatabase.h>
+#endif
+#include <qdebug.h>
+
+#include <QtCore/private/qcore_mac_p.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+// The CUPS PPD APIs were deprecated in CUPS 1.6/macOS 10.8, but
+// the replacement APIs are unfortunately not sufficient. See:
+// https://bugreports.qt.io/browse/QTBUG-56545
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+static QPrint::DuplexMode macToDuplexMode(const PMDuplexMode &mode)
+{
+ if (mode == kPMDuplexTumble)
+ return QPrint::DuplexShortSide;
+ else if (mode == kPMDuplexNoTumble)
+ return QPrint::DuplexLongSide;
+ else // kPMDuplexNone or kPMSimplexTumble
+ return QPrint::DuplexNone;
+}
+
+QCocoaPrintDevice::QCocoaPrintDevice()
+ : QPlatformPrintDevice(),
+ m_printer(nullptr),
+ m_session(nullptr),
+ m_ppd(nullptr)
+{
+}
+
+QCocoaPrintDevice::QCocoaPrintDevice(const QString &id)
+ : QPlatformPrintDevice(id),
+ m_printer(nullptr),
+ m_session(nullptr),
+ m_ppd(nullptr)
+{
+ if (!id.isEmpty()) {
+ m_printer = PMPrinterCreateFromPrinterID(id.toCFString());
+ if (m_printer) {
+ m_name = QString::fromCFString(PMPrinterGetName(m_printer));
+ m_location = QString::fromCFString(PMPrinterGetLocation(m_printer));
+ CFStringRef cfMakeAndModel;
+ if (PMPrinterGetMakeAndModelName(m_printer, &cfMakeAndModel) == noErr)
+ m_makeAndModel = QString::fromCFString(cfMakeAndModel);
+ Boolean isRemote;
+ if (PMPrinterIsRemote(m_printer, &isRemote) == noErr)
+ m_isRemote = isRemote;
+ if (PMCreateSession(&m_session) == noErr)
+ PMSessionSetCurrentPMPrinter(m_session, m_printer);
+
+ // No native api to query these options, need to use PPD directly, note is deprecated from 1.6 onwards
+ if (openPpdFile()) {
+ // Note this is if the hardware does multiple copies, not if Cups can
+ m_supportsMultipleCopies = !m_ppd->manual_copies;
+ // Note this is if the hardware does collation, not if Cups can
+ ppd_option_t *collate = ppdFindOption(m_ppd, "Collate");
+ if (collate)
+ m_supportsCollateCopies = true;
+ m_supportsCustomPageSizes = m_ppd->custom_max[0] > 0 && m_ppd->custom_max[1] > 0;
+ m_minimumPhysicalPageSize = QSize(m_ppd->custom_min[0], m_ppd->custom_min[1]);
+ m_maximumPhysicalPageSize = QSize(m_ppd->custom_max[0], m_ppd->custom_max[1]);
+ m_customMargins = QMarginsF(m_ppd->custom_margins[0], m_ppd->custom_margins[3],
+ m_ppd->custom_margins[2], m_ppd->custom_margins[1]);
+ }
+ }
+ }
+}
+
+QCocoaPrintDevice::~QCocoaPrintDevice()
+{
+ if (m_ppd)
+ ppdClose(m_ppd);
+ for (PMPaper paper : m_macPapers)
+ PMRelease(paper);
+ // Releasing the session appears to also release the printer
+ if (m_session)
+ PMRelease(m_session);
+ else if (m_printer)
+ PMRelease(m_printer);
+}
+
+bool QCocoaPrintDevice::isValid() const
+{
+ return m_printer ? true : false;
+}
+
+bool QCocoaPrintDevice::isDefault() const
+{
+ return PMPrinterIsDefault(m_printer);
+}
+
+QPrint::DeviceState QCocoaPrintDevice::state() const
+{
+ PMPrinterState state;
+ if (PMPrinterGetState(m_printer, &state) == noErr) {
+ if (state == kPMPrinterIdle)
+ return QPrint::Idle;
+ else if (state == kPMPrinterProcessing)
+ return QPrint::Active;
+ else if (state == kPMPrinterStopped)
+ return QPrint::Error;
+ }
+ return QPrint::Error;
+}
+
+QPageSize QCocoaPrintDevice::createPageSize(const PMPaper &paper) const
+{
+ CFStringRef key;
+ double width;
+ double height;
+ CFStringRef localizedName;
+ if (PMPaperGetPPDPaperName(paper, &key) == noErr
+ && PMPaperGetWidth(paper, &width) == noErr
+ && PMPaperGetHeight(paper, &height) == noErr
+ && PMPaperCreateLocalizedName(paper, m_printer, &localizedName) == noErr) {
+ QPageSize pageSize = QPlatformPrintDevice::createPageSize(QString::fromCFString(key),QSize(width, height),
+ QString::fromCFString(localizedName));
+ CFRelease(localizedName);
+ return pageSize;
+ }
+ return QPageSize();
+}
+
+void QCocoaPrintDevice::loadPageSizes() const
+{
+ m_pageSizes.clear();
+ for (PMPaper paper : m_macPapers)
+ PMRelease(paper);
+ m_macPapers.clear();
+ m_printableMargins.clear();
+ CFArrayRef paperSizes;
+ if (PMPrinterGetPaperList(m_printer, &paperSizes) == noErr) {
+ int count = CFArrayGetCount(paperSizes);
+ for (int i = 0; i < count; ++i) {
+ PMPaper paper = static_cast<PMPaper>(const_cast<void *>(CFArrayGetValueAtIndex(paperSizes, i)));
+ QPageSize pageSize = createPageSize(paper);
+ if (pageSize.isValid()) {
+ m_pageSizes.append(pageSize);
+ PMRetain(paper);
+ m_macPapers.insert(pageSize.key(), paper);
+ PMPaperMargins printMargins;
+ PMPaperGetMargins(paper, &printMargins);
+ m_printableMargins.insert(pageSize.key(), QMarginsF(printMargins.left, printMargins.top,
+ printMargins.right, printMargins.bottom));
+ }
+ }
+ }
+ m_havePageSizes = true;
+}
+
+QPageSize QCocoaPrintDevice::defaultPageSize() const
+{
+ QPageSize pageSize;
+ PMPageFormat pageFormat;
+ PMPaper paper;
+ if (PMCreatePageFormat(&pageFormat) == noErr) {
+ if (PMSessionDefaultPageFormat(m_session, pageFormat) == noErr
+ && PMGetPageFormatPaper(pageFormat, &paper) == noErr) {
+ pageSize = createPageSize(paper);
+ }
+ PMRelease(pageFormat);
+ }
+ return pageSize;
+}
+
+QMarginsF QCocoaPrintDevice::printableMargins(const QPageSize &pageSize,
+ QPageLayout::Orientation orientation,
+ int resolution) const
+{
+ Q_UNUSED(orientation);
+ Q_UNUSED(resolution);
+ if (!m_havePageSizes)
+ loadPageSizes();
+ if (m_printableMargins.contains(pageSize.key()))
+ return m_printableMargins.value(pageSize.key());
+ return m_customMargins;
+}
+
+void QCocoaPrintDevice::loadResolutions() const
+{
+ m_resolutions.clear();
+ UInt32 count;
+ if (PMPrinterGetPrinterResolutionCount(m_printer, &count) == noErr) {
+ // 1-based index
+ for (UInt32 i = 1; i <= count; ++i) {
+ PMResolution resolution;
+ if (PMPrinterGetIndexedPrinterResolution(m_printer, i, &resolution) == noErr)
+ m_resolutions.append(int(resolution.hRes));
+ }
+ }
+ m_haveResolutions = true;
+}
+
+int QCocoaPrintDevice::defaultResolution() const
+{
+ int defaultResolution = 72;
+ PMPrintSettings settings;
+ if (PMCreatePrintSettings(&settings) == noErr) {
+ PMResolution resolution;
+ if (PMSessionDefaultPrintSettings(m_session, settings) == noErr
+ && PMPrinterGetOutputResolution(m_printer, settings, &resolution) == noErr) {
+ // PMPrinterGetOutputResolution usually fails with -9589 kPMKeyNotFound as not set in PPD
+ defaultResolution = int(resolution.hRes);
+ }
+ PMRelease(settings);
+ }
+ // If no value returned (usually means not set in PPD) then use supported resolutions which
+ // OSX will have populated with at least one default value (but why not returned by call?)
+ if (defaultResolution <= 0) {
+ if (!m_haveResolutions)
+ loadResolutions();
+ if (m_resolutions.count() > 0)
+ return m_resolutions.at(0); // First value or highest? Only likely to be one anyway.
+ return 72; // TDOD More sensible default value???
+ }
+ return defaultResolution;
+}
+
+void QCocoaPrintDevice::loadInputSlots() const
+{
+ // NOTE: Implemented in both CUPS and Mac plugins, please keep in sync
+ // TODO Deal with concatenated names like Tray1Manual or Tray1_Man,
+ // will currently show as CustomInputSlot
+ // TODO Deal with separate ManualFeed key
+ // Try load standard PPD options first
+ m_inputSlots.clear();
+ if (m_ppd) {
+ ppd_option_t *inputSlots = ppdFindOption(m_ppd, "InputSlot");
+ if (inputSlots) {
+ for (int i = 0; i < inputSlots->num_choices; ++i)
+ m_inputSlots.append(QPrintUtils::ppdChoiceToInputSlot(inputSlots->choices[i]));
+ }
+ // If no result, try just the default
+ if (m_inputSlots.size() == 0) {
+ inputSlots = ppdFindOption(m_ppd, "DefaultInputSlot");
+ if (inputSlots)
+ m_inputSlots.append(QPrintUtils::ppdChoiceToInputSlot(inputSlots->choices[0]));
+ }
+ }
+ // If still no result, just use Auto
+ if (m_inputSlots.size() == 0)
+ m_inputSlots.append(QPlatformPrintDevice::defaultInputSlot());
+ m_haveInputSlots = true;
+}
+
+QPrint::InputSlot QCocoaPrintDevice::defaultInputSlot() const
+{
+ // No native api to query, use PPD directly
+ // NOTE: Implemented in both CUPS and Mac plugins, please keep in sync
+ // Try load standard PPD option first
+ if (m_ppd) {
+ ppd_option_t *inputSlot = ppdFindOption(m_ppd, "DefaultInputSlot");
+ if (inputSlot)
+ return QPrintUtils::ppdChoiceToInputSlot(inputSlot->choices[0]);
+ // If no result, then try a marked option
+ ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd, "InputSlot");
+ if (defaultChoice)
+ return QPrintUtils::ppdChoiceToInputSlot(*defaultChoice);
+ }
+ // Otherwise return Auto
+ return QPlatformPrintDevice::defaultInputSlot();
+}
+
+void QCocoaPrintDevice::loadOutputBins() const
+{
+ // No native api to query, use PPD directly
+ // NOTE: Implemented in both CUPS and Mac plugins, please keep in sync
+ m_outputBins.clear();
+ if (m_ppd) {
+ ppd_option_t *outputBins = ppdFindOption(m_ppd, "OutputBin");
+ if (outputBins) {
+ for (int i = 0; i < outputBins->num_choices; ++i)
+ m_outputBins.append(QPrintUtils::ppdChoiceToOutputBin(outputBins->choices[i]));
+ }
+ // If no result, try just the default
+ if (m_outputBins.size() == 0) {
+ outputBins = ppdFindOption(m_ppd, "DefaultOutputBin");
+ if (outputBins)
+ m_outputBins.append(QPrintUtils::ppdChoiceToOutputBin(outputBins->choices[0]));
+ }
+ }
+ // If still no result, just use Auto
+ if (m_outputBins.size() == 0)
+ m_outputBins.append(QPlatformPrintDevice::defaultOutputBin());
+ m_haveOutputBins = true;
+}
+
+QPrint::OutputBin QCocoaPrintDevice::defaultOutputBin() const
+{
+ // No native api to query, use PPD directly
+ // NOTE: Implemented in both CUPS and Mac plugins, please keep in sync
+ // Try load standard PPD option first
+ if (m_ppd) {
+ ppd_option_t *outputBin = ppdFindOption(m_ppd, "DefaultOutputBin");
+ if (outputBin)
+ return QPrintUtils::ppdChoiceToOutputBin(outputBin->choices[0]);
+ // If no result, then try a marked option
+ ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd, "OutputBin");
+ if (defaultChoice)
+ return QPrintUtils::ppdChoiceToOutputBin(*defaultChoice);
+ }
+ // Otherwise return AutoBin
+ return QPlatformPrintDevice::defaultOutputBin();
+}
+
+void QCocoaPrintDevice::loadDuplexModes() const
+{
+ // No native api to query, use PPD directly
+ // NOTE: Implemented in both CUPS and Mac plugins, please keep in sync
+ // Try load standard PPD options first
+ m_duplexModes.clear();
+ if (m_ppd) {
+ ppd_option_t *duplexModes = ppdFindOption(m_ppd, "Duplex");
+ if (duplexModes) {
+ for (int i = 0; i < duplexModes->num_choices; ++i)
+ m_duplexModes.append(QPrintUtils::ppdChoiceToDuplexMode(duplexModes->choices[i].choice));
+ }
+ // If no result, try just the default
+ if (m_duplexModes.size() == 0) {
+ duplexModes = ppdFindOption(m_ppd, "DefaultDuplex");
+ if (duplexModes)
+ m_duplexModes.append(QPrintUtils::ppdChoiceToDuplexMode(duplexModes->choices[0].choice));
+ }
+ }
+ // If still no result, or not added in PPD, then add None
+ if (m_duplexModes.size() == 0 || !m_duplexModes.contains(QPrint::DuplexNone))
+ m_duplexModes.append(QPrint::DuplexNone);
+ // If have both modes, then can support DuplexAuto
+ if (m_duplexModes.contains(QPrint::DuplexLongSide) && m_duplexModes.contains(QPrint::DuplexShortSide))
+ m_duplexModes.append(QPrint::DuplexAuto);
+ m_haveDuplexModes = true;
+}
+
+QPrint::DuplexMode QCocoaPrintDevice::defaultDuplexMode() const
+{
+ QPrint::DuplexMode defaultMode = QPrint::DuplexNone;
+ PMPrintSettings settings;
+ if (PMCreatePrintSettings(&settings) == noErr) {
+ PMDuplexMode duplexMode;
+ if (PMSessionDefaultPrintSettings(m_session, settings) == noErr
+ && PMGetDuplex(settings, &duplexMode) == noErr) {
+ defaultMode = macToDuplexMode(duplexMode);
+ }
+ PMRelease(settings);
+ }
+ return defaultMode;
+}
+
+void QCocoaPrintDevice::loadColorModes() const
+{
+ // No native api to query, use PPD directly
+ m_colorModes.clear();
+ m_colorModes.append(QPrint::GrayScale);
+ if (!m_ppd || (m_ppd && m_ppd->color_device))
+ m_colorModes.append(QPrint::Color);
+ m_haveColorModes = true;
+}
+
+QPrint::ColorMode QCocoaPrintDevice::defaultColorMode() const
+{
+ // No native api to query, use PPD directly
+ // NOTE: Implemented in both CUPS and Mac plugins, please keep in sync
+ // Not a proper option, usually only know if supports color or not, but some
+ // users known to abuse ColorModel to always force GrayScale.
+ if (m_ppd && supportedColorModes().contains(QPrint::Color)) {
+ ppd_option_t *colorModel = ppdFindOption(m_ppd, "DefaultColorModel");
+ if (!colorModel)
+ colorModel = ppdFindOption(m_ppd, "ColorModel");
+ if (!colorModel || qstrcmp(colorModel->defchoice, "Gray") != 0)
+ return QPrint::Color;
+ }
+ return QPrint::GrayScale;
+}
+
+#if QT_CONFIG(mimetype)
+void QCocoaPrintDevice::loadMimeTypes() const
+{
+ // TODO Check how settings affect returned list
+ m_mimeTypes.clear();
+ QMimeDatabase db;
+ PMPrintSettings settings;
+ if (PMCreatePrintSettings(&settings) == noErr) {
+ CFArrayRef mimeTypes;
+ if (PMPrinterGetMimeTypes(m_printer, settings, &mimeTypes) == noErr) {
+ int count = CFArrayGetCount(mimeTypes);
+ for (int i = 0; i < count; ++i) {
+ CFStringRef mimeName = static_cast<CFStringRef>(const_cast<void *>(CFArrayGetValueAtIndex(mimeTypes, i)));
+ QMimeType mimeType = db.mimeTypeForName(QString::fromCFString(mimeName));
+ if (mimeType.isValid())
+ m_mimeTypes.append(mimeType);
+ }
+ }
+ PMRelease(settings);
+ }
+ m_haveMimeTypes = true;
+}
+#endif // mimetype
+
+bool QCocoaPrintDevice::openPpdFile()
+{
+ if (m_ppd)
+ ppdClose(m_ppd);
+ m_ppd = nullptr;
+ CFURLRef ppdURL = nullptr;
+ char ppdPath[MAXPATHLEN];
+ if (PMPrinterCopyDescriptionURL(m_printer, kPMPPDDescriptionType, &ppdURL) == noErr
+ && ppdURL) {
+ if (CFURLGetFileSystemRepresentation(ppdURL, true, (UInt8*)ppdPath, sizeof(ppdPath)))
+ m_ppd = ppdOpenFile(ppdPath);
+ CFRelease(ppdURL);
+ }
+ return m_ppd ? true : false;
+}
+
+PMPrinter QCocoaPrintDevice::macPrinter() const
+{
+ return m_printer;
+}
+
+// Returns a cached printer PMPaper, or creates and caches a new custom PMPaper
+// Caller should never release a cached PMPaper!
+PMPaper QCocoaPrintDevice::macPaper(const QPageSize &pageSize) const
+{
+ if (!m_havePageSizes)
+ loadPageSizes();
+ // If keys match, then is a supported size or an existing custom size
+ if (m_macPapers.contains(pageSize.key()))
+ return m_macPapers.value(pageSize.key());
+ // For any other page size, whether custom or just unsupported, needs to be a custom PMPaper
+ PMPaper paper = nullptr;
+ PMPaperMargins paperMargins;
+ paperMargins.left = m_customMargins.left();
+ paperMargins.right = m_customMargins.right();
+ paperMargins.top = m_customMargins.top();
+ paperMargins.bottom = m_customMargins.bottom();
+ PMPaperCreateCustom(m_printer, QCFString(pageSize.key()), QCFString(pageSize.name()),
+ pageSize.sizePoints().width(), pageSize.sizePoints().height(),
+ &paperMargins, &paper);
+ m_macPapers.insert(pageSize.key(), paper);
+ return paper;
+}
+
+#pragma clang diagnostic pop
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/platform/macos/qcocoaprintdevice_p.h b/src/printsupport/platform/macos/qcocoaprintdevice_p.h
new file mode 100644
index 0000000000..f27b544b0f
--- /dev/null
+++ b/src/printsupport/platform/macos/qcocoaprintdevice_p.h
@@ -0,0 +1,92 @@
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCOCOAPRINTDEVICE_H
+#define QCOCOAPRINTDEVICE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qpa/qplatformprintdevice.h>
+#include <private/qglobal_p.h>
+
+#ifndef QT_NO_PRINTER
+
+#include <QtCore/qhash.h>
+#include <ApplicationServices/ApplicationServices.h>
+
+#include <QtPrintSupport/qtprintsupportglobal.h>
+
+#include <cups/ppd.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCocoaPrintDevice : public QPlatformPrintDevice
+{
+public:
+ QCocoaPrintDevice();
+ explicit QCocoaPrintDevice(const QString &id);
+ virtual ~QCocoaPrintDevice();
+
+ bool isValid() const override;
+ bool isDefault() const override;
+
+ QPrint::DeviceState state() const override;
+
+ QPageSize defaultPageSize() const override;
+
+ QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation,
+ int resolution) const override;
+
+ int defaultResolution() const override;
+
+ QPrint::InputSlot defaultInputSlot() const override;
+
+ QPrint::OutputBin defaultOutputBin() const override;
+
+ QPrint::DuplexMode defaultDuplexMode() const override;
+
+ QPrint::ColorMode defaultColorMode() const override;
+
+ PMPrinter macPrinter() const;
+ PMPaper macPaper(const QPageSize &pageSize) const;
+
+protected:
+ void loadPageSizes() const override;
+ void loadResolutions() const override;
+ void loadInputSlots() const override;
+ void loadOutputBins() const override;
+ void loadDuplexModes() const override;
+ void loadColorModes() const override;
+#if QT_CONFIG(mimetype)
+ void loadMimeTypes() const override;
+#endif
+
+private:
+ QPageSize createPageSize(const PMPaper &paper) const;
+ bool openPpdFile();
+
+ // Mac Core Printing
+ PMPrinter m_printer;
+ PMPrintSession m_session;
+ mutable QHash<QString, PMPaper> m_macPapers;
+
+ // PPD File
+ ppd_file_t *m_ppd;
+
+ QMarginsF m_customMargins;
+ mutable QHash<QString, QMarginsF> m_printableMargins;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+#endif // QCOCOAPRINTDEVICE_H
diff --git a/src/printsupport/platform/macos/qcocoaprintersupport.mm b/src/printsupport/platform/macos/qcocoaprintersupport.mm
new file mode 100644
index 0000000000..ed03e87f29
--- /dev/null
+++ b/src/printsupport/platform/macos/qcocoaprintersupport.mm
@@ -0,0 +1,101 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <AppKit/AppKit.h>
+
+#include "qcocoaprintersupport_p.h"
+
+#ifndef QT_NO_PRINTER
+
+#include <AppKit/AppKit.h>
+
+#include <QtCore/private/qcore_mac_p.h>
+
+#include "qcocoaprintdevice_p.h"
+#include "qprintengine_mac_p.h"
+
+#include <private/qprinterinfo_p.h>
+
+#define QT_STATICPLUGIN
+#include <qpa/qplatformprintplugin.h>
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt::StringLiterals;
+
+QCocoaPrinterSupport::QCocoaPrinterSupport()
+{ }
+
+QCocoaPrinterSupport::~QCocoaPrinterSupport()
+{ }
+
+QPrintEngine *QCocoaPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode printerMode, const QString &deviceId)
+{
+ return new QMacPrintEngine(printerMode, deviceId);
+}
+
+QPaintEngine *QCocoaPrinterSupport::createPaintEngine(QPrintEngine *printEngine, QPrinter::PrinterMode printerMode)
+{
+ Q_UNUSED(printerMode);
+ /*
+ QMacPrintEngine multiply inherits from QPrintEngine and QPaintEngine,
+ the cast here allows conversion of QMacPrintEngine* to QPaintEngine*
+ */
+ return static_cast<QMacPrintEngine *>(printEngine);
+}
+
+QPrintDevice QCocoaPrinterSupport::createPrintDevice(const QString &id)
+{
+ return QPlatformPrinterSupport::createPrintDevice(new QCocoaPrintDevice(id));
+}
+
+QStringList QCocoaPrinterSupport::availablePrintDeviceIds() const
+{
+ QStringList list;
+ QCFType<CFArrayRef> printerList;
+ if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr) {
+ CFIndex count = CFArrayGetCount(printerList);
+ for (CFIndex i = 0; i < count; ++i) {
+ PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
+ list.append(QString::fromCFString(PMPrinterGetID(printer)));
+ }
+ }
+ return list;
+}
+
+QString QCocoaPrinterSupport::defaultPrintDeviceId() const
+{
+ QCFType<CFArrayRef> printerList;
+ if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr) {
+ CFIndex count = CFArrayGetCount(printerList);
+ for (CFIndex i = 0; i < count; ++i) {
+ PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
+ if (PMPrinterIsDefault(printer))
+ return QString::fromCFString(PMPrinterGetID(printer));
+ }
+ }
+ return QString();
+}
+
+class QCocoaPrinterSupportPlugin : public QPlatformPrinterSupportPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformPrinterSupportFactoryInterface_iid FILE "cocoa.json")
+
+public:
+ QPlatformPrinterSupport *create(const QString &);
+};
+
+QPlatformPrinterSupport *QCocoaPrinterSupportPlugin::create(const QString &key)
+{
+ if (key.compare(key, "cocoaprintersupport"_L1, Qt::CaseInsensitive) != 0)
+ return 0;
+
+ return new QCocoaPrinterSupport();
+}
+
+QT_END_NAMESPACE
+
+#include "qcocoaprintersupport.moc"
+
+#endif //QT_NO_PRINTER
diff --git a/src/printsupport/platform/macos/qcocoaprintersupport_p.h b/src/printsupport/platform/macos/qcocoaprintersupport_p.h
new file mode 100644
index 0000000000..73ebe7c90a
--- /dev/null
+++ b/src/printsupport/platform/macos/qcocoaprintersupport_p.h
@@ -0,0 +1,43 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCOCOAPRINTERSUPPORT_H
+#define QCOCOAPRINTERSUPPORT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qpa/qplatformprintersupport.h>
+#include <private/qglobal_p.h>
+#ifndef QT_NO_PRINTER
+
+#include <QtPrintSupport/qtprintsupportglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_PRINTSUPPORT_EXPORT QCocoaPrinterSupport : public QPlatformPrinterSupport
+{
+public:
+ QCocoaPrinterSupport();
+ ~QCocoaPrinterSupport();
+
+ QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode, const QString &deviceId = QString()) override;
+ QPaintEngine *createPaintEngine(QPrintEngine *, QPrinter::PrinterMode printerMode) override;
+
+ QPrintDevice createPrintDevice(const QString &id) override;
+ QStringList availablePrintDeviceIds() const override;
+ QString defaultPrintDeviceId() const override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+#endif // QCOCOAPRINTERSUPPORT_H
diff --git a/src/printsupport/platform/macos/qpaintengine_mac.mm b/src/printsupport/platform/macos/qpaintengine_mac.mm
new file mode 100644
index 0000000000..27274f116e
--- /dev/null
+++ b/src/printsupport/platform/macos/qpaintengine_mac.mm
@@ -0,0 +1,1386 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <AppKit/AppKit.h>
+#include <CoreGraphics/CoreGraphics.h>
+
+#include "qpaintengine_mac_p.h"
+#include "qprintengine_mac_p.h"
+
+#include <qbitmap.h>
+#include <qpaintdevice.h>
+#include <qpainterpath.h>
+#include <qpixmapcache.h>
+#include <private/qpaintengine_raster_p.h>
+#include <qprinter.h>
+#include <qstack.h>
+#include <qwidget.h>
+#include <qvarlengtharray.h>
+#include <qdebug.h>
+#include <qcoreapplication.h>
+#include <qmath.h>
+
+#include <qpa/qplatformpixmap.h>
+
+#include <private/qfont_p.h>
+#include <private/qfontengine_p.h>
+#include <private/qfontengine_coretext_p.h>
+#include <private/qnumeric_p.h>
+#include <private/qpainter_p.h>
+#include <private/qpainterpath_p.h>
+#include <private/qtextengine_p.h>
+#include <private/qcoregraphics_p.h>
+
+#include <string.h>
+
+QT_BEGIN_NAMESPACE
+
+/*****************************************************************************
+ QCoreGraphicsPaintEngine utility functions
+ *****************************************************************************/
+
+void qt_mac_cgimage_data_free(void *, const void *memoryToFree, size_t)
+{
+ free(const_cast<void *>(memoryToFree));
+}
+
+CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr)
+{
+ QImage image = pixmap.toImage();
+ if (image.format() != QImage::Format_ARGB32_Premultiplied)
+ image = std::move(image).convertToFormat(QImage::Format_ARGB32_Premultiplied);
+
+ const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height());
+ const qsizetype sbpr = image.bytesPerLine();
+ const uint nbytes = sw * sh;
+ // alpha is always 255 for bitmaps, ignore it in this case.
+ const quint32 mask = pixmap.depth() == 1 ? 0x00ffffff : 0xffffffff;
+ quint8 *dptr = static_cast<quint8 *>(malloc(nbytes));
+ quint32 *sptr = reinterpret_cast<quint32 *>(image.scanLine(0)), *srow;
+ for (int y = sy, offset=0; y < sh; ++y) {
+ srow = sptr + (y * (sbpr / 4));
+ for (int x = sx; x < sw; ++x)
+ *(dptr+(offset++)) = (*(srow+x) & mask) ? 255 : 0;
+ }
+ QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(nullptr, dptr, nbytes, qt_mac_cgimage_data_free);
+ return CGImageMaskCreate(sw, sh, 8, 8, nbytes / sh, provider, nullptr, false);
+}
+
+//conversion
+inline static float qt_mac_convert_color_to_cg(int c) { return ((float)c * 1000 / 255) / 1000; }
+CGAffineTransform qt_mac_convert_transform_to_cg(const QTransform &t) {
+ return CGAffineTransformMake(t.m11(), t.m12(), t.m21(), t.m22(), t.dx(), t.dy());
+}
+
+inline static QCFType<CGColorRef> cgColorForQColor(const QColor &col)
+{
+ CGFloat components[] = {
+ qt_mac_convert_color_to_cg(col.red()),
+ qt_mac_convert_color_to_cg(col.green()),
+ qt_mac_convert_color_to_cg(col.blue()),
+ qt_mac_convert_color_to_cg(col.alpha())
+ };
+ QCFType<CGColorSpaceRef> colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+ return CGColorCreate(colorSpace, components);
+}
+
+// There's architectural problems with using native gradients
+// on the Mac at the moment, so disable them.
+// #define QT_MAC_USE_NATIVE_GRADIENTS
+
+#ifdef QT_MAC_USE_NATIVE_GRADIENTS
+static bool drawGradientNatively(const QGradient *gradient)
+{
+ return gradient->spread() == QGradient::PadSpread;
+}
+
+// gradiant callback
+static void qt_mac_color_gradient_function(void *info, const CGFloat *in, CGFloat *out)
+{
+ QBrush *brush = static_cast<QBrush *>(info);
+ Q_ASSERT(brush && brush->gradient());
+
+ const QGradientStops stops = brush->gradient()->stops();
+ const int n = stops.count();
+ Q_ASSERT(n >= 1);
+ const QGradientStop *begin = stops.constBegin();
+ const QGradientStop *end = begin + n;
+
+ qreal p = in[0];
+ const QGradientStop *i = begin;
+ while (i != end && i->first < p)
+ ++i;
+
+ QRgb c;
+ if (i == begin) {
+ c = begin->second.rgba();
+ } else if (i == end) {
+ c = (end - 1)->second.rgba();
+ } else {
+ const QGradientStop &s1 = *(i - 1);
+ const QGradientStop &s2 = *i;
+ qreal p1 = s1.first;
+ qreal p2 = s2.first;
+ QRgb c1 = s1.second.rgba();
+ QRgb c2 = s2.second.rgba();
+ int idist = 256 * (p - p1) / (p2 - p1);
+ int dist = 256 - idist;
+ c = qRgba(INTERPOLATE_PIXEL_256(qRed(c1), dist, qRed(c2), idist),
+ INTERPOLATE_PIXEL_256(qGreen(c1), dist, qGreen(c2), idist),
+ INTERPOLATE_PIXEL_256(qBlue(c1), dist, qBlue(c2), idist),
+ INTERPOLATE_PIXEL_256(qAlpha(c1), dist, qAlpha(c2), idist));
+ }
+
+ out[0] = qt_mac_convert_color_to_cg(qRed(c));
+ out[1] = qt_mac_convert_color_to_cg(qGreen(c));
+ out[2] = qt_mac_convert_color_to_cg(qBlue(c));
+ out[3] = qt_mac_convert_color_to_cg(qAlpha(c));
+}
+#endif
+
+//clipping handling
+void QCoreGraphicsPaintEnginePrivate::resetClip()
+{
+ static bool inReset = false;
+ if (inReset)
+ return;
+ inReset = true;
+
+ CGAffineTransform old_xform = CGContextGetCTM(hd);
+
+ //setup xforms
+ CGContextConcatCTM(hd, CGAffineTransformInvert(old_xform));
+ while (stackCount > 0) {
+ restoreGraphicsState();
+ }
+ saveGraphicsState();
+ inReset = false;
+ //reset xforms
+ CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
+ CGContextConcatCTM(hd, old_xform);
+}
+
+static CGRect qt_mac_compose_rect(const QRectF &r, float off=0)
+{
+ return CGRectMake(r.x()+off, r.y()+off, r.width(), r.height());
+}
+
+static CGMutablePathRef qt_mac_compose_path(const QPainterPath &p, float off=0)
+{
+ CGMutablePathRef ret = CGPathCreateMutable();
+ QPointF startPt;
+ for (int i=0; i<p.elementCount(); ++i) {
+ const QPainterPath::Element &elm = p.elementAt(i);
+ switch (elm.type) {
+ case QPainterPath::MoveToElement:
+ if (i > 0
+ && p.elementAt(i - 1).x == startPt.x()
+ && p.elementAt(i - 1).y == startPt.y())
+ CGPathCloseSubpath(ret);
+ startPt = QPointF(elm.x, elm.y);
+ CGPathMoveToPoint(ret, 0, elm.x+off, elm.y+off);
+ break;
+ case QPainterPath::LineToElement:
+ CGPathAddLineToPoint(ret, 0, elm.x+off, elm.y+off);
+ break;
+ case QPainterPath::CurveToElement:
+ Q_ASSERT(p.elementAt(i+1).type == QPainterPath::CurveToDataElement);
+ Q_ASSERT(p.elementAt(i+2).type == QPainterPath::CurveToDataElement);
+ CGPathAddCurveToPoint(ret, 0,
+ elm.x+off, elm.y+off,
+ p.elementAt(i+1).x+off, p.elementAt(i+1).y+off,
+ p.elementAt(i+2).x+off, p.elementAt(i+2).y+off);
+ i+=2;
+ break;
+ default:
+ qFatal("QCoreGraphicsPaintEngine::drawPath(), unhandled type: %d", elm.type);
+ break;
+ }
+ }
+ if (!p.isEmpty()
+ && p.elementAt(p.elementCount() - 1).x == startPt.x()
+ && p.elementAt(p.elementCount() - 1).y == startPt.y())
+ CGPathCloseSubpath(ret);
+ return ret;
+}
+
+//pattern handling (tiling)
+#if 1
+# define QMACPATTERN_MASK_MULTIPLIER 32
+#else
+# define QMACPATTERN_MASK_MULTIPLIER 1
+#endif
+class QMacPattern
+{
+public:
+ QMacPattern() : as_mask(false), pdev(0), image(0) { data.bytes = 0; }
+ ~QMacPattern() { CGImageRelease(image); }
+ int width() {
+ if (image)
+ return CGImageGetWidth(image);
+ if (data.bytes)
+ return 8*QMACPATTERN_MASK_MULTIPLIER;
+ return data.pixmap.width();
+ }
+ int height() {
+ if (image)
+ return CGImageGetHeight(image);
+ if (data.bytes)
+ return 8*QMACPATTERN_MASK_MULTIPLIER;
+ return data.pixmap.height();
+ }
+
+ //input
+ QColor foreground;
+ bool as_mask;
+ struct {
+ QPixmap pixmap;
+ const uchar *bytes;
+ } data;
+ QPaintDevice *pdev;
+ //output
+ CGImageRef image;
+};
+static void qt_mac_draw_pattern(void *info, CGContextRef c)
+{
+ QMacPattern *pat = (QMacPattern*)info;
+ int w = 0, h = 0;
+ bool isBitmap = (pat->data.pixmap.depth() == 1);
+ if (!pat->image) { //lazy cache
+ if (pat->as_mask) {
+ Q_ASSERT(pat->data.bytes);
+ w = h = 8;
+#if (QMACPATTERN_MASK_MULTIPLIER == 1)
+ CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, pat->data.bytes, w*h, nullptr);
+ pat->image = CGImageMaskCreate(w, h, 1, 1, 1, provider, nullptr, false);
+ CGDataProviderRelease(provider);
+#else
+ const int numBytes = (w*h)/sizeof(uchar);
+ uchar xor_bytes[numBytes];
+ for (int i = 0; i < numBytes; ++i)
+ xor_bytes[i] = pat->data.bytes[i] ^ 0xFF;
+ CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, xor_bytes, w*h, nullptr);
+ CGImageRef swatch = CGImageMaskCreate(w, h, 1, 1, 1, provider, nullptr, false);
+ CGDataProviderRelease(provider);
+
+ const QColor c0(0, 0, 0, 0), c1(255, 255, 255, 255);
+ QPixmap pm(w*QMACPATTERN_MASK_MULTIPLIER, h*QMACPATTERN_MASK_MULTIPLIER);
+ pm.fill(c0);
+ QMacCGContext pm_ctx(&pm);
+ CGContextSetFillColorWithColor(c, cgColorForQColor(c1));
+ CGRect rect = CGRectMake(0, 0, w, h);
+ for (int x = 0; x < QMACPATTERN_MASK_MULTIPLIER; ++x) {
+ rect.origin.x = x * w;
+ for (int y = 0; y < QMACPATTERN_MASK_MULTIPLIER; ++y) {
+ rect.origin.y = y * h;
+ qt_mac_drawCGImage(pm_ctx, &rect, swatch);
+ }
+ }
+ pat->image = qt_mac_create_imagemask(pm, pm.rect());
+ CGImageRelease(swatch);
+ w *= QMACPATTERN_MASK_MULTIPLIER;
+ h *= QMACPATTERN_MASK_MULTIPLIER;
+#endif
+ } else {
+ w = pat->data.pixmap.width();
+ h = pat->data.pixmap.height();
+ if (isBitmap)
+ pat->image = qt_mac_create_imagemask(pat->data.pixmap, pat->data.pixmap.rect());
+ else
+ pat->image = qt_mac_toCGImage(pat->data.pixmap.toImage());
+ }
+ } else {
+ w = CGImageGetWidth(pat->image);
+ h = CGImageGetHeight(pat->image);
+ }
+
+ //draw
+ bool needRestore = false;
+ if (CGImageIsMask(pat->image)) {
+ CGContextSaveGState(c);
+ CGContextSetFillColorWithColor(c, cgColorForQColor(pat->foreground));
+ }
+ CGRect rect = CGRectMake(0, 0, w, h);
+ qt_mac_drawCGImage(c, &rect, pat->image);
+ if (needRestore)
+ CGContextRestoreGState(c);
+}
+static void qt_mac_dispose_pattern(void *info)
+{
+ QMacPattern *pat = (QMacPattern*)info;
+ delete pat;
+}
+
+/*****************************************************************************
+ QCoreGraphicsPaintEngine member functions
+ *****************************************************************************/
+
+inline static QPaintEngine::PaintEngineFeatures qt_mac_cg_features()
+{
+ return QPaintEngine::PaintEngineFeatures(QPaintEngine::AllFeatures & ~QPaintEngine::PaintOutsidePaintEvent
+ & ~QPaintEngine::PerspectiveTransform
+ & ~QPaintEngine::ConicalGradientFill
+ & ~QPaintEngine::LinearGradientFill
+ & ~QPaintEngine::RadialGradientFill
+ & ~QPaintEngine::BrushStroke);
+}
+
+QCoreGraphicsPaintEngine::QCoreGraphicsPaintEngine()
+: QPaintEngine(*(new QCoreGraphicsPaintEnginePrivate), qt_mac_cg_features())
+{
+}
+
+QCoreGraphicsPaintEngine::QCoreGraphicsPaintEngine(QPaintEnginePrivate &dptr)
+: QPaintEngine(dptr, qt_mac_cg_features())
+{
+}
+
+QCoreGraphicsPaintEngine::~QCoreGraphicsPaintEngine()
+{
+}
+
+bool
+QCoreGraphicsPaintEngine::begin(QPaintDevice *pdev)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ if (isActive()) { // already active painting
+ qWarning("QCoreGraphicsPaintEngine::begin: Painter already active");
+ return false;
+ }
+
+ //initialization
+ d->pdev = pdev;
+ d->complexXForm = false;
+ d->cosmeticPen = QCoreGraphicsPaintEnginePrivate::CosmeticSetPenWidth;
+ d->cosmeticPenSize = 1;
+ d->current.clipEnabled = false;
+ d->pixelSize = QPoint(1,1);
+
+ if (pdev->devType() != QInternal::Printer) {
+ QMacCGContext ctx(pdev);
+ d->hd = CGContextRetain(ctx);
+ if (d->hd) {
+ d->saveGraphicsState();
+ d->orig_xform = CGContextGetCTM(d->hd);
+ if (d->shading) {
+ CGShadingRelease(d->shading);
+ d->shading = nullptr;
+ }
+ d->setClip(nullptr); //clear the context's clipping
+ }
+ }
+
+ setActive(true);
+
+ if (d->pdev->devType() == QInternal::Widget) { // device is a widget
+ QWidget *w = (QWidget*)d->pdev;
+ bool unclipped = w->testAttribute(Qt::WA_PaintUnclipped);
+
+ if ((w->windowType() == Qt::Desktop)) {
+ if (!unclipped)
+ qWarning("QCoreGraphicsPaintEngine::begin: Does not support clipped desktop on OS X");
+ // ## need to do [qt_mac_window_for(w) makeKeyAndOrderFront]; (need to rename the file)
+ } else if (unclipped) {
+ qWarning("QCoreGraphicsPaintEngine::begin: Does not support unclipped painting");
+ }
+ } else if (d->pdev->devType() == QInternal::Pixmap) { // device is a pixmap
+ QPixmap *pm = (QPixmap*)d->pdev;
+ if (pm->isNull()) {
+ qWarning("QCoreGraphicsPaintEngine::begin: Cannot paint null pixmap");
+ end();
+ return false;
+ }
+ }
+
+ setDirty(QPaintEngine::DirtyPen);
+ setDirty(QPaintEngine::DirtyBrush);
+ setDirty(QPaintEngine::DirtyBackground);
+ setDirty(QPaintEngine::DirtyHints);
+ return true;
+}
+
+bool
+QCoreGraphicsPaintEngine::end()
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ setActive(false);
+ if (d->pdev->devType() == QInternal::Widget && static_cast<QWidget*>(d->pdev)->windowType() == Qt::Desktop) {
+ // ### need to do [qt_mac_window_for(static_cast<QWidget *>(d->pdev)) orderOut]; (need to rename)
+ }
+ if (d->shading) {
+ CGShadingRelease(d->shading);
+ d->shading = 0;
+ }
+ d->pdev = nullptr;
+ if (d->hd) {
+ d->restoreGraphicsState();
+ CGContextSynchronize(d->hd);
+ CGContextRelease(d->hd);
+ d->hd = nullptr;
+ }
+ return true;
+}
+
+void
+QCoreGraphicsPaintEngine::updateState(const QPaintEngineState &state)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ QPaintEngine::DirtyFlags flags = state.state();
+
+ if (flags & DirtyTransform)
+ updateMatrix(state.transform());
+
+ if (flags & DirtyClipEnabled) {
+ if (state.isClipEnabled())
+ updateClipPath(painter()->clipPath(), Qt::ReplaceClip);
+ else
+ updateClipPath(QPainterPath(), Qt::NoClip);
+ }
+
+ if (flags & DirtyClipPath) {
+ updateClipPath(state.clipPath(), state.clipOperation());
+ } else if (flags & DirtyClipRegion) {
+ updateClipRegion(state.clipRegion(), state.clipOperation());
+ }
+
+ // If the clip has changed we need to update all other states
+ // too, since they are included in the system context on OSX,
+ // and changing the clip resets that context back to scratch.
+ if (flags & (DirtyClipPath | DirtyClipRegion | DirtyClipEnabled))
+ flags |= AllDirty;
+
+ if (flags & DirtyPen)
+ updatePen(state.pen());
+ if (flags & (DirtyBrush|DirtyBrushOrigin))
+ updateBrush(state.brush(), state.brushOrigin());
+ if (flags & DirtyFont)
+ updateFont(state.font());
+ if (flags & DirtyOpacity)
+ updateOpacity(state.opacity());
+ if (flags & DirtyHints)
+ updateRenderHints(state.renderHints());
+ if (flags & DirtyCompositionMode)
+ updateCompositionMode(state.compositionMode());
+
+ if (flags & (DirtyPen | DirtyTransform | DirtyHints)) {
+ if (!d->current.pen.isCosmetic()) {
+ d->cosmeticPen = QCoreGraphicsPaintEnginePrivate::CosmeticNone;
+ } else if (d->current.transform.m11() < d->current.transform.m22()-1.0 ||
+ d->current.transform.m11() > d->current.transform.m22()+1.0) {
+ d->cosmeticPen = QCoreGraphicsPaintEnginePrivate::CosmeticTransformPath;
+ d->cosmeticPenSize = d->adjustPenWidth(d->current.pen.widthF());
+ if (!d->cosmeticPenSize)
+ d->cosmeticPenSize = 1.0;
+ } else {
+ d->cosmeticPen = QCoreGraphicsPaintEnginePrivate::CosmeticSetPenWidth;
+ static const float sqrt2 = std::sqrt(2.0f);
+ qreal width = d->current.pen.widthF();
+ if (!width)
+ width = 1;
+ d->cosmeticPenSize = std::sqrt(std::pow(d->pixelSize.y(), 2) + std::pow(d->pixelSize.x(), 2)) / sqrt2 * width;
+ }
+ }
+}
+
+void
+QCoreGraphicsPaintEngine::updatePen(const QPen &pen)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+ d->current.pen = pen;
+ d->setStrokePen(pen);
+}
+
+void
+QCoreGraphicsPaintEngine::updateBrush(const QBrush &brush, const QPointF &brushOrigin)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+ d->current.brush = brush;
+
+#ifdef QT_MAC_USE_NATIVE_GRADIENTS
+ // Quartz supports only pad spread
+ if (const QGradient *gradient = brush.gradient()) {
+ if (drawGradientNatively(gradient)) {
+ gccaps |= QPaintEngine::LinearGradientFill | QPaintEngine::RadialGradientFill;
+ } else {
+ gccaps &= ~(QPaintEngine::LinearGradientFill | QPaintEngine::RadialGradientFill);
+ }
+ }
+#endif
+
+ if (d->shading) {
+ CGShadingRelease(d->shading);
+ d->shading = nullptr;
+ }
+ d->setFillBrush(brushOrigin);
+}
+
+void
+QCoreGraphicsPaintEngine::updateOpacity(qreal opacity)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ CGContextSetAlpha(d->hd, opacity);
+}
+
+void
+QCoreGraphicsPaintEngine::updateFont(const QFont &)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+ updatePen(d->current.pen);
+}
+
+void
+QCoreGraphicsPaintEngine::updateMatrix(const QTransform &transform)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (qt_is_nan(transform.m11()) || qt_is_nan(transform.m12()) || qt_is_nan(transform.m13())
+ || qt_is_nan(transform.m21()) || qt_is_nan(transform.m22()) || qt_is_nan(transform.m23())
+ || qt_is_nan(transform.m31()) || qt_is_nan(transform.m32()) || qt_is_nan(transform.m33()))
+ return;
+
+ d->current.transform = transform;
+ d->setTransform(transform.isIdentity() ? 0 : &transform);
+ d->complexXForm = (transform.m11() != 1 || transform.m22() != 1
+ || transform.m12() != 0 || transform.m21() != 0);
+ d->pixelSize = d->devicePixelSize(d->hd);
+}
+
+void
+QCoreGraphicsPaintEngine::updateClipPath(const QPainterPath &p, Qt::ClipOperation op)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+ if (op == Qt::NoClip) {
+ if (d->current.clipEnabled) {
+ d->current.clipEnabled = false;
+ d->current.clip = QRegion();
+ d->setClip(nullptr);
+ }
+ } else {
+ if (!d->current.clipEnabled)
+ op = Qt::ReplaceClip;
+ d->current.clipEnabled = true;
+ QRegion clipRegion(p.toFillPolygon().toPolygon(), p.fillRule());
+ if (op == Qt::ReplaceClip) {
+ d->current.clip = clipRegion;
+ d->setClip(nullptr);
+ if (p.isEmpty()) {
+ CGRect rect = CGRectMake(0, 0, 0, 0);
+ CGContextClipToRect(d->hd, rect);
+ } else {
+ CGMutablePathRef path = qt_mac_compose_path(p);
+ CGContextBeginPath(d->hd);
+ CGContextAddPath(d->hd, path);
+ if (p.fillRule() == Qt::WindingFill)
+ CGContextClip(d->hd);
+ else
+ CGContextEOClip(d->hd);
+ CGPathRelease(path);
+ }
+ } else if (op == Qt::IntersectClip) {
+ d->current.clip = d->current.clip.intersected(clipRegion);
+ d->setClip(&d->current.clip);
+ }
+ }
+}
+
+void
+QCoreGraphicsPaintEngine::updateClipRegion(const QRegion &clipRegion, Qt::ClipOperation op)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+ if (op == Qt::NoClip) {
+ d->current.clipEnabled = false;
+ d->current.clip = QRegion();
+ d->setClip(nullptr);
+ } else {
+ if (!d->current.clipEnabled)
+ op = Qt::ReplaceClip;
+ d->current.clipEnabled = true;
+ if (op == Qt::IntersectClip)
+ d->current.clip = d->current.clip.intersected(clipRegion);
+ else if (op == Qt::ReplaceClip)
+ d->current.clip = clipRegion;
+ d->setClip(&d->current.clip);
+ }
+}
+
+void
+QCoreGraphicsPaintEngine::drawPath(const QPainterPath &p)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ CGMutablePathRef path = qt_mac_compose_path(p);
+ uchar ops = QCoreGraphicsPaintEnginePrivate::CGStroke;
+ if (p.fillRule() == Qt::WindingFill)
+ ops |= QCoreGraphicsPaintEnginePrivate::CGFill;
+ else
+ ops |= QCoreGraphicsPaintEnginePrivate::CGEOFill;
+ CGContextBeginPath(d->hd);
+ d->drawPath(ops, path);
+ CGPathRelease(path);
+}
+
+void
+QCoreGraphicsPaintEngine::drawRects(const QRectF *rects, int rectCount)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ for (int i=0; i<rectCount; ++i) {
+ QRectF r = rects[i];
+
+ CGMutablePathRef path = CGPathCreateMutable();
+ CGPathAddRect(path, nullptr, qt_mac_compose_rect(r));
+ d->drawPath(QCoreGraphicsPaintEnginePrivate::CGFill|QCoreGraphicsPaintEnginePrivate::CGStroke,
+ path);
+ CGPathRelease(path);
+ }
+}
+
+void
+QCoreGraphicsPaintEngine::drawPoints(const QPointF *points, int pointCount)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ if (d->current.pen.capStyle() == Qt::FlatCap)
+ CGContextSetLineCap(d->hd, kCGLineCapSquare);
+
+ CGMutablePathRef path = CGPathCreateMutable();
+ for (int i=0; i < pointCount; i++) {
+ float x = points[i].x(), y = points[i].y();
+ CGPathMoveToPoint(path, nullptr, x, y);
+ CGPathAddLineToPoint(path, nullptr, x+0.001, y);
+ }
+
+ bool doRestore = false;
+ if (d->cosmeticPen == QCoreGraphicsPaintEnginePrivate::CosmeticNone && !(state->renderHints() & QPainter::Antialiasing)) {
+ //we don't want adjusted pens for point rendering
+ doRestore = true;
+ d->saveGraphicsState();
+ CGContextSetLineWidth(d->hd, d->current.pen.widthF());
+ }
+ d->drawPath(QCoreGraphicsPaintEnginePrivate::CGStroke, path);
+ if (doRestore)
+ d->restoreGraphicsState();
+ CGPathRelease(path);
+ if (d->current.pen.capStyle() == Qt::FlatCap)
+ CGContextSetLineCap(d->hd, kCGLineCapButt);
+}
+
+void
+QCoreGraphicsPaintEngine::drawEllipse(const QRectF &r)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ CGMutablePathRef path = CGPathCreateMutable();
+ CGAffineTransform transform = CGAffineTransformMakeScale(r.width() / r.height(), 1);
+ CGPathAddArc(path, &transform,(r.x() + (r.width() / 2)) / (r.width() / r.height()),
+ r.y() + (r.height() / 2), r.height() / 2, 0, (2 * M_PI), false);
+ d->drawPath(QCoreGraphicsPaintEnginePrivate::CGFill | QCoreGraphicsPaintEnginePrivate::CGStroke,
+ path);
+ CGPathRelease(path);
+}
+
+void
+QCoreGraphicsPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ CGMutablePathRef path = CGPathCreateMutable();
+ CGPathMoveToPoint(path, nullptr, points[0].x(), points[0].y());
+ for (int x = 1; x < pointCount; ++x)
+ CGPathAddLineToPoint(path, nullptr, points[x].x(), points[x].y());
+ if (mode != PolylineMode && points[0] != points[pointCount-1])
+ CGPathAddLineToPoint(path, nullptr, points[0].x(), points[0].y());
+ uint op = QCoreGraphicsPaintEnginePrivate::CGStroke;
+ if (mode != PolylineMode)
+ op |= mode == OddEvenMode ? QCoreGraphicsPaintEnginePrivate::CGEOFill
+ : QCoreGraphicsPaintEnginePrivate::CGFill;
+ d->drawPath(op, path);
+ CGPathRelease(path);
+}
+
+void
+QCoreGraphicsPaintEngine::drawLines(const QLineF *lines, int lineCount)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ CGMutablePathRef path = CGPathCreateMutable();
+ for (int i = 0; i < lineCount; i++) {
+ const QPointF start = lines[i].p1(), end = lines[i].p2();
+ CGPathMoveToPoint(path, nullptr, start.x(), start.y());
+ CGPathAddLineToPoint(path, nullptr, end.x(), end.y());
+ }
+ d->drawPath(QCoreGraphicsPaintEnginePrivate::CGStroke, path);
+ CGPathRelease(path);
+}
+
+void QCoreGraphicsPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ if (pm.isNull())
+ return;
+
+ bool differentSize = (QRectF(0, 0, pm.width(), pm.height()) != sr), doRestore = false;
+ CGRect rect = CGRectMake(r.x(), r.y(), r.width(), r.height());
+ QCFType<CGImageRef> image;
+ bool isBitmap = (pm.depth() == 1);
+ if (isBitmap) {
+ doRestore = true;
+ d->saveGraphicsState();
+
+ const QColor &col = d->current.pen.color();
+ CGContextSetFillColorWithColor(d->hd, cgColorForQColor(col));
+ image = qt_mac_create_imagemask(pm, sr);
+ } else if (differentSize) {
+ QCFType<CGImageRef> img = qt_mac_toCGImage(pm.toImage());
+ if (img)
+ image = CGImageCreateWithImageInRect(img, CGRectMake(qRound(sr.x()), qRound(sr.y()), qRound(sr.width()), qRound(sr.height())));
+ } else {
+ image = qt_mac_toCGImage(pm.toImage());
+ }
+ qt_mac_drawCGImage(d->hd, &rect, image);
+ if (doRestore)
+ d->restoreGraphicsState();
+}
+
+void QCoreGraphicsPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRectF &sr,
+ Qt::ImageConversionFlags flags)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_UNUSED(flags);
+ Q_ASSERT(isActive());
+
+ if (img.isNull() || state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ QCFType<CGImageRef> cgimage = qt_mac_toCGImage(img);
+ CGRect rect = CGRectMake(r.x(), r.y(), r.width(), r.height());
+ if (QRectF(0, 0, img.width(), img.height()) != sr)
+ cgimage = CGImageCreateWithImageInRect(cgimage, CGRectMake(sr.x(), sr.y(),
+ sr.width(), sr.height()));
+ qt_mac_drawCGImage(d->hd, &rect, cgimage);
+}
+
+void QCoreGraphicsPaintEngine::initialize()
+{
+}
+
+void QCoreGraphicsPaintEngine::cleanup()
+{
+}
+
+CGContextRef
+QCoreGraphicsPaintEngine::handle() const
+{
+ return d_func()->hd;
+}
+
+void
+QCoreGraphicsPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap,
+ const QPointF &p)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ Q_ASSERT(isActive());
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ //save the old state
+ d->saveGraphicsState();
+
+ //setup the pattern
+ QMacPattern *qpattern = new QMacPattern;
+ qpattern->data.pixmap = pixmap;
+ qpattern->foreground = d->current.pen.color();
+ qpattern->pdev = d->pdev;
+ CGPatternCallbacks callbks;
+ callbks.version = 0;
+ callbks.drawPattern = qt_mac_draw_pattern;
+ callbks.releaseInfo = qt_mac_dispose_pattern;
+ const int width = qpattern->width(), height = qpattern->height();
+ CGAffineTransform trans = CGContextGetCTM(d->hd);
+ CGPatternRef pat = CGPatternCreate(qpattern, CGRectMake(0, 0, width, height),
+ trans, width, height,
+ kCGPatternTilingNoDistortion, true, &callbks);
+ CGColorSpaceRef cs = CGColorSpaceCreatePattern(nullptr);
+ CGContextSetFillColorSpace(d->hd, cs);
+ CGFloat component = 1.0; //just one
+ CGContextSetFillPattern(d->hd, pat, &component);
+ CGSize phase = CGSizeApplyAffineTransform(CGSizeMake(-(p.x()-r.x()), -(p.y()-r.y())), trans);
+ CGContextSetPatternPhase(d->hd, phase);
+
+ //fill the rectangle
+ CGRect mac_rect = CGRectMake(r.x(), r.y(), r.width(), r.height());
+ CGContextFillRect(d->hd, mac_rect);
+
+ //restore the state
+ d->restoreGraphicsState();
+ //cleanup
+ CGColorSpaceRelease(cs);
+ CGPatternRelease(pat);
+}
+
+void QCoreGraphicsPaintEngine::drawTextItem(const QPointF &pos, const QTextItem &item)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ if (d->current.transform.type() == QTransform::TxProject
+#ifndef QMAC_NATIVE_GRADIENTS
+ || painter()->pen().brush().gradient() //Just let the base engine "emulate" the gradient
+#endif
+ ) {
+ QPaintEngine::drawTextItem(pos, item);
+ return;
+ }
+
+ if (state->compositionMode() == QPainter::CompositionMode_Destination)
+ return;
+
+ const QTextItemInt &ti = static_cast<const QTextItemInt &>(item);
+
+ QPen oldPen = painter()->pen();
+ QBrush oldBrush = painter()->brush();
+ QPointF oldBrushOrigin = painter()->brushOrigin();
+ updatePen(Qt::NoPen);
+ updateBrush(oldPen.brush(), QPointF(0, 0));
+
+ Q_ASSERT(type() == QPaintEngine::CoreGraphics);
+
+ QFontEngine *fe = ti.fontEngine;
+
+ const bool textAA = ((state->renderHints() & QPainter::TextAntialiasing)
+ && !(fe->fontDef.styleStrategy & QFont::NoAntialias));
+ const bool lineAA = state->renderHints() & QPainter::Antialiasing;
+ if (textAA != lineAA)
+ CGContextSetShouldAntialias(d->hd, textAA);
+
+ const bool smoothing = textAA && !(fe->fontDef.styleStrategy & QFont::NoSubpixelAntialias);
+ if (d->disabledSmoothFonts == smoothing)
+ CGContextSetShouldSmoothFonts(d->hd, smoothing);
+
+ if (ti.glyphs.numGlyphs) {
+ switch (fe->type()) {
+ case QFontEngine::Mac:
+ static_cast<QCoreTextFontEngine *>(fe)->draw(d->hd, pos.x(), pos.y(), ti, paintDevice()->height());
+ break;
+ case QFontEngine::Box:
+ d->drawBoxTextItem(pos, ti);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (textAA != lineAA)
+ CGContextSetShouldAntialias(d->hd, !textAA);
+
+ if (smoothing == d->disabledSmoothFonts)
+ CGContextSetShouldSmoothFonts(d->hd, !d->disabledSmoothFonts);
+
+ updatePen(oldPen);
+ updateBrush(oldBrush, oldBrushOrigin);
+}
+
+QPainter::RenderHints
+QCoreGraphicsPaintEngine::supportedRenderHints() const
+{
+ return QPainter::RenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
+}
+enum CGCompositeMode {
+ kCGCompositeModeClear = 0,
+ kCGCompositeModeCopy = 1,
+ kCGCompositeModeSourceOver = 2,
+ kCGCompositeModeSourceIn = 3,
+ kCGCompositeModeSourceOut = 4,
+ kCGCompositeModeSourceAtop = 5,
+ kCGCompositeModeDestinationOver = 6,
+ kCGCompositeModeDestinationIn = 7,
+ kCGCompositeModeDestinationOut = 8,
+ kCGCompositeModeDestinationAtop = 9,
+ kCGCompositeModeXOR = 10,
+ kCGCompositeModePlusDarker = 11, // (max (0, (1-d) + (1-s)))
+ kCGCompositeModePlusLighter = 12, // (min (1, s + d))
+ };
+extern "C" {
+ extern void CGContextSetCompositeOperation(CGContextRef, int);
+} // private function, but is in all versions of OS X.
+void
+QCoreGraphicsPaintEngine::updateCompositionMode(QPainter::CompositionMode mode)
+{
+ int cg_mode = kCGBlendModeNormal;
+ switch (mode) {
+ case QPainter::CompositionMode_Multiply:
+ cg_mode = kCGBlendModeMultiply;
+ break;
+ case QPainter::CompositionMode_Screen:
+ cg_mode = kCGBlendModeScreen;
+ break;
+ case QPainter::CompositionMode_Overlay:
+ cg_mode = kCGBlendModeOverlay;
+ break;
+ case QPainter::CompositionMode_Darken:
+ cg_mode = kCGBlendModeDarken;
+ break;
+ case QPainter::CompositionMode_Lighten:
+ cg_mode = kCGBlendModeLighten;
+ break;
+ case QPainter::CompositionMode_ColorDodge:
+ cg_mode = kCGBlendModeColorDodge;
+ break;
+ case QPainter::CompositionMode_ColorBurn:
+ cg_mode = kCGBlendModeColorBurn;
+ break;
+ case QPainter::CompositionMode_HardLight:
+ cg_mode = kCGBlendModeHardLight;
+ break;
+ case QPainter::CompositionMode_SoftLight:
+ cg_mode = kCGBlendModeSoftLight;
+ break;
+ case QPainter::CompositionMode_Difference:
+ cg_mode = kCGBlendModeDifference;
+ break;
+ case QPainter::CompositionMode_Exclusion:
+ cg_mode = kCGBlendModeExclusion;
+ break;
+ case QPainter::CompositionMode_Plus:
+ cg_mode = kCGBlendModePlusLighter;
+ break;
+ case QPainter::CompositionMode_SourceOver:
+ cg_mode = kCGBlendModeNormal;
+ break;
+ case QPainter::CompositionMode_DestinationOver:
+ cg_mode = kCGBlendModeDestinationOver;
+ break;
+ case QPainter::CompositionMode_Clear:
+ cg_mode = kCGBlendModeClear;
+ break;
+ case QPainter::CompositionMode_Source:
+ cg_mode = kCGBlendModeCopy;
+ break;
+ case QPainter::CompositionMode_Destination:
+ cg_mode = -1;
+ break;
+ case QPainter::CompositionMode_SourceIn:
+ cg_mode = kCGBlendModeSourceIn;
+ break;
+ case QPainter::CompositionMode_DestinationIn:
+ cg_mode = kCGCompositeModeDestinationIn;
+ break;
+ case QPainter::CompositionMode_SourceOut:
+ cg_mode = kCGBlendModeSourceOut;
+ break;
+ case QPainter::CompositionMode_DestinationOut:
+ cg_mode = kCGBlendModeDestinationOver;
+ break;
+ case QPainter::CompositionMode_SourceAtop:
+ cg_mode = kCGBlendModeSourceAtop;
+ break;
+ case QPainter::CompositionMode_DestinationAtop:
+ cg_mode = kCGBlendModeDestinationAtop;
+ break;
+ case QPainter::CompositionMode_Xor:
+ cg_mode = kCGBlendModeXOR;
+ break;
+ default:
+ break;
+ }
+ if (cg_mode > -1) {
+ CGContextSetBlendMode(d_func()->hd, CGBlendMode(cg_mode));
+ }
+}
+
+void
+QCoreGraphicsPaintEngine::updateRenderHints(QPainter::RenderHints hints)
+{
+ Q_D(QCoreGraphicsPaintEngine);
+ CGContextSetShouldAntialias(d->hd, hints & QPainter::Antialiasing);
+ CGContextSetInterpolationQuality(d->hd, (hints & QPainter::SmoothPixmapTransform) ?
+ kCGInterpolationHigh : kCGInterpolationNone);
+ bool textAntialiasing = (hints & QPainter::TextAntialiasing) == QPainter::TextAntialiasing;
+ if (!textAntialiasing || d->disabledSmoothFonts) {
+ d->disabledSmoothFonts = !textAntialiasing;
+ CGContextSetShouldSmoothFonts(d->hd, textAntialiasing);
+ }
+}
+
+/*
+ Returns the size of one device pixel in user-space coordinates.
+*/
+QPointF QCoreGraphicsPaintEnginePrivate::devicePixelSize(CGContextRef)
+{
+ QPointF p1 = current.transform.inverted().map(QPointF(0, 0));
+ QPointF p2 = current.transform.inverted().map(QPointF(1, 1));
+ return QPointF(qAbs(p2.x() - p1.x()), qAbs(p2.y() - p1.y()));
+}
+
+/*
+ Adjusts the pen width so we get correct line widths in the
+ non-transformed, aliased case.
+*/
+float QCoreGraphicsPaintEnginePrivate::adjustPenWidth(float penWidth)
+{
+ Q_Q(QCoreGraphicsPaintEngine);
+ float ret = penWidth;
+ if (!complexXForm && !(q->state->renderHints() & QPainter::Antialiasing)) {
+ if (penWidth < 2)
+ ret = 1;
+ else if (penWidth < 3)
+ ret = 1.5;
+ else
+ ret = penWidth -1;
+ }
+ return ret;
+}
+
+void
+QCoreGraphicsPaintEnginePrivate::setStrokePen(const QPen &pen)
+{
+ //pencap
+ CGLineCap cglinecap = kCGLineCapButt;
+ if (pen.capStyle() == Qt::SquareCap)
+ cglinecap = kCGLineCapSquare;
+ else if (pen.capStyle() == Qt::RoundCap)
+ cglinecap = kCGLineCapRound;
+ CGContextSetLineCap(hd, cglinecap);
+ CGContextSetLineWidth(hd, adjustPenWidth(pen.widthF()));
+
+ //join
+ CGLineJoin cglinejoin = kCGLineJoinMiter;
+ if (pen.joinStyle() == Qt::BevelJoin)
+ cglinejoin = kCGLineJoinBevel;
+ else if (pen.joinStyle() == Qt::RoundJoin)
+ cglinejoin = kCGLineJoinRound;
+ CGContextSetLineJoin(hd, cglinejoin);
+// CGContextSetMiterLimit(hd, pen.miterLimit());
+
+ //pen style
+ QVector<CGFloat> linedashes;
+ if (pen.style() == Qt::CustomDashLine) {
+ QVector<qreal> customs = pen.dashPattern();
+ for (int i = 0; i < customs.size(); ++i)
+ linedashes.append(customs.at(i));
+ } else if (pen.style() == Qt::DashLine) {
+ linedashes.append(4);
+ linedashes.append(2);
+ } else if (pen.style() == Qt::DotLine) {
+ linedashes.append(1);
+ linedashes.append(2);
+ } else if (pen.style() == Qt::DashDotLine) {
+ linedashes.append(4);
+ linedashes.append(2);
+ linedashes.append(1);
+ linedashes.append(2);
+ } else if (pen.style() == Qt::DashDotDotLine) {
+ linedashes.append(4);
+ linedashes.append(2);
+ linedashes.append(1);
+ linedashes.append(2);
+ linedashes.append(1);
+ linedashes.append(2);
+ }
+ const CGFloat cglinewidth = pen.widthF() <= 0.0f ? 1.0f : float(pen.widthF());
+ for (int i = 0; i < linedashes.size(); ++i) {
+ linedashes[i] *= cglinewidth;
+ if (cglinewidth < 3 && (cglinecap == kCGLineCapSquare || cglinecap == kCGLineCapRound)) {
+ if ((i%2))
+ linedashes[i] += cglinewidth/2;
+ else
+ linedashes[i] -= cglinewidth/2;
+ }
+ }
+ CGContextSetLineDash(hd, pen.dashOffset() * cglinewidth, linedashes.data(), linedashes.size());
+
+ // color
+ CGContextSetStrokeColorWithColor(hd, cgColorForQColor(pen.color()));
+}
+
+// Add our own patterns here to deal with the fact that the coordinate system
+// is flipped vertically with Quartz2D.
+static const uchar *qt_mac_patternForBrush(int brushStyle)
+{
+ Q_ASSERT(brushStyle > Qt::SolidPattern && brushStyle < Qt::LinearGradientPattern);
+ static const uchar dense1_pat[] = { 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00 };
+ static const uchar dense2_pat[] = { 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00, 0x88 };
+ static const uchar dense3_pat[] = { 0x11, 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa };
+ static const uchar dense4_pat[] = { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 };
+ static const uchar dense5_pat[] = { 0xee, 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55 };
+ static const uchar dense6_pat[] = { 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff, 0x77 };
+ static const uchar dense7_pat[] = { 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff };
+ static const uchar hor_pat[] = { 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff };
+ static const uchar ver_pat[] = { 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef, 0xef };
+ static const uchar cross_pat[] = { 0xef, 0xef, 0xef, 0xef, 0x00, 0xef, 0xef, 0xef };
+ static const uchar fdiag_pat[] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe };
+ static const uchar bdiag_pat[] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f };
+ static const uchar dcross_pat[] = { 0x7e, 0xbd, 0xdb, 0xe7, 0xe7, 0xdb, 0xbd, 0x7e };
+ static const uchar *const pat_tbl[] = {
+ dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat,
+ dense6_pat, dense7_pat,
+ hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat };
+ return pat_tbl[brushStyle - Qt::Dense1Pattern];
+}
+
+void QCoreGraphicsPaintEnginePrivate::setFillBrush(const QPointF &offset)
+{
+ // pattern
+ Qt::BrushStyle bs = current.brush.style();
+#ifdef QT_MAC_USE_NATIVE_GRADIENTS
+ if (bs == Qt::LinearGradientPattern || bs == Qt::RadialGradientPattern) {
+ const QGradient *grad = static_cast<const QGradient*>(current.brush.gradient());
+ if (drawGradientNatively(grad)) {
+ Q_ASSERT(grad->spread() == QGradient::PadSpread);
+
+ static const CGFloat domain[] = { 0.0f, +1.0f };
+ static const CGFunctionCallbacks callbacks = { 0, qt_mac_color_gradient_function, nullptr };
+ CGFunctionRef fill_func = CGFunctionCreate(reinterpret_cast<void *>(&current.brush),
+ 1, domain, 4, nullptr, &callbacks);
+
+ CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB)
+ if (bs == Qt::LinearGradientPattern) {
+ const QLinearGradient *linearGrad = static_cast<const QLinearGradient *>(grad);
+ const QPointF start(linearGrad->start());
+ const QPointF stop(linearGrad->finalStop());
+ shading = CGShadingCreateAxial(colorspace, CGPointMake(start.x(), start.y()),
+ CGPointMake(stop.x(), stop.y()), fill_func, true, true);
+ } else {
+ Q_ASSERT(bs == Qt::RadialGradientPattern);
+ const QRadialGradient *radialGrad = static_cast<const QRadialGradient *>(grad);
+ QPointF center(radialGrad->center());
+ QPointF focal(radialGrad->focalPoint());
+ qreal radius = radialGrad->radius();
+ qreal focalRadius = radialGrad->focalRadius();
+ shading = CGShadingCreateRadial(colorspace, CGPointMake(focal.x(), focal.y()),
+ focalRadius, CGPointMake(center.x(), center.y()), radius, fill_func, false, true);
+ }
+
+ CGFunctionRelease(fill_func);
+ }
+ } else
+#endif
+ if (bs != Qt::SolidPattern && bs != Qt::NoBrush
+#ifndef QT_MAC_USE_NATIVE_GRADIENTS
+ && (bs < Qt::LinearGradientPattern || bs > Qt::ConicalGradientPattern)
+#endif
+ )
+ {
+ QMacPattern *qpattern = new QMacPattern;
+ qpattern->pdev = pdev;
+ CGFloat components[4] = { 1.0, 1.0, 1.0, 1.0 };
+ CGColorSpaceRef base_colorspace = nullptr;
+ if (bs == Qt::TexturePattern) {
+ qpattern->data.pixmap = current.brush.texture();
+ if (qpattern->data.pixmap.isQBitmap()) {
+ const QColor &col = current.brush.color();
+ components[0] = qt_mac_convert_color_to_cg(col.red());
+ components[1] = qt_mac_convert_color_to_cg(col.green());
+ components[2] = qt_mac_convert_color_to_cg(col.blue());
+ base_colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+ }
+ } else {
+ qpattern->as_mask = true;
+
+ qpattern->data.bytes = qt_mac_patternForBrush(bs);
+ const QColor &col = current.brush.color();
+ components[0] = qt_mac_convert_color_to_cg(col.red());
+ components[1] = qt_mac_convert_color_to_cg(col.green());
+ components[2] = qt_mac_convert_color_to_cg(col.blue());
+ base_colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+ }
+ int width = qpattern->width(), height = qpattern->height();
+ qpattern->foreground = current.brush.color();
+
+ CGColorSpaceRef fill_colorspace = CGColorSpaceCreatePattern(base_colorspace);
+ CGContextSetFillColorSpace(hd, fill_colorspace);
+
+ CGAffineTransform xform = CGContextGetCTM(hd);
+ xform = CGAffineTransformConcat(qt_mac_convert_transform_to_cg(current.brush.transform()), xform);
+ xform = CGAffineTransformTranslate(xform, offset.x(), offset.y());
+
+ CGPatternCallbacks callbks;
+ callbks.version = 0;
+ callbks.drawPattern = qt_mac_draw_pattern;
+ callbks.releaseInfo = qt_mac_dispose_pattern;
+ CGPatternRef fill_pattern = CGPatternCreate(qpattern, CGRectMake(0, 0, width, height),
+ xform, width, height, kCGPatternTilingNoDistortion,
+ !base_colorspace, &callbks);
+ CGContextSetFillPattern(hd, fill_pattern, components);
+
+
+ CGPatternRelease(fill_pattern);
+ CGColorSpaceRelease(base_colorspace);
+ CGColorSpaceRelease(fill_colorspace);
+ } else if (bs != Qt::NoBrush) {
+ CGContextSetFillColorWithColor(hd, cgColorForQColor(current.brush.color()));
+ }
+}
+
+void
+QCoreGraphicsPaintEnginePrivate::setClip(const QRegion *rgn)
+{
+ Q_Q(QCoreGraphicsPaintEngine);
+ if (hd) {
+ resetClip();
+ QRegion sysClip = q->systemClip();
+ if (!sysClip.isEmpty())
+ qt_mac_clip_cg(hd, sysClip, &orig_xform);
+ if (rgn)
+ qt_mac_clip_cg(hd, *rgn, nullptr);
+ }
+}
+
+struct qt_mac_cg_transform_path {
+ CGMutablePathRef path;
+ CGAffineTransform transform;
+};
+
+void qt_mac_cg_transform_path_apply(void *info, const CGPathElement *element)
+{
+ Q_ASSERT(info && element);
+ qt_mac_cg_transform_path *t = (qt_mac_cg_transform_path*)info;
+ switch (element->type) {
+ case kCGPathElementMoveToPoint:
+ CGPathMoveToPoint(t->path, &t->transform, element->points[0].x, element->points[0].y);
+ break;
+ case kCGPathElementAddLineToPoint:
+ CGPathAddLineToPoint(t->path, &t->transform, element->points[0].x, element->points[0].y);
+ break;
+ case kCGPathElementAddQuadCurveToPoint:
+ CGPathAddQuadCurveToPoint(t->path, &t->transform, element->points[0].x, element->points[0].y,
+ element->points[1].x, element->points[1].y);
+ break;
+ case kCGPathElementAddCurveToPoint:
+ CGPathAddCurveToPoint(t->path, &t->transform, element->points[0].x, element->points[0].y,
+ element->points[1].x, element->points[1].y,
+ element->points[2].x, element->points[2].y);
+ break;
+ case kCGPathElementCloseSubpath:
+ CGPathCloseSubpath(t->path);
+ break;
+ default:
+ qDebug() << "Unhandled path transform type: " << element->type;
+ }
+}
+
+void QCoreGraphicsPaintEnginePrivate::drawPath(uchar ops, CGMutablePathRef path)
+{
+ Q_Q(QCoreGraphicsPaintEngine);
+ Q_ASSERT((ops & (CGFill | CGEOFill)) != (CGFill | CGEOFill)); //can't really happen
+ if ((ops & (CGFill | CGEOFill))) {
+ if (shading) {
+ Q_ASSERT(path);
+ CGContextBeginPath(hd);
+ CGContextAddPath(hd, path);
+ saveGraphicsState();
+ if (ops & CGFill)
+ CGContextClip(hd);
+ else if (ops & CGEOFill)
+ CGContextEOClip(hd);
+ if (current.brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode) {
+ CGRect boundingBox = CGPathGetBoundingBox(path);
+ CGContextConcatCTM(hd,
+ CGAffineTransformMake(boundingBox.size.width, 0,
+ 0, boundingBox.size.height,
+ boundingBox.origin.x, boundingBox.origin.y));
+ }
+ CGContextDrawShading(hd, shading);
+ restoreGraphicsState();
+ ops &= ~CGFill;
+ ops &= ~CGEOFill;
+ } else if (current.brush.style() == Qt::NoBrush) {
+ ops &= ~CGFill;
+ ops &= ~CGEOFill;
+ }
+ }
+ if ((ops & CGStroke) && current.pen.style() == Qt::NoPen)
+ ops &= ~CGStroke;
+
+ if (ops & (CGEOFill | CGFill)) {
+ CGContextBeginPath(hd);
+ CGContextAddPath(hd, path);
+ if (ops & CGEOFill) {
+ CGContextEOFillPath(hd);
+ } else {
+ CGContextFillPath(hd);
+ }
+ }
+
+ // Avoid saving and restoring the context if we can.
+ const bool needContextSave = (cosmeticPen != QCoreGraphicsPaintEnginePrivate::CosmeticNone ||
+ !(q->state->renderHints() & QPainter::Antialiasing));
+ if (ops & CGStroke) {
+ if (needContextSave)
+ saveGraphicsState();
+ CGContextBeginPath(hd);
+
+ // Translate a fraction of a pixel size in the y direction
+ // to make sure that primitives painted at pixel borders
+ // fills the right pixel. This is needed since the y xais
+ // in the Quartz coordinate system is inverted compared to Qt.
+ if (!(q->state->renderHints() & QPainter::Antialiasing)) {
+ if (current.pen.style() == Qt::SolidLine || current.pen.width() >= 3)
+ CGContextTranslateCTM(hd, double(pixelSize.x()) * 0.25, double(pixelSize.y()) * 0.25);
+ else
+ CGContextTranslateCTM(hd, 0, double(pixelSize.y()) * 0.1);
+ }
+
+ if (cosmeticPen != QCoreGraphicsPaintEnginePrivate::CosmeticNone) {
+ // If antialiazing is enabled, use the cosmetic pen size directly.
+ if (q->state->renderHints() & QPainter::Antialiasing)
+ CGContextSetLineWidth(hd, cosmeticPenSize);
+ else if (current.pen.widthF() <= 1)
+ CGContextSetLineWidth(hd, cosmeticPenSize * 0.9f);
+ else
+ CGContextSetLineWidth(hd, cosmeticPenSize);
+ }
+ if (cosmeticPen == QCoreGraphicsPaintEnginePrivate::CosmeticTransformPath) {
+ qt_mac_cg_transform_path t;
+ t.transform = qt_mac_convert_transform_to_cg(current.transform);
+ t.path = CGPathCreateMutable();
+ CGPathApply(path, &t, qt_mac_cg_transform_path_apply); //transform the path
+ setTransform(nullptr); //unset the context transform
+ CGContextSetLineWidth(hd, cosmeticPenSize);
+ CGContextAddPath(hd, t.path);
+ CGPathRelease(t.path);
+ } else {
+ CGContextAddPath(hd, path);
+ }
+
+ CGContextStrokePath(hd);
+ if (needContextSave)
+ restoreGraphicsState();
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/platform/macos/qpaintengine_mac_p.h b/src/printsupport/platform/macos/qpaintengine_mac_p.h
new file mode 100644
index 0000000000..a619a3a04a
--- /dev/null
+++ b/src/printsupport/platform/macos/qpaintengine_mac_p.h
@@ -0,0 +1,170 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPAINTENGINE_MAC_P_H
+#define QPAINTENGINE_MAC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtPrintSupport/qtprintsupportglobal.h>
+
+#include <QtGui/qpaintengine.h>
+#include <QtGui/private/qpaintengine_p.h>
+#include <QtGui/private/qfont_p.h>
+#include <QtCore/qhash.h>
+
+typedef struct CGColorSpace *CGColorSpaceRef;
+typedef struct CGContext *CGContextRef;
+
+QT_BEGIN_NAMESPACE
+
+class QCoreGraphicsPaintEnginePrivate;
+class QCoreGraphicsPaintEngine : public QPaintEngine
+{
+ Q_DECLARE_PRIVATE(QCoreGraphicsPaintEngine)
+
+public:
+ QCoreGraphicsPaintEngine();
+ ~QCoreGraphicsPaintEngine();
+
+ bool begin(QPaintDevice *pdev);
+ bool end();
+
+ void updateState(const QPaintEngineState &state);
+
+ void updatePen(const QPen &pen);
+ void updateBrush(const QBrush &brush, const QPointF &pt);
+ void updateFont(const QFont &font);
+ void updateOpacity(qreal opacity);
+ void updateMatrix(const QTransform &matrix);
+ void updateTransform(const QTransform &matrix);
+ void updateClipRegion(const QRegion &region, Qt::ClipOperation op);
+ void updateClipPath(const QPainterPath &path, Qt::ClipOperation op);
+ void updateCompositionMode(QPainter::CompositionMode mode);
+ void updateRenderHints(QPainter::RenderHints hints);
+
+ void drawLines(const QLineF *lines, int lineCount);
+ void drawRects(const QRectF *rects, int rectCount);
+ void drawPoints(const QPointF *p, int pointCount);
+ void drawEllipse(const QRectF &r);
+ void drawPath(const QPainterPath &path);
+
+ void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
+ void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
+ void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
+
+ void drawTextItem(const QPointF &pos, const QTextItem &item);
+ void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
+ Qt::ImageConversionFlags flags = Qt::AutoColor);
+
+ Type type() const { return QPaintEngine::CoreGraphics; }
+
+ CGContextRef handle() const;
+
+ static void initialize();
+ static void cleanup();
+
+ QPainter::RenderHints supportedRenderHints() const;
+
+ //avoid partial shadowed overload warnings...
+ void drawLines(const QLine *lines, int lineCount) { QPaintEngine::drawLines(lines, lineCount); }
+ void drawRects(const QRect *rects, int rectCount) { QPaintEngine::drawRects(rects, rectCount); }
+ void drawPoints(const QPoint *p, int pointCount) { QPaintEngine::drawPoints(p, pointCount); }
+ void drawEllipse(const QRect &r) { QPaintEngine::drawEllipse(r); }
+ void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
+ { QPaintEngine::drawPolygon(points, pointCount, mode); }
+
+protected:
+ friend class QMacPrintEngine;
+ friend class QMacPrintEnginePrivate;
+ QCoreGraphicsPaintEngine(QPaintEnginePrivate &dptr);
+
+private:
+ Q_DISABLE_COPY(QCoreGraphicsPaintEngine)
+};
+
+/*****************************************************************************
+ Private data
+ *****************************************************************************/
+class QCoreGraphicsPaintEnginePrivate : public QPaintEnginePrivate
+{
+ Q_DECLARE_PUBLIC(QCoreGraphicsPaintEngine)
+public:
+ QCoreGraphicsPaintEnginePrivate()
+ : hd(nullptr), shading(nullptr), stackCount(0), complexXForm(false), disabledSmoothFonts(false)
+ {
+ }
+
+ struct {
+ QPen pen;
+ QBrush brush;
+ uint clipEnabled : 1;
+ QRegion clip;
+ QTransform transform;
+ } current;
+
+ //state info (shared with QD)
+ CGAffineTransform orig_xform;
+
+ //cg structures
+ CGContextRef hd;
+ CGShadingRef shading;
+ int stackCount;
+ bool complexXForm;
+ bool disabledSmoothFonts;
+ enum { CosmeticNone, CosmeticTransformPath, CosmeticSetPenWidth } cosmeticPen;
+
+ // pixel and cosmetic pen size in user coordinates.
+ QPointF pixelSize;
+ float cosmeticPenSize;
+
+ //internal functions
+ enum { CGStroke=0x01, CGEOFill=0x02, CGFill=0x04 };
+ void drawPath(uchar ops, CGMutablePathRef path = nullptr);
+ void setClip(const QRegion *rgn = nullptr);
+ void resetClip();
+ void setFillBrush(const QPointF &origin=QPoint());
+ void setStrokePen(const QPen &pen);
+ inline void saveGraphicsState();
+ inline void restoreGraphicsState();
+ float penOffset();
+ QPointF devicePixelSize(CGContextRef context);
+ float adjustPenWidth(float penWidth);
+ inline void setTransform(const QTransform *matrix = nullptr)
+ {
+ CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
+ CGAffineTransform xform = orig_xform;
+ if (matrix) {
+ extern CGAffineTransform qt_mac_convert_transform_to_cg(const QTransform &);
+ xform = CGAffineTransformConcat(qt_mac_convert_transform_to_cg(*matrix), xform);
+ }
+ CGContextConcatCTM(hd, xform);
+ CGContextSetTextMatrix(hd, xform);
+ }
+};
+
+inline void QCoreGraphicsPaintEnginePrivate::saveGraphicsState()
+{
+ ++stackCount;
+ CGContextSaveGState(hd);
+}
+
+inline void QCoreGraphicsPaintEnginePrivate::restoreGraphicsState()
+{
+ --stackCount;
+ Q_ASSERT(stackCount >= 0);
+ CGContextRestoreGState(hd);
+}
+
+QT_END_NAMESPACE
+
+#endif // QPAINTENGINE_MAC_P_H
diff --git a/src/printsupport/platform/macos/qprintengine_mac.mm b/src/printsupport/platform/macos/qprintengine_mac.mm
new file mode 100644
index 0000000000..d6eb71f66d
--- /dev/null
+++ b/src/printsupport/platform/macos/qprintengine_mac.mm
@@ -0,0 +1,770 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include <AppKit/AppKit.h>
+#include <ApplicationServices/ApplicationServices.h>
+
+#include "qprintengine_mac_p.h"
+#include "qcocoaprintersupport_p.h"
+#include <quuid.h>
+#include <QtGui/qpagelayout.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdebug.h>
+
+#include <QtCore/private/qcore_mac_p.h>
+
+#ifndef QT_NO_PRINTER
+
+QT_BEGIN_NAMESPACE
+
+extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
+
+QMacPrintEngine::QMacPrintEngine(QPrinter::PrinterMode mode, const QString &deviceId)
+ : QPaintEngine(*(new QMacPrintEnginePrivate))
+{
+ Q_D(QMacPrintEngine);
+ d->mode = mode;
+ QString id = deviceId;
+ if (id.isEmpty())
+ id = QCocoaPrinterSupport().defaultPrintDeviceId();
+ else
+ setProperty(QPrintEngine::PPK_PrinterName, deviceId);
+ d->m_printDevice.reset(new QCocoaPrintDevice(id));
+ d->m_pageLayout.setPageSize(d->m_printDevice->defaultPageSize());
+ d->initialize();
+}
+
+bool QMacPrintEngine::begin(QPaintDevice *dev)
+{
+ Q_D(QMacPrintEngine);
+
+ Q_ASSERT(dev && dev->devType() == QInternal::Printer);
+ if (!static_cast<QPrinter *>(dev)->isValid())
+ return false;
+
+ if (d->state == QPrinter::Idle && !d->isPrintSessionInitialized()) // Need to reinitialize
+ d->initialize();
+
+ d->paintEngine->state = state;
+ d->paintEngine->begin(dev);
+ Q_ASSERT_X(d->state == QPrinter::Idle, "QMacPrintEngine", "printer already active");
+
+ if (PMSessionValidatePrintSettings(d->session(), d->settings(), kPMDontWantBoolean) != noErr
+ || PMSessionValidatePageFormat(d->session(), d->format(), kPMDontWantBoolean) != noErr) {
+ d->state = QPrinter::Error;
+ return false;
+ }
+
+ if (!d->outputFilename.isEmpty()) {
+ QCFType<CFURLRef> outFile = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault,
+ QCFString(d->outputFilename),
+ kCFURLPOSIXPathStyle,
+ false);
+ if (PMSessionSetDestination(d->session(), d->settings(), kPMDestinationFile,
+ kPMDocumentFormatPDF, outFile) != noErr) {
+ qWarning("QMacPrintEngine::begin: Problem setting file [%s]", d->outputFilename.toUtf8().constData());
+ return false;
+ }
+ }
+
+ OSStatus status = PMSessionBeginCGDocumentNoDialog(d->session(), d->settings(), d->format());
+ if (status != noErr) {
+ d->state = QPrinter::Error;
+ return false;
+ }
+
+ d->state = QPrinter::Active;
+ setActive(true);
+ d->newPage_helper();
+ return true;
+}
+
+bool QMacPrintEngine::end()
+{
+ Q_D(QMacPrintEngine);
+ if (d->state == QPrinter::Aborted)
+ return true; // I was just here a function call ago :)
+ if (d->paintEngine->type() == QPaintEngine::CoreGraphics) {
+ // We don't need the paint engine to call restoreGraphicsState()
+ static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->stackCount = 0;
+ static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->hd = nullptr;
+ }
+ d->paintEngine->end();
+ if (d->state != QPrinter::Idle)
+ d->releaseSession();
+ d->state = QPrinter::Idle;
+ return true;
+}
+
+QPaintEngine *
+QMacPrintEngine::paintEngine() const
+{
+ return d_func()->paintEngine;
+}
+
+Qt::HANDLE QMacPrintEngine::handle() const
+{
+ QCoreGraphicsPaintEngine *cgEngine = static_cast<QCoreGraphicsPaintEngine*>(paintEngine());
+ return cgEngine->d_func()->hd;
+}
+
+QMacPrintEnginePrivate::~QMacPrintEnginePrivate()
+{
+ [printInfo release];
+ delete paintEngine;
+}
+
+QPrinter::PrinterState QMacPrintEngine::printerState() const
+{
+ return d_func()->state;
+}
+
+bool QMacPrintEngine::newPage()
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ OSStatus err = PMSessionEndPageNoDialog(d->session());
+ if (err != noErr) {
+ if (err == kPMCancel) {
+ // User canceled, we need to abort!
+ abort();
+ } else {
+ // Not sure what the problem is...
+ qWarning("QMacPrintEngine::newPage: Cannot end current page. %ld", long(err));
+ d->state = QPrinter::Error;
+ }
+ return false;
+ }
+ return d->newPage_helper();
+}
+
+bool QMacPrintEngine::abort()
+{
+ Q_D(QMacPrintEngine);
+ if (d->state != QPrinter::Active)
+ return false;
+ bool ret = end();
+ d->state = QPrinter::Aborted;
+ return ret;
+}
+
+int QMacPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
+{
+ Q_D(const QMacPrintEngine);
+ int val = 1;
+ switch (m) {
+ case QPaintDevice::PdmWidth:
+ val = d->m_pageLayout.paintRectPixels(d->resolution.hRes).width();
+ break;
+ case QPaintDevice::PdmHeight:
+ val = d->m_pageLayout.paintRectPixels(d->resolution.hRes).height();
+ break;
+ case QPaintDevice::PdmWidthMM:
+ val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).width());
+ break;
+ case QPaintDevice::PdmHeightMM:
+ val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).height());
+ break;
+ case QPaintDevice::PdmPhysicalDpiX:
+ case QPaintDevice::PdmPhysicalDpiY: {
+ PMPrinter printer;
+ if (PMSessionGetCurrentPrinter(d->session(), &printer) == noErr) {
+ PMResolution resolution;
+ PMPrinterGetOutputResolution(printer, d->settings(), &resolution);
+ val = (int)resolution.vRes;
+ break;
+ }
+ Q_FALLTHROUGH();
+ }
+ case QPaintDevice::PdmDpiY:
+ val = (int)d->resolution.vRes;
+ break;
+ case QPaintDevice::PdmDpiX:
+ val = (int)d->resolution.hRes;
+ break;
+ case QPaintDevice::PdmNumColors:
+ val = (1 << metric(QPaintDevice::PdmDepth));
+ break;
+ case QPaintDevice::PdmDepth:
+ val = 24;
+ break;
+ case QPaintDevice::PdmDevicePixelRatio:
+ val = 1;
+ break;
+ case QPaintDevice::PdmDevicePixelRatioScaled:
+ val = 1 * QPaintDevice::devicePixelRatioFScale();
+ break;
+ default:
+ val = 0;
+ qWarning("QPrinter::metric: Invalid metric command");
+ }
+ return val;
+}
+
+void QMacPrintEnginePrivate::initialize()
+{
+ Q_Q(QMacPrintEngine);
+
+ Q_ASSERT(!printInfo);
+
+ if (!paintEngine)
+ paintEngine = new QCoreGraphicsPaintEngine();
+
+ q->gccaps = paintEngine->gccaps;
+
+ QMacAutoReleasePool pool;
+ printInfo = [[NSPrintInfo alloc] initWithDictionary:[NSDictionary dictionary]];
+
+ QList<int> resolutions = m_printDevice->supportedResolutions();
+ if (!resolutions.isEmpty() && mode != QPrinter::ScreenResolution) {
+ std::sort(resolutions.begin(), resolutions.end());
+ if (resolutions.count() > 1 && mode == QPrinter::HighResolution)
+ resolution.hRes = resolution.vRes = resolutions.constLast();
+ else
+ resolution.hRes = resolution.vRes = resolutions.constFirst();
+ if (resolution.hRes == 0)
+ resolution.hRes = resolution.vRes = 600;
+ } else {
+ resolution.hRes = resolution.vRes = qt_defaultDpi();
+ }
+
+ setPageSize(m_pageLayout.pageSize());
+
+ QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant>::const_iterator propC;
+ for (propC = valueCache.constBegin(); propC != valueCache.constEnd(); ++propC) {
+ q->setProperty(propC.key(), propC.value());
+ }
+}
+
+void QMacPrintEnginePrivate::releaseSession()
+{
+ PMSessionEndPageNoDialog(session());
+ PMSessionEndDocumentNoDialog(session());
+ [printInfo release];
+ printInfo = nil;
+}
+
+bool QMacPrintEnginePrivate::newPage_helper()
+{
+ Q_Q(QMacPrintEngine);
+ Q_ASSERT(state == QPrinter::Active);
+
+ if (PMSessionError(session()) != noErr) {
+ q->abort();
+ return false;
+ }
+
+ // pop the stack of saved graphic states, in case we get the same
+ // context back - either way, the stack count should be 0 when we
+ // get the new one
+ QCoreGraphicsPaintEngine *cgEngine = static_cast<QCoreGraphicsPaintEngine*>(paintEngine);
+ while (cgEngine->d_func()->stackCount > 0)
+ cgEngine->d_func()->restoreGraphicsState();
+
+ OSStatus status = PMSessionBeginPageNoDialog(session(), format(), nullptr);
+ if (status != noErr) {
+ state = QPrinter::Error;
+ return false;
+ }
+
+ QRect page = m_pageLayout.paintRectPixels(resolution.hRes);
+ QRect paper = m_pageLayout.fullRectPixels(resolution.hRes);
+
+ CGContextRef cgContext;
+ OSStatus err = noErr;
+ err = PMSessionGetCGGraphicsContext(session(), &cgContext);
+ if (err != noErr) {
+ qWarning("QMacPrintEngine::newPage: Cannot retrieve CoreGraphics context: %ld", long(err));
+ state = QPrinter::Error;
+ return false;
+ }
+ cgEngine->d_func()->hd = cgContext;
+
+ // Set the resolution as a scaling ration of 72 (the default).
+ CGContextScaleCTM(cgContext, 72 / resolution.hRes, 72 / resolution.vRes);
+
+ CGContextScaleCTM(cgContext, 1, -1);
+ CGContextTranslateCTM(cgContext, 0, -paper.height());
+ if (m_pageLayout.mode() != QPageLayout::FullPageMode)
+ CGContextTranslateCTM(cgContext, page.x() - paper.x(), page.y() - paper.y());
+ cgEngine->d_func()->orig_xform = CGContextGetCTM(cgContext);
+ cgEngine->d_func()->setClip(nullptr);
+ cgEngine->state->dirtyFlags = QPaintEngine::DirtyFlags(QPaintEngine::AllDirty)
+ & ~(QPaintEngine::DirtyClipEnabled
+ | QPaintEngine::DirtyClipRegion
+ | QPaintEngine::DirtyClipPath);
+ if (cgEngine->painter()->hasClipping())
+ cgEngine->state->dirtyFlags |= QPaintEngine::DirtyClipEnabled;
+ cgEngine->syncState();
+ return true;
+}
+
+void QMacPrintEnginePrivate::setPageSize(const QPageSize &pageSize)
+{
+ if (!pageSize.isValid())
+ return;
+
+ // Get the matching printer paper
+ QPageSize printerPageSize = m_printDevice->supportedPageSize(pageSize);
+ QPageSize usePageSize = printerPageSize.isValid() ? printerPageSize : pageSize;
+
+ // Get the PMPaper and check it is valid
+ PMPaper macPaper = m_printDevice->macPaper(usePageSize);
+ if (!macPaper) {
+ qWarning() << "QMacPrintEngine: Invalid PMPaper returned for " << pageSize;
+ return;
+ }
+
+ QMarginsF printable = m_printDevice->printableMargins(usePageSize, m_pageLayout.orientation(), resolution.hRes);
+ m_pageLayout.setPageSize(usePageSize, qt_convertMargins(printable, QPageLayout::Point, m_pageLayout.units()));
+
+ // You cannot set the page size on a PMPageFormat, you must create a new PMPageFormat
+ PMPageFormat pageFormat;
+ PMCreatePageFormatWithPMPaper(&pageFormat, macPaper);
+ PMSetOrientation(pageFormat, m_pageLayout.orientation() == QPageLayout::Landscape ? kPMLandscape : kPMPortrait, kPMUnlocked);
+ PMCopyPageFormat(pageFormat, format());
+ if (PMSessionValidatePageFormat(session(), format(), kPMDontWantBoolean) != noErr)
+ qWarning("QMacPrintEngine: Invalid page format");
+ PMRelease(pageFormat);
+}
+
+void QMacPrintEngine::updateState(const QPaintEngineState &state)
+{
+ d_func()->paintEngine->updateState(state);
+}
+
+void QMacPrintEngine::drawRects(const QRectF *r, int num)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawRects(r, num);
+}
+
+void QMacPrintEngine::drawPoints(const QPointF *points, int pointCount)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawPoints(points, pointCount);
+}
+
+void QMacPrintEngine::drawEllipse(const QRectF &r)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawEllipse(r);
+}
+
+void QMacPrintEngine::drawLines(const QLineF *lines, int lineCount)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawLines(lines, lineCount);
+}
+
+void QMacPrintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawPolygon(points, pointCount, mode);
+}
+
+void QMacPrintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawPixmap(r, pm, sr);
+}
+
+void QMacPrintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawImage(r, pm, sr, flags);
+}
+
+void QMacPrintEngine::drawTextItem(const QPointF &p, const QTextItem &ti)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ if (!d->embedFonts)
+ QPaintEngine::drawTextItem(p, ti);
+ else
+ d->paintEngine->drawTextItem(p, ti);
+}
+
+void QMacPrintEngine::drawTiledPixmap(const QRectF &dr, const QPixmap &pixmap, const QPointF &sr)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawTiledPixmap(dr, pixmap, sr);
+}
+
+void QMacPrintEngine::drawPath(const QPainterPath &path)
+{
+ Q_D(QMacPrintEngine);
+ Q_ASSERT(d->state == QPrinter::Active);
+ d->paintEngine->drawPath(path);
+}
+
+
+void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
+{
+ Q_D(QMacPrintEngine);
+
+ d->valueCache.insert(key, value);
+ if (!d->printInfo)
+ return;
+
+ switch (key) {
+
+ // The following keys are properties or derived values and so cannot be set
+ case PPK_PageRect:
+ break;
+ case PPK_PaperRect:
+ break;
+ case PPK_PaperSources:
+ break;
+ case PPK_SupportsMultipleCopies:
+ break;
+ case PPK_SupportedResolutions:
+ break;
+
+ // The following keys are settings that are unsupported by the Mac PrintEngine
+ case PPK_ColorMode:
+ break;
+ case PPK_CustomBase:
+ break;
+ case PPK_PageOrder:
+ // TODO Check if can be supported via Cups Options
+ break;
+ case PPK_PaperSource:
+ // TODO Check if can be supported via Cups Options
+ break;
+ case PPK_PrinterProgram:
+ break;
+ case PPK_SelectionOption:
+ break;
+
+ // The following keys are properties and settings that are supported by the Mac PrintEngine
+ case PPK_FontEmbedding:
+ d->embedFonts = value.toBool();
+ break;
+ case PPK_Resolution: {
+ int bestResolution = 0;
+ int dpi = value.toInt();
+ int bestDistance = INT_MAX;
+ for (int resolution : d->m_printDevice->supportedResolutions()) {
+ if (dpi == resolution) {
+ bestResolution = resolution;
+ break;
+ } else {
+ int distance = qAbs(dpi - resolution);
+ if (distance < bestDistance) {
+ bestDistance = distance;
+ bestResolution = resolution;
+ }
+ }
+ }
+ PMResolution resolution;
+ resolution.hRes = resolution.vRes = bestResolution;
+ if (PMPrinterSetOutputResolution(d->m_printDevice->macPrinter(), d->settings(), &resolution) == noErr) {
+ // Setting the resolution succeeded.
+ // Now try to read the actual resolution selected by the OS.
+ if (PMPrinterGetOutputResolution(d->m_printDevice->macPrinter(), d->settings(), &d->resolution) != noErr) {
+ // Reading the resolution somehow failed; d->resolution is in undefined state.
+ // So use the value which was acceptable to PMPrinterSetOutputResolution.
+ d->resolution = resolution;
+ }
+ }
+ break;
+ }
+ case PPK_CollateCopies:
+ PMSetCollate(d->settings(), value.toBool());
+ break;
+ case PPK_Creator:
+ d->m_creator = value.toString();
+ break;
+ case PPK_DocumentName:
+ PMPrintSettingsSetJobName(d->settings(), QCFString(value.toString()));
+ break;
+ case PPK_Duplex: {
+ QPrint::DuplexMode mode = QPrint::DuplexMode(value.toInt());
+ if (mode == property(PPK_Duplex).toInt() || !d->m_printDevice->supportedDuplexModes().contains(mode))
+ break;
+ switch (mode) {
+ case QPrint::DuplexNone:
+ PMSetDuplex(d->settings(), kPMDuplexNone);
+ break;
+ case QPrint::DuplexAuto:
+ PMSetDuplex(d->settings(), d->m_pageLayout.orientation() == QPageLayout::Landscape ? kPMDuplexTumble : kPMDuplexNoTumble);
+ break;
+ case QPrint::DuplexLongSide:
+ PMSetDuplex(d->settings(), kPMDuplexNoTumble);
+ break;
+ case QPrint::DuplexShortSide:
+ PMSetDuplex(d->settings(), kPMDuplexTumble);
+ break;
+ default:
+ // Don't change
+ break;
+ }
+ break;
+ }
+ case PPK_FullPage:
+ if (value.toBool())
+ d->m_pageLayout.setMode(QPageLayout::FullPageMode);
+ else
+ d->m_pageLayout.setMode(QPageLayout::StandardMode);
+ break;
+ case PPK_CopyCount: // fallthrough
+ case PPK_NumberOfCopies:
+ PMSetCopies(d->settings(), value.toInt(), false);
+ break;
+ case PPK_Orientation: {
+ // First try set the Mac format orientation, then set our orientation to match result
+ QPageLayout::Orientation newOrientation = QPageLayout::Orientation(value.toInt());
+ PMOrientation macOrientation = (newOrientation == QPageLayout::Landscape) ? kPMLandscape : kPMPortrait;
+ PMSetOrientation(d->format(), macOrientation, kPMUnlocked);
+ PMSessionValidatePageFormat(d->session(), d->format(), kPMDontWantBoolean);
+ PMGetOrientation(d->format(), &macOrientation);
+ d->m_pageLayout.setOrientation(macOrientation == kPMLandscape ? QPageLayout::Landscape : QPageLayout::Portrait);
+ break;
+ }
+ case PPK_OutputFileName:
+ d->outputFilename = value.toString();
+ break;
+ case PPK_PageSize:
+ d->setPageSize(QPageSize(QPageSize::PageSizeId(value.toInt())));
+ break;
+ case PPK_PaperName:
+ // Get the named page size from the printer if supported
+ d->setPageSize(d->m_printDevice->supportedPageSize(value.toString()));
+ break;
+ case PPK_WindowsPageSize:
+ d->setPageSize(QPageSize(QPageSize::id(value.toInt())));
+ break;
+ case PPK_PrinterName: {
+ QVariant pageSize = QVariant::fromValue(d->m_pageLayout.pageSize());
+ const bool isFullPage = d->m_pageLayout.mode() == QPageLayout::FullPageMode;
+ QVariant orientation = QVariant::fromValue(d->m_pageLayout.orientation());
+ QVariant margins = QVariant::fromValue(QPair<QMarginsF, QPageLayout::Unit>(d->m_pageLayout.margins(),
+ d->m_pageLayout.units()));
+ QString id = value.toString();
+ if (id.isEmpty())
+ id = QCocoaPrinterSupport().defaultPrintDeviceId();
+ else if (!QCocoaPrinterSupport().availablePrintDeviceIds().contains(id))
+ break;
+ d->m_printDevice.reset(new QCocoaPrintDevice(id));
+ PMPrinter printer = d->m_printDevice->macPrinter();
+ PMRetain(printer);
+ PMSessionSetCurrentPMPrinter(d->session(), printer);
+ // Ensure the settings are up to date and valid
+ if (d->m_printDevice->supportedPageSize(pageSize.value<QPageSize>()).isValid())
+ setProperty(PPK_QPageSize, pageSize);
+ else
+ setProperty(PPK_CustomPaperSize, pageSize.value<QPageSize>().size(QPageSize::Point));
+ setProperty(PPK_FullPage, QVariant(isFullPage));
+ setProperty(PPK_Orientation, orientation);
+ setProperty(PPK_QPageMargins, margins);
+ break;
+ }
+ case PPK_CustomPaperSize:
+ d->setPageSize(QPageSize(value.toSizeF(), QPageSize::Point));
+ break;
+ case PPK_PageMargins:
+ {
+ QList<QVariant> margins(value.toList());
+ Q_ASSERT(margins.size() == 4);
+ d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
+ margins.at(2).toReal(), margins.at(3).toReal()),
+ QPageLayout::OutOfBoundsPolicy::Clamp);
+ break;
+ }
+ case PPK_QPageSize:
+ d->setPageSize(value.value<QPageSize>());
+ break;
+ case PPK_QPageMargins: {
+ QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
+ d->m_pageLayout.setUnits(pair.second);
+ d->m_pageLayout.setMargins(pair.first, QPageLayout::OutOfBoundsPolicy::Clamp);
+ break;
+ }
+ case PPK_QPageLayout: {
+ QPageLayout pageLayout = value.value<QPageLayout>();
+ if (pageLayout.isValid() && d->m_printDevice->isValidPageLayout(pageLayout, d->resolution.hRes)) {
+ setProperty(PPK_QPageSize, QVariant::fromValue(pageLayout.pageSize()));
+ setProperty(PPK_FullPage, pageLayout.mode() == QPageLayout::FullPageMode);
+ setProperty(PPK_Orientation, QVariant::fromValue(pageLayout.orientation()));
+ d->m_pageLayout.setUnits(pageLayout.units());
+ d->m_pageLayout.setMargins(pageLayout.margins(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ }
+ break;
+ }
+ // No default so that compiler will complain if new keys added and not handled in this engine
+ }
+}
+
+QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
+{
+ Q_D(const QMacPrintEngine);
+ QVariant ret;
+
+ if (!d->printInfo && d->valueCache.contains(key))
+ return *d->valueCache.find(key);
+
+ switch (key) {
+
+ // The following keys are settings that are unsupported by the Mac PrintEngine
+ // Return sensible default values to ensure consistent behavior across platforms
+ case PPK_ColorMode:
+ ret = QPrinter::Color;
+ break;
+ case PPK_CustomBase:
+ // Special case, leave null
+ break;
+ case PPK_PageOrder:
+ // TODO Check if can be supported via Cups Options
+ ret = QPrinter::FirstPageFirst;
+ break;
+ case PPK_PaperSource:
+ // TODO Check if can be supported via Cups Options
+ ret = QPrinter::Auto;
+ break;
+ case PPK_PaperSources: {
+ // TODO Check if can be supported via Cups Options
+ QList<QVariant> out;
+ out << int(QPrinter::Auto);
+ ret = out;
+ break;
+ }
+ case PPK_PrinterProgram:
+ ret = QString();
+ break;
+ case PPK_SelectionOption:
+ ret = QString();
+ break;
+
+ // The following keys are properties and settings that are supported by the Mac PrintEngine
+ case PPK_FontEmbedding:
+ ret = d->embedFonts;
+ break;
+ case PPK_CollateCopies: {
+ Boolean status;
+ PMGetCollate(d->settings(), &status);
+ ret = bool(status);
+ break;
+ }
+ case PPK_Creator:
+ ret = d->m_creator;
+ break;
+ case PPK_DocumentName: {
+ CFStringRef name;
+ PMPrintSettingsGetJobName(d->settings(), &name);
+ ret = QString::fromCFString(name);
+ break;
+ }
+ case PPK_Duplex: {
+ PMDuplexMode mode = kPMDuplexNone;
+ PMGetDuplex(d->settings(), &mode);
+ switch (mode) {
+ case kPMDuplexNoTumble:
+ ret = QPrinter::DuplexLongSide;
+ break;
+ case kPMDuplexTumble:
+ ret = QPrinter::DuplexShortSide;
+ break;
+ case kPMDuplexNone:
+ default:
+ ret = QPrinter::DuplexNone;
+ break;
+ }
+ break;
+ }
+ case PPK_FullPage:
+ ret = d->m_pageLayout.mode() == QPageLayout::FullPageMode;
+ break;
+ case PPK_NumberOfCopies:
+ ret = 1;
+ break;
+ case PPK_CopyCount: {
+ UInt32 copies = 1;
+ PMGetCopies(d->settings(), &copies);
+ ret = (uint) copies;
+ break;
+ }
+ case PPK_SupportsMultipleCopies:
+ ret = true;
+ break;
+ case PPK_Orientation:
+ ret = d->m_pageLayout.orientation();
+ break;
+ case PPK_OutputFileName:
+ ret = d->outputFilename;
+ break;
+ case PPK_PageRect:
+ // PageRect is returned in device pixels
+ ret = d->m_pageLayout.paintRectPixels(d->resolution.hRes);
+ break;
+ case PPK_PageSize:
+ ret = d->m_pageLayout.pageSize().id();
+ break;
+ case PPK_PaperName:
+ ret = d->m_pageLayout.pageSize().name();
+ break;
+ case PPK_WindowsPageSize:
+ ret = d->m_pageLayout.pageSize().windowsId();
+ break;
+ case PPK_PaperRect:
+ // PaperRect is returned in device pixels
+ ret = d->m_pageLayout.fullRectPixels(d->resolution.hRes);
+ break;
+ case PPK_PrinterName:
+ return d->m_printDevice->id();
+ break;
+ case PPK_Resolution: {
+ ret = d->resolution.hRes;
+ break;
+ }
+ case PPK_SupportedResolutions: {
+ QList<QVariant> list;
+ for (int resolution : d->m_printDevice->supportedResolutions())
+ list << resolution;
+ ret = list;
+ break;
+ }
+ case PPK_CustomPaperSize:
+ ret = d->m_pageLayout.fullRectPoints().size();
+ break;
+ case PPK_PageMargins: {
+ QList<QVariant> list;
+ QMarginsF margins = d->m_pageLayout.margins(QPageLayout::Point);
+ list << margins.left() << margins.top() << margins.right() << margins.bottom();
+ ret = list;
+ break;
+ }
+ case PPK_QPageSize:
+ ret.setValue(d->m_pageLayout.pageSize());
+ break;
+ case PPK_QPageMargins: {
+ QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(d->m_pageLayout.margins(), d->m_pageLayout.units());
+ ret.setValue(pair);
+ break;
+ }
+ case PPK_QPageLayout:
+ ret.setValue(d->m_pageLayout);
+ // No default so that compiler will complain if new keys added and not handled in this engine
+ }
+ return ret;
+}
+
+NSPrintInfo *QMacPrintEngine::printInfo()
+{
+ Q_D(QMacPrintEngine);
+ if (d->state == QPrinter::Idle && !d->isPrintSessionInitialized())
+ d->initialize();
+ return d->printInfo;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
diff --git a/src/printsupport/platform/macos/qprintengine_mac_p.h b/src/printsupport/platform/macos/qprintengine_mac_p.h
new file mode 100644
index 0000000000..7a0390cf41
--- /dev/null
+++ b/src/printsupport/platform/macos/qprintengine_mac_p.h
@@ -0,0 +1,123 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPRINTENGINE_MAC_P_H
+#define QPRINTENGINE_MAC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtPrintSupport/qtprintsupportglobal.h>
+
+#ifndef QT_NO_PRINTER
+
+#include <QtPrintSupport/qprinter.h>
+#include <QtPrintSupport/qprintengine.h>
+#include <QtGui/private/qpainter_p.h>
+#include <QtGui/qpagelayout.h>
+
+#include "qcocoaprintdevice_p.h"
+
+#include "qpaintengine_mac_p.h"
+
+Q_FORWARD_DECLARE_OBJC_CLASS(NSPrintInfo);
+
+QT_BEGIN_NAMESPACE
+
+class QPrinterPrivate;
+class QMacPrintEnginePrivate;
+class QMacPrintEngine : public QPaintEngine, public QPrintEngine
+{
+ Q_DECLARE_PRIVATE(QMacPrintEngine)
+public:
+ QMacPrintEngine(QPrinter::PrinterMode mode, const QString &deviceId);
+
+ Qt::HANDLE handle() const;
+
+ bool begin(QPaintDevice *dev);
+ bool end();
+ virtual QPaintEngine::Type type() const { return QPaintEngine::MacPrinter; }
+
+ QPaintEngine *paintEngine() const;
+
+ void setProperty(PrintEnginePropertyKey key, const QVariant &value);
+ QVariant property(PrintEnginePropertyKey key) const;
+
+ QPrinter::PrinterState printerState() const;
+
+ bool newPage();
+ bool abort();
+ int metric(QPaintDevice::PaintDeviceMetric) const;
+
+ NSPrintInfo *printInfo();
+
+ //forwarded functions
+
+ void updateState(const QPaintEngineState &state);
+
+ virtual void drawLines(const QLineF *lines, int lineCount);
+ virtual void drawRects(const QRectF *r, int num);
+ virtual void drawPoints(const QPointF *p, int pointCount);
+ virtual void drawEllipse(const QRectF &r);
+ virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
+ virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
+ virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags);
+ virtual void drawTextItem(const QPointF &p, const QTextItem &ti);
+ virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
+ virtual void drawPath(const QPainterPath &);
+
+private:
+ friend class QCocoaNativeInterface;
+};
+
+class QMacPrintEnginePrivate : public QPaintEnginePrivate
+{
+ Q_DECLARE_PUBLIC(QMacPrintEngine)
+public:
+ QPrinter::PrinterMode mode;
+ QPrinter::PrinterState state;
+ QSharedPointer<QCocoaPrintDevice> m_printDevice;
+ QPageLayout m_pageLayout;
+ NSPrintInfo *printInfo;
+ PMResolution resolution;
+ QString outputFilename;
+ QString m_creator;
+ QPaintEngine *paintEngine;
+ QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant> valueCache;
+ uint embedFonts;
+
+ QMacPrintEnginePrivate() : mode(QPrinter::ScreenResolution), state(QPrinter::Idle),
+ m_pageLayout(QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0, 0, 0, 0))),
+ printInfo(nullptr), paintEngine(nullptr), embedFonts(true) {}
+ ~QMacPrintEnginePrivate();
+
+ void initialize();
+ void releaseSession();
+ bool newPage_helper();
+ void setPageSize(const QPageSize &pageSize);
+ inline bool isPrintSessionInitialized() const
+ {
+ return printInfo != 0;
+ }
+
+ PMPageFormat format() const { return static_cast<PMPageFormat>([printInfo PMPageFormat]); }
+ PMPrintSession session() const { return static_cast<PMPrintSession>([printInfo PMPrintSession]); }
+ PMPrintSettings settings() const { return static_cast<PMPrintSettings>([printInfo PMPrintSettings]); }
+
+ QPaintEngine *aggregateEngine() override { return paintEngine; }
+ Qt::HANDLE nativeHandle() override { return q_func()->handle(); }
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+
+#endif // QPRINTENGINE_WIN_P_H
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/platform/windows/qprintengine_win.cpp
index add57e9d95..fa8d03a615 100644
--- a/src/printsupport/kernel/qprintengine_win.cpp
+++ b/src/printsupport/platform/windows/qprintengine_win.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtPrintSupport/qtprintsupportglobal.h>
@@ -49,13 +13,16 @@
#include <private/qfont_p.h>
#include <private/qfontengine_p.h>
#include <private/qpainter_p.h>
+#if QT_CONFIG(directwrite)
+# include <private/qwindowsfontenginedirectwrite_p.h>
+#endif
#include <qpa/qplatformprintplugin.h>
#include <qpa/qplatformprintersupport.h>
#include <qbitmap.h>
#include <qdebug.h>
-#include <qvector.h>
+#include <qlist.h>
#include <qpicture.h>
#include <qpa/qplatformpixmap.h>
#include <private/qpicture_p.h>
@@ -63,13 +30,10 @@
#include <QtCore/QMetaType>
#include <QtCore/qt_windows.h>
#include <QtGui/qpagelayout.h>
-
-Q_DECLARE_METATYPE(HFONT)
-Q_DECLARE_METATYPE(LOGFONT)
+#include <QtGui/private/qpixmap_win_p.h>
QT_BEGIN_NAMESPACE
-Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0);
extern QPainterPath qt_regionToPath(const QRegion &region);
extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
@@ -291,24 +255,40 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem
bool fallBack = state->pen().brush().style() != Qt::SolidPattern
|| qAlpha(brushColor) != 0xff
|| d->txop >= QTransform::TxProject
- || ti.fontEngine->type() != QFontEngine::Win
|| !d->embed_fonts;
if (!fallBack) {
- const QVariantMap userData = ti.fontEngine->userData().toMap();
- const QVariant hFontV = userData.value(QStringLiteral("hFont"));
- const QVariant logFontV = userData.value(QStringLiteral("logFont"));
- if (hFontV.canConvert<HFONT>() && logFontV.canConvert<LOGFONT>()) {
- const HFONT hfont = hFontV.value<HFONT>();
- const LOGFONT logFont = logFontV.value<LOGFONT>();
+ bool deleteFont = false;
+ HFONT hfont = nullptr;
+ if (ti.fontEngine->type() == QFontEngine::Win) {
+ hfont = static_cast<HFONT>(ti.fontEngine->handle());
+ }
+#if QT_CONFIG(directwrite)
+ else if (ti.fontEngine->type() == QFontEngine::DirectWrite) {
+ QWindowsFontEngineDirectWrite *fedw = static_cast<QWindowsFontEngineDirectWrite *>(ti.fontEngine);
+ hfont = fedw->createHFONT();
+ if (hfont)
+ deleteFont = true;
+ }
+#endif
+
+ if (hfont) {
// Try selecting the font to see if we get a substitution font
SelectObject(d->hdc, hfont);
if (GetDeviceCaps(d->hdc, TECHNOLOGY) != DT_CHARSTREAM) {
+ LOGFONT logFont;
+ GetObject(hfont, sizeof(LOGFONT), &logFont);
+
wchar_t n[64];
GetTextFace(d->hdc, 64, n);
fallBack = QString::fromWCharArray(n)
!= QString::fromWCharArray(logFont.lfFaceName);
+
+ if (deleteFont)
+ DeleteObject(hfont);
}
+ } else {
+ fallBack = true;
}
}
@@ -382,9 +362,9 @@ int QWin32PrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
case QPaintDevice::PdmNumColors:
{
int bpp = GetDeviceCaps(d->hdc, BITSPIXEL);
- if(bpp==32)
+ if (bpp==32)
val = INT_MAX;
- else if(bpp<=8)
+ else if (bpp<=8)
val = GetDeviceCaps(d->hdc, NUMCOLORS);
else
val = 1 << (bpp * GetDeviceCaps(d->hdc, PLANES));
@@ -453,7 +433,7 @@ void QWin32PrintEngine::updateClipPath(const QPainterPath &clipPath, Qt::ClipOpe
bool doclip = true;
if (op == Qt::NoClip) {
- SelectClipRgn(d->hdc, 0);
+ SelectClipRgn(d->hdc, nullptr);
doclip = false;
}
@@ -581,6 +561,7 @@ void QWin32PrintEngine::drawPixmap(const QRectF &targetRect,
QImage img(QSize(imgw, imgh), QImage::Format_RGB32);
+ img.setDevicePixelRatio(pixmap.devicePixelRatio());
img.fill(Qt::white);
QPainter painter(&img);
painter.drawPixmap(0,0, pixmap, tileSize * x, tileSize * y, imgw, imgh);
@@ -741,7 +722,7 @@ void QWin32PrintEnginePrivate::strokePath_dev(const QPainterPath &path, const QC
joinStyle = PS_JOIN_ROUND;
HPEN pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | capStyle | joinStyle,
- (penWidth == 0) ? 1 : penWidth, &brush, 0, 0);
+ (penWidth == 0) ? 1 : penWidth, &brush, 0, nullptr);
HGDIOBJ old_pen = SelectObject(hdc, pen);
StrokePath(hdc);
@@ -756,8 +737,6 @@ void QWin32PrintEnginePrivate::fillPath(const QPainterPath &path, const QColor &
void QWin32PrintEnginePrivate::strokePath(const QPainterPath &path, const QColor &color)
{
- Q_Q(QWin32PrintEngine);
-
QPainterPathStroker stroker;
if (pen.style() == Qt::CustomDashLine) {
stroker.setDashPattern(pen.dashPattern());
@@ -771,7 +750,7 @@ void QWin32PrintEnginePrivate::strokePath(const QPainterPath &path, const QColor
QPainterPath stroke;
qreal width = pen.widthF();
- bool cosmetic = qt_pen_is_cosmetic(pen, q->state->renderHints());
+ bool cosmetic = pen.isCosmetic();
if (pen.style() == Qt::SolidLine && (cosmetic || matrix.type() < QTransform::TxScale)) {
strokePath_dev(path * matrix, color, width);
} else {
@@ -863,7 +842,8 @@ void QWin32PrintEnginePrivate::initialize()
txop = QTransform::TxNone;
QString printerName = m_printDevice.id();
- bool ok = OpenPrinter((LPWSTR)printerName.utf16(), (LPHANDLE)&hPrinter, 0);
+ bool ok = OpenPrinter(reinterpret_cast<LPWSTR>(const_cast<ushort *>(printerName.utf16())),
+ reinterpret_cast<LPHANDLE>(&hPrinter), nullptr);
if (!ok) {
qErrnoWarning("QWin32PrintEngine::initialize: OpenPrinter failed");
return;
@@ -872,10 +852,10 @@ void QWin32PrintEnginePrivate::initialize()
// Fetch the PRINTER_INFO_2 with DEVMODE data containing the
// printer settings.
DWORD infoSize, numBytes;
- GetPrinter(hPrinter, 2, NULL, 0, &infoSize);
+ GetPrinter(hPrinter, 2, nullptr, 0, &infoSize);
hMem = GlobalAlloc(GHND, infoSize);
- pInfo = (PRINTER_INFO_2*) GlobalLock(hMem);
- ok = GetPrinter(hPrinter, 2, (LPBYTE)pInfo, infoSize, &numBytes);
+ pInfo = reinterpret_cast<PRINTER_INFO_2*>(GlobalLock(hMem));
+ ok = GetPrinter(hPrinter, 2, reinterpret_cast<LPBYTE>(pInfo), infoSize, &numBytes);
if (!ok) {
qErrnoWarning("QWin32PrintEngine::initialize: GetPrinter failed");
@@ -893,23 +873,26 @@ void QWin32PrintEnginePrivate::initialize()
// Attempt to get the DEVMODE a different way.
// Allocate the required buffer
- LONG result = DocumentProperties(NULL, hPrinter, (LPWSTR)printerName.utf16(),
- NULL, NULL, 0);
- devMode = (DEVMODE *) malloc(result);
+ auto *lpwPrinterName = reinterpret_cast<LPWSTR>(const_cast<ushort *>(printerName.utf16()));
+ LONG result = DocumentProperties(nullptr, hPrinter, lpwPrinterName,
+ nullptr, nullptr, 0);
+ devMode = reinterpret_cast<DEVMODE *>(malloc(result));
+ initializeDevMode(devMode);
ownsDevMode = true;
// Get the default DevMode
- result = DocumentProperties(NULL, hPrinter, (LPWSTR)printerName.utf16(),
- devMode, NULL, DM_OUT_BUFFER);
+ result = DocumentProperties(nullptr, hPrinter, lpwPrinterName,
+ devMode, nullptr, DM_OUT_BUFFER);
if (result != IDOK) {
qErrnoWarning("QWin32PrintEngine::initialize: Failed to obtain devMode");
free(devMode);
- devMode = NULL;
+ devMode = nullptr;
ownsDevMode = false;
}
}
- hdc = CreateDC(NULL, (LPCWSTR)printerName.utf16(), 0, devMode);
+ hdc = CreateDC(nullptr, reinterpret_cast<LPCWSTR>(printerName.utf16()),
+ nullptr, devMode);
if (!hdc) {
qErrnoWarning("QWin32PrintEngine::initialize: CreateDC failed");
@@ -934,15 +917,22 @@ void QWin32PrintEnginePrivate::initialize()
#endif // QT_DEBUG_DRAW || QT_DEBUG_METRICS
}
+void QWin32PrintEnginePrivate::initializeDevMode(DEVMODE *devMode)
+{
+ memset(devMode, 0, sizeof(DEVMODE));
+ devMode->dmSize = sizeof(DEVMODE);
+ devMode->dmSpecVersion = DM_SPECVERSION;
+}
+
void QWin32PrintEnginePrivate::initHDC()
{
Q_ASSERT(hdc);
- HDC display_dc = GetDC(0);
+ HDC display_dc = GetDC(nullptr);
dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
dpi_display = GetDeviceCaps(display_dc, LOGPIXELSY);
- ReleaseDC(0, display_dc);
+ ReleaseDC(nullptr, display_dc);
if (dpi_display == 0) {
qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
"might be a driver problem");
@@ -985,11 +975,11 @@ void QWin32PrintEnginePrivate::release()
if (ownsDevMode)
free(devMode);
- hdc = 0;
- hPrinter = 0;
- pInfo = 0;
- hMem = 0;
- devMode = 0;
+ hdc = nullptr;
+ hPrinter = nullptr;
+ pInfo = nullptr;
+ hMem = nullptr;
+ devMode = nullptr;
ownsDevMode = false;
}
@@ -1018,7 +1008,7 @@ bool QWin32PrintEnginePrivate::resetDC()
return hdc != 0;
}
-static int indexOfId(const QVector<QPrint::InputSlot> &inputSlots, QPrint::InputSlotId id)
+static int indexOfId(const QList<QPrint::InputSlot> &inputSlots, QPrint::InputSlotId id)
{
for (int i = 0; i < inputSlots.size(); ++i) {
if (inputSlots.at(i).id == id)
@@ -1027,7 +1017,7 @@ static int indexOfId(const QVector<QPrint::InputSlot> &inputSlots, QPrint::Input
return -1;
}
-static int indexOfWindowsId(const QVector<QPrint::InputSlot> &inputSlots, int windowsId)
+static int indexOfWindowsId(const QList<QPrint::InputSlot> &inputSlots, int windowsId)
{
for (int i = 0; i < inputSlots.size(); ++i) {
if (inputSlots.at(i).windowsId == windowsId)
@@ -1073,6 +1063,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
if (!d->devMode)
break;
d->devMode->dmCollate = value.toBool() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE;
+ d->devMode->dmFields |= DM_COLLATE;
d->doReinit();
}
break;
@@ -1082,6 +1073,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
if (!d->devMode)
break;
d->devMode->dmColor = (value.toInt() == QPrinter::Color) ? DMCOLOR_COLOR : DMCOLOR_MONOCHROME;
+ d->devMode->dmFields |= DM_COLOR;
d->doReinit();
}
break;
@@ -1107,15 +1099,19 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
switch (mode) {
case QPrint::DuplexNone:
d->devMode->dmDuplex = DMDUP_SIMPLEX;
+ d->devMode->dmFields |= DM_DUPLEX;
break;
case QPrint::DuplexAuto:
d->devMode->dmDuplex = d->m_pageLayout.orientation() == QPageLayout::Landscape ? DMDUP_HORIZONTAL : DMDUP_VERTICAL;
+ d->devMode->dmFields |= DM_DUPLEX;
break;
case QPrint::DuplexLongSide:
d->devMode->dmDuplex = DMDUP_VERTICAL;
+ d->devMode->dmFields |= DM_DUPLEX;
break;
case QPrint::DuplexShortSide:
d->devMode->dmDuplex = DMDUP_HORIZONTAL;
+ d->devMode->dmFields |= DM_DUPLEX;
break;
default:
// Don't change
@@ -1143,6 +1139,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
break;
d->num_copies = value.toInt();
d->devMode->dmCopies = d->num_copies;
+ d->devMode->dmFields |= DM_COPIES;
d->doReinit();
break;
@@ -1151,9 +1148,10 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
break;
QPageLayout::Orientation orientation = QPageLayout::Orientation(value.toInt());
d->devMode->dmOrientation = orientation == QPageLayout::Landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
+ d->devMode->dmFields |= DM_ORIENTATION;
d->m_pageLayout.setOrientation(orientation);
- d->updateMetrics();
d->doReinit();
+ d->updateMetrics();
#ifdef QT_DEBUG_METRICS
qDebug() << "QWin32PrintEngine::setProperty(PPK_Orientation," << orientation << ')';
d->debugMetrics();
@@ -1287,7 +1285,8 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
Q_ASSERT(margins.size() == 4);
d->m_pageLayout.setUnits(QPageLayout::Point);
d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
- margins.at(2).toReal(), margins.at(3).toReal()));
+ margins.at(2).toReal(), margins.at(3).toReal()),
+ QPageLayout::OutOfBoundsPolicy::Clamp);
d->updateMetrics();
#ifdef QT_DEBUG_METRICS
qDebug() << "QWin32PrintEngine::setProperty(PPK_PageMargins," << margins << ')';
@@ -1315,7 +1314,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
case PPK_QPageMargins: {
QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
d->m_pageLayout.setUnits(pair.second);
- d->m_pageLayout.setMargins(pair.first);
+ d->m_pageLayout.setMargins(pair.first, QPageLayout::OutOfBoundsPolicy::Clamp);
d->updateMetrics();
#ifdef QT_DEBUG_METRICS
qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageMargins," << pair.first << pair.second << ')';
@@ -1331,7 +1330,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
setProperty(PPK_FullPage, pageLayout.mode() == QPageLayout::FullPageMode);
setProperty(PPK_Orientation, QVariant::fromValue(pageLayout.orientation()));
d->m_pageLayout.setUnits(pageLayout.units());
- d->m_pageLayout.setMargins(pageLayout.margins());
+ d->m_pageLayout.setMargins(pageLayout.margins(), QPageLayout::OutOfBoundsPolicy::Clamp);
d->updateMetrics();
#ifdef QT_DEBUG_METRICS
qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageLayout," << pageLayout << ')';
@@ -1555,7 +1554,7 @@ HGLOBAL *QWin32PrintEngine::createGlobalDevNames()
{
Q_D(QWin32PrintEngine);
- int size = sizeof(DEVNAMES) + d->m_printDevice.id().length() * 2 + 2;
+ const size_t size = sizeof(DEVNAMES) + d->m_printDevice.id().length() * 2 + 2;
auto hGlobal = reinterpret_cast<HGLOBAL *>(GlobalAlloc(GMEM_MOVEABLE, size));
auto dn = reinterpret_cast<DEVNAMES*>(GlobalLock(hGlobal));
@@ -1593,7 +1592,7 @@ void QWin32PrintEngine::setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalD
d->ownsDevMode = false;
}
d->devMode = dm;
- d->hdc = CreateDC(NULL, reinterpret_cast<const wchar_t *>(d->m_printDevice.id().utf16()), 0, dm);
+ d->hdc = CreateDC(nullptr, reinterpret_cast<LPCWSTR>(d->m_printDevice.id().utf16()), nullptr, dm);
d->num_copies = d->devMode->dmCopies;
d->updatePageLayout();
@@ -1607,7 +1606,7 @@ void QWin32PrintEngine::setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalD
#if defined QT_DEBUG_DRAW || defined QT_DEBUG_METRICS
qDebug("QWin32PrintEngine::setGlobalDevMode()");
- debugMetrics();
+ d->debugMetrics();
#endif // QT_DEBUG_DRAW || QT_DEBUG_METRICS
}
@@ -1696,13 +1695,23 @@ void QWin32PrintEnginePrivate::updatePageLayout()
void QWin32PrintEnginePrivate::updateMetrics()
{
m_paintRectPixels = m_pageLayout.paintRectPixels(resolution);
+ // Some print devices allow scaling, so that "virtual" page size != current paper size
+ const int devWidth = GetDeviceCaps(hdc, PHYSICALWIDTH);
+ const int devHeight = GetDeviceCaps(hdc, PHYSICALHEIGHT);
+ const int pageWidth = m_pageLayout.fullRectPixels(dpi_x).width();
+ const int pageHeight = m_pageLayout.fullRectPixels(dpi_y).height();
+ const qreal pageScaleX = (devWidth && pageWidth) ? qreal(devWidth) / pageWidth : 1;
+ const qreal pageScaleY = (devHeight && pageHeight) ? qreal(devHeight) / pageHeight : 1;
+ m_paintRectPixels = QTransform::fromScale(pageScaleX, pageScaleY).mapRect(m_paintRectPixels);
+
QSizeF sizeMM = m_pageLayout.paintRect(QPageLayout::Millimeter).size();
m_paintSizeMM = QSize(qRound(sizeMM.width()), qRound(sizeMM.height()));
// Calculate the origin using the physical device pixels, not our paint pixels
// Origin is defined as User Margins - Device Margins
- QMarginsF margins = m_pageLayout.margins(QPageLayout::Millimeter) / 25.4;
- origin_x = qRound(margins.left() * dpi_x) - GetDeviceCaps(hdc, PHYSICALOFFSETX);
- origin_y = qRound(margins.top() * dpi_y) - GetDeviceCaps(hdc, PHYSICALOFFSETY);
+ const bool isFullPage = (m_pageLayout.mode() == QPageLayout::FullPageMode);
+ const QMarginsF margins = isFullPage ? QMarginsF() : (m_pageLayout.margins(QPageLayout::Millimeter) / 25.4);
+ origin_x = qRound(pageScaleX * margins.left() * dpi_x) - GetDeviceCaps(hdc, PHYSICALOFFSETX);
+ origin_y = qRound(pageScaleY * margins.top() * dpi_y) - GetDeviceCaps(hdc, PHYSICALOFFSETY);
}
void QWin32PrintEnginePrivate::debugMetrics() const
@@ -1727,15 +1736,21 @@ static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC h
const bool has_kerning = ti.f && ti.f->kerning();
- HFONT hfont = 0;
+ HFONT hfont = nullptr;
+ bool deleteFont = false;
if (ti.fontEngine->type() == QFontEngine::Win) {
- const QVariantMap userData = ti.fontEngine->userData().toMap();
- const QVariant hfontV = userData.value(QStringLiteral("hFont"));
- const QVariant ttfV = userData.value(QStringLiteral("trueType"));
- if (ttfV.toBool() && hfontV.canConvert<HFONT>())
- hfont = hfontV.value<HFONT>();
+ if (ti.fontEngine->supportsTransformation(QTransform::fromScale(0.5, 0.5))) // is TrueType font?
+ hfont = static_cast<HFONT>(ti.fontEngine->handle());
+ }
+#if QT_CONFIG(directwrite)
+ else if (ti.fontEngine->type() == QFontEngine::DirectWrite) {
+ QWindowsFontEngineDirectWrite *fedw = static_cast<QWindowsFontEngineDirectWrite *>(ti.fontEngine);
+ hfont = fedw->createHFONT();
+ if (hfont)
+ deleteFont = true;
}
+#endif
if (!hfont)
hfont = (HFONT)GetStockObject(ANSI_VAR_FONT);
@@ -1808,6 +1823,9 @@ static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC h
SetWorldTransform(hdc, &win_xform);
SelectObject(hdc, old_font);
+
+ if (deleteFont)
+ DeleteObject(hfont);
}
QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qprintengine_win_p.h b/src/printsupport/platform/windows/qprintengine_win_p.h
index 876155a3a5..995c31ff1e 100644
--- a/src/printsupport/kernel/qprintengine_win_p.h
+++ b/src/printsupport/platform/windows/qprintengine_win_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTENGINE_WIN_P_H
#define QPRINTENGINE_WIN_P_H
@@ -44,8 +8,8 @@
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
@@ -76,30 +40,30 @@ public:
QWin32PrintEngine(QPrinter::PrinterMode mode, const QString &deviceId);
// override QWin32PaintEngine
- bool begin(QPaintDevice *dev);
- bool end();
+ bool begin(QPaintDevice *dev) override;
+ bool end() override;
- void updateState(const QPaintEngineState &state);
+ void updateState(const QPaintEngineState &state) override;
void updateMatrix(const QTransform &matrix);
void updateClipPath(const QPainterPath &clip, Qt::ClipOperation op);
- void drawPath(const QPainterPath &path);
- void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
- void drawTextItem(const QPointF &p, const QTextItem &textItem);
+ void drawPath(const QPainterPath &path) override;
+ void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override;
+ void drawTextItem(const QPointF &p, const QTextItem &textItem) override;
- void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
- void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p);
- void setProperty(PrintEnginePropertyKey key, const QVariant &value);
- QVariant property(PrintEnginePropertyKey key) const;
+ void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override;
+ void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p) override;
+ void setProperty(PrintEnginePropertyKey key, const QVariant &value) override;
+ QVariant property(PrintEnginePropertyKey key) const override;
- bool newPage();
- bool abort();
- int metric(QPaintDevice::PaintDeviceMetric) const;
+ bool newPage() override;
+ bool abort() override;
+ int metric(QPaintDevice::PaintDeviceMetric) const override;
- QPrinter::PrinterState printerState() const;
+ QPrinter::PrinterState printerState() const override;
- QPaintEngine::Type type() const { return Windows; }
+ QPaintEngine::Type type() const override { return Windows; }
HDC getDC() const;
void releaseDC(HDC) const;
@@ -119,25 +83,9 @@ class QWin32PrintEnginePrivate : public QAlphaPaintEnginePrivate
Q_DECLARE_PUBLIC(QWin32PrintEngine)
public:
QWin32PrintEnginePrivate() :
- hPrinter(0),
- globalDevMode(0),
- devMode(0),
- pInfo(0),
- hMem(0),
- hdc(0),
- ownsDevMode(false),
- mode(QPrinter::ScreenResolution),
- state(QPrinter::Idle),
- resolution(0),
- m_pageLayout(QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0, 0, 0, 0))),
- stretch_x(1), stretch_y(1), origin_x(0), origin_y(0),
- dpi_x(96), dpi_y(96), dpi_display(96),
- num_copies(1),
- printToFile(false),
- reinit(false),
+ printToFile(false), reinit(false),
complex_xform(false), has_pen(false), has_brush(false), has_custom_paper_size(false),
- embed_fonts(true),
- txop(0 /* QTransform::TxNone */)
+ embed_fonts(true)
{
}
@@ -163,6 +111,8 @@ public:
is handled in the next begin or newpage. */
void doReinit();
+ static void initializeDevMode(DEVMODE *);
+
bool resetDC();
void strokePath(const QPainterPath &path, const QColor &color);
@@ -178,19 +128,19 @@ public:
void debugMetrics() const;
// Windows GDI printer references.
- HANDLE hPrinter;
+ HANDLE hPrinter = nullptr;
- HGLOBAL globalDevMode;
- DEVMODE *devMode;
- PRINTER_INFO_2 *pInfo;
- HGLOBAL hMem;
+ HGLOBAL globalDevMode = nullptr;
+ DEVMODE *devMode = nullptr;
+ PRINTER_INFO_2 *pInfo = nullptr;
+ HGLOBAL hMem = nullptr;
- HDC hdc;
+ HDC hdc = nullptr;
// True if devMode was allocated separately from pInfo.
- bool ownsDevMode;
+ bool ownsDevMode = false;
- QPrinter::PrinterMode mode;
+ QPrinter::PrinterMode mode = QPrinter::ScreenResolution;
// Print Device
QPrintDevice m_printDevice;
@@ -200,26 +150,26 @@ public:
QString m_creator;
QString fileName;
- QPrinter::PrinterState state;
- int resolution;
+ QPrinter::PrinterState state = QPrinter::Idle;
+ int resolution = 0;
// Page Layout
- QPageLayout m_pageLayout;
-
+ QPageLayout m_pageLayout{QPageSize(QPageSize::A4),
+ QPageLayout::Portrait, QMarginsF{0, 0, 0, 0}};
// Page metrics cache
QRect m_paintRectPixels;
QSize m_paintSizeMM;
// Windows painting
- qreal stretch_x;
- qreal stretch_y;
- int origin_x;
- int origin_y;
+ qreal stretch_x = 1;
+ qreal stretch_y = 1;
+ int origin_x = 0;
+ int origin_y = 0;
- int dpi_x;
- int dpi_y;
- int dpi_display;
- int num_copies;
+ int dpi_x = 96;
+ int dpi_y = 96;
+ int dpi_display = 96;
+ int num_copies = 1;
uint printToFile : 1;
uint reinit : 1;
@@ -230,7 +180,7 @@ public:
uint has_custom_paper_size : 1;
uint embed_fonts : 1;
- uint txop;
+ uint txop = 0; // QTransform::TxNone
QColor brush_color;
QPen pen;
diff --git a/src/printsupport/platform/windows/qwindowsprintdevice.cpp b/src/printsupport/platform/windows/qwindowsprintdevice.cpp
new file mode 100644
index 0000000000..9445871ed7
--- /dev/null
+++ b/src/printsupport/platform/windows/qwindowsprintdevice.cpp
@@ -0,0 +1,520 @@
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsprintdevice_p.h"
+
+#include <QtCore/qdebug.h>
+
+#ifndef DC_COLLATE
+# define DC_COLLATE 22
+#endif
+
+QT_BEGIN_NAMESPACE
+
+using WindowsPrinterLookup = QList<QWindowsPrinterInfo>;
+Q_GLOBAL_STATIC(WindowsPrinterLookup, windowsDeviceLookup);
+
+extern qreal qt_pointMultiplier(QPageLayout::Unit unit);
+
+static inline uint qwcsnlen(const wchar_t *str, uint maxlen)
+{
+ uint length = 0;
+ if (str) {
+ while (length < maxlen && *str++)
+ length++;
+ }
+ return length;
+}
+
+static LPDEVMODE getDevmode(HANDLE hPrinter, const QString &printerId)
+{
+ LPWSTR printerIdUtf16 = const_cast<LPWSTR>(reinterpret_cast<LPCWSTR>(printerId.utf16()));
+ // Allocate the required DEVMODE buffer
+ LONG dmSize = DocumentProperties(nullptr, hPrinter, printerIdUtf16, nullptr, nullptr, 0);
+ if (dmSize <= 0)
+ return nullptr;
+ LPDEVMODE pDevMode = reinterpret_cast<LPDEVMODE>(malloc(dmSize));
+ // Get the default DevMode
+ LONG result = DocumentProperties(nullptr, hPrinter, printerIdUtf16, pDevMode, nullptr, DM_OUT_BUFFER);
+ if (result != IDOK) {
+ free(pDevMode);
+ pDevMode = nullptr;
+ }
+ return pDevMode;
+}
+
+QWindowsPrintDevice::QWindowsPrintDevice()
+ : QPlatformPrintDevice(),
+ m_hPrinter(0)
+{
+}
+
+QWindowsPrintDevice::QWindowsPrintDevice(const QString &id)
+ : QPlatformPrintDevice(id),
+ m_hPrinter(0)
+{
+ // First do a fast lookup to see if printer exists, if it does then open it
+ if (!id.isEmpty() && QWindowsPrintDevice::availablePrintDeviceIds().contains(id)) {
+ if (OpenPrinter(const_cast<LPWSTR>(wcharId()), &m_hPrinter, nullptr)) {
+ DWORD needed = 0;
+ GetPrinter(m_hPrinter, 2, 0, 0, &needed);
+ QScopedArrayPointer<BYTE> buffer(new BYTE[needed]);
+ if (GetPrinter(m_hPrinter, 2, buffer.data(), needed, &needed)) {
+ PPRINTER_INFO_2 info = reinterpret_cast<PPRINTER_INFO_2>(buffer.data());
+ m_name = QString::fromWCharArray(info->pPrinterName);
+ m_location = QString::fromWCharArray(info->pLocation);
+ m_makeAndModel = QString::fromWCharArray(info->pDriverName); // TODO Check is not available elsewhere
+ m_isRemote = info->Attributes & PRINTER_ATTRIBUTE_NETWORK;
+ }
+ QWindowsPrinterInfo m_info;
+ m_info.m_id = m_id;
+ m_info.m_name = m_name;
+ m_info.m_location = m_location;
+ m_info.m_makeAndModel = m_makeAndModel;
+ m_info.m_isRemote = m_isRemote;
+ m_infoIndex = windowsDeviceLookup()->indexOf(m_info);
+ if (m_infoIndex != -1) {
+ m_info = windowsDeviceLookup()->at(m_infoIndex);
+ m_havePageSizes = m_info.m_havePageSizes;
+ m_pageSizes = m_info.m_pageSizes;
+ m_haveResolutions = m_info.m_haveResolutions;
+ m_resolutions = m_info.m_resolutions;
+ m_haveCopies = m_info.m_haveCopies;
+ m_supportsMultipleCopies = m_info.m_supportsMultipleCopies;
+ m_supportsCollateCopies = m_info.m_supportsCollateCopies;
+ m_haveMinMaxPageSizes = m_info.m_haveMinMaxPageSizes;
+ m_minimumPhysicalPageSize = m_info.m_minimumPhysicalPageSize;
+ m_maximumPhysicalPageSize = m_info.m_maximumPhysicalPageSize;
+ m_supportsCustomPageSizes = m_info.m_supportsCustomPageSizes;
+ m_haveInputSlots = m_info.m_haveInputSlots;
+ m_inputSlots = m_info.m_inputSlots;
+ m_haveOutputBins = m_info.m_haveOutputBins;
+ m_outputBins = m_info.m_outputBins;
+ m_haveDuplexModes = m_info.m_haveDuplexModes;
+ m_duplexModes = m_info.m_duplexModes;
+ m_haveColorModes = m_info.m_haveColorModes;
+ m_colorModes = m_info.m_colorModes;
+ m_infoIndex = windowsDeviceLookup()->indexOf(m_info);
+ } else {
+ windowsDeviceLookup()->append(m_info);
+ m_infoIndex = windowsDeviceLookup()->count() - 1;
+ }
+ }
+ }
+}
+
+QWindowsPrintDevice::~QWindowsPrintDevice()
+{
+ ClosePrinter(m_hPrinter);
+}
+
+bool QWindowsPrintDevice::isValid() const
+{
+ return m_hPrinter;
+}
+
+bool QWindowsPrintDevice::isDefault() const
+{
+ return m_id == defaultPrintDeviceId();
+}
+
+QPrint::DeviceState QWindowsPrintDevice::state() const
+{
+ DWORD needed = 0;
+ GetPrinter(m_hPrinter, 6, 0, 0, &needed);
+ QScopedArrayPointer<BYTE> buffer(new BYTE[needed]);
+
+ if (GetPrinter(m_hPrinter, 6, buffer.data(), needed, &needed)) {
+ PPRINTER_INFO_6 info = reinterpret_cast<PPRINTER_INFO_6>(buffer.data());
+ // TODO Check mapping
+ if (info->dwStatus == 0
+ || (info->dwStatus & PRINTER_STATUS_WAITING) == PRINTER_STATUS_WAITING
+ || (info->dwStatus & PRINTER_STATUS_POWER_SAVE) == PRINTER_STATUS_POWER_SAVE) {
+ return QPrint::Idle;
+ } else if ((info->dwStatus & PRINTER_STATUS_PRINTING) == PRINTER_STATUS_PRINTING
+ || (info->dwStatus & PRINTER_STATUS_BUSY) == PRINTER_STATUS_BUSY
+ || (info->dwStatus & PRINTER_STATUS_INITIALIZING) == PRINTER_STATUS_INITIALIZING
+ || (info->dwStatus & PRINTER_STATUS_IO_ACTIVE) == PRINTER_STATUS_IO_ACTIVE
+ || (info->dwStatus & PRINTER_STATUS_PROCESSING) == PRINTER_STATUS_PROCESSING
+ || (info->dwStatus & PRINTER_STATUS_WARMING_UP) == PRINTER_STATUS_WARMING_UP) {
+ return QPrint::Active;
+ }
+ }
+
+ return QPrint::Error;
+}
+
+void QWindowsPrintDevice::loadPageSizes() const
+{
+ // Get the number of paper sizes and check all 3 attributes have same count
+ const int paperCount = DeviceCapabilities(wcharId(), nullptr, DC_PAPERNAMES, nullptr, nullptr);
+ if (paperCount > 0
+ && DeviceCapabilities(wcharId(), nullptr, DC_PAPERSIZE, nullptr, nullptr) == paperCount
+ && DeviceCapabilities(wcharId(), nullptr, DC_PAPERS, nullptr, nullptr) == paperCount) {
+
+ QScopedArrayPointer<wchar_t> paperNames(new wchar_t[paperCount*64]);
+ QScopedArrayPointer<POINT> winSizes(new POINT[paperCount]);
+ QScopedArrayPointer<wchar_t> papers(new wchar_t[paperCount]);
+
+ // Get the details and match the default paper size
+ if (DeviceCapabilities(wcharId(), nullptr, DC_PAPERNAMES, paperNames.data(), nullptr) == paperCount
+ && DeviceCapabilities(wcharId(), nullptr, DC_PAPERSIZE,
+ reinterpret_cast<wchar_t *>(winSizes.data()), nullptr) == paperCount
+ && DeviceCapabilities(wcharId(), nullptr, DC_PAPERS, papers.data(), nullptr) == paperCount) {
+
+ // Returned size is in tenths of a millimeter
+ const qreal multiplier = qt_pointMultiplier(QPageLayout::Millimeter);
+ for (int i = 0; i < int(paperCount); ++i) {
+ QSize size = QSize(qRound((winSizes[i].x / 10.0) * multiplier), qRound((winSizes[i].y / 10.0) * multiplier));
+ wchar_t *paper = paperNames.data() + (i * 64);
+ QString name = QString::fromWCharArray(paper, qwcsnlen(paper, 64));
+ m_pageSizes.append(createPageSize(papers[i], size, name));
+ }
+
+ }
+ }
+
+ m_havePageSizes = true;
+ QWindowsPrinterInfo *info = windowsDeviceLookup()->data();
+ info[m_infoIndex].m_havePageSizes = true;
+ info[m_infoIndex].m_pageSizes = m_pageSizes;
+}
+
+QPageSize QWindowsPrintDevice::defaultPageSize() const
+{
+ if (!m_havePageSizes)
+ loadPageSizes();
+
+ QPageSize pageSize;
+
+ if (LPDEVMODE pDevMode = getDevmode(m_hPrinter, m_id)) {
+ // Get the default paper size
+ if (pDevMode->dmFields & DM_PAPERSIZE) {
+ // Find the supported page size that matches, in theory default should be one of them
+ for (const QPageSize &ps : m_pageSizes) {
+ if (ps.windowsId() == pDevMode->dmPaperSize) {
+ pageSize = ps;
+ break;
+ }
+ }
+ }
+ // Clean-up
+ free(pDevMode);
+ }
+
+ return pageSize;
+}
+
+QMarginsF QWindowsPrintDevice::printableMargins(const QPageSize &pageSize,
+ QPageLayout::Orientation orientation,
+ int resolution) const
+{
+ // TODO This is slow, need to cache values or find better way!
+ // Modify the DevMode to get the DC printable margins in device pixels
+ QMarginsF margins = QMarginsF(0, 0, 0, 0);
+ DWORD needed = 0;
+ GetPrinter(m_hPrinter, 2, 0, 0, &needed);
+ QScopedArrayPointer<BYTE> buffer(new BYTE[needed]);
+ if (GetPrinter(m_hPrinter, 2, buffer.data(), needed, &needed)) {
+ PPRINTER_INFO_2 info = reinterpret_cast<PPRINTER_INFO_2>(buffer.data());
+ LPDEVMODE devMode = info->pDevMode;
+ bool separateDevMode = false;
+ if (!devMode) {
+ // GetPrinter() didn't include the DEVMODE. Get it a different way.
+ devMode = getDevmode(m_hPrinter, m_id);
+ if (!devMode)
+ return margins;
+ separateDevMode = true;
+ }
+
+ HDC pDC = CreateDC(nullptr, wcharId(), nullptr, devMode);
+ if (pageSize.id() == QPageSize::Custom || pageSize.windowsId() <= 0 || pageSize.windowsId() > DMPAPER_LAST) {
+ devMode->dmPaperSize = 0;
+ devMode->dmPaperWidth = pageSize.size(QPageSize::Millimeter).width() * 10.0;
+ devMode->dmPaperLength = pageSize.size(QPageSize::Millimeter).height() * 10.0;
+ } else {
+ devMode->dmPaperSize = pageSize.windowsId();
+ }
+ devMode->dmPrintQuality = resolution;
+ devMode->dmOrientation = orientation == QPageLayout::Portrait ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
+ ResetDC(pDC, devMode);
+ const int dpiWidth = GetDeviceCaps(pDC, LOGPIXELSX);
+ const int dpiHeight = GetDeviceCaps(pDC, LOGPIXELSY);
+ const qreal wMult = 72.0 / dpiWidth;
+ const qreal hMult = 72.0 / dpiHeight;
+ const qreal physicalWidth = GetDeviceCaps(pDC, PHYSICALWIDTH) * wMult;
+ const qreal physicalHeight = GetDeviceCaps(pDC, PHYSICALHEIGHT) * hMult;
+ const qreal printableWidth = GetDeviceCaps(pDC, HORZRES) * wMult;
+ const qreal printableHeight = GetDeviceCaps(pDC, VERTRES) * hMult;
+ const qreal leftMargin = GetDeviceCaps(pDC, PHYSICALOFFSETX)* wMult;
+ const qreal topMargin = GetDeviceCaps(pDC, PHYSICALOFFSETY) * hMult;
+ const qreal rightMargin = physicalWidth - leftMargin - printableWidth;
+ const qreal bottomMargin = physicalHeight - topMargin - printableHeight;
+ margins = QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin);
+ if (separateDevMode)
+ free(devMode);
+ DeleteDC(pDC);
+ }
+ return margins;
+}
+
+void QWindowsPrintDevice::loadResolutions() const
+{
+ const int resCount = DeviceCapabilities(wcharId(), nullptr, DC_ENUMRESOLUTIONS, nullptr, nullptr);
+ if (resCount > 0) {
+ QScopedArrayPointer<LONG> resolutions(new LONG[resCount*2]);
+ // Get the details and match the default paper size
+ if (DeviceCapabilities(wcharId(), nullptr, DC_ENUMRESOLUTIONS,
+ reinterpret_cast<LPWSTR>(resolutions.data()), nullptr) == resCount) {
+ for (int i = 0; i < int(resCount * 2); i += 2)
+ m_resolutions.append(resolutions[i+1]);
+ }
+ }
+ m_haveResolutions = true;
+ QWindowsPrinterInfo *info = windowsDeviceLookup()->data();
+ info[m_infoIndex].m_haveResolutions = true;
+ info[m_infoIndex].m_resolutions = m_resolutions;
+}
+
+int QWindowsPrintDevice::defaultResolution() const
+{
+ int resolution = 72; // TODO Set a sensible default?
+
+ if (LPDEVMODE pDevMode = getDevmode(m_hPrinter, m_id)) {
+ // Get the default resolution
+ if (pDevMode->dmFields & DM_YRESOLUTION) {
+ if (pDevMode->dmPrintQuality > 0)
+ resolution = pDevMode->dmPrintQuality;
+ else
+ resolution = pDevMode->dmYResolution;
+ }
+ // Clean-up
+ free(pDevMode);
+ }
+ return resolution;
+}
+
+void QWindowsPrintDevice::loadInputSlots() const
+{
+ const auto printerId = wcharId();
+ const int binCount = DeviceCapabilities(printerId, nullptr, DC_BINS, nullptr, nullptr);
+ if (binCount > 0
+ && DeviceCapabilities(printerId, nullptr, DC_BINNAMES, nullptr, nullptr) == binCount) {
+
+ QScopedArrayPointer<WORD> bins(new WORD[binCount]);
+ QScopedArrayPointer<wchar_t> binNames(new wchar_t[binCount*24]);
+
+ // Get the details and match the default paper size
+ if (DeviceCapabilities(printerId, nullptr, DC_BINS,
+ reinterpret_cast<LPWSTR>(bins.data()), nullptr) == binCount
+ && DeviceCapabilities(printerId, nullptr, DC_BINNAMES, binNames.data(),
+ nullptr) == binCount) {
+
+ for (int i = 0; i < int(binCount); ++i) {
+ wchar_t *binName = binNames.data() + (i * 24);
+ QString name = QString::fromWCharArray(binName, qwcsnlen(binName, 24));
+ m_inputSlots.append(QPrintUtils::paperBinToInputSlot(bins[i], name));
+ }
+
+ }
+ }
+
+ m_haveInputSlots = true;
+ QWindowsPrinterInfo *info = windowsDeviceLookup()->data();
+ info[m_infoIndex].m_haveInputSlots = true;
+ info[m_infoIndex].m_inputSlots = m_inputSlots;
+}
+
+QPrint::InputSlot QWindowsPrintDevice::defaultInputSlot() const
+{
+ QPrint::InputSlot inputSlot = QPlatformPrintDevice::defaultInputSlot();
+
+ if (LPDEVMODE pDevMode = getDevmode(m_hPrinter, m_id)) {
+ // Get the default input slot
+ if (pDevMode->dmFields & DM_DEFAULTSOURCE) {
+ QPrint::InputSlot tempSlot =
+ QPrintUtils::paperBinToInputSlot(pDevMode->dmDefaultSource, QString());
+ const auto inputSlots = supportedInputSlots();
+ for (const QPrint::InputSlot &slot : inputSlots) {
+ if (slot.key == tempSlot.key) {
+ inputSlot = slot;
+ break;
+ }
+ }
+ }
+ // Clean-up
+ free(pDevMode);
+ }
+ return inputSlot;
+}
+
+void QWindowsPrintDevice::loadOutputBins() const
+{
+ m_outputBins.append(QPlatformPrintDevice::defaultOutputBin());
+ m_haveOutputBins = true;
+ QWindowsPrinterInfo *info = windowsDeviceLookup()->data();
+ info[m_infoIndex].m_haveOutputBins = true;
+ info[m_infoIndex].m_outputBins = m_outputBins;
+}
+
+void QWindowsPrintDevice::loadDuplexModes() const
+{
+ m_duplexModes.append(QPrint::DuplexNone);
+ DWORD duplex = DeviceCapabilities(wcharId(), nullptr, DC_DUPLEX, nullptr, nullptr);
+ if (int(duplex) == 1) {
+ // TODO Assume if duplex flag supports both modes
+ m_duplexModes.append(QPrint::DuplexAuto);
+ m_duplexModes.append(QPrint::DuplexLongSide);
+ m_duplexModes.append(QPrint::DuplexShortSide);
+ }
+ m_haveDuplexModes = true;
+ QWindowsPrinterInfo *info = windowsDeviceLookup()->data();
+ info[m_infoIndex].m_haveDuplexModes = true;
+ info[m_infoIndex].m_duplexModes = m_duplexModes;
+}
+
+QPrint::DuplexMode QWindowsPrintDevice::defaultDuplexMode() const
+{
+ QPrint::DuplexMode duplexMode = QPrint::DuplexNone;
+
+ if (LPDEVMODE pDevMode = getDevmode(m_hPrinter, m_id)) {
+ // Get the default duplex mode
+ if (pDevMode->dmFields & DM_DUPLEX) {
+ if (pDevMode->dmDuplex == DMDUP_VERTICAL)
+ duplexMode = QPrint::DuplexLongSide;
+ else if (pDevMode->dmDuplex == DMDUP_HORIZONTAL)
+ duplexMode = QPrint::DuplexShortSide;
+ }
+ // Clean-up
+ free(pDevMode);
+ }
+ return duplexMode;
+}
+
+void QWindowsPrintDevice::loadColorModes() const
+{
+ m_colorModes.append(QPrint::GrayScale);
+ DWORD color = DeviceCapabilities(wcharId(), nullptr, DC_COLORDEVICE, nullptr, nullptr);
+ if (int(color) == 1)
+ m_colorModes.append(QPrint::Color);
+ m_haveColorModes = true;
+ QWindowsPrinterInfo *info = windowsDeviceLookup()->data();
+ info[m_infoIndex].m_haveColorModes = true;
+ info[m_infoIndex].m_colorModes = m_colorModes;
+}
+
+QPrint::ColorMode QWindowsPrintDevice::defaultColorMode() const
+{
+ if (!m_haveColorModes)
+ loadColorModes();
+ if (!m_colorModes.contains(QPrint::Color))
+ return QPrint::GrayScale;
+
+ QPrint::ColorMode colorMode = QPrint::GrayScale;
+
+ if (LPDEVMODE pDevMode = getDevmode(m_hPrinter, m_id)) {
+ // Get the default color mode
+ if (pDevMode->dmFields & DM_COLOR && pDevMode->dmColor == DMCOLOR_COLOR)
+ colorMode = QPrint::Color;
+ // Clean-up
+ free(pDevMode);
+ }
+ return colorMode;
+}
+
+QStringList QWindowsPrintDevice::availablePrintDeviceIds()
+{
+ QStringList list;
+ DWORD needed = 0;
+ DWORD returned = 0;
+ if ((!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, nullptr, 4, 0, 0, &needed, &returned)
+ && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ || !needed) {
+ return list;
+ }
+ QScopedArrayPointer<BYTE> buffer(new BYTE[needed]);
+ if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, nullptr, 4, buffer.data(), needed, &needed, &returned))
+ return list;
+ PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer.data());
+ for (uint i = 0; i < returned; ++i)
+ list.append(QString::fromWCharArray(infoList[i].pPrinterName));
+ return list;
+}
+
+QString QWindowsPrintDevice::defaultPrintDeviceId()
+{
+ DWORD size = 0;
+ if (GetDefaultPrinter(nullptr, &size) == ERROR_FILE_NOT_FOUND || size < 2)
+ return QString();
+
+ QScopedArrayPointer<wchar_t> name(new wchar_t[size]);
+ GetDefaultPrinter(name.data(), &size);
+ return QString::fromWCharArray(name.data());
+}
+
+void QWindowsPrintDevice::loadCopiesSupport() const
+{
+ auto printerId = wcharId();
+ m_supportsMultipleCopies = (DeviceCapabilities(printerId, nullptr, DC_COPIES, nullptr, nullptr) > 1);
+ m_supportsCollateCopies = DeviceCapabilities(printerId, nullptr, DC_COLLATE, nullptr, nullptr);
+ m_haveCopies = true;
+ QWindowsPrinterInfo *info = windowsDeviceLookup()->data();
+ info[m_infoIndex].m_haveCopies = true;
+ info[m_infoIndex].m_supportsMultipleCopies = m_supportsMultipleCopies;
+ info[m_infoIndex].m_supportsCollateCopies = m_supportsCollateCopies;
+}
+
+bool QWindowsPrintDevice::supportsCollateCopies() const
+{
+ if (!m_haveCopies)
+ loadCopiesSupport();
+ return m_supportsCollateCopies;
+}
+
+bool QWindowsPrintDevice::supportsMultipleCopies() const
+{
+ if (!m_haveCopies)
+ loadCopiesSupport();
+ return m_supportsMultipleCopies;
+}
+
+bool QWindowsPrintDevice::supportsCustomPageSizes() const
+{
+ if (!m_haveMinMaxPageSizes)
+ loadMinMaxPageSizes();
+ return m_supportsCustomPageSizes;
+}
+
+QSize QWindowsPrintDevice::minimumPhysicalPageSize() const
+{
+ if (!m_haveMinMaxPageSizes)
+ loadMinMaxPageSizes();
+ return m_minimumPhysicalPageSize;
+}
+
+QSize QWindowsPrintDevice::maximumPhysicalPageSize() const
+{
+ if (!m_haveMinMaxPageSizes)
+ loadMinMaxPageSizes();
+ return m_maximumPhysicalPageSize;
+}
+
+void QWindowsPrintDevice::loadMinMaxPageSizes() const
+{
+ // Min/Max custom size is in tenths of a millimeter
+ const qreal multiplier = qt_pointMultiplier(QPageLayout::Millimeter);
+ auto printerId = wcharId();
+ DWORD min = DeviceCapabilities(printerId, nullptr, DC_MINEXTENT, nullptr, nullptr);
+ m_minimumPhysicalPageSize = QSize((LOWORD(min) / 10.0) * multiplier, (HIWORD(min) / 10.0) * multiplier);
+ DWORD max = DeviceCapabilities(printerId, nullptr, DC_MAXEXTENT, nullptr, nullptr);
+ m_maximumPhysicalPageSize = QSize((LOWORD(max) / 10.0) * multiplier, (HIWORD(max) / 10.0) * multiplier);
+ m_supportsCustomPageSizes = (m_maximumPhysicalPageSize.width() > 0 && m_maximumPhysicalPageSize.height() > 0);
+ m_haveMinMaxPageSizes = true;
+ QWindowsPrinterInfo *info = windowsDeviceLookup()->data();
+ info[m_infoIndex].m_haveCopies = true;
+ info[m_infoIndex].m_supportsMultipleCopies = m_supportsMultipleCopies;
+ info[m_infoIndex].m_supportsCollateCopies = m_supportsCollateCopies;
+}
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/platform/windows/qwindowsprintdevice_p.h b/src/printsupport/platform/windows/qwindowsprintdevice_p.h
new file mode 100644
index 0000000000..edca1894e6
--- /dev/null
+++ b/src/printsupport/platform/windows/qwindowsprintdevice_p.h
@@ -0,0 +1,119 @@
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QWINDOWSPRINTDEVICE_H
+#define QWINDOWSPRINTDEVICE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qpa/qplatformprintdevice.h>
+
+#include <QtPrintSupport/qtprintsupportglobal.h>
+#include <QtCore/qt_windows.h>
+#include <QtCore/private/qglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_PRINTSUPPORT_EXPORT QWindowsPrinterInfo
+{
+public:
+ bool operator==(const QWindowsPrinterInfo &other) const
+ {
+ // We only need to check if these are the same for matching up
+ return m_id == other.m_id && m_name == other.m_name &&
+ m_location == other.m_location &&
+ m_makeAndModel == other.m_makeAndModel &&
+ m_isRemote == other.m_isRemote;
+ }
+ QString m_id;
+ QString m_name;
+ QString m_location;
+ QString m_makeAndModel;
+ QList<QPageSize> m_pageSizes;
+ QList<int> m_resolutions;
+ QList<QPrint::InputSlot> m_inputSlots;
+ QList<QPrint::OutputBin> m_outputBins;
+ QList<QPrint::DuplexMode> m_duplexModes;
+ QList<QPrint::ColorMode> m_colorModes;
+ QSize m_minimumPhysicalPageSize;
+ QSize m_maximumPhysicalPageSize;
+ bool m_isRemote = false;
+ bool m_havePageSizes = false;
+ bool m_haveResolutions = false;
+ bool m_haveCopies = false;
+ bool m_supportsMultipleCopies = false;
+ bool m_supportsCollateCopies = false;
+ bool m_haveMinMaxPageSizes = false;
+ bool m_supportsCustomPageSizes = false;
+ bool m_haveInputSlots = false;
+ bool m_haveOutputBins = false;
+ bool m_haveDuplexModes = false;
+ bool m_haveColorModes = false;
+};
+
+class Q_PRINTSUPPORT_EXPORT QWindowsPrintDevice : public QPlatformPrintDevice
+{
+public:
+ QWindowsPrintDevice();
+ explicit QWindowsPrintDevice(const QString &id);
+ virtual ~QWindowsPrintDevice();
+
+ bool isValid() const override;
+ bool isDefault() const override;
+
+ QPrint::DeviceState state() const override;
+
+ QPageSize defaultPageSize() const override;
+
+ QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation,
+ int resolution) const override;
+
+ int defaultResolution() const override;
+
+ QPrint::InputSlot defaultInputSlot() const override;
+
+ QPrint::DuplexMode defaultDuplexMode() const override;
+
+ QPrint::ColorMode defaultColorMode() const override;
+
+ static QStringList availablePrintDeviceIds();
+ static QString defaultPrintDeviceId();
+
+ bool supportsCollateCopies() const override;
+ bool supportsMultipleCopies() const override;
+ bool supportsCustomPageSizes() const override;
+ QSize minimumPhysicalPageSize() const override;
+ QSize maximumPhysicalPageSize() const override;
+
+protected:
+ void loadPageSizes() const override;
+ void loadResolutions() const override;
+ void loadInputSlots() const override;
+ void loadOutputBins() const override;
+ void loadDuplexModes() const override;
+ void loadColorModes() const override;
+ void loadCopiesSupport() const;
+ void loadMinMaxPageSizes() const;
+
+private:
+ LPCWSTR wcharId() const { return reinterpret_cast<LPCWSTR>(m_id.utf16()); }
+
+ HANDLE m_hPrinter;
+ mutable bool m_haveCopies;
+ mutable bool m_haveMinMaxPageSizes;
+ int m_infoIndex;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSPRINTDEVICE_H
diff --git a/src/printsupport/platform/windows/qwindowsprinterinfo.cpp b/src/printsupport/platform/windows/qwindowsprinterinfo.cpp
new file mode 100644
index 0000000000..73040de60f
--- /dev/null
+++ b/src/printsupport/platform/windows/qwindowsprinterinfo.cpp
@@ -0,0 +1,86 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qprinterinfo.h"
+#include "qprinterinfo_p.h"
+
+#include <qstringlist.h>
+
+#include <qt_windows.h>
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt::StringLiterals;
+
+#ifndef QT_NO_PRINTER
+
+extern QPrinter::PaperSize mapDevmodePaperSize(int s);
+
+//QList<QPrinterInfo> QPrinterInfo::availablePrinters()
+//{
+// QList<QPrinterInfo> printers;
+
+// DWORD needed = 0;
+// DWORD returned = 0;
+// if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned)) {
+// LPBYTE buffer = new BYTE[needed];
+// if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, buffer, needed, &needed, &returned)) {
+// PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer);
+// QPrinterInfo defPrn = defaultPrinter();
+// for (uint i = 0; i < returned; ++i) {
+// QString printerName(QString::fromWCharArray(infoList[i].pPrinterName));
+
+// QPrinterInfo printerInfo(printerName);
+// if (printerInfo.printerName() == defPrn.printerName())
+// printerInfo.d_ptr->isDefault = true;
+// printers.append(printerInfo);
+// }
+// }
+// delete [] buffer;
+// }
+
+// return printers;
+//}
+
+//QPrinterInfo QPrinterInfo::defaultPrinter()
+//{
+// QString noPrinters("qt_no_printers"_L1);
+// wchar_t buffer[256];
+// GetProfileString(L"windows", L"device", (wchar_t*)noPrinters.utf16(), buffer, 256);
+// QString output = QString::fromWCharArray(buffer);
+// if (output != noPrinters) {
+// // Filter out the name of the printer, which should be everything before a comma.
+// QString printerName = output.split(u',').value(0);
+// QPrinterInfo printerInfo(printerName);
+// printerInfo.d_ptr->isDefault = true;
+// return printerInfo;
+// }
+
+// return QPrinterInfo();
+//}
+
+//QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
+//{
+// const Q_D(QPrinterInfo);
+
+// QList<QPrinter::PaperSize> paperSizes;
+// if (isNull())
+// return paperSizes;
+
+// DWORD size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()),
+// NULL, DC_PAPERS, NULL, NULL);
+// if ((int)size != -1) {
+// wchar_t *papers = new wchar_t[size];
+// size = DeviceCapabilities(reinterpret_cast<const wchar_t*>(d->name.utf16()),
+// NULL, DC_PAPERS, papers, NULL);
+// for (int c = 0; c < (int)size; ++c)
+// paperSizes.append(mapDevmodePaperSize(papers[c]));
+// delete [] papers;
+// }
+
+// return paperSizes;
+//}
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/platform/windows/qwindowsprintersupport.cpp b/src/printsupport/platform/windows/qwindowsprintersupport.cpp
new file mode 100644
index 0000000000..7cbd4dc491
--- /dev/null
+++ b/src/printsupport/platform/windows/qwindowsprintersupport.cpp
@@ -0,0 +1,76 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qwindowsprintersupport_p.h"
+
+#ifndef QT_NO_PRINTER
+
+#include "qwindowsprintdevice_p.h"
+
+#include <QtCore/QStringList>
+#include <private/qprintengine_win_p.h>
+#include <private/qprintdevice_p.h>
+
+#define QT_STATICPLUGIN
+#include <qpa/qplatformprintplugin.h>
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt::StringLiterals;
+
+QWindowsPrinterSupport::QWindowsPrinterSupport()
+ : QPlatformPrinterSupport()
+{
+}
+
+QWindowsPrinterSupport::~QWindowsPrinterSupport()
+{
+}
+
+QPrintEngine *QWindowsPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode printerMode, const QString &deviceId)
+{
+ return new QWin32PrintEngine(printerMode, deviceId);
+}
+
+QPaintEngine *QWindowsPrinterSupport::createPaintEngine(QPrintEngine *engine, QPrinter::PrinterMode printerMode)
+{
+ Q_UNUSED(printerMode);
+ return static_cast<QWin32PrintEngine *>(engine);
+}
+
+QPrintDevice QWindowsPrinterSupport::createPrintDevice(const QString &id)
+{
+ return QPlatformPrinterSupport::createPrintDevice(new QWindowsPrintDevice(id));
+}
+
+QStringList QWindowsPrinterSupport::availablePrintDeviceIds() const
+{
+ return QWindowsPrintDevice::availablePrintDeviceIds();
+}
+
+QString QWindowsPrinterSupport::defaultPrintDeviceId() const
+{
+ return QWindowsPrintDevice::defaultPrintDeviceId();
+}
+
+class QWindowsPrinterSupportPlugin : public QPlatformPrinterSupportPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QPlatformPrinterSupportFactoryInterface_iid FILE "windows.json")
+
+public:
+ QPlatformPrinterSupport *create(const QString &) override;
+};
+
+QPlatformPrinterSupport *QWindowsPrinterSupportPlugin::create(const QString &key)
+{
+ if (key.compare(key, "windowsprintsupport"_L1, Qt::CaseInsensitive) == 0)
+ return new QWindowsPrinterSupport;
+ return nullptr;
+}
+
+QT_END_NAMESPACE
+
+#include "qwindowsprintersupport.moc"
+
+#endif // QT_NO_PRINTER
diff --git a/src/printsupport/platform/windows/qwindowsprintersupport_p.h b/src/printsupport/platform/windows/qwindowsprintersupport_p.h
new file mode 100644
index 0000000000..cee04e97d6
--- /dev/null
+++ b/src/printsupport/platform/windows/qwindowsprintersupport_p.h
@@ -0,0 +1,44 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef WINDOWSPRINTERSUPPORT_H
+#define WINDOWSPRINTERSUPPORT_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtPrintSupport/qtprintsupportglobal.h>
+
+#include <qpa/qplatformprintersupport.h>
+#include <private/qglobal_p.h>
+#ifndef QT_NO_PRINTER
+
+QT_BEGIN_NAMESPACE
+
+class Q_PRINTSUPPORT_EXPORT QWindowsPrinterSupport : public QPlatformPrinterSupport
+{
+ Q_DISABLE_COPY_MOVE(QWindowsPrinterSupport)
+public:
+ QWindowsPrinterSupport();
+ ~QWindowsPrinterSupport() override;
+
+ QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode, const QString &deviceId = QString()) override;
+ QPaintEngine *createPaintEngine(QPrintEngine *printEngine, QPrinter::PrinterMode) override;
+
+ QPrintDevice createPrintDevice(const QString &id) override;
+ QStringList availablePrintDeviceIds() const override;
+ QString defaultPrintDeviceId() const override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+#endif // WINDOWSPRINTERSUPPORT_H
diff --git a/src/printsupport/platform/windows/windows.json b/src/printsupport/platform/windows/windows.json
new file mode 100644
index 0000000000..803052854e
--- /dev/null
+++ b/src/printsupport/platform/windows/windows.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "windowsprintsupport" ]
+}
diff --git a/src/printsupport/printsupport.pro b/src/printsupport/printsupport.pro
deleted file mode 100644
index 52e99803c3..0000000000
--- a/src/printsupport/printsupport.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-TARGET = QtPrintSupport
-QT = core-private gui-private widgets-private
-
-DEFINES += QT_NO_USING_NAMESPACE QT_NO_FOREACH
-
-QMAKE_DOCS = $$PWD/doc/qtprintsupport.qdocconf
-
-QMAKE_LIBS += $$QMAKE_LIBS_PRINTSUPPORT
-
-include(kernel/kernel.pri)
-include(widgets/widgets.pri)
-include(dialogs/dialogs.pri)
-
-MODULE_PLUGIN_TYPES = \
- printsupport
-load(qt_module)
diff --git a/src/printsupport/qt_cmdline.cmake b/src/printsupport/qt_cmdline.cmake
new file mode 100644
index 0000000000..dfbe5febe4
--- /dev/null
+++ b/src/printsupport/qt_cmdline.cmake
@@ -0,0 +1 @@
+qt_commandline_option(cups TYPE boolean)
diff --git a/src/printsupport/widgets/qcupsjobwidget.cpp b/src/printsupport/widgets/qcupsjobwidget.cpp
index dcdb933f73..dea5286583 100644
--- a/src/printsupport/widgets/qcupsjobwidget.cpp
+++ b/src/printsupport/widgets/qcupsjobwidget.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPrintSupport module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcupsjobwidget_p.h"
@@ -125,7 +89,7 @@ void QCupsJobWidget::initJobHold()
m_ui.jobHoldComboBox->addItem(tr("Weekend (Saturday to Sunday)"), QVariant::fromValue(QCUPSSupport::Weekend));
m_ui.jobHoldComboBox->addItem(tr("Specific Time"), QVariant::fromValue(QCUPSSupport::SpecificTime));
- connect(m_ui.jobHoldComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QCupsJobWidget::toggleJobHoldTime);
+ connect(m_ui.jobHoldComboBox, &QComboBox::currentIndexChanged, this, &QCupsJobWidget::toggleJobHoldTime);
QCUPSSupport::JobHoldUntilWithTime jobHoldWithTime;
@@ -138,7 +102,7 @@ void QCupsJobWidget::initJobHold()
toggleJobHoldTime();
}
-void QCupsJobWidget::setJobHold(QCUPSSupport::JobHoldUntil jobHold, const QTime &holdUntilTime)
+void QCupsJobWidget::setJobHold(QCUPSSupport::JobHoldUntil jobHold, QTime holdUntilTime)
{
if (jobHold == QCUPSSupport::SpecificTime && holdUntilTime.isNull()) {
jobHold = QCUPSSupport::NoHold;
@@ -150,7 +114,7 @@ void QCupsJobWidget::setJobHold(QCUPSSupport::JobHoldUntil jobHold, const QTime
QCUPSSupport::JobHoldUntil QCupsJobWidget::jobHold() const
{
- return m_ui.jobHoldComboBox->itemData(m_ui.jobHoldComboBox->currentIndex()).value<QCUPSSupport::JobHoldUntil>();
+ return qvariant_cast<QCUPSSupport::JobHoldUntil>(m_ui.jobHoldComboBox->itemData(m_ui.jobHoldComboBox->currentIndex()));
}
void QCupsJobWidget::toggleJobHoldTime()
@@ -247,7 +211,7 @@ void QCupsJobWidget::setStartBannerPage(const QCUPSSupport::BannerPage bannerPag
QCUPSSupport::BannerPage QCupsJobWidget::startBannerPage() const
{
- return m_ui.startBannerPageCombo->itemData(m_ui.startBannerPageCombo->currentIndex()).value<QCUPSSupport::BannerPage>();
+ return qvariant_cast<QCUPSSupport::BannerPage>(m_ui.startBannerPageCombo->itemData(m_ui.startBannerPageCombo->currentIndex()));
}
void QCupsJobWidget::setEndBannerPage(const QCUPSSupport::BannerPage bannerPage)
@@ -257,7 +221,9 @@ void QCupsJobWidget::setEndBannerPage(const QCUPSSupport::BannerPage bannerPage)
QCUPSSupport::BannerPage QCupsJobWidget::endBannerPage() const
{
- return m_ui.endBannerPageCombo->itemData(m_ui.endBannerPageCombo->currentIndex()).value<QCUPSSupport::BannerPage>();
+ return qvariant_cast<QCUPSSupport::BannerPage>(m_ui.endBannerPageCombo->itemData(m_ui.endBannerPageCombo->currentIndex()));
}
QT_END_NAMESPACE
+
+#include "moc_qcupsjobwidget_p.cpp"
diff --git a/src/printsupport/widgets/qcupsjobwidget_p.h b/src/printsupport/widgets/qcupsjobwidget_p.h
index 4b6b047e26..22d190edc8 100644
--- a/src/printsupport/widgets/qcupsjobwidget_p.h
+++ b/src/printsupport/widgets/qcupsjobwidget_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPrintSupport module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCUPSJOBWIDGET_P_H
@@ -83,7 +47,7 @@ private Q_SLOTS:
private:
- void setJobHold(QCUPSSupport::JobHoldUntil jobHold = QCUPSSupport::NoHold, const QTime &holdUntilTime = QTime());
+ void setJobHold(QCUPSSupport::JobHoldUntil jobHold = QCUPSSupport::NoHold, QTime holdUntilTime = QTime());
QCUPSSupport::JobHoldUntil jobHold() const;
QTime jobHoldTime() const;
@@ -113,7 +77,7 @@ private:
int m_savedPriority;
QCUPSSupport::JobSheets m_savedJobSheets;
- Q_DISABLE_COPY(QCupsJobWidget)
+ Q_DISABLE_COPY_MOVE(QCupsJobWidget)
};
QT_END_NAMESPACE
diff --git a/src/printsupport/widgets/qprintpreviewwidget.cpp b/src/printsupport/widgets/qprintpreviewwidget.cpp
index 92370be2bd..637eb42505 100644
--- a/src/printsupport/widgets/qprintpreviewwidget.cpp
+++ b/src/printsupport/widgets/qprintpreviewwidget.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qprintpreviewwidget.h"
#include "private/qwidget_p.h"
@@ -50,7 +14,7 @@
QT_BEGIN_NAMESPACE
-namespace {
+namespace QtPrivate {
class PageItem : public QGraphicsItem
{
public:
@@ -61,7 +25,6 @@ public:
qreal border = qMax(paperSize.height(), paperSize.width()) / 25;
brect = QRectF(QPointF(-border, -border),
QSizeF(paperSize)+QSizeF(2*border, 2*border));
- setCacheMode(DeviceCoordinateCache);
}
QRectF boundingRect() const override
@@ -172,7 +135,10 @@ protected:
}
};
-} // anonymous namespace
+} // namespace QtPrivate
+
+using GraphicsView = QtPrivate::GraphicsView;
+using PageItem = QtPrivate::PageItem;
class QPrintPreviewWidgetPrivate : public QWidgetPrivate
{
@@ -218,7 +184,7 @@ void QPrintPreviewWidgetPrivate::_q_fit(bool doFitting)
{
Q_Q(QPrintPreviewWidget);
- if (curPage < 1 || curPage > pages.count())
+ if (curPage < 1 || curPage > pages.size())
return;
if (!doFitting && !fitting)
@@ -264,7 +230,7 @@ void QPrintPreviewWidgetPrivate::_q_fit(bool doFitting)
} else {
graphicsView->fitInView(target, Qt::KeepAspectRatio);
if (zoomMode == QPrintPreviewWidget::FitInView) {
- int step = qRound(graphicsView->matrix().mapRect(target).height());
+ const int step = qRound(graphicsView->transform().mapRect(target).height());
graphicsView->verticalScrollBar()->setSingleStep(step);
graphicsView->verticalScrollBar()->setPageStep(step);
}
@@ -332,7 +298,7 @@ void QPrintPreviewWidgetPrivate::init()
void QPrintPreviewWidgetPrivate::populateScene()
{
// remove old pages
- for (auto *page : qAsConst(pages))
+ for (auto *page : std::as_const(pages))
scene->removeItem(page);
qDeleteAll(pages);
pages.clear();
@@ -341,7 +307,7 @@ void QPrintPreviewWidgetPrivate::populateScene()
QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution());
int page = 1;
- for (auto *picture : qAsConst(pictures)) {
+ for (auto *picture : std::as_const(pictures)) {
PageItem* item = new PageItem(page++, picture, paperSize, pageRect);
scene->addItem(item);
pages.append(item);
@@ -350,14 +316,14 @@ void QPrintPreviewWidgetPrivate::populateScene()
void QPrintPreviewWidgetPrivate::layoutPages()
{
- int numPages = pages.count();
+ int numPages = pages.size();
if (numPages < 1)
return;
int numPagePlaces = numPages;
int cols = 1; // singleMode and default
if (viewMode == QPrintPreviewWidget::AllPagesView) {
- if (printer->orientation() == QPrinter::Portrait)
+ if (printer->pageLayout().orientation() == QPageLayout::Portrait)
cols = qCeil(qSqrt((float) numPages));
else
cols = qFloor(qSqrt((float) numPages));
@@ -395,13 +361,16 @@ void QPrintPreviewWidgetPrivate::generatePreview()
//### emit paintRequested() until the user changes some parameter
Q_Q(QPrintPreviewWidget);
+ // Avoid previewing a preview
+ if (printer->d_func()->previewMode())
+ return;
printer->d_func()->setPreviewMode(true);
emit q->paintRequested(printer);
printer->d_func()->setPreviewMode(false);
pictures = printer->d_func()->previewPages();
populateScene(); // i.e. setPreviewPrintedPictures() e.l.
layoutPages();
- curPage = qBound(1, curPage, pages.count());
+ curPage = pages.size() > 0 ? qBound(1, curPage, pages.size()) : 1;
if (fitting)
_q_fit();
emit q->previewChanged();
@@ -409,13 +378,13 @@ void QPrintPreviewWidgetPrivate::generatePreview()
void QPrintPreviewWidgetPrivate::setCurrentPage(int pageNumber)
{
- if (pageNumber < 1 || pageNumber > pages.count())
+ if (pageNumber < 1 || pageNumber > pages.size())
return;
int lastPage = curPage;
curPage = pageNumber;
- if (lastPage != curPage && lastPage > 0 && lastPage <= pages.count()) {
+ if (lastPage != curPage && lastPage > 0 && lastPage <= pages.size()) {
if (zoomMode != QPrintPreviewWidget::FitInView) {
QScrollBar *hsc = graphicsView->horizontalScrollBar();
QScrollBar *vsc = graphicsView->verticalScrollBar();
@@ -590,20 +559,20 @@ void QPrintPreviewWidget::setViewMode(ViewMode mode)
Returns the current orientation of the preview. This value is
obtained from the QPrinter object associated with the preview.
*/
-QPrinter::Orientation QPrintPreviewWidget::orientation() const
+QPageLayout::Orientation QPrintPreviewWidget::orientation() const
{
Q_D(const QPrintPreviewWidget);
- return d->printer->orientation();
+ return d->printer->pageLayout().orientation();
}
/*!
Sets the current orientation to \a orientation. This value will be
set on the QPrinter object associated with the preview.
*/
-void QPrintPreviewWidget::setOrientation(QPrinter::Orientation orientation)
+void QPrintPreviewWidget::setOrientation(QPageLayout::Orientation orientation)
{
Q_D(QPrintPreviewWidget);
- d->printer->setOrientation(orientation);
+ d->printer->setPageOrientation(orientation);
d->generatePreview();
}
@@ -742,20 +711,20 @@ QPrintPreviewWidget::ZoomMode QPrintPreviewWidget::zoomMode() const
/*!
This is a convenience function and is the same as calling \c
- {setOrientation(QPrinter::Landscape)}.
+ {setOrientation(QPageLayout::Landscape)}.
*/
void QPrintPreviewWidget::setLandscapeOrientation()
{
- setOrientation(QPrinter::Landscape);
+ setOrientation(QPageLayout::Landscape);
}
/*!
This is a convenience function and is the same as calling \c
- {setOrientation(QPrinter::Portrait)}.
+ {setOrientation(QPageLayout::Portrait)}.
*/
void QPrintPreviewWidget::setPortraitOrientation()
{
- setOrientation(QPrinter::Portrait);
+ setOrientation(QPageLayout::Portrait);
}
/*!
diff --git a/src/printsupport/widgets/qprintpreviewwidget.h b/src/printsupport/widgets/qprintpreviewwidget.h
index f11d686602..bda4124a5c 100644
--- a/src/printsupport/widgets/qprintpreviewwidget.h
+++ b/src/printsupport/widgets/qprintpreviewwidget.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPRINTPREVIEWWIDGET_H
#define QPRINTPREVIEWWIDGET_H
@@ -75,7 +39,7 @@ public:
~QPrintPreviewWidget();
qreal zoomFactor() const;
- QPrinter::Orientation orientation() const;
+ QPageLayout::Orientation orientation() const;
ViewMode viewMode() const;
ZoomMode zoomMode() const;
int currentPage() const;
@@ -88,7 +52,7 @@ public Q_SLOTS:
void zoomIn(qreal zoom = 1.1);
void zoomOut(qreal zoom = 1.1);
void setZoomFactor(qreal zoomFactor);
- void setOrientation(QPrinter::Orientation orientation);
+ void setOrientation(QPageLayout::Orientation orientation);
void setViewMode(ViewMode viewMode);
void setZoomMode(ZoomMode zoomMode);
void setCurrentPage(int pageNumber);
diff --git a/src/printsupport/widgets/widgets.pri b/src/printsupport/widgets/widgets.pri
deleted file mode 100644
index 1b5f0aca34..0000000000
--- a/src/printsupport/widgets/widgets.pri
+++ /dev/null
@@ -1,13 +0,0 @@
-qtConfig(printpreviewwidget) {
- HEADERS += widgets/qprintpreviewwidget.h
- SOURCES += widgets/qprintpreviewwidget.cpp
-}
-
-unix:!darwin:qtConfig(cupsjobwidget) {
- HEADERS += widgets/qcupsjobwidget_p.h
- SOURCES += widgets/qcupsjobwidget.cpp
- FORMS += widgets/qcupsjobwidget.ui
-
-}
-
-INCLUDEPATH += $$PWD