1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the dialog module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qpagesetupdialog.h"
31
#include "qcombobox.h"
35
#include "qpushbutton.h"
37
#include <private/qabstractpagesetupdialog_p.h>
39
// Disabled untill we have support for papersources on unix
40
// #define PSD_ENABLE_PAPERSOURCE
42
static const char *pageSizeNames[] = {
43
"A4 (210x297 mm, 8.26x11.7 inches)",
44
"B5 (176 x 250 mm, 6.93x9.84 inches)",
45
"Letter (8.5x11 inches, 216x279 mm)",
46
"Legal (8.5x14 inches, 216x356 mm)",
47
"Executive (7.5x10 inches, 191x254 mm)",
57
"B0 (1000 x 1414 mm)",
68
"US Common #10 Envelope (105 x 241 mm)",
70
"Folio (210 x 330 mm)",
71
"Ledger (432 x 279 mm)",
72
"Tabloid (279 x 432 mm)",
76
#ifdef PSD_ENABLE_PAPERSOURCE
77
static const char *paperSourceNames[] = {
94
struct PaperSourceNames
96
PaperSourceNames(const char *nam, QPrinter::PaperSource ps)
97
: paperSource(ps), name(nam) {}
98
QPrinter::PaperSource paperSource;
104
class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
108
#ifdef PSD_ENABLE_PAPERSOURCE
109
QComboBox *paperSource;
111
QComboBox *orientation;
115
\class QPageSetupDialog
117
The QPageSetupDialog offers configuration for the page related
118
options on a printer.
120
On Windows and Mac OS X the page setup dialog is implemented using
121
the native page setup dialogs.
125
Constructs a page setup dialog that configures \a printer with \a
126
parent as the parent widget.
128
QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
129
: QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
131
Q_D(QPageSetupDialog);
132
QVBoxLayout *layout = new QVBoxLayout(this);
133
layout->setMargin(11);
134
layout->setSpacing(6);
136
QFrame *frame = new QFrame(this);
137
frame->setFrameShape(QFrame::StyledPanel);
138
frame->setFrameShadow(QFrame::Sunken);
139
QGridLayout *frameLayout = new QGridLayout(frame);
140
frameLayout->setMargin(11);
141
frameLayout->setSpacing(6);
142
frameLayout->setObjectName("frame3Layout");
144
QLabel *pageSizeLabel = new QLabel(tr("Page Size"), frame);
145
d->pageSize = new QComboBox(frame);
146
d->pageSize->setObjectName("pageSizeCombo");
147
frameLayout->addWidget(pageSizeLabel, 0, 0);
148
frameLayout->addWidget(d->pageSize, 0, 1);
150
QLabel *orientationLabel = new QLabel(tr("Orientation"), frame);
151
d->orientation = new QComboBox(frame);
152
d->orientation->setObjectName("orientationCombo");
153
frameLayout->addWidget(orientationLabel, 2, 0);
154
frameLayout->addWidget(d->orientation, 2, 1);
156
#ifdef PSD_ENABLE_PAPERSOURCE
157
QLabel *paperSourceLabel = new QLabel(tr("Paper Source"), frame);
158
d->paperSource = new QComboBox(frame);
159
d->paperSource->setObjectName("paperSourceCombo");
160
frameLayout->addWidget(paperSourceLabel, 1, 0);
161
frameLayout->addWidget(d->paperSource, 1, 1);
164
layout->addWidget(frame);
166
QSpacerItem* spacer = new QSpacerItem(20, 50, QSizePolicy::Minimum, QSizePolicy::Expanding);
167
layout->addItem(spacer);
169
QHBoxLayout *buttonLayout = new QHBoxLayout;
170
buttonLayout->setMargin(0);
171
buttonLayout->setSpacing(6);
172
buttonLayout->setObjectName("layout2");
173
QSpacerItem *buttonSpacer = new QSpacerItem(71, 20, QSizePolicy::Expanding,
174
QSizePolicy::Minimum);
175
QPushButton *okButton = new QPushButton(tr("OK"), this);
176
okButton->setObjectName("okButton");
177
QPushButton *cancelButton = new QPushButton(tr("Cancel"), this);
178
cancelButton->setObjectName("cancelButton");
180
buttonLayout->addItem(buttonSpacer);
181
buttonLayout->addWidget(okButton);
182
buttonLayout->addWidget(cancelButton);
184
layout->addItem(buttonLayout);
186
setAttribute(Qt::WA_WState_Polished, false);
188
for (int i=0; pageSizeNames[i]; ++i)
189
d->pageSize->addItem(pageSizeNames[i]);
190
d->pageSize->setCurrentIndex(printer->pageSize());
192
#ifdef PSD_ENABLE_PAPERSOURCE
193
for (int i=0; paperSourceNames[i]; ++i)
194
d->paperSource->insertItem(paperSourceNames[i]);
195
d->paperSource->setCurrentItem(printer->paperSource());
198
d->orientation->addItem(tr("Portrait"));
199
d->orientation->addItem(tr("Landscape"));
200
d->orientation->setCurrentIndex(printer->orientation());
203
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
204
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
208
\fn int QPageSetupDialog::exec()
210
Executes the the page setup dialog. The printer will be configure
211
according to the users choices when the function exists.
214
int QPageSetupDialog::exec()
216
Q_D(QPageSetupDialog);
217
int ret = QDialog::exec();
218
if (ret == Accepted) {
220
d->printer->setPageSize((QPrinter::PageSize)d->pageSize->currentIndex());
221
d->printer->setOrientation((QPrinter::Orientation)d->orientation->currentIndex());
222
#ifdef PSD_ENABLE_PAPERSOURCE
223
d->printer->setPaperSource((QPrinter::PaperSource)d->paperSource->currentIndex());