3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
17 #include "qt_helpers.h"
18 #include "PrinterParams.h"
21 #include "BufferParams.h"
22 #include "FuncRequest.h"
25 #include "support/convert.h"
26 #include "support/FileFilterList.h"
27 #include "support/filetools.h"
28 #include "support/gettext.h"
29 #include "support/os.h"
33 #include <QRadioButton>
35 #include <QPushButton>
38 using namespace lyx::support;
44 GuiPrint::GuiPrint(GuiView & lv)
45 : GuiDialog(lv, "print", qt_("Print Document"))
49 connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK()));
50 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
52 connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int)));
53 connect(printerED, SIGNAL(textChanged(QString)),
54 this, SLOT(printerChanged()));
55 connect(fileED, SIGNAL(textChanged(QString)),
56 this, SLOT(fileChanged() ));
57 connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
58 connect(allRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
59 connect(reverseCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
60 connect(collateCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
61 connect(fromED, SIGNAL(textChanged(const QString&)),
62 this, SLOT(pagerangeChanged()));
63 connect(fromED, SIGNAL(textChanged(const QString&)),
64 this, SLOT(change_adaptor()));
65 connect(toED, SIGNAL(textChanged(const QString&)),
66 this, SLOT(pagerangeChanged()));
67 connect(toED, SIGNAL(textChanged(const QString&)),
68 this, SLOT(change_adaptor()));
69 connect(fileRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
70 connect(printerRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
71 connect(rangeRB, SIGNAL(toggled(bool)), fromED, SLOT(setEnabled(bool)));
72 connect(rangeRB, SIGNAL(toggled(bool)), toED, SLOT(setEnabled(bool)));
74 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
76 bc().setCancel(closePB);
80 void GuiPrint::change_adaptor()
86 void GuiPrint::browseClicked()
89 browseRelFile(QString(), bufferFilepath(), qt_("Print to file"),
90 FileFilterList(_("PostScript files (*.ps)")), true);
91 if (!file.isEmpty()) {
92 fileED->setText(file);
98 void GuiPrint::fileChanged()
100 if (!fileED->text().isEmpty())
101 fileRB->setChecked(true);
106 void GuiPrint::copiesChanged(int i)
108 collateCB->setEnabled(i != 1);
113 void GuiPrint::printerChanged()
115 printerRB->setChecked(true);
120 void GuiPrint::pagerangeChanged()
126 void GuiPrint::updateContents()
128 // only reset params if a different buffer
129 if (!params_.file_name.empty()
130 && params_.file_name == fromqstr(fileED->text()))
133 printerED->setText(toqstr(params_.printer_name));
134 fileED->setText(toqstr(params_.file_name));
136 printerRB->setChecked(true);
137 if (params_.target == PrinterParams::FILE)
138 fileRB->setChecked(true);
140 reverseCB->setChecked(params_.reverse_order);
142 copiesSB->setValue(params_.count_copies);
144 oddCB->setChecked(params_.odd_pages);
145 evenCB->setChecked(params_.even_pages);
147 collateCB->setChecked(params_.sorted_copies);
149 if (params_.all_pages) {
150 allRB->setChecked(true);
152 rangeRB->setChecked(true);
153 fromED->setText(QString::number(params_.from_page));
154 toED->setText(QString::number(params_.to_page));
159 void GuiPrint::applyView()
161 params_.target = fileRB->isChecked()
162 ? PrinterParams::FILE : PrinterParams::PRINTER;
163 params_.printer_name = fromqstr(printerED->text());
164 params_.file_name = os::internal_path(fromqstr(fileED->text()));
165 params_.all_pages = allRB->isChecked();
166 params_.from_page = fromED->text().toUInt();
167 params_.to_page = toED->text().toUInt();
168 params_.odd_pages = oddCB->isChecked();
169 params_.even_pages = evenCB->isChecked();
170 params_.count_copies = copiesSB->text().toUInt();
171 params_.sorted_copies = collateCB->isChecked();
172 params_.reverse_order = reverseCB->isChecked();
176 bool GuiPrint::initialiseParams(string const &)
178 /// get global printer parameters
179 string const name = support::changeExtension(buffer().absFileName(),
180 lyxrc.print_file_extension);
181 params_ = PrinterParams();
182 params_.file_name = name;
184 setButtonsValid(true); // so that the user can press Ok
189 void GuiPrint::clearParams()
191 params_ = PrinterParams();
195 /// print the current buffer
196 void GuiPrint::dispatchParams()
198 string command = lyxrc.print_command + ' ';
200 if (params_.target == PrinterParams::PRINTER
201 && lyxrc.print_adapt_output // dvips wants a printer name
202 && !params_.printer_name.empty()) {// printer name given
203 command += lyxrc.print_to_printer + params_.printer_name + ' ';
206 if (!params_.all_pages && params_.from_page) {
207 command += lyxrc.print_pagerange_flag + ' ';
208 command += convert<string>(params_.from_page);
209 if (params_.to_page) {
210 // we have a range "from-to"
211 command += '-' + convert<string>(params_.to_page);
216 // If both are, or both are not selected, then skip the odd/even printing
217 if (params_.odd_pages != params_.even_pages) {
218 if (params_.odd_pages)
219 command += lyxrc.print_oddpage_flag + ' ';
220 else if (params_.even_pages)
221 command += lyxrc.print_evenpage_flag + ' ';
224 if (params_.count_copies > 1) {
225 if (params_.sorted_copies)
226 command += lyxrc.print_collcopies_flag;
228 command += lyxrc.print_copies_flag;
229 command += ' ' + convert<string>(params_.count_copies) + ' ';
232 if (params_.reverse_order)
233 command += lyxrc.print_reverse_flag + ' ';
235 if (!lyxrc.print_extra_options.empty())
236 command += lyxrc.print_extra_options + ' ';
238 command += buffer().params().dvips_options();
240 string const target = (params_.target == PrinterParams::PRINTER) ?
243 string const target_name = (params_.target == PrinterParams::PRINTER) ?
244 (params_.printer_name.empty() ? "default" : params_.printer_name) :
247 string const data = target + " \"" + target_name + "\" \"" + command + '"';
248 dispatch(FuncRequest(getLfun(), data));
252 Dialog * createGuiPrint(GuiView & lv) { return new GuiPrint(lv); }
255 } // namespace frontend
258 #include "GuiPrint_moc.cpp"