Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets
Commits:
82d4a69c by ali kettab at 2026-01-28T12:26:54+01:00
wxQt: Add PrintSupport check to configure
- - - - -
8d09cac1 by ali kettab at 2026-01-28T12:39:09+01:00
wxQt: Add PrintSupport component to cmake
- - - - -
79451500 by Lauri Nurmi at 2026-01-28T13:27:39+01:00
Remove implementation details from wxGetLinuxDistribution() docs
An introduction to lsb_release is unnecessary, and saying it is very
common on modern Linux distributions is an exaggeration, at least today.
And besides those, the details are not even accurate since
aef7df6 (Read Linux distribution info from os-release file, 2023-07-14)
(#23712), which made lsb_release the fallback method for obtaining
information.
Closes #26125.
- - - - -
2d7a886c by Vadim Zeitlin at 2026-01-28T15:21:07+01:00
Deprecate and stop using wxPropertyGrid::RescaleBitmap()
There is wxBitmap::Rescale() which can, and should, be used instead.
- - - - -
9e69106c by Vadim Zeitlin at 2026-01-28T15:27:34+01:00
Revert "Fix deleted items remaining displayed in MSW wxTreeCtrl"
This reverts commit 5edd516add0051d6f51ec87b8001999b6c4035a6 because it
is not necessary any more after reverting the use of WS_EX_COMPOSITED by
default in #25808.
See #23719.
- - - - -
02e1efd5 by 0tkl at 2026-01-28T18:05:12+01:00
Use wxBITMAP_BUNDLE_2 for icons in vertical toolbar
Make them better looking and consistent with the main toolbar.
Closes #26124.
- - - - -
59963f1c by ali kettab at 2026-01-28T18:10:56+01:00
wxQt: Implement wxQtPrintNativeData and wxPrinterDC
- - - - -
17c01459 by ali kettab at 2026-01-28T18:10:56+01:00
wxQt: Implement wxQtPrintDialog and wxQtPageSetupDialog
- - - - -
1e9bead5 by ali kettab at 2026-01-28T18:10:56+01:00
wxQt: Implement wxQtPrinter and wxQtPrintPreview
- - - - -
84a8b816 by Vadim Zeitlin at 2026-01-29T01:08:35+01:00
Merge branch 'qt_printsupport' of github.com:AliKet/wxWidgets
Add print support to wxQt.
See #26126.
- - - - -
16 changed files:
- build/cmake/toolkit.cmake
- configure
-
configure.ac
- include/wx/propgrid/propgrid.h
- include/wx/qt/dcprint.h
- include/wx/qt/printdlg.h
- include/wx/qt/printqt.h
- interface/wx/platinfo.h
- interface/wx/utils.h
- samples/toolbar/toolbar.cpp
- src/msw/treectrl.cpp
- src/propgrid/property.cpp
- src/propgrid/propgrid.cpp
- src/qt/dcprint.cpp
- src/qt/printdlg.cpp
- src/qt/printqt.cpp
Changes:
=====================================
build/cmake/toolkit.cmake
=====================================
@@ -132,9 +132,9 @@ if(WXQT)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
if(QT_VERSION_MAJOR EQUAL 5)
- set(QT_COMPONENTS Core Widgets Gui OpenGL OpenGL Test)
+ set(QT_COMPONENTS Core Widgets Gui OpenGL OpenGL Test PrintSupport)
elseif(QT_VERSION_MAJOR EQUAL 6)
- set(QT_COMPONENTS Core Widgets Gui OpenGL OpenGLWidgets Test)
+ set(QT_COMPONENTS Core Widgets Gui OpenGL OpenGLWidgets Test PrintSupport)
endif()
foreach(QT_COMPONENT ${QT_COMPONENTS})
=====================================
configure
=====================================
@@ -1053,6 +1053,7 @@ infodir
docdir
oldincludedir
includedir
+runstatedir
localstatedir
sharedstatedir
sysconfdir
@@ -1509,6 +1510,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1761,6 +1763,15 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
+ -runstatedir | --runstatedir | --runstatedi | --runstated \
+ | --runstate | --runstat | --runsta | --runst | --runs \
+ | --run | --ru | --r)
+ ac_prev=runstatedir ;;
+ -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+ | --run=* | --ru=* | --r=*)
+ runstatedir=$ac_optarg ;;
+
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1898,7 +1909,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
- libdir localedir mandir
+ libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@@ -2051,6 +2062,7 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
+ --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -29634,7 +29646,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
if test -n "$QT5_CUSTOM_DIR" ; then
TOOLKIT_INCLUDE="${TOOLKIT_INCLUDE} -I${QT5_CUSTOM_DIR}/include"
GUI_TK_LIBRARY="${GUI_TK_LIBRARY} -L${QT5_CUSTOM_DIR}/lib \
- -lQt5Core -lQt5Widgets -lQt5Gui -lQt5OpenGL -lQt5Test \
+ -lQt5Core -lQt5Widgets -lQt5Gui -lQt5OpenGL -lQt5Test -lQt5PrintSupport \
-Wl,-rpath,${QT5_CUSTOM_DIR}/lib"
elif test -z "$PKG_CONFIG" ; then
@@ -29643,19 +29655,19 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
else
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test" >&5
-$as_echo_n "checking for Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport" >&5
+$as_echo_n "checking for Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport... " >&6; }
if test -n "$QT5_CFLAGS"; then
pkg_cv_QT5_CFLAGS="$QT5_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test\""; } >&5
- ($PKG_CONFIG --exists --print-errors "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_QT5_CFLAGS=`$PKG_CONFIG --cflags "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test" 2>/dev/null`
+ pkg_cv_QT5_CFLAGS=`$PKG_CONFIG --cflags "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -29667,12 +29679,12 @@ if test -n "$QT5_LIBS"; then
pkg_cv_QT5_LIBS="$QT5_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test\""; } >&5
- ($PKG_CONFIG --exists --print-errors "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_QT5_LIBS=`$PKG_CONFIG --libs "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test" 2>/dev/null`
+ pkg_cv_QT5_LIBS=`$PKG_CONFIG --libs "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -29693,9 +29705,9 @@ else
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- QT5_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test" 2>&1`
+ QT5_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport" 2>&1`
else
- QT5_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test" 2>&1`
+ QT5_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$QT5_PKG_ERRORS" >&5
=====================================
configure.ac
=====================================
@@ -3296,7 +3296,7 @@ installed, where VER is 2, 3 or 4.
dnl the name of the directory where the files for this toolkit live
TOOLKIT_INCLUDE="${TOOLKIT_INCLUDE} -I${QT5_CUSTOM_DIR}/include"
GUI_TK_LIBRARY="${GUI_TK_LIBRARY} -L${QT5_CUSTOM_DIR}/lib \
- -lQt5Core -lQt5Widgets -lQt5Gui -lQt5OpenGL -lQt5Test \
+ -lQt5Core -lQt5Widgets -lQt5Gui -lQt5OpenGL -lQt5Test -lQt5PrintSupport \
-Wl,-rpath,${QT5_CUSTOM_DIR}/lib"
elif test -z "$PKG_CONFIG" ; then
@@ -3304,7 +3304,7 @@ installed, where VER is 2, 3 or 4.
else
PKG_CHECK_MODULES(QT5,
- [Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test],
+ [Qt5Core Qt5Widgets Qt5Gui Qt5OpenGL Qt5Test Qt5PrintSupport],
[
TOOLKIT_INCLUDE="${TOOLKIT_INCLUDE} ${QT5_CFLAGS}"
GUI_TK_LIBRARY="${GUI_TK_LIBRARY} ${QT5_LIBS}"
=====================================
include/wx/propgrid/propgrid.h
=====================================
@@ -1165,8 +1165,11 @@ public:
// Checks system screen design used for laying out various dialogs.
static bool IsSmallScreen();
+#if WXWIN_COMPATIBILITY_3_2
// Returns rescaled bitmap
+ wxDEPRECATED_MSG("use wxBitmap::Rescale instead")
static wxBitmap RescaleBitmap(const wxBitmap& srcBmp, double scaleX, double scaleY);
+#endif // WXWIN_COMPATIBILITY_3_2
// Returns rectangle that fully contains properties between and including
// p1 and p2. Rectangle is in virtual scrolled window coordinates.
=====================================
include/wx/qt/dcprint.h
=====================================
@@ -8,95 +8,39 @@
#ifndef _WX_QT_DCPRINT_H_
#define _WX_QT_DCPRINT_H_
-#include "wx/dc.h"
+#include "wx/dcprint.h"
+#include "wx/cmndata.h"
+#include "wx/qt/dc.h"
-class WXDLLIMPEXP_CORE wxPrinterDCImpl : public wxDCImpl
+class QPrinter;
+
+class WXDLLIMPEXP_CORE wxPrinterDCImpl : public wxQtDCImpl
{
public:
- wxPrinterDCImpl( wxPrinterDC *, const wxPrintData & );
-
- virtual bool CanDrawBitmap() const override;
- virtual bool CanGetTextExtent() const override;
-
- virtual void DoGetSize(int *width, int *height) const override;
- virtual void DoGetSizeMM(int* width, int* height) const override;
-
- virtual int GetDepth() const override;
- virtual wxSize GetPPI() const override;
-
- virtual void SetFont(const wxFont& font) override;
- virtual void SetPen(const wxPen& pen) override;
- virtual void SetBrush(const wxBrush& brush) override;
- virtual void SetBackground(const wxBrush& brush) override;
- virtual void SetBackgroundMode(int mode) override;
-
-#if wxUSE_PALETTE
- virtual void SetPalette(const wxPalette& palette) override;
-#endif // wxUSE_PALETTE
-
- virtual void SetLogicalFunction(wxRasterOperationMode function) override;
-
- virtual wxCoord GetCharHeight() const override;
- virtual wxCoord GetCharWidth() const override;
- virtual void DoGetTextExtent(const wxString& string,
- wxCoord *x, wxCoord *y,
- wxCoord *descent = nullptr,
- wxCoord *externalLeading = nullptr,
- const wxFont *theFont = nullptr) const override;
+ wxPrinterDCImpl(wxPrinterDC* owner, const wxPrintData& data);
+ ~wxPrinterDCImpl();
- virtual void Clear() override;
+ // override some base class virtuals
+ virtual bool StartDoc(const wxString& message) override;
+ virtual void EndDoc() override;
+ virtual void StartPage() override;
+ virtual void EndPage() override;
- virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
- wxCoord width, wxCoord height) override;
+ virtual wxRect GetPaperRect() const override;
- virtual void DoSetDeviceClippingRegion(const wxRegion& region) override;
+ virtual int GetResolution() const override;
- virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
- wxFloodFillStyle style = wxFLOOD_SURFACE) override;
-
- virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const override;
-
- virtual void DoDrawPoint(wxCoord x, wxCoord y) override;
- virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) override;
-
- virtual void DoDrawArc(wxCoord x1, wxCoord y1,
- wxCoord x2, wxCoord y2,
- wxCoord xc, wxCoord yc) override;
- virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
- double sa, double ea) override;
-
- virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) override;
- virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
- wxCoord width, wxCoord height,
- double radius) override;
- virtual void DoDrawEllipse(wxCoord x, wxCoord y,
- wxCoord width, wxCoord height) override;
-
- virtual void DoCrossHair(wxCoord x, wxCoord y) override;
-
- virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) override;
- virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
- bool useMask = false) override;
-
- virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) override;
- virtual void DoDrawRotatedText(const wxString& text,
- wxCoord x, wxCoord y, double angle) override;
+ virtual wxSize GetPPI() const override;
- virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
- wxCoord width, wxCoord height,
- wxDC *source,
- wxCoord xsrc, wxCoord ysrc,
- wxRasterOperationMode rop = wxCOPY,
- bool useMask = false,
- wxCoord xsrcMask = wxDefaultCoord,
- wxCoord ysrcMask = wxDefaultCoord) override;
+ virtual void DoGetSize(int* width, int* height) const override;
+ virtual void DoGetSizeMM(int* width, int* height) const override;
- virtual void DoDrawLines(int n, const wxPoint points[],
- wxCoord xoffset, wxCoord yoffset ) override;
+ QPrinter* GetQtPrinter() const { return m_qtPrinter; }
- virtual void DoDrawPolygon(int n, const wxPoint points[],
- wxCoord xoffset, wxCoord yoffset,
- wxPolygonFillMode fillStyle = wxODDEVEN_RULE) override;
+protected:
+ wxPrintData m_printData;
+ QPrinter* m_qtPrinter = nullptr; // This pointer is obtained from m_printData
+ // and stored here for convenience.
private:
wxDECLARE_CLASS(wxPrinterDCImpl);
=====================================
include/wx/qt/printdlg.h
=====================================
@@ -11,46 +11,67 @@
#include "wx/prntbase.h"
#include "wx/printdlg.h"
+#include <memory>
+
+class QPrinter;
+
class WXDLLIMPEXP_CORE wxQtPrintNativeData: public wxPrintNativeDataBase
{
public:
wxQtPrintNativeData();
+ ~wxQtPrintNativeData();
- virtual bool TransferTo( wxPrintData &data ) override;
- virtual bool TransferFrom( const wxPrintData &data ) override;
+ virtual bool TransferTo(wxPrintData& data) override;
+ virtual bool TransferFrom(const wxPrintData& data) override;
virtual bool IsOk() const override;
+ QPrinter* GetQtPrinter() const { return m_qtPrinter.get(); }
+
+private:
+ std::unique_ptr<QPrinter> m_qtPrinter;
+
+ wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxQtPrintNativeData);
};
-class WXDLLIMPEXP_CORE wxQtPrintDialog : public wxPrintDialogBase
+class WXDLLIMPEXP_CORE wxQtPrintDialog: public wxPrintDialogBase
{
public:
- wxQtPrintDialog(wxWindow *parent, wxPrintDialogData *data);
- wxQtPrintDialog(wxWindow *parent, wxPrintData *data);
+ wxQtPrintDialog() = default;
+ explicit wxQtPrintDialog(wxWindow* parent, wxPrintDialogData* data = nullptr);
+ wxQtPrintDialog(wxWindow* parent, wxPrintData* data);
- virtual wxPrintDialogData& GetPrintDialogData() override;
- virtual wxPrintData& GetPrintData() override;
- virtual wxDC *GetPrintDC() override;
+ virtual int ShowModal() override;
-protected:
+ virtual wxPrintDialogData& GetPrintDialogData() override { return m_printDialogData; }
+ virtual wxPrintData& GetPrintData() override { return m_printDialogData.GetPrintData(); }
+
+ virtual wxDC* GetPrintDC() override;
private:
-};
+ wxWindow* m_dialogParent = nullptr;
+ wxPrinterDC* m_printerDC = nullptr;
+ wxPrintDialogData m_printDialogData;
+ wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxQtPrintDialog);
+};
class WXDLLIMPEXP_CORE wxQtPageSetupDialog: public wxPageSetupDialogBase
{
public:
- wxQtPageSetupDialog();
- wxQtPageSetupDialog(wxWindow *parent, wxPageSetupDialogData *data = nullptr);
+ wxQtPageSetupDialog() = default;
+ explicit wxQtPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data = nullptr);
- bool Create(wxWindow *parent, wxPageSetupDialogData *data = nullptr);
+ virtual int ShowModal() override;
- virtual wxPageSetupDialogData& GetPageSetupDialogData() override;
+ virtual wxPageSetupDialogData& GetPageSetupDialogData() override { return m_pageSetupData; }
private:
+ wxWindow* m_dialogParent = nullptr;
+ wxPageSetupDialogData m_pageSetupData;
+
+ wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxQtPageSetupDialog);
};
#endif // _WX_QT_PRINTDLG_H_
=====================================
include/wx/qt/printqt.h
=====================================
@@ -10,33 +10,44 @@
#include "wx/prntbase.h"
+// ---------------------------------------------------------------------------
+// Represents the printer: manages printing a wxPrintout object
+// ---------------------------------------------------------------------------
+
class WXDLLIMPEXP_CORE wxQtPrinter : public wxPrinterBase
{
public:
- explicit wxQtPrinter( wxPrintDialogData *data = nullptr );
+ explicit wxQtPrinter(wxPrintDialogData* data = nullptr);
+
+ virtual bool Setup(wxWindow* parent) override;
+ virtual bool Print(wxWindow* parent, wxPrintout* printout, bool prompt = true) override;
+ virtual wxDC* PrintDialog(wxWindow* parent) override;
- virtual bool Setup(wxWindow *parent) override;
- virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = true) override;
- virtual wxDC* PrintDialog(wxWindow *parent) override;
private:
+ wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxQtPrinter);
};
+// ---------------------------------------------------------------------------
+// wxPrintPreview: programmer creates an object of this class to preview a
+// wxPrintout.
+// ---------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxQtPrintPreview : public wxPrintPreviewBase
{
public:
- wxQtPrintPreview(wxPrintout *printout,
- wxPrintout *printoutForPrinting = nullptr,
- wxPrintDialogData *data = nullptr);
- wxQtPrintPreview(wxPrintout *printout,
- wxPrintout *printoutForPrinting,
- wxPrintData *data);
+ wxQtPrintPreview(wxPrintout* printout,
+ wxPrintout* printoutForPrinting = nullptr,
+ wxPrintDialogData* data = nullptr);
+ wxQtPrintPreview(wxPrintout* printout,
+ wxPrintout* printoutForPrinting,
+ wxPrintData* data);
virtual bool Print(bool interactive) override;
virtual void DetermineScaling() override;
protected:
+ wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxQtPrintPreview);
};
#endif // _WX_QT_PRINTQT_H_
=====================================
interface/wx/platinfo.h
=====================================
@@ -120,8 +120,7 @@ enum wxEndianness
};
/**
- A structure containing information about a Linux distribution as returned
- by the @c lsb_release utility.
+ A structure containing information about a Linux distribution.
See wxGetLinuxDistributionInfo() or wxPlatformInfo::GetLinuxDistributionInfo()
for more info.
=====================================
interface/wx/utils.h
=====================================
@@ -1067,13 +1067,8 @@ wxString wxGetNativeCpuArchitectureName();
Returns a structure containing information about the currently running
Linux distribution.
- This function uses the @c lsb_release utility which is part of the
- <tt>Linux Standard Base Core</tt> specification
- (see
http://refspecs.linux-foundation.org/lsb.shtml) since the very first LSB
- release 1.0 (released in 2001).
- The @c lsb_release utility is very common on modern Linux distributions but in
- case it's not available, then this function will return a ::wxLinuxDistributionInfo
- structure containing empty strings.
+ In case such information cannot be obtained, this function will return
+ a ::wxLinuxDistributionInfo structure containing empty strings.
This function is Linux-specific and is only available when the @c \__LINUX__
symbol is defined.
=====================================
samples/toolbar/toolbar.cpp
=====================================
@@ -815,12 +815,12 @@ void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event))
m_tbar->SetMargins(4, 4);
- m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_1, "First", wxBITMAP_PNG(new));
- m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_2, "Second", wxBITMAP_PNG(open));
- m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_3, "Third", wxBITMAP_PNG(save));
+ m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_1, "First", wxBITMAP_BUNDLE_2(new));
+ m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_2, "Second", wxBITMAP_BUNDLE_2(open));
+ m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_3, "Third", wxBITMAP_BUNDLE_2(save));
m_tbar->AddSeparator();
- m_tbar->AddTool(wxID_HELP, "Help", wxBITMAP_PNG(help));
- m_tbar->AddTool(IDM_TOOLBAR_OTHER_4, "Disabled", wxBITMAP_PNG(cut), wxBITMAP_PNG(paste));
+ m_tbar->AddTool(wxID_HELP, "Help", wxBITMAP_BUNDLE_2(help));
+ m_tbar->AddTool(IDM_TOOLBAR_OTHER_4, "Disabled", wxBITMAP_BUNDLE_2(cut), wxBITMAP_BUNDLE_2(paste));
m_tbar->EnableTool(IDM_TOOLBAR_OTHER_4, false);
m_tbar->Realize();
@@ -1068,7 +1068,7 @@ void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event))
wxToolBarBase *tb = GetToolBar();
tb->InsertTool(0, wxID_PRINT, "New print",
- wxBITMAP_PNG(print), wxNullBitmap,
+ wxBITMAP_BUNDLE_2(print), wxNullBitmap,
wxITEM_NORMAL,
"Delete this tool",
"This button was inserted into the toolbar");
=====================================
src/msw/treectrl.cpp
=====================================
@@ -1749,15 +1749,9 @@ void wxTreeCtrl::DeleteChildren(const wxTreeItemId& item)
Delete(children[n]);
}
- // Refresh to update the "+" button which otherwise can remain displayed
- // and also to refresh the area that used to be taken by the children:
- // without this, the last child of the control could remain visible after
- // being deleted, see #23719.
- //
- // We could compute the exact rect to refresh, but as we use double
- // buffering anyhow now, it doesn't make any visible difference to just
- // refresh the entire control.
- Refresh();
+ // Refresh update the "+" button which otherwise can remain displayed.
+ if ( !IsHiddenRoot(item) )
+ wxTreeView_RefreshItem(GetHwnd(), HITEM(item));
}
void wxTreeCtrl::DeleteAllItems()
@@ -1782,10 +1776,6 @@ void wxTreeCtrl::DeleteAllItems()
{
wxLogLastError(wxT("TreeView_DeleteAllItems"));
}
-
- // As in DeleteChildren() above, we need a refresh to get rid of the
- // phantom items remaining displayed when using double buffering.
- Refresh();
}
void wxTreeCtrl::DoExpand(const wxTreeItemId& item, int flag)
=====================================
src/propgrid/property.cpp
=====================================
@@ -159,25 +159,23 @@ int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPropert
if ( bmp.IsOk() )
{
int hMax = rect.height - wxPG_CUSTOM_IMAGE_SPACINGY;
- wxBitmap scaledBmp;
int yOfs;
if ( bmp.GetHeight() <= hMax )
{
- scaledBmp = bmp;
yOfs = (hMax - bmp.GetHeight()) / 2;
}
else
{
- double scale = (double)hMax / bmp.GetHeight();
- scaledBmp = wxPropertyGrid::RescaleBitmap(bmp, scale, scale);
+ int w = wxRound(bmp.GetWidth() * (double)hMax / bmp.GetHeight());
+ wxBitmap::Rescale(bmp, wxSize(w, hMax));
yOfs = 0;
}
- dc.DrawBitmap( scaledBmp,
+ dc.DrawBitmap( bmp,
rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
rect.y + wxPG_CUSTOM_IMAGE_SPACINGY + yOfs,
true );
- imageWidth = scaledBmp.GetWidth();
+ imageWidth = bmp.GetWidth();
}
return imageWidth;
@@ -1527,21 +1525,19 @@ void wxPGProperty::OnCustomPaint( wxDC& dc,
wxCHECK_RET( m_valueBitmapBundle.IsOk(), wxS("invalid bitmap bundle") );
wxBitmap bmp = m_valueBitmapBundle.GetBitmapFor(paintData.m_parent);
- wxBitmap scaledBmp;
int yOfs;
if ( bmp.GetHeight() <= rect.height )
{
- scaledBmp = bmp;
yOfs = (rect.height - bmp.GetHeight()) / 2;
}
else
{
- double scale = (double)rect.height / bmp.GetHeight();
- scaledBmp = wxPropertyGrid::RescaleBitmap(bmp, scale, scale);
+ int w = wxRound(bmp.GetWidth() * (double)rect.height / bmp.GetHeight());
+ wxBitmap::Rescale(bmp, wxSize(w, rect.height));
yOfs = 0;
}
- dc.DrawBitmap(scaledBmp,rect.x, rect.y + yOfs);
+ dc.DrawBitmap(bmp, rect.x, rect.y + yOfs);
}
const wxPGEditor* wxPGProperty::DoGetEditorClass() const
=====================================
src/propgrid/propgrid.cpp
=====================================
@@ -1862,27 +1862,12 @@ bool wxPropertyGrid::IsSmallScreen()
wxBitmap wxPropertyGrid::RescaleBitmap(const wxBitmap& srcBmp,
double scaleX, double scaleY)
{
- int w = wxRound(srcBmp.GetWidth()*scaleX);
- int h = wxRound(srcBmp.GetHeight()*scaleY);
-
-#if wxUSE_IMAGE
- // Here we use high-quality wxImage scaling functions available
- wxImage img = srcBmp.ConvertToImage();
- img.Rescale(w, h, wxIMAGE_QUALITY_HIGH);
- wxBitmap dstBmp(img);
-#else // !wxUSE_IMAGE
- wxBitmap dstBmp(w, h, srcBmp.GetDepth());
-#if defined(__WXMSW__) || defined(__WXOSX__)
- // wxBitmap::UseAlpha() is used only on wxMSW and wxOSX.
- dstBmp.UseAlpha(srcBmp.HasAlpha());
-#endif // __WXMSW__ || __WXOSX__
- {
- wxMemoryDC dc(dstBmp);
- dc.SetUserScale(scaleX, scaleY);
- dc.DrawBitmap(srcBmp, 0, 0);
- }
-#endif // wxUSE_IMAGE/!wxUSE_IMAGE
+ wxSize size = srcBmp.GetSize();
+ size.x = wxRound(size.x * scaleX);
+ size.y = wxRound(size.y * scaleY);
+ wxBitmap dstBmp(srcBmp);
+ wxBitmap::Rescale(dstBmp, size);
return dstBmp;
}
=====================================
src/qt/dcprint.cpp
=====================================
@@ -12,192 +12,115 @@
#include "wx/dcprint.h"
#include "wx/qt/dcprint.h"
+#include "wx/qt/printdlg.h"
+#include "wx/qt/private/converter.h"
-wxIMPLEMENT_CLASS(wxPrinterDCImpl,wxDCImpl)
+#include <QtGui/QPainter>
-wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC *owner, const wxPrintData & )
- : wxDCImpl( owner )
-{
-}
-
-
-bool wxPrinterDCImpl::CanDrawBitmap() const
-{
- return false;
-}
-
-bool wxPrinterDCImpl::CanGetTextExtent() const
-{
- return false;
-}
-
-void wxPrinterDCImpl::DoGetSize(int *WXUNUSED(width), int *WXUNUSED(height)) const
-{
-}
-
-void wxPrinterDCImpl::DoGetSizeMM(int* WXUNUSED(width), int* WXUNUSED(height)) const
-{
-}
-
-int wxPrinterDCImpl::GetDepth() const
-{
- return 0;
-}
-
-wxSize wxPrinterDCImpl::GetPPI() const
-{
- return wxSize();
-}
-
-void wxPrinterDCImpl::SetFont(const wxFont& WXUNUSED(font))
-{
-}
-
-void wxPrinterDCImpl::SetPen(const wxPen& WXUNUSED(pen))
-{
-}
-
-void wxPrinterDCImpl::SetBrush(const wxBrush& WXUNUSED(brush))
-{
-}
-
-void wxPrinterDCImpl::SetBackground(const wxBrush& WXUNUSED(brush))
-{
-}
-
-void wxPrinterDCImpl::SetBackgroundMode(int WXUNUSED(mode))
-{
-}
-
-
-#if wxUSE_PALETTE
-void wxPrinterDCImpl::SetPalette(const wxPalette& WXUNUSED(palette))
-{
-}
-#endif // wxUSE_PALETTE
-
-void wxPrinterDCImpl::SetLogicalFunction(wxRasterOperationMode WXUNUSED(function))
-{
-}
-
-wxCoord wxPrinterDCImpl::GetCharHeight() const
-{
- return wxCoord();
-}
+#include <QPrinter>
-wxCoord wxPrinterDCImpl::GetCharWidth() const
-{
- return wxCoord();
-}
+wxIMPLEMENT_ABSTRACT_CLASS(wxPrinterDCImpl, wxQtDCImpl)
-void wxPrinterDCImpl::DoGetTextExtent(const wxString& WXUNUSED(string),
- wxCoord *WXUNUSED(x), wxCoord *WXUNUSED(y),
- wxCoord *WXUNUSED(descent),
- wxCoord *WXUNUSED(externalLeading),
- const wxFont *WXUNUSED(theFont) ) const
+wxPrinterDCImpl::wxPrinterDCImpl(wxPrinterDC* owner, const wxPrintData& data)
+ : wxQtDCImpl(owner)
+ , m_printData(data)
{
-}
+ if ( m_printData.IsOk() )
+ {
+ auto* nativeData =
+ static_cast<wxQtPrintNativeData*>(m_printData.GetNativeData());
-void wxPrinterDCImpl::Clear()
-{
-}
+ m_qtPrinter = nativeData->GetQtPrinter();
+ m_qtPainter = new QPainter();
-void wxPrinterDCImpl::DoSetClippingRegion(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
- wxCoord WXUNUSED(width), wxCoord WXUNUSED(height))
-{
+ m_ok = m_qtPainter->begin(m_qtPrinter);
+ }
}
-void wxPrinterDCImpl::DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region))
-{
-}
+wxPrinterDCImpl::~wxPrinterDCImpl() = default;
-bool wxPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxColour& WXUNUSED(col),
- wxFloodFillStyle WXUNUSED(style) )
+wxRect wxPrinterDCImpl::GetPaperRect() const
{
- return false;
-}
+ if ( !IsOk() )
+ {
+ return wxRect{};
+ }
-bool wxPrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col)) const
-{
- return false;
+ return wxQtConvertRect(m_qtPrinter->paperRect(QPrinter::DevicePixel).toRect());
}
-void wxPrinterDCImpl::DoDrawPoint(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
+int wxPrinterDCImpl::GetResolution() const
{
-}
+ if ( IsOk() )
+ {
+ return m_qtPrinter->resolution();
+ }
-void wxPrinterDCImpl::DoDrawLine(wxCoord WXUNUSED(x1), wxCoord WXUNUSED(y1), wxCoord WXUNUSED(x2), wxCoord WXUNUSED(y2))
-{
+ return wxQtDCImpl::GetResolution();
}
-void wxPrinterDCImpl::DoDrawArc(wxCoord WXUNUSED(x1), wxCoord WXUNUSED(y1),
- wxCoord WXUNUSED(x2), wxCoord WXUNUSED(y2),
- wxCoord WXUNUSED(xc), wxCoord WXUNUSED(yc))
+wxSize wxPrinterDCImpl::GetPPI() const
{
-}
+ if ( IsOk() )
+ {
+ return wxSize(m_qtPrinter->logicalDpiX(),
+ m_qtPrinter->logicalDpiY());
+ }
-void wxPrinterDCImpl::DoDrawEllipticArc(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxCoord WXUNUSED(w), wxCoord WXUNUSED(h),
- double WXUNUSED(sa), double WXUNUSED(ea))
-{
+ return wxQtDCImpl::GetPPI();
}
-void wxPrinterDCImpl::DoDrawRectangle(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxCoord WXUNUSED(width), wxCoord WXUNUSED(height))
+void wxPrinterDCImpl::DoGetSize(int* width, int* height) const
{
-}
+ const int w = m_qtPrinter ? m_qtPrinter->width() : 0;
+ const int h = m_qtPrinter ? m_qtPrinter->height() : 0;
-void wxPrinterDCImpl::DoDrawRoundedRectangle(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
- wxCoord WXUNUSED(width), wxCoord WXUNUSED(height),
- double WXUNUSED(radius))
-{
+ if ( width )
+ *width = w;
+ if ( height )
+ *height = h;
}
-void wxPrinterDCImpl::DoDrawEllipse(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
- wxCoord WXUNUSED(width), wxCoord WXUNUSED(height))
+void wxPrinterDCImpl::DoGetSizeMM(int* width, int* height) const
{
-}
+ const int w = m_qtPrinter ? m_qtPrinter->widthMM() : 0;
+ const int h = m_qtPrinter ? m_qtPrinter->heightMM() : 0;
-void wxPrinterDCImpl::DoCrossHair(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
-{
+ if ( width )
+ *width = w;
+ if ( height )
+ *height = h;
}
-void wxPrinterDCImpl::DoDrawIcon(const wxIcon& WXUNUSED(icon), wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
+bool wxPrinterDCImpl::StartDoc(const wxString& message)
{
-}
+ if ( m_ok )
+ {
+ // Commented out because Qt doesn't allow us to change the document name
+ // after calling m_qtPainter->begin(m_qtPrinter) and logs this message:
+ // 'QPrinter::setDocName: Cannot be changed while printer is active'
-void wxPrinterDCImpl::DoDrawBitmap(const wxBitmap &WXUNUSED(bmp), wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
- bool WXUNUSED(useMask))
-{
-}
+ // m_qtPrinter->setDocName(wxQtConvertString(message));
-void wxPrinterDCImpl::DoDrawText(const wxString& WXUNUSED(text), wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
-{
-}
+ wxUnusedVar(message);
+ }
-void wxPrinterDCImpl::DoDrawRotatedText(const wxString& WXUNUSED(text),
- wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), double WXUNUSED(angle))
-{
+ return m_ok;
}
-bool wxPrinterDCImpl::DoBlit(wxCoord WXUNUSED(xdest), wxCoord WXUNUSED(ydest),
- wxCoord WXUNUSED(width), wxCoord WXUNUSED(height),
- wxDC *WXUNUSED(source),
- wxCoord WXUNUSED(xsrc), wxCoord WXUNUSED(ysrc),
- wxRasterOperationMode WXUNUSED(rop),
- bool WXUNUSED(useMask),
- wxCoord WXUNUSED(xsrcMask),
- wxCoord WXUNUSED(ysrcMask))
+void wxPrinterDCImpl::EndDoc()
{
- return false;
+ if ( m_ok )
+ {
+ m_qtPainter->end();
+ }
}
-void wxPrinterDCImpl::DoDrawLines(int WXUNUSED(n), const wxPoint WXUNUSED(points)[],
- wxCoord WXUNUSED(xoffset), wxCoord WXUNUSED(yoffset) )
+void wxPrinterDCImpl::StartPage()
{
}
-void wxPrinterDCImpl::DoDrawPolygon(int WXUNUSED(n), const wxPoint WXUNUSED(points)[],
- wxCoord WXUNUSED(xoffset), wxCoord WXUNUSED(yoffset),
- wxPolygonFillMode WXUNUSED(fillStyle) )
+void wxPrinterDCImpl::EndPage()
{
}
=====================================
src/qt/printdlg.cpp
=====================================
@@ -10,77 +10,400 @@
#if wxUSE_PRINTING_ARCHITECTURE
+#include "wx/display.h"
+#include "wx/modalhook.h"
+#include "wx/paper.h"
+#include "wx/qt/dcprint.h"
#include "wx/qt/printdlg.h"
+#include "wx/qt/private/converter.h"
-wxQtPrintNativeData::wxQtPrintNativeData()
+#include <QPrinter>
+#include <QPrinterInfo>
+#include <QPrintDialog>
+#include <QPageSetupDialog>
+#include <QPageSize>
+
+
+namespace // anonymous
+{
+QPrinter::DuplexMode ConvertDuplexMode(wxDuplexMode wxmode)
{
+ switch (wxmode)
+ {
+ case wxDUPLEX_SIMPLEX: return QPrinter::DuplexNone;
+ case wxDUPLEX_HORIZONTAL: return QPrinter::DuplexLongSide;
+ case wxDUPLEX_VERTICAL: return QPrinter::DuplexShortSide;
+ default:
+ wxFAIL_MSG("Unknown wxDuplexMode wxmode");
+ }
+
+ return QPrinter::DuplexNone;
}
-bool wxQtPrintNativeData::TransferTo( wxPrintData &WXUNUSED(data) )
+wxDuplexMode ConvertDuplexMode(QPrinter::DuplexMode qtmode)
{
- return false;
+ switch (qtmode)
+ {
+ case QPrinter::DuplexNone: return wxDUPLEX_SIMPLEX;
+ case QPrinter::DuplexLongSide: return wxDUPLEX_HORIZONTAL;
+ case QPrinter::DuplexShortSide: return wxDUPLEX_VERTICAL;
+ default:
+ wxFAIL_MSG("Unknown QPrinter::DuplexMode qtmode");
+ }
+
+ return wxDUPLEX_SIMPLEX;
}
-bool wxQtPrintNativeData::TransferFrom( const wxPrintData &WXUNUSED(data) )
+QPrinter::PaperSource ConvertBin(wxPrintBin wxsource)
{
- return false;
+ switch (wxsource)
+ {
+ case wxPRINTBIN_ONLYONE: return QPrinter::OnlyOne;
+ case wxPRINTBIN_LOWER: return QPrinter::Lower;
+ case wxPRINTBIN_MIDDLE: return QPrinter::Middle;
+ case wxPRINTBIN_MANUAL: return QPrinter::Manual;
+ case wxPRINTBIN_ENVELOPE: return QPrinter::Envelope;
+ case wxPRINTBIN_ENVMANUAL: return QPrinter::EnvelopeManual;
+ case wxPRINTBIN_AUTO: return QPrinter::Auto;
+ case wxPRINTBIN_TRACTOR: return QPrinter::Tractor;
+ case wxPRINTBIN_SMALLFMT: return QPrinter::SmallFormat;
+ case wxPRINTBIN_LARGEFMT: return QPrinter::LargeFormat;
+ case wxPRINTBIN_LARGECAPACITY: return QPrinter::LargeCapacity;
+ case wxPRINTBIN_CASSETTE: return QPrinter::Cassette;
+ case wxPRINTBIN_FORMSOURCE: return QPrinter::FormSource;
+ case wxPRINTBIN_DEFAULT: wxFALLTHROUGH;
+ case wxPRINTBIN_USER: return QPrinter::CustomSource;
+ default:
+ wxFAIL_MSG("Unknown wxPrintBin wxsource");
+ }
+
+ return QPrinter::CustomSource;
}
-bool wxQtPrintNativeData::IsOk() const
+wxPrintBin ConvertBin(QPrinter::PaperSource qtsource)
{
- return false;
+ switch (qtsource)
+ {
+ case QPrinter::OnlyOne: return wxPRINTBIN_ONLYONE;
+ case QPrinter::Lower: return wxPRINTBIN_LOWER;
+ case QPrinter::Middle: return wxPRINTBIN_MIDDLE;
+ case QPrinter::Manual: return wxPRINTBIN_MANUAL;
+ case QPrinter::Envelope: return wxPRINTBIN_ENVELOPE;
+ case QPrinter::EnvelopeManual: return wxPRINTBIN_ENVMANUAL;
+ case QPrinter::Auto: return wxPRINTBIN_AUTO;
+ case QPrinter::Tractor: return wxPRINTBIN_TRACTOR;
+ case QPrinter::SmallFormat: return wxPRINTBIN_SMALLFMT;
+ case QPrinter::LargeFormat: return wxPRINTBIN_LARGEFMT;
+ case QPrinter::LargeCapacity: return wxPRINTBIN_LARGECAPACITY;
+ case QPrinter::Cassette: return wxPRINTBIN_CASSETTE;
+ case QPrinter::FormSource: return wxPRINTBIN_FORMSOURCE;
+ case QPrinter::CustomSource: return wxPRINTBIN_USER;
+ default:
+ wxFAIL_MSG("Unknown QPrinter::PaperSource qtsource");
+ }
+
+ return wxPRINTBIN_DEFAULT;
}
-//##############################################################################
+void ConvertPageSize(const wxPrintData& data, QPrinter* qtPrinter)
+{
+ QPageSize qtPageSize;
-wxQtPrintDialog::wxQtPrintDialog(wxWindow *WXUNUSED(parent), wxPrintDialogData *WXUNUSED(data))
+ if ( data.GetPaperId() != wxPAPER_NONE )
+ {
+ const wxSize size = wxThePrintPaperDatabase->GetSize(data.GetPaperId()) / 10;
+
+ const auto pageSizeId = QPageSize::id(wxQtConvertSize(size), QPageSize::Millimeter);
+
+ qtPageSize = QPageSize(pageSizeId);
+ }
+ else // custom paper size
+ {
+ const wxSize size = data.GetPaperSize() / 10;
+
+ if ( size.GetWidth() > 0 && size.GetHeight() > 0 )
+ {
+ qtPageSize = QPageSize(wxQtConvertSize(size), QPageSize::Millimeter);
+ }
+ }
+
+ if ( !qtPageSize.isValid() )
+ {
+ QPrinterInfo printerInfo(*qtPrinter);
+
+ qtPageSize = printerInfo.defaultPageSize();
+ }
+
+ qtPrinter->setPageSize(qtPageSize);
+}
+
+void ConvertPageSize(const QPrinter* qtPrinter, wxPrintData& data)
{
+ const auto qtPageSize = qtPrinter->pageLayout().pageSize();
+ const auto qtSize = qtPageSize.size(QPageSize::Millimeter).toSize() * 10;
+ const wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxQtConvertSize(qtSize));
+
+ data.SetPaperId(id);
+ data.SetPaperSize(wxQtConvertSize(qtSize));
}
+} // anonymous namespace
+
+wxIMPLEMENT_CLASS(wxQtPrintNativeData, wxPrintNativeDataBase);
-wxQtPrintDialog::wxQtPrintDialog(wxWindow *WXUNUSED(parent), wxPrintData *WXUNUSED(data))
+wxQtPrintNativeData::wxQtPrintNativeData() = default;
+wxQtPrintNativeData::~wxQtPrintNativeData() = default;
+
+bool wxQtPrintNativeData::TransferTo(wxPrintData& data)
{
+ if ( !m_qtPrinter )
+ {
+ m_qtPrinter.reset(new QPrinter());
+ }
+
+ data.SetPrinterName(wxQtConvertString(m_qtPrinter->printerName()));
+ data.SetFilename(wxQtConvertString(m_qtPrinter->outputFileName()));
+ data.SetColour(m_qtPrinter->colorMode() == QPrinter::Color);
+ data.SetDuplex(ConvertDuplexMode(m_qtPrinter->duplex()));
+ data.SetNoCopies(m_qtPrinter->copyCount());
+ data.SetCollate(m_qtPrinter->collateCopies());
+ data.SetBin(ConvertBin(m_qtPrinter->paperSource()));
+
+ const wxPrintOrientation orientation =
+ m_qtPrinter->pageLayout().orientation() == QPageLayout::Portrait
+ ? wxPORTRAIT : wxLANDSCAPE;
+ data.SetOrientation(orientation);
+
+ ConvertPageSize(GetQtPrinter(), data);
+
+ return true;
}
+bool wxQtPrintNativeData::TransferFrom(const wxPrintData& data)
+{
+ const QPrinter::PrinterMode mode = data.GetQuality() == wxPRINT_QUALITY_HIGH
+ ? QPrinter::HighResolution
+ : QPrinter::ScreenResolution;
+
+ m_qtPrinter.reset(new QPrinter(mode));
+
+ m_qtPrinter->setPrinterName(wxQtConvertString(data.GetPrinterName()));
+ m_qtPrinter->setOutputFileName(wxQtConvertString(data.GetFilename()));
+ m_qtPrinter->setColorMode(data.GetColour() ? QPrinter::Color : QPrinter::GrayScale);
+ m_qtPrinter->setDuplex(ConvertDuplexMode(data.GetDuplex()));
+ m_qtPrinter->setCopyCount(data.GetNoCopies());
+ m_qtPrinter->setCollateCopies(data.GetCollate());
+ m_qtPrinter->setPaperSource(ConvertBin(data.GetBin()));
+ m_qtPrinter->setResolution(wxDisplay::GetStdPPIValue());
+
+ const QPageLayout::Orientation orientation =
+ data.GetOrientation() == wxPORTRAIT
+ ? QPageLayout::Portrait
+ : QPageLayout::Landscape;
+
+ m_qtPrinter->setPageOrientation(orientation);
+
+ ConvertPageSize(data, GetQtPrinter());
+
+ return true;
+}
+
+bool wxQtPrintNativeData::IsOk() const
+{
+ return m_qtPrinter && m_qtPrinter->isValid();
+}
+
+//##############################################################################
+
+namespace // anonymous
+{
+// ConvertToNative/ConvertFromNative for wxQtPrintDialog.
+bool ConvertToNative(wxPrintDialogData& printData, QPrintDialog* printDialog = nullptr)
+{
+ if ( !printDialog )
+ {
+ printData.GetPrintData().ConvertToNative();
+ }
+ else
+ {
+ QAbstractPrintDialog::PrintDialogOptions options;
+
+ if ( printData.GetCollate() )
+ options |= QAbstractPrintDialog::PrintCollateCopies;
+ if ( printData.GetEnablePrintToFile() )
+ options |= QAbstractPrintDialog::PrintToFile;
+ if ( printData.GetEnableSelection() )
+ options |= QAbstractPrintDialog::PrintSelection;
+ if ( printData.GetEnableCurrentPage() )
+ options |= QAbstractPrintDialog::PrintCurrentPage;
+ if ( printData.GetEnablePageNumbers() )
+ options |= QAbstractPrintDialog::PrintPageRange;
+ // TODO: Add GetEnableShowPageSize() to wxPrintDialogData
+ // if ( printData.GetEnableShowPageSize() )
+ // options |= QAbstractPrintDialog::PrintShowPageSize;
+
+ printDialog->setOptions(options);
+
+ printDialog->setMinMax(printData.GetMinPage(),
+ printData.GetMaxPage());
+ printDialog->setFromTo(printData.GetFromPage(),
+ printData.GetToPage());
+
+ QAbstractPrintDialog::PrintRange printRange = QAbstractPrintDialog::AllPages;
+
+ if ( printData.GetSelection() )
+ printRange = QAbstractPrintDialog::Selection;
+ else if ( printData.GetCurrentPage() )
+ printRange = QAbstractPrintDialog::CurrentPage;
+ else if ( printData.GetSpecifiedPages() )
+ printRange = QAbstractPrintDialog::PageRange;
+
+ printDialog->setPrintRange(printRange);
+ }
+
+ return true;
+}
-wxPrintDialogData& wxQtPrintDialog::GetPrintDialogData()
+bool ConvertFromNative(wxPrintDialogData& printData, QPrintDialog* printDialog = nullptr)
{
- static wxPrintDialogData s_data;
+ printData.GetPrintData().ConvertFromNative();
+
+ if ( printDialog )
+ {
+ printData.SetMinPage(printDialog->minPage());
+ printData.SetMaxPage(printDialog->maxPage());
+ printData.SetFromPage(printDialog->fromPage());
+ printData.SetToPage(printDialog->toPage());
+
+ auto printRange = printDialog->printRange();
- return s_data;
+ printData.SetAllPages(printRange == QAbstractPrintDialog::AllPages);
+ printData.SetSelection(printRange == QAbstractPrintDialog::Selection);
+ printData.SetCurrentPage(printRange == QAbstractPrintDialog::CurrentPage);
+ // TODO: Add SetSpecifiedPages() to wxPrintDialogData
+ // printData.SetSpecifiedPages(printRange == QAbstractPrintDialog::PageRange);
+ }
+
+ return true;
}
-wxPrintData& wxQtPrintDialog::GetPrintData()
+// ConvertToNative/ConvertFromNative for wxQtPageSetupDialog.
+bool ConvertToNative(wxPageSetupDialogData& setupData)
{
- static wxPrintData s_data;
+ auto& data = setupData.GetPrintData();
+ data.ConvertToNative();
+
+ auto* nativeData = static_cast<wxQtPrintNativeData*>(data.GetNativeData());
+ auto* qtPrinter = nativeData->GetQtPrinter();
- return s_data;
+ const wxRealPoint minTopLeft = setupData.GetMinMarginTopLeft();
+ const wxRealPoint minBottomRight = setupData.GetMinMarginBottomRight();
+ const wxRealPoint topLeft = setupData.GetMarginTopLeft();
+ const wxRealPoint bottomRight = setupData.GetMarginBottomRight();
+
+ QPageLayout pageLayout = qtPrinter->pageLayout();
+ pageLayout.setUnits(QPageLayout::Millimeter);
+ pageLayout.setMargins(QMarginsF{topLeft.x, topLeft.y, bottomRight.x, bottomRight.y});
+ pageLayout.setMinimumMargins(QMarginsF{minTopLeft.x, minTopLeft.y, minBottomRight.x, minBottomRight.y});
+
+ return qtPrinter->setPageLayout(pageLayout);
}
-wxDC *wxQtPrintDialog::GetPrintDC()
+bool ConvertFromNative(wxPageSetupDialogData& setupData)
{
- return nullptr;
+ auto& data = setupData.GetPrintData();
+ data.ConvertFromNative();
+
+ auto* nativeData = static_cast<wxQtPrintNativeData*>(data.GetNativeData());
+ auto* qtPrinter = nativeData->GetQtPrinter();
+
+ QPageLayout pageLayout = qtPrinter->pageLayout();
+ pageLayout.setUnits(QPageLayout::Millimeter);
+
+ const auto margins = pageLayout.margins();
+ const auto minMargins = pageLayout.minimumMargins();
+
+ setupData.SetMarginTopLeft(wxPoint(margins.left(), margins.top()));
+ setupData.SetMarginBottomRight(wxPoint(margins.right(), margins.bottom()));
+ setupData.SetMinMarginTopLeft(wxPoint(minMargins.left(), minMargins.top()));
+ setupData.SetMinMarginBottomRight(wxPoint(minMargins.right(), minMargins.bottom()));
+
+ return true;
}
+} // anonymous namespace
//##############################################################################
+wxIMPLEMENT_CLASS(wxQtPrintDialog, wxPrintDialogBase);
-wxQtPageSetupDialog::wxQtPageSetupDialog()
+wxQtPrintDialog::wxQtPrintDialog(wxWindow* parent, wxPrintDialogData* data)
+ : m_dialogParent(parent), m_printDialogData(*data)
{
}
-wxQtPageSetupDialog::wxQtPageSetupDialog(wxWindow *WXUNUSED(parent), wxPageSetupDialogData *WXUNUSED(data))
+wxQtPrintDialog::wxQtPrintDialog(wxWindow* parent, wxPrintData* data)
+ : m_dialogParent(parent), m_printDialogData(*data)
{
}
-bool wxQtPageSetupDialog::Create(wxWindow *WXUNUSED(parent), wxPageSetupDialogData *WXUNUSED(data))
+int wxQtPrintDialog::ShowModal()
{
- return false;
+ WX_HOOK_MODAL_DIALOG();
+
+ ConvertToNative( m_printDialogData );
+
+ auto& data = GetPrintData();
+ auto* nativeData = static_cast<wxQtPrintNativeData*>(data.GetNativeData());
+ auto* qtPrinter = nativeData->GetQtPrinter();
+
+ QPrintDialog printDialog(qtPrinter, m_dialogParent->GetHandle());
+
+ ConvertToNative( m_printDialogData, &printDialog );
+
+ if ( printDialog.exec() == QDialog::Accepted )
+ {
+ ConvertFromNative( m_printDialogData, &printDialog );
+
+ m_printerDC = new wxPrinterDC(data);
+
+ return wxID_OK;
+ }
+ else
+ {
+ return wxID_CANCEL;
+ }
}
-wxPageSetupDialogData& wxQtPageSetupDialog::GetPageSetupDialogData()
+wxDC* wxQtPrintDialog::GetPrintDC() { return m_printerDC; }
+
+//##############################################################################
+wxIMPLEMENT_CLASS(wxQtPageSetupDialog, wxPageSetupDialogBase);
+
+wxQtPageSetupDialog::wxQtPageSetupDialog(wxWindow* parent, wxPageSetupDialogData* data)
+ : m_dialogParent(parent), m_pageSetupData(*data)
+{
+}
+
+int wxQtPageSetupDialog::ShowModal()
{
- static wxPageSetupDialogData s_data;
+ WX_HOOK_MODAL_DIALOG();
+
+ ConvertToNative( m_pageSetupData );
+
+ auto& data = m_pageSetupData.GetPrintData();
+ auto* nativeData = static_cast<wxQtPrintNativeData*>(data.GetNativeData());
+ auto* qtPrinter = nativeData->GetQtPrinter();
+
+ QPageSetupDialog pageSetupDialog(qtPrinter, m_dialogParent->GetHandle());
+
+ if ( pageSetupDialog.exec() == QDialog::Accepted )
+ {
+ ConvertFromNative( m_pageSetupData );
- return s_data;
+ return wxID_OK;
+ }
+ else
+ {
+ return wxID_CANCEL;
+ }
}
#endif // wxUSE_PRINTING_ARCHITECTURE
=====================================
src/qt/printqt.cpp
=====================================
@@ -10,50 +10,265 @@
#if wxUSE_PRINTING_ARCHITECTURE
+#include "wx/log.h"
+#include "wx/display.h"
#include "wx/print.h"
+#include "wx/qt/dcprint.h"
+#include "wx/qt/printdlg.h"
+#include "wx/private/print.h"
-wxQtPrinter::wxQtPrinter( wxPrintDialogData *WXUNUSED(data))
+#include <QPrinter>
+
+wxIMPLEMENT_DYNAMIC_CLASS(wxQtPrinter, wxPrinterBase);
+
+wxQtPrinter::wxQtPrinter(wxPrintDialogData* data)
+ : wxPrinterBase(data)
{
}
-bool wxQtPrinter::Setup(wxWindow *WXUNUSED(parent))
+bool wxQtPrinter::Setup(wxWindow* WXUNUSED(parent))
{
return false;
}
-bool wxQtPrinter::Print(wxWindow *WXUNUSED(parent), wxPrintout *WXUNUSED(printout), bool WXUNUSED(prompt))
+bool wxQtPrinter::Print(wxWindow* parent, wxPrintout* printout, bool prompt)
{
- return false;
+ if ( !printout )
+ {
+ sm_lastError = wxPRINTER_ERROR;
+
+ return false;
+ }
+
+ if ( m_printDialogData.GetMinPage() < 1 )
+ m_printDialogData.SetMinPage(1);
+
+ if ( m_printDialogData.GetMaxPage() < 1 )
+ m_printDialogData.SetMaxPage(9999);
+
+ // Create a suitable device context
+ std::unique_ptr<wxPrinterDC> dc;
+
+ if ( prompt )
+ dc.reset(wxDynamicCast(PrintDialog(parent), wxPrinterDC));
+ else
+ dc.reset(new wxPrinterDC(m_printDialogData.GetPrintData()));
+
+ // May have pressed cancel.
+ if ( !dc || !dc->IsOk() )
+ {
+ return false;
+ }
+
+ // Set printout parameters
+ if ( !printout->SetUp(*dc) )
+ {
+ sm_lastError = wxPRINTER_ERROR;
+
+ return false;
+ }
+
+ wxBusyCursor busyCursor;
+
+ printout->OnPreparePrinting();
+
+ // Initialize page ranges with the value from the dialog, but then allow
+ // the printout to customize them.
+ std::vector<wxPrintPageRange> pageRanges;
+
+ if ( m_printDialogData.GetSpecifiedPages() )
+ pageRanges = m_printDialogData.GetPageRanges();
+
+ const wxPrintPageRange allPages = printout->GetPagesInfo(pageRanges);
+
+ if ( !allPages.IsValid() )
+ {
+ sm_lastError = wxPRINTER_ERROR;
+ return false;
+ }
+
+ if ( pageRanges.empty() )
+ {
+ // Not having any ranges to print is equivalent to printing all pages.
+ pageRanges.push_back(allPages);
+ }
+
+ // Only set min and max, because from and to have been
+ // set by the user
+ m_printDialogData.SetMinPage(allPages.fromPage);
+ m_printDialogData.SetMaxPage(allPages.toPage);
+
+ wxPrintingGuard guard(printout);
+
+ sm_lastError = wxPRINTER_NO_ERROR;
+
+ auto* const impl = static_cast<wxPrinterDCImpl*>(dc->GetImpl());
+ auto* const qtPrinter = impl->GetQtPrinter();
+
+ // The dc we get from the PrintDialog will do multiple copies without help
+ // if the device supports it. Loop only if we have created a dc from our
+ // own m_printDialogData or the device does not support multiple copies.
+ // m_printDialogData.GetPrintData().GetNoCopies() is set from device
+ // m_qtPrinter in printdlg.cpp/wxQtPrintNativeData::TransferTo()
+ const int maxCopyCount = !prompt ||
+ !m_printDialogData.GetPrintData().GetNoCopies()
+ ? m_printDialogData.GetNoCopies() : 1;
+ for ( int copyCount = 1; copyCount <= maxCopyCount; ++copyCount )
+ {
+ if ( !printout->OnBeginDocument(allPages.fromPage, allPages.toPage) )
+ {
+ QPrinter::PrinterState state = qtPrinter->printerState();
+
+ if ( state == QPrinter::Aborted )
+ {
+ // No need to log an error if printing was cancelled by user.
+ sm_lastError = wxPRINTER_CANCELLED;
+ }
+ else
+ {
+ sm_lastError = wxPRINTER_ERROR;
+
+ wxLogError(_("Could not start printing."));
+ }
+ break;
+ }
+
+ int numPrinted = 0;
+
+ for ( const wxPrintPageRange& range : pageRanges )
+ {
+ for ( int pn = range.fromPage; pn <= range.toPage; ++pn )
+ {
+ if ( !printout->HasPage(pn) )
+ continue;
+
+ if ( ++numPrinted > 1 )
+ {
+ if ( !qtPrinter->newPage() )
+ {
+ sm_lastError = wxPRINTER_ERROR;
+ break;
+ }
+ }
+
+ wxPrintingPageGuard pageGuard(*dc);
+
+ if ( !printout->OnPrintPage(pn) )
+ {
+ sm_lastError = wxPRINTER_CANCELLED;
+ break;
+ }
+ }
+ }
+
+ printout->OnEndDocument();
+ }
+
+ return sm_lastError == wxPRINTER_NO_ERROR;
}
-wxDC* wxQtPrinter::PrintDialog(wxWindow *WXUNUSED(parent))
+wxDC* wxQtPrinter::PrintDialog(wxWindow* parent)
{
- return nullptr;
+ wxDC* dc = nullptr;
+
+ wxQtPrintDialog dialog(parent, &m_printDialogData);
+
+ if ( dialog.ShowModal() == wxID_OK )
+ {
+ dc = dialog.GetPrintDC();
+ m_printDialogData = dialog.GetPrintDialogData();
+
+ sm_lastError = dc != nullptr ? wxPRINTER_NO_ERROR : wxPRINTER_ERROR;
+ }
+ else
+ sm_lastError = wxPRINTER_CANCELLED;
+
+ return dc;
}
//##############################################################################
+wxIMPLEMENT_CLASS(wxQtPrintPreview, wxPrintPreviewBase);
-wxQtPrintPreview::wxQtPrintPreview(wxPrintout *printout,
- wxPrintout *printoutForPrinting,
- wxPrintDialogData *data)
- : wxPrintPreviewBase( printout, printoutForPrinting, data )
+wxQtPrintPreview::wxQtPrintPreview(wxPrintout* printout,
+ wxPrintout* printoutForPrinting,
+ wxPrintDialogData* data)
+ : wxPrintPreviewBase(printout, printoutForPrinting, data)
{
+ DetermineScaling();
}
-wxQtPrintPreview::wxQtPrintPreview(wxPrintout *printout,
- wxPrintout *printoutForPrinting,
- wxPrintData *data)
- : wxPrintPreviewBase( printout, printoutForPrinting, data )
+wxQtPrintPreview::wxQtPrintPreview(wxPrintout* printout,
+ wxPrintout* printoutForPrinting,
+ wxPrintData* data)
+ : wxPrintPreviewBase(printout, printoutForPrinting, data)
{
+ DetermineScaling();
}
-bool wxQtPrintPreview::Print(bool WXUNUSED(interactive))
+bool wxQtPrintPreview::Print(bool interactive)
{
- return false;
+ if ( !m_printPrintout )
+ return false;
+
+ wxQtPrinter printer(&m_printDialogData);
+ return printer.Print(m_previewFrame, m_printPrintout, interactive);
}
void wxQtPrintPreview::DetermineScaling()
{
+ const wxSize logPPIScreen = wxDisplay::GetStdPPI();
+ m_previewPrintout->SetPPIScreen(logPPIScreen);
+
+ // Get a device context for the currently selected printer
+ wxPrinterDC printerDC(m_printDialogData.GetPrintData());
+
+ int printerWidthMM;
+ int printerHeightMM;
+ int printerXRes;
+ int printerYRes;
+ wxSize logPPIPrinter;
+
+ wxRect paperRect;
+
+ if ( printerDC.IsOk() )
+ {
+ printerDC.GetSizeMM(&printerWidthMM, &printerHeightMM);
+ printerDC.GetSize(&printerXRes, &printerYRes);
+
+ logPPIPrinter = printerDC.GetPPI();
+
+ paperRect = printerDC.GetPaperRect();
+
+ if ( logPPIPrinter.x == 0 ||
+ logPPIPrinter.y == 0 ||
+ printerWidthMM == 0 ||
+ printerHeightMM == 0 )
+ {
+ m_isOk = false;
+ }
+ }
+ else
+ {
+ // use some defaults
+ printerWidthMM = 150;
+ printerHeightMM = 250;
+ printerXRes = 1500;
+ printerYRes = 2500;
+ logPPIPrinter = wxSize(600, 600);
+
+ paperRect = wxRect(0, 0, printerXRes, printerYRes);
+ }
+
+ m_pageWidth = printerXRes;
+ m_pageHeight = printerYRes;
+ m_previewPrintout->SetPageSizePixels(printerXRes, printerYRes);
+ m_previewPrintout->SetPageSizeMM(printerWidthMM, printerHeightMM);
+ m_previewPrintout->SetPaperRectPixels(paperRect);
+ m_previewPrintout->SetPPIPrinter(logPPIPrinter);
+
+ // At 100%, the page should look about page-size on the screen.
+ m_previewScaleX = float(logPPIScreen.x) / logPPIPrinter.x;
+ m_previewScaleY = float(logPPIScreen.y) / logPPIPrinter.y;
}
#endif // wxUSE_PRINTING_ARCHITECTURE
View it on GitLab:
https://gitlab.com/wxwidgets/wxwidgets/-/compare/b4f09add0115751cd8b3032f7ef25315a3fb2dba...84a8b816bbc71981586568f3ea0afb15127263d1
--
View it on GitLab:
https://gitlab.com/wxwidgets/wxwidgets/-/compare/b4f09add0115751cd8b3032f7ef25315a3fb2dba...84a8b816bbc71981586568f3ea0afb15127263d1
You're receiving this email because of your account on
gitlab.com.