Skip to content

Commit 70b1097

Browse files
committed
Add CPDB support to Qt print dialog
The Common Print Dialog Backends (CPDB) concept has GUI-toolkit-independent backends for each print technology (CUPS, Print to File, cloud printing services, ...) and each print dialog (GTK, Qt, Chromium, Firefox, ...) is supposed to use this backend, so that changes in print technologies can be centrally and quickly covered by changing the backends and everything new gets available in all print dialogs. This commit provides Qt print dialog implementation which adds support for the CPDB concept. It communincates with all the installed CPDB backends and so gives support for all these print technologies to the Qt print dialog. To make use of CPDB, Qt should be configured with cpdb and cpdbjobwidget enabled and other print technologies (eg. cups and cupsjobwidget) disabled to prevent printer duplication. Change-Id: Ic97c41979040adb6e9ffab540c09edadb6b5de3e
1 parent a2e0f3d commit 70b1097

30 files changed

+1837
-77
lines changed

cmake/FindWrapCPDB.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (C) 2022 The Qt Company Ltd.
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
if (TARGET WrapCPDB::WrapCPDB)
5+
set(WrapCPDB_FOUND ON)
6+
return()
7+
endif()
8+
9+
find_package(PkgConfig QUIET)
10+
if (PKG_CONFIG_FOUND)
11+
pkg_check_modules(CPDB QUIET cpdb-frontend)
12+
if (CPDB_FOUND)
13+
add_library(WrapCPDB::WrapCPDB INTERFACE IMPORTED)
14+
target_compile_definitions(WrapCPDB::WrapCPDB INTERFACE -DQT_NO_KEYWORDS)
15+
set_target_properties(WrapCPDB::WrapCPDB PROPERTIES
16+
INTERFACE_INCLUDE_DIRECTORIES "${CPDB_INCLUDE_DIRS}")
17+
set_target_properties(WrapCPDB::WrapCPDB PROPERTIES
18+
INTERFACE_LINK_LIBRARIES "${CPDB_LIBRARIES}")
19+
endif()
20+
endif()
21+
22+
find_package_handle_standard_args(WrapCPDB
23+
REQUIRED_VARS CPDB_INCLUDE_DIRS CPDB_LIBRARIES
24+
VERSION_VAR CPDB_VERSION)
25+

src/gui/painting/qpagesize.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,8 @@ class QPageSizePrivate : public QSharedData
692692
const QString &name,
693693
QPageSize::SizeMatchPolicy matchPolicy);
694694
QPageSizePrivate(const QString &key, const QSize &size, const QString &name);
695+
QPageSizePrivate(const QString &key, const QSizeF &size,
696+
QPageSize::Unit units, const QString &name);
695697
QPageSizePrivate(int windowsId, const QSize &pointSize, const QString &name);
696698
~QPageSizePrivate();
697699

@@ -773,6 +775,15 @@ QPageSizePrivate::QPageSizePrivate(const QString &key, const QSize &pointSize, c
773775
}
774776
}
775777

778+
QPageSizePrivate::QPageSizePrivate(const QString &key, const QSizeF &size,
779+
QPageSize::Unit units, const QString &name)
780+
: m_id(QPageSize::Custom),
781+
m_windowsId(0)
782+
{
783+
init(size, units, name);
784+
m_key = key;
785+
}
786+
776787
QPageSizePrivate::QPageSizePrivate(int windowsId, const QSize &pointSize, const QString &name)
777788
: m_id(QPageSize::Custom),
778789
m_windowsId(0),
@@ -1156,6 +1167,18 @@ QPageSize::QPageSize(const QString &key, const QSize &pointSize, const QString &
11561167
{
11571168
}
11581169

1170+
/*!
1171+
\internal
1172+
1173+
Create page with given key, size, units and name, for use by printer plugin.
1174+
*/
1175+
1176+
QPageSize::QPageSize(const QString &key, const QSizeF &size,
1177+
QPageSize::Unit units, const QString &name)
1178+
: d(new QPageSizePrivate(key, size, units, name))
1179+
{
1180+
}
1181+
11591182
/*!
11601183
\internal
11611184

src/gui/painting/qpagesize.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ class Q_GUI_EXPORT QPageSize
255255
{ return !(lhs == rhs); }
256256

257257
QPageSize(const QString &key, const QSize &pointSize, const QString &name);
258+
QPageSize(const QString &key, const QSizeF &size,
259+
QPageSize::Unit units, const QString &name);
258260
QPageSize(int windowsId, const QSize &pointSize, const QString &name);
259261
QPageSize(QPageSizePrivate &dd);
260262
QSharedDataPointer<QPageSizePrivate> d;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Copyright (C) 2022 The Qt Company Ltd.
22
# SPDX-License-Identifier: BSD-3-Clause
33

4-
if(QT_FEATURE_cups AND UNIX AND NOT APPLE)
4+
# Generated from printsupport.pro.
5+
6+
if(QT_FEATURE_cpdb AND UNIX AND NOT APPLE)
7+
add_subdirectory(cpdb)
8+
elseif(QT_FEATURE_cups AND UNIX AND NOT APPLE)
59
add_subdirectory(cups)
610
endif()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
qt_find_package(WrapCPDB
3+
PROVIDED_TARGETS WrapCPDB::WrapCPDB MODULE_NAME printsupport QMAKE_LIB cpdb)
4+
5+
qt_internal_add_plugin(QCpdbPrinterSupportPlugin
6+
OUTPUT_NAME cpdbprintersupport
7+
PLUGIN_TYPE printsupport
8+
SOURCES
9+
main.cpp
10+
qcpdbprintengine.cpp qcpdbprintengine_p.h
11+
qcpdbprintersupport.cpp qcpdbprintersupport_p.h
12+
qcpdbprintdevice.cpp qcpdbprintdevice.h
13+
INCLUDE_DIRECTORIES
14+
../../../printsupport/kernel
15+
LIBRARIES
16+
WrapCPDB::WrapCPDB
17+
Qt::Core
18+
Qt::CorePrivate
19+
Qt::Gui
20+
Qt::GuiPrivate
21+
Qt::PrintSupport
22+
Qt::PrintSupportPrivate
23+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Keys": [ "cpdbprintersupport" ]
3+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (C) 2022-2023 Gaurav Guleria <tinytrebuchet@protonmail.com>
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3+
4+
#include "qcpdbprintersupport_p.h"
5+
6+
#include <qpa/qplatformprintplugin.h>
7+
#include <QtCore/QStringList>
8+
9+
QT_BEGIN_NAMESPACE
10+
11+
using namespace Qt::StringLiterals;
12+
13+
class QCpdbPrinterSupportPlugin : public QPlatformPrinterSupportPlugin
14+
{
15+
Q_OBJECT
16+
Q_PLUGIN_METADATA(IID QPlatformPrinterSupportFactoryInterface_iid FILE "cpdb.json")
17+
18+
public:
19+
QStringList keys() const;
20+
QPlatformPrinterSupport *create(const QString &) override;
21+
};
22+
23+
QStringList QCpdbPrinterSupportPlugin::keys() const
24+
{
25+
return QStringList(QStringLiteral("cpdbprintersupport"));
26+
}
27+
28+
QPlatformPrinterSupport *QCpdbPrinterSupportPlugin::create(const QString &key)
29+
{
30+
if (key.compare(key, "cpdbprintersupport"_L1, Qt::CaseInsensitive) == 0)
31+
return new QCpdbPrinterSupport;
32+
return 0;
33+
}
34+
35+
QT_END_NAMESPACE
36+
37+
#include "main.moc"

0 commit comments

Comments
 (0)