2001-02-14 19:43:56 +00:00
|
|
|
/**
|
2001-08-19 13:25:15 +00:00
|
|
|
* \file QPrint.C
|
2001-02-14 19:43:56 +00:00
|
|
|
* Copyright 2001 LyX Team
|
|
|
|
* see the file COPYING
|
|
|
|
*
|
|
|
|
* \author John Levon, moz@compsoc.man.ac.uk
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
#include "QPrintDialog.h"
|
|
|
|
#include "QPrint.h"
|
2001-02-14 19:43:56 +00:00
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "QtLyXView.h"
|
|
|
|
|
|
|
|
#include "PrinterParams.h"
|
|
|
|
#include "Liason.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "qmessagebox.h"
|
|
|
|
|
|
|
|
using Liason::printBuffer;
|
|
|
|
using Liason::getPrinterParams;
|
|
|
|
using std::max;
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
QPrint::QPrint(LyXView *v, Dialogs *d)
|
2001-02-14 19:43:56 +00:00
|
|
|
: dialog_(0), lv_(v), d_(d), h_(0), u_(0)
|
|
|
|
{
|
2001-08-19 13:25:15 +00:00
|
|
|
d->showPrint.connect(SigC::slot(this, &QPrint::show));
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
QPrint::~QPrint()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
delete dialog_;
|
|
|
|
}
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
// we can safely ignore the parameter because we can always update
|
2001-08-19 13:25:15 +00:00
|
|
|
void QPrint::update(bool)
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
if (!lv_->view()->available())
|
|
|
|
return;
|
|
|
|
|
|
|
|
PrinterParams pp(getPrinterParams(lv_->buffer()));
|
|
|
|
|
|
|
|
dialog_->setTarget(pp.target);
|
|
|
|
dialog_->setPrinter(pp.printer_name.c_str());
|
|
|
|
dialog_->setFile(pp.file_name.c_str());
|
|
|
|
dialog_->setWhichPages(pp.which_pages);
|
|
|
|
dialog_->setReverse(pp.reverse_order);
|
|
|
|
dialog_->setSort(pp.unsorted_copies);
|
|
|
|
dialog_->setCount(pp.count_copies);
|
|
|
|
|
|
|
|
if (!pp.from_page.empty()) {
|
|
|
|
dialog_->setFrom(pp.from_page.c_str());
|
|
|
|
if (pp.to_page)
|
|
|
|
dialog_->setTo(tostr(pp.to_page).c_str());
|
|
|
|
else
|
|
|
|
dialog_->setTo("");
|
|
|
|
} else {
|
|
|
|
dialog_->setFrom("");
|
|
|
|
dialog_->setTo("");
|
|
|
|
}
|
|
|
|
}
|
2001-08-19 13:25:15 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QPrint::print()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
if (!lv_->view()->available())
|
|
|
|
return;
|
|
|
|
|
|
|
|
string from;
|
|
|
|
int to(0);
|
|
|
|
|
|
|
|
if (strlen(dialog_->getFrom())) {
|
|
|
|
from = dialog_->getFrom();
|
|
|
|
if (strlen(dialog_->getTo()))
|
|
|
|
to = strToInt(dialog_->getTo());
|
|
|
|
}
|
|
|
|
|
2001-03-15 18:21:56 +00:00
|
|
|
int retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(),
|
2001-02-14 19:43:56 +00:00
|
|
|
string(dialog_->getPrinter()), string(dialog_->getFile()),
|
|
|
|
dialog_->getWhichPages(), from, to, dialog_->getReverse(),
|
|
|
|
dialog_->getSort(), max(strToInt(dialog_->getCount()),1)));
|
|
|
|
|
|
|
|
if (!retval) {
|
|
|
|
// FIXME: should have a utility class for this
|
|
|
|
string message(_("An error occured while printing.\n\n"));
|
|
|
|
message += _("Check the parameters are correct.\n");
|
|
|
|
QMessageBox msg( _("LyX: Print Error"), message.c_str(), QMessageBox::Warning, 1,0,0);
|
|
|
|
msg.raise();
|
|
|
|
msg.setActiveWindow();
|
|
|
|
msg.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
void QPrint::show()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
if (!dialog_)
|
2001-08-19 13:25:15 +00:00
|
|
|
dialog_ = new QPrintDialog(this, 0, _("LyX: Print"));
|
2001-02-14 19:43:56 +00:00
|
|
|
|
|
|
|
if (!dialog_->isVisible()) {
|
2001-08-19 13:25:15 +00:00
|
|
|
h_ = d_->hideBufferDependent.connect(SigC::slot(this, &QPrint::hide));
|
|
|
|
u_ = d_->updateBufferDependent.connect(SigC::slot(this, &QPrint::update));
|
2001-02-14 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dialog_->raise();
|
|
|
|
dialog_->setActiveWindow();
|
|
|
|
|
|
|
|
update();
|
|
|
|
dialog_->show();
|
|
|
|
}
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
void QPrint::close()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
h_.disconnect();
|
|
|
|
u_.disconnect();
|
|
|
|
}
|
2001-08-19 13:25:15 +00:00
|
|
|
|
2001-02-14 19:43:56 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QPrint::hide()
|
2001-02-14 19:43:56 +00:00
|
|
|
{
|
|
|
|
dialog_->hide();
|
|
|
|
close();
|
|
|
|
}
|