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"
23 #include "support/gettext.h"
25 #include "support/convert.h"
26 #include "support/FileFilterList.h"
27 #include "support/filetools.h"
28 #include "support/os.h"
32 #include <QRadioButton>
34 #include <QPushButton>
41 using support::FileFilterList;
44 GuiPrint::GuiPrint(GuiView & lv)
45 : GuiDialog(lv, "print")
48 setViewTitle(_("Print Document"));
50 connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK()));
51 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
53 connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int)));
54 connect(printerED, SIGNAL(textChanged(QString)),
55 this, SLOT(printerChanged()));
56 connect(fileED, SIGNAL(textChanged(QString)),
57 this, SLOT(fileChanged() ));
58 connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
59 connect(allRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
60 connect(reverseCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
61 connect(collateCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
62 connect(fromED, SIGNAL(textChanged(const QString&)),
63 this, SLOT(pagerangeChanged()));
64 connect(fromED, SIGNAL(textChanged(const QString&)),
65 this, SLOT(change_adaptor()));
66 connect(toED, SIGNAL(textChanged(const QString&)),
67 this, SLOT(pagerangeChanged()));
68 connect(toED, SIGNAL(textChanged(const QString&)),
69 this, SLOT(change_adaptor()));
70 connect(fileRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
71 connect(printerRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
72 connect(rangeRB, SIGNAL(toggled(bool)), fromED, SLOT(setEnabled(bool)));
73 connect(rangeRB, SIGNAL(toggled(bool)), toED, SLOT(setEnabled(bool)));
75 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
77 bc().setCancel(closePB);
81 void GuiPrint::change_adaptor()
87 void GuiPrint::browseClicked()
90 browseRelFile(docstring(), from_utf8(buffer().filePath()),
92 FileFilterList(_("PostScript files (*.ps)")),
94 QString file = toqstr(name);
96 fileED->setText(file);
102 void GuiPrint::fileChanged()
104 if (!fileED->text().isEmpty())
105 fileRB->setChecked(true);
110 void GuiPrint::copiesChanged(int i)
112 collateCB->setEnabled(i != 1);
117 void GuiPrint::printerChanged()
119 printerRB->setChecked(true);
124 void GuiPrint::pagerangeChanged()
130 void GuiPrint::updateContents()
132 // only reset params if a different buffer
133 if (!params_.file_name.empty()
134 && params_.file_name == fromqstr(fileED->text()))
137 printerED->setText(toqstr(params_.printer_name));
138 fileED->setText(toqstr(params_.file_name));
140 printerRB->setChecked(true);
141 if (params_.target == PrinterParams::FILE)
142 fileRB->setChecked(true);
144 reverseCB->setChecked(params_.reverse_order);
146 copiesSB->setValue(params_.count_copies);
148 oddCB->setChecked(params_.odd_pages);
149 evenCB->setChecked(params_.even_pages);
151 collateCB->setChecked(params_.sorted_copies);
153 if (params_.all_pages) {
154 allRB->setChecked(true);
156 rangeRB->setChecked(true);
157 fromED->setText(QString::number(params_.from_page));
158 toED->setText(QString::number(params_.to_page));
163 void GuiPrint::applyView()
165 PrinterParams::Target t = PrinterParams::PRINTER;
166 if (fileRB->isChecked())
167 t = PrinterParams::FILE;
169 params_ = PrinterParams(t,
170 fromqstr(printerED->text()),
171 support::os::internal_path(fromqstr(fileED->text())),
173 fromED->text().toUInt(),
174 toED->text().toUInt(),
177 copiesSB->text().toUInt(),
178 collateCB->isChecked(),
179 reverseCB->isChecked()
184 bool GuiPrint::initialiseParams(std::string const &)
186 /// get global printer parameters
187 string const name = support::changeExtension(buffer().absFileName(),
188 lyxrc.print_file_extension);
189 params_ = PrinterParams(PrinterParams::PRINTER, lyxrc.printer, name);
191 setButtonsValid(true); // so that the user can press Ok
196 void GuiPrint::clearParams()
198 params_ = PrinterParams();
202 /// print the current buffer
203 void GuiPrint::dispatchParams()
205 string command = lyxrc.print_command + ' ';
207 if (params_.target == PrinterParams::PRINTER
208 && lyxrc.print_adapt_output // dvips wants a printer name
209 && !params_.printer_name.empty()) {// printer name given
210 command += lyxrc.print_to_printer + params_.printer_name + ' ';
213 if (!params_.all_pages && params_.from_page) {
214 command += lyxrc.print_pagerange_flag + ' ';
215 command += convert<string>(params_.from_page);
216 if (params_.to_page) {
217 // we have a range "from-to"
218 command += '-' + convert<string>(params_.to_page);
223 // If both are, or both are not selected, then skip the odd/even printing
224 if (params_.odd_pages != params_.even_pages) {
225 if (params_.odd_pages)
226 command += lyxrc.print_oddpage_flag + ' ';
227 else if (params_.even_pages)
228 command += lyxrc.print_evenpage_flag + ' ';
231 if (params_.count_copies > 1) {
232 if (params_.sorted_copies)
233 command += lyxrc.print_collcopies_flag;
235 command += lyxrc.print_copies_flag;
236 command += ' ' + convert<string>(params_.count_copies) + ' ';
239 if (params_.reverse_order)
240 command += lyxrc.print_reverse_flag + ' ';
242 if (!lyxrc.print_extra_options.empty())
243 command += lyxrc.print_extra_options + ' ';
245 command += buffer().params().dvips_options();
247 string const target = (params_.target == PrinterParams::PRINTER) ?
250 string const target_name = (params_.target == PrinterParams::PRINTER) ?
251 (params_.printer_name.empty() ? "default" : params_.printer_name) :
254 string const data = target + " \"" + target_name + "\" \"" + command + '"';
255 dispatch(FuncRequest(getLfun(), data));
259 Dialog * createGuiPrint(GuiView & lv) { return new GuiPrint(lv); }
262 } // namespace frontend
265 #include "GuiPrint_moc.cpp"