~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/dialogs/qpagesetupdialog_unix.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the dialog module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qpagesetupdialog.h"
 
30
 
 
31
#include "qcombobox.h"
 
32
#include "qlabel.h"
 
33
#include "qlayout.h"
 
34
#include "qprinter.h"
 
35
#include "qpushbutton.h"
 
36
 
 
37
#include <private/qabstractpagesetupdialog_p.h>
 
38
 
 
39
// Disabled untill we have support for papersources on unix
 
40
// #define PSD_ENABLE_PAPERSOURCE
 
41
 
 
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)",
 
48
    "A0 (841 x 1189 mm)",
 
49
    "A1 (594 x 841 mm)",
 
50
    "A2 (420 x 594 mm)",
 
51
    "A3 (297 x 420 mm)",
 
52
    "A5 (148 x 210 mm)",
 
53
    "A6 (105 x 148 mm)",
 
54
    "A7 (74 x 105 mm)",
 
55
    "A8 (52 x 74 mm)",
 
56
    "A9 (37 x 52 mm)",
 
57
    "B0 (1000 x 1414 mm)",
 
58
    "B1 (707 x 1000 mm)",
 
59
    "B2 (500 x 707 mm)",
 
60
    "B3 (353 x 500 mm)",
 
61
    "B4 (250 x 353 mm)",
 
62
    "B6 (125 x 176 mm)",
 
63
    "B7 (88 x 125 mm)",
 
64
    "B8 (62 x 88 mm)",
 
65
    "B9 (44 x 62 mm)",
 
66
    "B10 (31 x 44 mm)",
 
67
    "C5E (163 x 229 mm)",
 
68
    "US Common #10 Envelope (105 x 241 mm)",
 
69
    "DLE (110 x 220 mm)",
 
70
    "Folio (210 x 330 mm)",
 
71
    "Ledger (432 x 279 mm)",
 
72
    "Tabloid (279 x 432 mm)",
 
73
    0
 
74
};
 
75
 
 
76
#ifdef PSD_ENABLE_PAPERSOURCE
 
77
static const char *paperSourceNames[] = {
 
78
    "Only One",
 
79
    "Lower",
 
80
    "Middle",
 
81
    "Manual",
 
82
    "Envelope",
 
83
    "Envelope manual",
 
84
    "Auto",
 
85
    "Tractor",
 
86
    "Small format",
 
87
    "Large format",
 
88
    "Large capacity",
 
89
    "Cassette",
 
90
    "Form source",
 
91
    0
 
92
};
 
93
 
 
94
struct PaperSourceNames
 
95
{
 
96
    PaperSourceNames(const char *nam, QPrinter::PaperSource ps)
 
97
        : paperSource(ps), name(nam) {}
 
98
    QPrinter::PaperSource paperSource;
 
99
    const char *name;
 
100
};
 
101
#endif
 
102
 
 
103
 
 
104
class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
 
105
{
 
106
public:
 
107
    QComboBox *pageSize;
 
108
#ifdef PSD_ENABLE_PAPERSOURCE
 
109
    QComboBox *paperSource;
 
110
#endif
 
111
    QComboBox *orientation;
 
112
};
 
113
 
 
114
/*!
 
115
    \class QPageSetupDialog
 
116
 
 
117
    The QPageSetupDialog offers configuration for the page related
 
118
    options on a printer.
 
119
 
 
120
    On Windows and Mac OS X the page setup dialog is implemented using
 
121
    the native page setup dialogs.
 
122
*/
 
123
 
 
124
/*!
 
125
    Constructs a page setup dialog that configures \a printer with \a
 
126
    parent as the parent widget.
 
127
*/
 
128
QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
 
129
    : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
 
130
{
 
131
    Q_D(QPageSetupDialog);
 
132
    QVBoxLayout *layout = new QVBoxLayout(this);
 
133
    layout->setMargin(11);
 
134
    layout->setSpacing(6);
 
135
 
 
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");
 
143
 
 
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);
 
149
 
 
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);
 
155
 
 
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);
 
162
#endif
 
163
 
 
164
    layout->addWidget(frame);
 
165
 
 
166
    QSpacerItem* spacer = new QSpacerItem(20, 50, QSizePolicy::Minimum, QSizePolicy::Expanding);
 
167
    layout->addItem(spacer);
 
168
 
 
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");
 
179
 
 
180
    buttonLayout->addItem(buttonSpacer);
 
181
    buttonLayout->addWidget(okButton);
 
182
    buttonLayout->addWidget(cancelButton);
 
183
 
 
184
    layout->addItem(buttonLayout);
 
185
 
 
186
    setAttribute(Qt::WA_WState_Polished, false);
 
187
 
 
188
    for (int i=0; pageSizeNames[i]; ++i)
 
189
        d->pageSize->addItem(pageSizeNames[i]);
 
190
    d->pageSize->setCurrentIndex(printer->pageSize());
 
191
 
 
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());
 
196
#endif
 
197
 
 
198
    d->orientation->addItem(tr("Portrait"));
 
199
    d->orientation->addItem(tr("Landscape"));
 
200
    d->orientation->setCurrentIndex(printer->orientation());
 
201
 
 
202
 
 
203
    connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
 
204
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
 
205
}
 
206
 
 
207
/*!
 
208
    \fn int QPageSetupDialog::exec()
 
209
 
 
210
    Executes the the page setup dialog. The printer will be configure
 
211
    according to the users choices when the function exists.
 
212
*/
 
213
 
 
214
int QPageSetupDialog::exec()
 
215
{
 
216
    Q_D(QPageSetupDialog);
 
217
    int ret = QDialog::exec();
 
218
    if (ret == Accepted) {
 
219
        // Read out the data
 
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());
 
224
#endif
 
225
    }
 
226
    return ret;
 
227
}