Qt 4.8
qpagesetupdialog_win.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qpagesetupdialog.h"
43 
44 #ifndef QT_NO_PRINTDIALOG
45 #include <qapplication.h>
46 
47 #include <private/qprintengine_win_p.h>
48 #include <private/qabstractpagesetupdialog_p.h>
49 
51 
53 {
54 };
55 
57  : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
58 {
59 }
60 
63 {
64 }
65 
67 {
69 
70  if (d->printer->outputFormat() != QPrinter::NativeFormat)
71  return Rejected;
72 
73  QWin32PrintEngine *engine = static_cast<QWin32PrintEngine*>(d->printer->paintEngine());
74  QWin32PrintEnginePrivate *ep = static_cast<QWin32PrintEnginePrivate *>(engine->d_ptr.data());
75 
76  PAGESETUPDLG psd;
77  memset(&psd, 0, sizeof(PAGESETUPDLG));
78  psd.lStructSize = sizeof(PAGESETUPDLG);
79 
80  // we need a temp DEVMODE struct if we don't have a global DEVMODE
81  HGLOBAL hDevMode = 0;
82  int devModeSize = 0;
83  if (!ep->globalDevMode) {
84  devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra;
85  hDevMode = GlobalAlloc(GHND, devModeSize);
86  if (hDevMode) {
87  void *dest = GlobalLock(hDevMode);
88  memcpy(dest, ep->devMode, devModeSize);
89  GlobalUnlock(hDevMode);
90  }
91  psd.hDevMode = hDevMode;
92  } else {
93  psd.hDevMode = ep->devMode;
94  }
95 
96  HGLOBAL *tempDevNames = ep->createDevNames();
97  psd.hDevNames = tempDevNames;
98 
100  parent = parent ? parent->window() : QApplication::activeWindow();
101  Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
102  psd.hwndOwner = parent ? parent->winId() : 0;
103 
104  psd.Flags = PSD_MARGINS;
105  double multiplier = 1;
106  switch (QLocale::system().measurementSystem()) {
108  psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
109  multiplier = 1;
110  break;
112  psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
113  multiplier = 25.4/10;
114  break;
115  }
116 
117  QRect marginRect = ep->getPageMargins();
118  psd.rtMargin.left = marginRect.left() / multiplier;
119  psd.rtMargin.top = marginRect.top() / multiplier;
120  psd.rtMargin.right = marginRect.width() / multiplier;;
121  psd.rtMargin.bottom = marginRect.height() / multiplier;;
122 
123  bool result = PageSetupDlg(&psd);
124  if (result) {
125  ep->readDevnames(psd.hDevNames);
126  ep->readDevmode(psd.hDevMode);
127 
128  QRect theseMargins = QRect(psd.rtMargin.left * multiplier,
129  psd.rtMargin.top * multiplier,
130  psd.rtMargin.right * multiplier,
131  psd.rtMargin.bottom * multiplier);
132 
133  if (theseMargins != marginRect) {
134  ep->setPageMargins(psd.rtMargin.left * multiplier,
135  psd.rtMargin.top * multiplier,
136  psd.rtMargin.right * multiplier,
137  psd.rtMargin.bottom * multiplier);
138  }
139 
140  ep->updateCustomPaperSize();
141 
142  // copy from our temp DEVMODE struct
143  if (!ep->globalDevMode && hDevMode) {
144  void *src = GlobalLock(hDevMode);
145  memcpy(ep->devMode, src, devModeSize);
146  GlobalUnlock(hDevMode);
147  }
148  }
149 
150  if (!ep->globalDevMode && hDevMode)
151  GlobalFree(hDevMode);
152  GlobalFree(tempDevNames);
153  done(result);
154  return result;
155 }
156 
158 {
159  if (!visible)
160  return;
161  exec();
162 }
163 
165 #endif
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
T * data() const
Returns the value of the pointer referenced by this object.
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or 0 if no application wi...
void readDevmode(HGLOBAL globalDevmode)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
The QAbstractPageSetupDialog class provides a base for implementations of page setup dialogs...
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition: qlocale.cpp:1917
QPageSetupDialog(QPrinter *printer, QWidget *parent=0)
Constructs a page setup dialog that configures printer with parent as the parent widget.
The QPageSetupDialog class provides a configuration dialog for the page-related options on a printer...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setPageMargins(int margin_left, int margin_top, int margin_right, int margin_bottom)
bool visible
whether the widget is visible
Definition: qwidget.h:191
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QScopedPointer< QPaintEnginePrivate > d_ptr
Definition: qpaintengine.h:246
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
QObject * parent
Definition: qobject.h:92
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
void readDevnames(HGLOBAL globalDevnames)
virtual void setVisible(bool visible)
Reimplemented Function