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"
20 #include "frontend_helpers.h"
23 #include "BufferParams.h"
24 #include "FuncRequest.h"
27 #include "support/convert.h"
28 #include "support/FileFilterList.h"
29 #include "support/filetools.h"
30 #include "support/os.h"
34 #include <QRadioButton>
36 #include <QPushButton>
44 using support::FileFilterList;
47 GuiPrint::GuiPrint(LyXView & lv)
48 : GuiDialog(lv, "print")
51 setViewTitle(_("Print Document"));
53 connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK()));
54 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
56 connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int)));
57 connect(printerED, SIGNAL(textChanged(QString)),
58 this, SLOT(printerChanged()));
59 connect(fileED, SIGNAL(textChanged(QString)),
60 this, SLOT(fileChanged() ));
61 connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
62 connect(allRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
63 connect(reverseCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
64 connect(collateCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
65 connect(fromED, SIGNAL(textChanged(const QString&)),
66 this, SLOT(pagerangeChanged()));
67 connect(fromED, SIGNAL(textChanged(const QString&)),
68 this, SLOT(change_adaptor()));
69 connect(toED, SIGNAL(textChanged(const QString&)),
70 this, SLOT(pagerangeChanged()));
71 connect(toED, SIGNAL(textChanged(const QString&)),
72 this, SLOT(change_adaptor()));
73 connect(fileRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
74 connect(printerRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
75 connect(rangeRB, SIGNAL(toggled(bool)), fromED, SLOT(setEnabled(bool)));
76 connect(rangeRB, SIGNAL(toggled(bool)), toED, SLOT(setEnabled(bool)));
78 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
80 bc().setCancel(closePB);
84 void GuiPrint::change_adaptor()
90 void GuiPrint::browseClicked()
93 browseRelFile(docstring(), from_utf8(buffer().filePath()),
95 FileFilterList(_("PostScript files (*.ps)")),
97 QString file = toqstr(name);
99 fileED->setText(file);
105 void GuiPrint::fileChanged()
107 if (!fileED->text().isEmpty())
108 fileRB->setChecked(true);
113 void GuiPrint::copiesChanged(int i)
115 collateCB->setEnabled(i != 1);
120 void GuiPrint::printerChanged()
122 printerRB->setChecked(true);
127 void GuiPrint::pagerangeChanged()
133 void GuiPrint::updateContents()
135 // only reset params if a different buffer
136 if (!params_.file_name.empty()
137 && params_.file_name == fromqstr(fileED->text()))
140 printerED->setText(toqstr(params_.printer_name));
141 fileED->setText(toqstr(params_.file_name));
143 printerRB->setChecked(true);
144 if (params_.target == PrinterParams::FILE)
145 fileRB->setChecked(true);
147 reverseCB->setChecked(params_.reverse_order);
149 copiesSB->setValue(params_.count_copies);
151 oddCB->setChecked(params_.odd_pages);
152 evenCB->setChecked(params_.even_pages);
154 collateCB->setChecked(params_.sorted_copies);
156 if (params_.all_pages) {
157 allRB->setChecked(true);
159 rangeRB->setChecked(true);
160 fromED->setText(QString::number(params_.from_page));
161 toED->setText(QString::number(params_.to_page));
166 void GuiPrint::applyView()
168 PrinterParams::Target t = PrinterParams::PRINTER;
169 if (fileRB->isChecked())
170 t = PrinterParams::FILE;
172 params_ = PrinterParams(t,
173 fromqstr(printerED->text()),
174 support::os::internal_path(fromqstr(fileED->text())),
176 fromED->text().toUInt(),
177 toED->text().toUInt(),
180 copiesSB->text().toUInt(),
181 collateCB->isChecked(),
182 reverseCB->isChecked()
187 bool GuiPrint::initialiseParams(std::string const &)
189 /// get global printer parameters
190 string const name = support::changeExtension(buffer().absFileName(),
191 lyxrc.print_file_extension);
192 params_ = PrinterParams(PrinterParams::PRINTER, lyxrc.printer, name);
194 setButtonsValid(true); // so that the user can press Ok
199 void GuiPrint::clearParams()
201 params_ = PrinterParams();
205 /// print the current buffer
206 void GuiPrint::dispatchParams()
208 string command = lyxrc.print_command + ' ';
210 if (params_.target == PrinterParams::PRINTER
211 && lyxrc.print_adapt_output // dvips wants a printer name
212 && !params_.printer_name.empty()) {// printer name given
213 command += lyxrc.print_to_printer + params_.printer_name + ' ';
216 if (!params_.all_pages && params_.from_page) {
217 command += lyxrc.print_pagerange_flag + ' ';
218 command += convert<string>(params_.from_page);
219 if (params_.to_page) {
220 // we have a range "from-to"
221 command += '-' + convert<string>(params_.to_page);
226 // If both are, or both are not selected, then skip the odd/even printing
227 if (params_.odd_pages != params_.even_pages) {
228 if (params_.odd_pages)
229 command += lyxrc.print_oddpage_flag + ' ';
230 else if (params_.even_pages)
231 command += lyxrc.print_evenpage_flag + ' ';
234 if (params_.count_copies > 1) {
235 if (params_.sorted_copies)
236 command += lyxrc.print_collcopies_flag;
238 command += lyxrc.print_copies_flag;
239 command += ' ' + convert<string>(params_.count_copies) + ' ';
242 if (params_.reverse_order)
243 command += lyxrc.print_reverse_flag + ' ';
245 if (!lyxrc.print_extra_options.empty())
246 command += lyxrc.print_extra_options + ' ';
248 command += buffer().params().dvips_options();
250 string const target = (params_.target == PrinterParams::PRINTER) ?
253 string const target_name = (params_.target == PrinterParams::PRINTER) ?
254 (params_.printer_name.empty() ? "default" : params_.printer_name) :
257 string const data = target + " \"" + target_name + "\" \"" + command + '"';
258 dispatch(FuncRequest(getLfun(), data));
262 Dialog * createGuiPrint(LyXView & lv) { return new GuiPrint(lv); }
265 } // namespace frontend
268 #include "GuiPrint_moc.cpp"