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 "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "FuncRequest.h"
|
2008-04-19 20:39:48 +00:00
|
|
|
#include "LyXRC.h"
|
2007-10-06 21:31:01 +00:00
|
|
|
|
|
|
|
#include "support/convert.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-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
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
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiPrint::GuiPrint(GuiView & lv)
|
2008-02-05 12:43:19 +00:00
|
|
|
: GuiDialog(lv, "print", qt_("Print Document"))
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
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()));
|
2008-04-20 21:27:42 +00:00
|
|
|
connect(fromED, SIGNAL(textChanged(QString)),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(pagerangeChanged()));
|
2008-04-20 21:27:42 +00:00
|
|
|
connect(fromED, SIGNAL(textChanged(QString)),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2008-04-20 21:27:42 +00:00
|
|
|
connect(toED, SIGNAL(textChanged(QString)),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(pagerangeChanged()));
|
2008-04-20 21:27:42 +00:00
|
|
|
connect(toED, SIGNAL(textChanged(QString)),
|
2007-08-31 22:16:11 +00:00
|
|
|
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
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
QString file =
|
|
|
|
browseRelFile(QString(), bufferFilepath(), qt_("Print to file"),
|
2008-04-20 19:56:01 +00:00
|
|
|
QStringList(qt_("PostScript files (*.ps)")), true);
|
2008-03-06 00:07:19 +00:00
|
|
|
if (!file.isEmpty()) {
|
2007-08-31 22:16:11 +00:00
|
|
|
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
|
|
|
|
2009-04-22 21:17:49 +00:00
|
|
|
if (params_.all_pages)
|
2007-09-05 20:33:29 +00:00
|
|
|
allRB->setChecked(true);
|
2009-04-22 21:17:49 +00:00
|
|
|
else {
|
2007-09-05 20:33:29 +00:00
|
|
|
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
|
|
|
{
|
2008-04-19 20:39:48 +00:00
|
|
|
params_.target = fileRB->isChecked()
|
|
|
|
? PrinterParams::FILE : PrinterParams::PRINTER;
|
|
|
|
params_.printer_name = fromqstr(printerED->text());
|
|
|
|
params_.file_name = os::internal_path(fromqstr(fileED->text()));
|
|
|
|
params_.all_pages = allRB->isChecked();
|
|
|
|
params_.from_page = fromED->text().toUInt();
|
|
|
|
params_.to_page = toED->text().toUInt();
|
|
|
|
params_.odd_pages = oddCB->isChecked();
|
|
|
|
params_.even_pages = evenCB->isChecked();
|
|
|
|
params_.count_copies = copiesSB->text().toUInt();
|
|
|
|
params_.sorted_copies = collateCB->isChecked();
|
|
|
|
params_.reverse_order = reverseCB->isChecked();
|
2007-10-06 21:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
bool GuiPrint::initialiseParams(string const &)
|
2007-10-06 21:31:01 +00:00
|
|
|
{
|
|
|
|
/// get global printer parameters
|
2008-04-19 20:39:48 +00:00
|
|
|
params_ = PrinterParams();
|
2008-04-21 06:53:00 +00:00
|
|
|
params_.file_name = support::changeExtension(buffer().absFileName(),
|
2008-04-20 21:27:42 +00:00
|
|
|
lyxrc.print_file_extension);
|
2007-10-06 21:31:01 +00:00
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiPrint(GuiView & lv) { return new GuiPrint(lv); }
|
2007-10-06 21:31:01 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-08-31 22:16:11 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiPrint.cpp"
|