2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiPrint.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Edwin Leuven
|
2007-10-06 21:31:01 +00:00
|
|
|
* \author Angus Leeming
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiPrint.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "PrinterParams.h"
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
#include "frontend_helpers.h"
|
|
|
|
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
#include "support/convert.h"
|
|
|
|
#include "support/FileFilterList.h"
|
|
|
|
#include "support/filetools.h"
|
2007-06-26 16:46:40 +00:00
|
|
|
#include "support/os.h"
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QPushButton>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
using std::string;
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
using support::FileFilterList;
|
|
|
|
|
|
|
|
|
|
|
|
GuiPrint::GuiPrint(LyXView & lv)
|
2007-10-09 19:34:27 +00:00
|
|
|
: GuiDialog(lv, "print")
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
setViewTitle(_("Print Document"));
|
2007-08-31 22:16:11 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
2007-08-31 22:16:11 +00:00
|
|
|
|
|
|
|
connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int)));
|
2007-10-06 21:31:01 +00:00
|
|
|
connect(printerED, SIGNAL(textChanged(QString)),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(printerChanged()));
|
2007-10-06 21:31:01 +00:00
|
|
|
connect(fileED, SIGNAL(textChanged(QString)),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(fileChanged() ));
|
|
|
|
connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
|
|
|
|
connect(allRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(reverseCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(collateCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(fromED, SIGNAL(textChanged(const QString&)),
|
|
|
|
this, SLOT(pagerangeChanged()));
|
|
|
|
connect(fromED, SIGNAL(textChanged(const QString&)),
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(toED, SIGNAL(textChanged(const QString&)),
|
|
|
|
this, SLOT(pagerangeChanged()));
|
|
|
|
connect(toED, SIGNAL(textChanged(const QString&)),
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(fileRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(printerRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(rangeRB, SIGNAL(toggled(bool)), fromED, SLOT(setEnabled(bool)));
|
|
|
|
connect(rangeRB, SIGNAL(toggled(bool)), toED, SLOT(setEnabled(bool)));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
|
|
|
|
bc().setOK(printPB);
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::change_adaptor()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::browseClicked()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2007-10-06 21:31:01 +00:00
|
|
|
docstring name =
|
|
|
|
browseRelFile(docstring(), from_utf8(buffer().filePath()),
|
|
|
|
_("Print to file"),
|
|
|
|
FileFilterList(_("PostScript files (*.ps)")),
|
|
|
|
true);
|
|
|
|
QString file = toqstr(name);
|
2007-08-31 22:16:11 +00:00
|
|
|
if (!file.isNull()) {
|
|
|
|
fileED->setText(file);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::fileChanged()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
if (!fileED->text().isEmpty())
|
|
|
|
fileRB->setChecked(true);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::copiesChanged(int i)
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
collateCB->setEnabled(i != 1);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::printerChanged()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
printerRB->setChecked(true);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::pagerangeChanged()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
// only reset params if a different buffer
|
2007-10-06 21:31:01 +00:00
|
|
|
if (!params_.file_name.empty()
|
|
|
|
&& params_.file_name == fromqstr(fileED->text()))
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
printerED->setText(toqstr(params_.printer_name));
|
|
|
|
fileED->setText(toqstr(params_.file_name));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
printerRB->setChecked(true);
|
2007-10-06 21:31:01 +00:00
|
|
|
if (params_.target == PrinterParams::FILE)
|
2007-09-05 20:33:29 +00:00
|
|
|
fileRB->setChecked(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
reverseCB->setChecked(params_.reverse_order);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
copiesSB->setValue(params_.count_copies);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
oddCB->setChecked(params_.odd_pages);
|
|
|
|
evenCB->setChecked(params_.even_pages);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
collateCB->setChecked(params_.sorted_copies);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
if (params_.all_pages) {
|
2007-09-05 20:33:29 +00:00
|
|
|
allRB->setChecked(true);
|
|
|
|
} else {
|
|
|
|
rangeRB->setChecked(true);
|
2007-10-06 21:31:01 +00:00
|
|
|
fromED->setText(QString::number(params_.from_page));
|
|
|
|
toED->setText(QString::number(params_.to_page));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
PrinterParams::Target t = PrinterParams::PRINTER;
|
2007-09-05 20:33:29 +00:00
|
|
|
if (fileRB->isChecked())
|
2006-03-05 17:24:44 +00:00
|
|
|
t = PrinterParams::FILE;
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
params_ = PrinterParams(t,
|
2007-09-05 20:33:29 +00:00
|
|
|
fromqstr(printerED->text()),
|
|
|
|
support::os::internal_path(fromqstr(fileED->text())),
|
|
|
|
allRB->isChecked(),
|
|
|
|
fromED->text().toUInt(),
|
|
|
|
toED->text().toUInt(),
|
|
|
|
oddCB->isChecked(),
|
|
|
|
evenCB->isChecked(),
|
|
|
|
copiesSB->text().toUInt(),
|
|
|
|
collateCB->isChecked(),
|
2007-10-06 21:31:01 +00:00
|
|
|
reverseCB->isChecked()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiPrint::initialiseParams(std::string const &)
|
|
|
|
{
|
|
|
|
/// get global printer parameters
|
2007-10-20 10:03:45 +00:00
|
|
|
string const name = support::changeExtension(buffer().absFileName(),
|
2007-10-06 21:31:01 +00:00
|
|
|
lyxrc.print_file_extension);
|
|
|
|
params_ = PrinterParams(PrinterParams::PRINTER, lyxrc.printer, name);
|
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
setButtonsValid(true); // so that the user can press Ok
|
2007-10-06 21:31:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
void GuiPrint::clearParams()
|
|
|
|
{
|
|
|
|
params_ = PrinterParams();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 21:31:01 +00:00
|
|
|
|
|
|
|
/// print the current buffer
|
|
|
|
void GuiPrint::dispatchParams()
|
|
|
|
{
|
|
|
|
string command = lyxrc.print_command + ' ';
|
|
|
|
|
|
|
|
if (params_.target == PrinterParams::PRINTER
|
|
|
|
&& lyxrc.print_adapt_output // dvips wants a printer name
|
|
|
|
&& !params_.printer_name.empty()) {// printer name given
|
|
|
|
command += lyxrc.print_to_printer + params_.printer_name + ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!params_.all_pages && params_.from_page) {
|
|
|
|
command += lyxrc.print_pagerange_flag + ' ';
|
|
|
|
command += convert<string>(params_.from_page);
|
|
|
|
if (params_.to_page) {
|
|
|
|
// we have a range "from-to"
|
|
|
|
command += '-' + convert<string>(params_.to_page);
|
|
|
|
}
|
|
|
|
command += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
// If both are, or both are not selected, then skip the odd/even printing
|
|
|
|
if (params_.odd_pages != params_.even_pages) {
|
|
|
|
if (params_.odd_pages)
|
|
|
|
command += lyxrc.print_oddpage_flag + ' ';
|
|
|
|
else if (params_.even_pages)
|
|
|
|
command += lyxrc.print_evenpage_flag + ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params_.count_copies > 1) {
|
|
|
|
if (params_.sorted_copies)
|
|
|
|
command += lyxrc.print_collcopies_flag;
|
|
|
|
else
|
|
|
|
command += lyxrc.print_copies_flag;
|
|
|
|
command += ' ' + convert<string>(params_.count_copies) + ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params_.reverse_order)
|
|
|
|
command += lyxrc.print_reverse_flag + ' ';
|
|
|
|
|
|
|
|
if (!lyxrc.print_extra_options.empty())
|
|
|
|
command += lyxrc.print_extra_options + ' ';
|
|
|
|
|
|
|
|
command += buffer().params().dvips_options();
|
|
|
|
|
|
|
|
string const target = (params_.target == PrinterParams::PRINTER) ?
|
|
|
|
"printer" : "file";
|
|
|
|
|
|
|
|
string const target_name = (params_.target == PrinterParams::PRINTER) ?
|
|
|
|
(params_.printer_name.empty() ? "default" : params_.printer_name) :
|
|
|
|
params_.file_name;
|
|
|
|
|
|
|
|
string const data = target + " \"" + target_name + "\" \"" + command + '"';
|
|
|
|
dispatch(FuncRequest(getLfun(), data));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dialog * createGuiPrint(LyXView & lv) { return new GuiPrint(lv); }
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-08-31 22:16:11 +00:00
|
|
|
|
|
|
|
#include "GuiPrint_moc.cpp"
|