comparison libgui/languages/build_ts/octave-qt/qprintdialog_qws.cpp @ 31537:5ceb4bfcdb0f stable

add tools and files for updating the gui's language files for translation * libgui/languages/build_ts/README.md: readme for updating language files * libgui/languages/build_ts/octave-qsci: QScintilla source files for languages without translation provided by QScintilla * libgui/languages/build_ts/octave-qt: Qt source files for languages without translation provided by Qt
author Torsten Lilge <ttl-octave@mailbox.org>
date Thu, 24 Nov 2022 06:48:25 +0100
parents
children
comparison
equal deleted inserted replaced
31535:4b80982e0af8 31537:5ceb4bfcdb0f
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qplatformdefs.h"
43
44 #include <private/qabstractprintdialog_p.h>
45 #include "qprintdialog.h"
46
47 #ifndef QT_NO_PRINTDIALOG
48
49 #include "qapplication.h"
50 #include "qbuttongroup.h"
51 #include "qradiobutton.h"
52 #include "qcombobox.h"
53 #include "qspinbox.h"
54 #include "qprinter.h"
55 #include "qlineedit.h"
56 #include "qdir.h"
57 #include "qmessagebox.h"
58 #include "qinputdialog.h"
59 #include "qlayout.h"
60 #include "qlabel.h"
61
62 #include "qlibrary.h"
63
64 #ifndef QT_NO_NIS
65
66 #ifndef BOOL_DEFINED
67 #define BOOL_DEFINED
68 #endif
69
70 #include <rpcsvc/ypclnt.h>
71 #include <rpcsvc/yp_prot.h>
72
73 #endif //QT_NO_NIS
74
75 #include <ctype.h>
76 #include <stdlib.h>
77
78 #include <qdebug.h>
79
80 QT_BEGIN_NAMESPACE
81
82 typedef void (*QPrintDialogCreator)(QPrintDialog *parent);
83 Q_GUI_EXPORT QPrintDialogCreator _qt_print_dialog_creator;
84
85 class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
86 {
87 Q_DECLARE_PUBLIC(QPrintDialog)
88 public:
89 QButtonGroup *printerOrFile;
90 bool outputToFile;
91 QRadioButton *printToPrinterButton;
92 QRadioButton *printToFileButton;
93 QLineEdit *fileName;
94
95 QButtonGroup *colorMode;
96 QRadioButton *printColor;
97 QRadioButton *printGray;
98 QPrinter::ColorMode colorMode2;
99
100 QComboBox *orientationCombo, *sizeCombo;
101 QPrinter::PaperSize pageSize;
102 QPrinter::Orientation orientation;
103
104 QSpinBox *copies;
105 int numCopies;
106 QPrinter::PaperSize indexToPaperSize[QPrinter::NPaperSize];
107
108 QComboBox *rangeCombo;
109 QSpinBox *firstPage;
110 QSpinBox *lastPage;
111
112 QComboBox *pageOrderCombo;
113 QPrinter::PageOrder pageOrder2;
114
115 QString faxNum;
116
117 void init();
118
119 void _q_okClicked();
120 void _q_printerOrFileSelected(QAbstractButton *b);
121 void _q_paperSizeSelected(int);
122 void _q_orientSelected(int);
123 void _q_pageOrderSelected(int);
124 void _q_colorModeSelected(QAbstractButton *);
125 void _q_setNumCopies(int);
126 void _q_printRangeSelected(int);
127 void _q_setFirstPage(int);
128 void _q_setLastPage(int);
129 void _q_fileNameEditChanged(const QString &text);
130
131 void setupDestination();
132 void setupPrinterSettings();
133 void setupPaper();
134 void setupOptions();
135
136 void setPrinter(QPrinter *p, bool pickUpSettings);
137 };
138
139 static void isc(QPrintDialogPrivate *d, const QString & text,
140 QPrinter::PaperSize ps);
141
142 void QPrintDialogPrivate::_q_okClicked()
143 {
144 Q_Q(QPrintDialog);
145 #ifndef QT_NO_MESSAGEBOX
146 if (outputToFile && fileName->isModified() && QFileInfo(fileName->text()).exists()) {
147 int confirm = QMessageBox::warning(
148 q, QPrintDialog::tr("File exists"),
149 QPrintDialog::tr("<qt>Do you want to overwrite it?</qt>"),
150 QMessageBox::Yes, QMessageBox::No);
151 if (confirm == QMessageBox::No)
152 return;
153 }
154 #endif // QT_NO_MESSAGEBOX
155
156 lastPage->interpretText();
157 firstPage->interpretText();
158 copies->interpretText();
159 if (outputToFile) {
160 printer->setOutputFileName(fileName->text());
161 }
162 printer->setOrientation(orientation);
163 printer->setPaperSize(pageSize);
164 printer->setPageOrder(pageOrder2);
165 printer->setColorMode(colorMode2);
166 printer->setCopyCount(numCopies);
167
168 switch ((rangeCombo->itemData(rangeCombo->currentIndex())).toInt()){
169 case (int)QPrintDialog::AllPages:
170 q->setPrintRange(QPrintDialog::AllPages);
171 q->setFromTo(0, 0);
172 break;
173 case (int)QPrintDialog::Selection:
174 q->setPrintRange(QPrintDialog::Selection);
175 q->setFromTo(0, 0);
176 break;
177 case (int)QPrintDialog::PageRange:
178 q->setPrintRange(QPrintDialog::PageRange);
179 q->setFromTo(firstPage->value(), lastPage->value());
180 break;
181 case (int)QPrintDialog::CurrentPage:
182 q->setPrintRange(QPrintDialog::CurrentPage);
183 q->setFromTo(0, 0);
184 break;
185 }
186 q->accept();
187 }
188
189 void QPrintDialogPrivate::_q_printerOrFileSelected(QAbstractButton *b)
190 {
191 outputToFile = (b == printToFileButton);
192 if (outputToFile) {
193 _q_fileNameEditChanged(fileName->text());
194 if (!fileName->isModified() && fileName->text().isEmpty()) {
195 QString file = "print.tiff";
196 fileName->setText(file);
197 fileName->setCursorPosition(file.length());
198 fileName->selectAll();
199 fileName->setModified(true); // confirm overwrite when OK clicked
200
201 }
202 fileName->setEnabled(true);
203 fileName->setFocus();
204 } else {
205 fileName->setText(QString());
206 if (fileName->isEnabled())
207 fileName->setEnabled(false);
208 }
209 }
210
211 void QPrintDialogPrivate::_q_paperSizeSelected(int id)
212 {
213 if (id < QPrinter::NPaperSize)
214 pageSize = QPrinter::PaperSize(indexToPaperSize[id]);
215 }
216
217 void QPrintDialogPrivate::_q_orientSelected(int id)
218 {
219 orientation = (QPrinter::Orientation)id;
220 }
221
222 void QPrintDialogPrivate::_q_pageOrderSelected(int id)
223 {
224 pageOrder2 = (QPrinter::PageOrder)id;
225 }
226
227 void QPrintDialogPrivate::_q_colorModeSelected(QAbstractButton *b)
228 {
229 colorMode2 = (b == printColor) ? QPrinter::Color : QPrinter::GrayScale;
230 }
231
232 void QPrintDialogPrivate::_q_setNumCopies(int copies)
233 {
234 numCopies = copies;
235 }
236
237 void QPrintDialogPrivate::_q_printRangeSelected(int id)
238 {
239 bool enable = (rangeCombo->itemData(id).toInt() == (int)QPrintDialog::PageRange);
240 firstPage->setEnabled(enable);
241 lastPage->setEnabled(enable);
242 }
243
244 void QPrintDialogPrivate::_q_setFirstPage(int fp)
245 {
246 Q_Q(QPrintDialog);
247 if (printer) {
248 lastPage->setMinimum(fp);
249 lastPage->setMaximum(qMax(fp, q->maxPage()));
250 }
251 }
252
253 void QPrintDialogPrivate::_q_setLastPage(int lp)
254 {
255 Q_Q(QPrintDialog);
256 if (printer) {
257 firstPage->setMinimum(qMin(lp, q->minPage()));
258 firstPage->setMaximum(lp);
259 }
260 }
261
262 void QPrintDialogPrivate::_q_fileNameEditChanged(const QString &text)
263 {
264 Q_UNUSED(text);
265 }
266
267 void QPrintDialogPrivate::setupDestination()
268 {
269 Q_Q(QPrintDialog);
270
271 // print destinations
272 printerOrFile = new QButtonGroup(q);
273 QObject::connect(printerOrFile, SIGNAL(buttonClicked(QAbstractButton*)),
274 q, SLOT(_q_printerOrFileSelected(QAbstractButton*)));
275
276 printToPrinterButton = q->findChild<QRadioButton *>("printToPrinterButton");
277 printerOrFile->addButton(printToPrinterButton);
278 printToFileButton = q->findChild<QRadioButton *>("printToFileButton");
279 printerOrFile->addButton(printToFileButton);
280
281 // file name
282 fileName = q->findChild<QLineEdit *>("fileName");
283 QObject::connect(fileName, SIGNAL(textChanged(QString)),
284 q, SLOT(_q_fileNameEditChanged(QString)));
285
286 outputToFile = false;
287 }
288
289 void QPrintDialogPrivate::setupPrinterSettings()
290 {
291 Q_Q(QPrintDialog);
292
293 // color mode
294 colorMode = new QButtonGroup(q);
295 QObject::connect(colorMode, SIGNAL(buttonClicked(QAbstractButton*)),
296 q, SLOT(_q_colorModeSelected(QAbstractButton*)));
297
298 printColor = q->findChild<QRadioButton *>("printColor");
299 colorMode->addButton(printColor);
300 printGray = q->findChild<QRadioButton *>("printGray");
301 colorMode->addButton(printGray);
302 }
303
304 void isc(QPrintDialogPrivate *ptr, const QString & text, QPrinter::PaperSize ps)
305 {
306 if (ptr && !text.isEmpty() && ps < QPrinter::NPaperSize) {
307 ptr->sizeCombo->addItem(text);
308 int index = ptr->sizeCombo->count()-1;
309 if (index >= 0 && index < QPrinter::NPaperSize)
310 ptr->indexToPaperSize[index] = ps;
311 }
312 }
313
314 void QPrintDialogPrivate::setupPaper()
315 {
316 Q_Q(QPrintDialog);
317
318 pageSize = QPrinter::A4;
319
320 // paper orientation
321 orientationCombo = q->findChild<QComboBox *>("orientationCombo");
322 orientation = QPrinter::Portrait;
323 QObject::connect(orientationCombo, SIGNAL(activated(int)),
324 q, SLOT(_q_orientSelected(int)));
325
326 // paper size
327 sizeCombo = q->findChild<QComboBox *>("sizeCombo");
328
329 int n;
330 for(n=0; n<QPrinter::NPaperSize; n++)
331 indexToPaperSize[n] = QPrinter::A4;
332
333 isc(this, QPrintDialog::tr("A0 (841 x 1189 mm)"), QPrinter::A0);
334 isc(this, QPrintDialog::tr("A1 (594 x 841 mm)"), QPrinter::A1);
335 isc(this, QPrintDialog::tr("A2 (420 x 594 mm)"), QPrinter::A2);
336 isc(this, QPrintDialog::tr("A3 (297 x 420 mm)"), QPrinter::A3);
337 isc(this, QPrintDialog::tr("A4 (210 x 297 mm, 8.26 x 11.7 inches)"), QPrinter::A4);
338 isc(this, QPrintDialog::tr("A5 (148 x 210 mm)"), QPrinter::A5);
339 isc(this, QPrintDialog::tr("A6 (105 x 148 mm)"), QPrinter::A6);
340 isc(this, QPrintDialog::tr("A7 (74 x 105 mm)"), QPrinter::A7);
341 isc(this, QPrintDialog::tr("A8 (52 x 74 mm)"), QPrinter::A8);
342 isc(this, QPrintDialog::tr("A9 (37 x 52 mm)"), QPrinter::A9);
343 isc(this, QPrintDialog::tr("B0 (1000 x 1414 mm)"), QPrinter::B0);
344 isc(this, QPrintDialog::tr("B1 (707 x 1000 mm)"), QPrinter::B1);
345 isc(this, QPrintDialog::tr("B2 (500 x 707 mm)"), QPrinter::B2);
346 isc(this, QPrintDialog::tr("B3 (353 x 500 mm)"), QPrinter::B3);
347 isc(this, QPrintDialog::tr("B4 (250 x 353 mm)"), QPrinter::B4);
348 isc(this, QPrintDialog::tr("B5 (176 x 250 mm, 6.93 x 9.84 inches)"), QPrinter::B5);
349 isc(this, QPrintDialog::tr("B6 (125 x 176 mm)"), QPrinter::B6);
350 isc(this, QPrintDialog::tr("B7 (88 x 125 mm)"), QPrinter::B7);
351 isc(this, QPrintDialog::tr("B8 (62 x 88 mm)"), QPrinter::B8);
352 isc(this, QPrintDialog::tr("B9 (44 x 62 mm)"), QPrinter::B9);
353 isc(this, QPrintDialog::tr("B10 (31 x 44 mm)"), QPrinter::B10);
354 isc(this, QPrintDialog::tr("C5E (163 x 229 mm)"), QPrinter::C5E);
355 isc(this, QPrintDialog::tr("DLE (110 x 220 mm)"), QPrinter::DLE);
356 isc(this, QPrintDialog::tr("Executive (7.5 x 10 inches, 191 x 254 mm)"), QPrinter::Executive);
357 isc(this, QPrintDialog::tr("Folio (210 x 330 mm)"), QPrinter::Folio);
358 isc(this, QPrintDialog::tr("Ledger (432 x 279 mm)"), QPrinter::Ledger);
359 isc(this, QPrintDialog::tr("Legal (8.5 x 14 inches, 216 x 356 mm)"), QPrinter::Legal);
360 isc(this, QPrintDialog::tr("Letter (8.5 x 11 inches, 216 x 279 mm)"), QPrinter::Letter);
361 isc(this, QPrintDialog::tr("Tabloid (279 x 432 mm)"), QPrinter::Tabloid);
362 isc(this, QPrintDialog::tr("US Common #10 Envelope (105 x 241 mm)"), QPrinter::Comm10E);
363
364 QObject::connect(sizeCombo, SIGNAL(activated(int)),
365 q, SLOT(_q_paperSizeSelected(int)));
366 }
367
368 void QPrintDialogPrivate::setupOptions()
369 {
370 Q_Q(QPrintDialog);
371
372 // no. of copies
373 copies = q->findChild<QSpinBox *>("copies");
374 QObject::connect(copies, SIGNAL(valueChanged(int)),
375 q, SLOT(_q_setNumCopies(int)));
376
377 // print range
378 rangeCombo = q->findChild<QComboBox *>("rangeCombo");
379 rangeCombo->addItem(QPrintDialog::tr("Print all"), QPrintDialog::AllPages);
380 rangeCombo->addItem(QPrintDialog::tr("Print selection"), QPrintDialog::Selection);
381 rangeCombo->addItem(QPrintDialog::tr("Print range"), QPrintDialog::PageRange);
382 rangeCombo->addItem(QPrintDialog::tr("Print current page"), QPrintDialog::CurrentPage);
383 QObject::connect(rangeCombo, SIGNAL(activated(int)),
384 q, SLOT(_q_printRangeSelected(int)));
385
386 // page range
387 firstPage = q->findChild<QSpinBox *>("firstPage");
388 firstPage->setRange(1, 9999);
389 firstPage->setValue(1);
390 QObject::connect(firstPage, SIGNAL(valueChanged(int)),
391 q, SLOT(_q_setFirstPage(int)));
392
393 lastPage = q->findChild<QSpinBox *>("lastPage");
394 lastPage->setRange(1, 9999);
395 lastPage->setValue(1);
396 QObject::connect(lastPage, SIGNAL(valueChanged(int)),
397 q, SLOT(_q_setLastPage(int)));
398
399 // print order
400 pageOrderCombo = q->findChild<QComboBox *>("pageOrderCombo");
401 QObject::connect(pageOrderCombo, SIGNAL(activated(int)),
402 q, SLOT(_q_pageOrderSelected(int)));
403 }
404
405 bool QPrintDialog::eventFilter(QObject *o, QEvent *e)
406 {
407 Q_UNUSED(o);
408
409 Q_D(QPrintDialog);
410 switch (e->type()){
411 case QEvent::KeyPress:
412 switch (static_cast<QKeyEvent*>(e)->key()) {
413 case Qt::Key_Back:
414 d->_q_okClicked();
415 return true;
416 }
417 break;
418 default:
419 break;
420 }
421 return false;
422 }
423
424 QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent)
425 : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent)
426 {
427 d_func()->init();
428 }
429
430 QPrintDialog::QPrintDialog(QWidget *parent)
431 : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent)
432 {
433 d_func()->init();
434 }
435
436 QPrintDialog::~QPrintDialog()
437 {
438 }
439
440 void QPrintDialogPrivate::setPrinter(QPrinter *p, bool pickUpSettings)
441 {
442 Q_Q(QPrintDialog);
443 printer = p;
444
445 if (p && pickUpSettings) {
446 // top to bottom in the old dialog.
447 // printer or file
448 outputToFile = !p->outputFileName().isEmpty() && q->isOptionEnabled(QPrintDialog::PrintToFile);
449 if (outputToFile)
450 printToFileButton->setChecked(true);
451 else
452 printToPrinterButton->setChecked(true);
453 fileName->setEnabled(outputToFile);
454
455 // file name
456 if (q->isOptionEnabled(QPrintDialog::PrintToFile)) {
457 fileName->setText(p->outputFileName());
458 fileName->setModified(!fileName->text().isEmpty());
459 } else {
460 printToFileButton->setEnabled(false);
461 }
462
463 // orientation
464 orientationCombo->setCurrentIndex((int)p->orientation());
465 _q_orientSelected(p->orientation());
466
467 // page size
468 int n = 0;
469 while (n < QPrinter::NPaperSize &&
470 indexToPaperSize[n] != p->pageSize())
471 n++;
472 sizeCombo->setCurrentIndex(n);
473 _q_paperSizeSelected(n);
474
475 // page order
476 pageOrder2 = p->pageOrder();
477 pageOrderCombo->setCurrentIndex((int)pageOrder2);
478
479 // color mode
480 colorMode2 = p->colorMode();
481 if (colorMode2 == QPrinter::Color)
482 printColor->setChecked(true);
483 else
484 printGray->setChecked(true);
485
486 // number of copies
487 copies->setValue(p->copyCount());
488 _q_setNumCopies(p->copyCount());
489 }
490
491 if (p) {
492 if (!q->isOptionEnabled(QPrintDialog::PrintSelection)
493 && rangeCombo->findData(QPrintDialog::Selection) > 0)
494 rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::Selection));
495 if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)
496 && rangeCombo->findData(QPrintDialog::PageRange) > 0)
497 rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::PageRange));
498 if (!q->isOptionEnabled(QPrintDialog::PrintCurrentPage)
499 && rangeCombo->findData(QPrintDialog::CurrentPage) > 0)
500 rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::CurrentPage));
501
502 switch (q->printRange()) {
503 case QPrintDialog::AllPages:
504 rangeCombo->setCurrentIndex((int)(QPrintDialog::AllPages));
505 break;
506 case QPrintDialog::Selection:
507 rangeCombo->setCurrentIndex((int)(QPrintDialog::Selection));
508 break;
509 case QPrintDialog::PageRange:
510 rangeCombo->setCurrentIndex((int)(QPrintDialog::PageRange));
511 break;
512 case QPrintDialog::CurrentPage:
513 rangeCombo->setCurrentIndex((int)(QPrintDialog::CurrentPage));
514 break;
515 }
516 }
517
518 if (p && q->maxPage()) {
519 int from = q->minPage();
520 int to = q->maxPage();
521 if (q->printRange() == QPrintDialog::PageRange) {
522 from = q->fromPage();
523 to = q->toPage();
524 }
525 firstPage->setRange(q->minPage(), to);
526 lastPage->setRange(from, q->maxPage());
527 firstPage->setValue(from);
528 lastPage->setValue(to);
529 }
530 }
531
532 int QPrintDialog::exec()
533 {
534 Q_D(QPrintDialog);
535 d->setPrinter(d->printer, true);
536 return QDialog::exec();
537 }
538
539 void QPrintDialogPrivate::init()
540 {
541 Q_Q(QPrintDialog);
542 numCopies = 1;
543
544 if (_qt_print_dialog_creator)
545 (*_qt_print_dialog_creator)(q);
546
547 setupDestination();
548 setupPrinterSettings();
549 setupPaper();
550 setupOptions();
551
552 setPrinter(printer, true);
553
554 q->installEventFilter(q);
555 }
556
557 void QPrintDialog::setVisible(bool visible)
558 {
559 QAbstractPrintDialog::setVisible(visible);
560 }
561
562 QT_END_NAMESPACE
563
564 #include "moc_qprintdialog.cpp"
565 #include "qrc_qprintdialog.cpp"
566
567 #endif // QT_NO_PRINTDIALOG