3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
16 #include "ControlPrint.h"
17 #include "qt_helpers.h"
18 #include "PrinterParams.h"
20 #include "support/os.h"
24 #include <QRadioButton>
26 #include <QPushButton>
32 GuiPrintDialog::GuiPrintDialog(LyXView & lv)
33 : GuiDialog(lv, "print")
36 setController(new ControlPrint(*this));
37 setViewTitle(_("Print Document"));
39 connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK()));
40 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
42 connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int)));
43 connect(printerED, SIGNAL(textChanged(const QString&)),
44 this, SLOT(printerChanged()));
45 connect(fileED, SIGNAL(textChanged(const QString&)),
46 this, SLOT(fileChanged() ));
47 connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
48 connect(allRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
49 connect(reverseCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
50 connect(collateCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
51 connect(fromED, SIGNAL(textChanged(const QString&)),
52 this, SLOT(pagerangeChanged()));
53 connect(fromED, SIGNAL(textChanged(const QString&)),
54 this, SLOT(change_adaptor()));
55 connect(toED, SIGNAL(textChanged(const QString&)),
56 this, SLOT(pagerangeChanged()));
57 connect(toED, SIGNAL(textChanged(const QString&)),
58 this, SLOT(change_adaptor()));
59 connect(fileRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
60 connect(printerRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
61 connect(rangeRB, SIGNAL(toggled(bool)), fromED, SLOT(setEnabled(bool)));
62 connect(rangeRB, SIGNAL(toggled(bool)), toED, SLOT(setEnabled(bool)));
64 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
66 bc().setCancel(closePB);
70 ControlPrint & GuiPrintDialog::controller()
72 return static_cast<ControlPrint &>(GuiDialog::controller());
76 void GuiPrintDialog::change_adaptor()
82 void GuiPrintDialog::browseClicked()
84 QString file = toqstr(controller().browse(docstring()));
86 fileED->setText(file);
92 void GuiPrintDialog::fileChanged()
94 if (!fileED->text().isEmpty())
95 fileRB->setChecked(true);
100 void GuiPrintDialog::copiesChanged(int i)
102 collateCB->setEnabled(i != 1);
107 void GuiPrintDialog::printerChanged()
109 printerRB->setChecked(true);
114 void GuiPrintDialog::pagerangeChanged()
120 void GuiPrintDialog::updateContents()
122 PrinterParams & pp = controller().params();
124 // only reset params if a different buffer
125 if (!pp.file_name.empty() && pp.file_name == fromqstr(fileED->text()))
128 printerED->setText(toqstr(pp.printer_name));
129 fileED->setText(toqstr(pp.file_name));
131 printerRB->setChecked(true);
132 if (pp.target == PrinterParams::FILE)
133 fileRB->setChecked(true);
135 reverseCB->setChecked(pp.reverse_order);
137 copiesSB->setValue(pp.count_copies);
139 oddCB->setChecked(pp.odd_pages);
140 evenCB->setChecked(pp.even_pages);
142 collateCB->setChecked(pp.sorted_copies);
145 allRB->setChecked(true);
147 rangeRB->setChecked(true);
148 fromED->setText(QString::number(pp.from_page));
149 toED->setText(QString::number(pp.to_page));
154 void GuiPrintDialog::applyView()
156 PrinterParams::Target t = PrinterParams::PRINTER;
157 if (fileRB->isChecked())
158 t = PrinterParams::FILE;
160 PrinterParams const pp(t,
161 fromqstr(printerED->text()),
162 support::os::internal_path(fromqstr(fileED->text())),
164 fromED->text().toUInt(),
165 toED->text().toUInt(),
168 copiesSB->text().toUInt(),
169 collateCB->isChecked(),
170 reverseCB->isChecked());
172 controller().params() = pp;
175 } // namespace frontend
178 #include "GuiPrint_moc.cpp"