diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 1d63652512..62e381dfd3 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,10 @@ +2001-08-29 John Levon + + * Dialogs.C: + * QPrint.[Ch]: + * QPrintDialog.[Ch]: + * ui/QPrintDialog.ui: add print dialog back + 2001-08-29 John Levon * Makefile.am: diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index afbf87d3c5..629f992e28 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -26,6 +26,7 @@ #include "QLogDialog.h" #include "QMinipageDialog.h" #include "QPreambleDialog.h" +#include "QPrintDialog.h" #include "QRefDialog.h" #include "QTabularCreateDialog.h" #include "QThesaurusDialog.h" @@ -77,6 +78,7 @@ #include "controllers/ControlLog.h" #include "controllers/ControlMinipage.h" #include "controllers/ControlPreamble.h" +#include "controllers/ControlPrint.h" #include "controllers/ControlRef.h" #include "controllers/ControlSplash.h" #include "controllers/ControlTabularCreate.h" @@ -88,7 +90,6 @@ #include "controllers/ControlCitation.h" #include "controllers/ControlFloat.h" #include "controllers/ControlLabel.h" -#include "controllers/ControlPrint.h" #include "controllers/ControlRef.h" #include "controllers/ControlSearch.h" #include "controllers/ControlSpellchecker.h" @@ -120,6 +121,7 @@ Dialogs::Dialogs(LyXView * lv) add(new GUILog(*lv, *this)); add(new GUIMinipage(*lv, *this)); add(new GUIPreamble(*lv, *this)); + add(new GUIPrint(*lv, *this)); add(new GUIRef(*lv, *this)); add(new GUITabularCreate(*lv, *this)); add(new GUIThesaurus(*lv, *this)); diff --git a/src/frontends/qt2/QPrint.C b/src/frontends/qt2/QPrint.C index 52a3080333..0a0ad259cd 100644 --- a/src/frontends/qt2/QPrint.C +++ b/src/frontends/qt2/QPrint.C @@ -1,131 +1,121 @@ /** * \file QPrint.C - * Copyright 2001 LyX Team - * see the file COPYING + * Copyright 2001 the LyX Team + * Read the file COPYING * - * \author John Levon, moz@compsoc.man.ac.uk + * \author John Levon + * \author Edwin Leuven, leuven@fee.uva.nl */ #include +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include +#include +#include +#include + #include "QPrintDialog.h" #include "QPrint.h" -#include "Dialogs.h" +#include "Qt2BC.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; - -QPrint::QPrint(LyXView *v, Dialogs *d) - : dialog_(0), lv_(v), d_(d), h_(0), u_(0) -{ - d->showPrint.connect(SigC::slot(this, &QPrint::show)); -} - - -QPrint::~QPrint() -{ - delete dialog_; -} - - -// we can safely ignore the parameter because we can always update -void QPrint::update(bool) -{ - 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(""); - } -} - -void QPrint::print() +#include "QtLyXView.h" +#include "ControlPrint.h" + +#include "support/lstrings.h" + +typedef Qt2CB > base_class; + +QPrint::QPrint(ControlPrint & c) + : base_class(c, _("Print")) { - if (!lv_->view()->available()) - return; +} + + +void QPrint::build_dialog() +{ + dialog_.reset(new QPrintDialog(this)); + + bc().setOK(dialog_->printPB); + bc().setCancel(dialog_->closePB); +} + + +void QPrint::update_contents() +{ + PrinterParams & pp = controller().params(); + + dialog_->printerED->setText(pp.printer_name.c_str()); + dialog_->fileED->setText(pp.file_name.c_str()); + + dialog_->printerRB->setChecked(true); + if (pp.target == PrinterParams::FILE) + dialog_->fileRB->setChecked(true); + + dialog_->reverseCB->setChecked(pp.reverse_order); + + QRadioButton * button; + switch (pp.which_pages) { + case PrinterParams::ALL: button = dialog_->allRB; break; + case PrinterParams::ODD: button = dialog_->oddRB; break; + case PrinterParams::EVEN: button = dialog_->evenRB; break; + } + button->setChecked(true); + + // hmmm... maybe a bit weird but maybe not + // we might just be remembering the last + // time this was printed. + if (!pp.from_page.empty()) { + dialog_->fromED->setText(pp.from_page.c_str()); + + dialog_->toED->setText(""); + if (pp.to_page) + dialog_->toED->setText(tostr(pp.to_page).c_str()); + } else { + dialog_->fromED->setText(""); + dialog_->toED->setText(""); + } + + dialog_->copiesSB->setValue(pp.count_copies); +} + + +void QPrint::apply() +{ + PrinterParams::WhichPages wp; + + if (dialog_->allRB->isChecked()) + wp = PrinterParams::ALL; + else if (dialog_->oddRB->isChecked()) + wp = PrinterParams::ODD; + else + wp = PrinterParams::EVEN; string from; int to(0); - - if (strlen(dialog_->getFrom())) { - from = dialog_->getFrom(); - if (strlen(dialog_->getTo())) - to = strToInt(dialog_->getTo()); - } - - int retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(), - 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(); - } -} - - -void QPrint::show() -{ - if (!dialog_) - dialog_ = new QPrintDialog(this, 0, _("LyX: Print")); - - if (!dialog_->isVisible()) { - h_ = d_->hideBufferDependent.connect(SigC::slot(this, &QPrint::hide)); - u_ = d_->updateBufferDependent.connect(SigC::slot(this, &QPrint::update)); + if (!dialog_->fromED->text().isEmpty()) { + // we have at least one page requested + from = dialog_->fromED->text().latin1(); + if (!dialog_->toED->text().isEmpty()) + to = strToInt(dialog_->toED->text().latin1()); } - dialog_->raise(); - dialog_->setActiveWindow(); + PrinterParams::Target t = PrinterParams::PRINTER; + if (dialog_->fileRB->isChecked()) + t = PrinterParams::FILE; + + PrinterParams const pp(t, + dialog_->printerED->text().latin1(), + dialog_->fileED->text().latin1(), + wp, from, to, + dialog_->reverseCB->isChecked(), + !dialog_->collateCB->isChecked(), + strToInt(dialog_->copiesSB->text().latin1())); - update(); - dialog_->show(); -} - - -void QPrint::close() -{ - h_.disconnect(); - u_.disconnect(); -} - - -void QPrint::hide() -{ - dialog_->hide(); - close(); + controller().params() = pp; } diff --git a/src/frontends/qt2/QPrint.h b/src/frontends/qt2/QPrint.h index 18630dddc5..e6606deb84 100644 --- a/src/frontends/qt2/QPrint.h +++ b/src/frontends/qt2/QPrint.h @@ -1,54 +1,42 @@ // -*- C++ -*- /** * \file QPrint.h - * Copyright 2001 LyX Team - * see the file COPYING + * Copyright 2001 the LyX Team + * Read the file COPYING * - * \author John Levon, moz@compsoc.man.ac.uk + * \author John Levon + * \author Edwin Leuven, leuven@fee.uva.nl */ + #ifndef QPRINT_H #define QPRINT_H -#include "DialogBase.h" -#include "boost/utility.hpp" +#ifdef __GNUG__ +#pragma interface +#endif -class Dialogs; -class LyXView; +#include "Qt2Base.h" + +class ControlPrint; class QPrintDialog; -class QPrint : public DialogBase { -public: - QPrint(LyXView *, Dialogs *); - ~QPrint(); +/// +class QPrint + : public Qt2CB > +{ +public: + /// + friend class QPrintDialog; + /// + QPrint(ControlPrint &); - /// start print - void print(); - /// close - void close(); - -private: - /// Create the dialog if necessary, update it and display it. - void show(); - /// Hide the dialog. - void hide(); - /// Update the dialog. - void update(bool = false); - - /// Real GUI implementation. - QPrintDialog * dialog_; - - /// the LyXView we belong to - LyXView * lv_; - - /** Which Dialogs do we belong to? - Used so we can get at the signals we have to connect to. - */ - Dialogs * d_; - - /// Hide connection. - SigC::Connection h_; - /// Update connection. - SigC::Connection u_; +private: + /// Apply changes + virtual void apply(); + /// update + virtual void update_contents(); + /// build the dialog + virtual void build_dialog(); }; #endif // QPRINT_H diff --git a/src/frontends/qt2/QPrintDialog.C b/src/frontends/qt2/QPrintDialog.C index 859a8c5779..19831a61b7 100644 --- a/src/frontends/qt2/QPrintDialog.C +++ b/src/frontends/qt2/QPrintDialog.C @@ -22,161 +22,66 @@ #include "support/filetools.h" #include "support/lstrings.h" -#include "lyxrc.h" -#include "PrinterParams.h" #include -#include -QPrintDialog::QPrintDialog(QPrint * f, QWidget * parent, const char * name, bool modal, WFlags fl) - : QPrintDialogBase(parent, name, modal, fl), +QPrintDialog::QPrintDialog(QPrint * f) + : QPrintDialogBase(0, 0, false, 0), form_(f) { - setCaption(name); + connect(printPB, SIGNAL(clicked()), + form_, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), + form_, SLOT(slotClose())); } - -QPrintDialog::~QPrintDialog() +void QPrintDialog::change_adaptor() { + form_->changed(); } - - -const char * QPrintDialog::getFrom() { - return fromPage->text(); -} - - -const char * QPrintDialog::getTo() { - return toPage->text(); -} - - -PrinterParams::Target QPrintDialog::getTarget() { - if (toPrinter->isChecked()) - return PrinterParams::PRINTER; - else - return PrinterParams::FILE; -} - - -const char * QPrintDialog::getPrinter() { - return printerName->text(); -} - - -const char * QPrintDialog::getFile() { - return fileName->text(); -} - - -PrinterParams::WhichPages QPrintDialog::getWhichPages() { - if (oddPages->isChecked()) - return PrinterParams::ODD; - else if (evenPages->isChecked()) - return PrinterParams::EVEN; - else - return PrinterParams::ALL; -} - - -bool QPrintDialog::getReverse() { - return reverse->isChecked(); -} - - -bool QPrintDialog::getSort() { - return collate->isChecked(); -} - - -const char * QPrintDialog::getCount() { - return copies->text(); -} - - -void QPrintDialog::setTarget(PrinterParams::Target t) { - toPrinter->setChecked(t==PrinterParams::PRINTER); - toFile->setChecked(t!=PrinterParams::PRINTER); -} - - -void QPrintDialog::setPrinter(const char * name) { - printerName->setText(name); -} - - -void QPrintDialog::setFile(const char * name) { - fileName->setText(name); -} - - -void QPrintDialog::setWhichPages(PrinterParams::WhichPages wp) { - switch (wp) { - case PrinterParams::ALL: - allPages->setChecked(true); - break; - case PrinterParams::EVEN: - evenPages->setChecked(true); - break; - case PrinterParams::ODD: - oddPages->setChecked(true); - break; + + +void QPrintDialog::browseClicked() +{ + QString file = QFileDialog::getOpenFileName(QString::null, + _("PostScript files (*.ps)"), this, 0, _("Select a file to print to")); + if (!file.isNull()) { + fileED->setText(file); + form_->changed(); } } - -void QPrintDialog::setReverse(bool on) { - reverse->setChecked(on); -} - - -void QPrintDialog::setSort(bool on) { - collate->setChecked(on); -} - - -void QPrintDialog::setCount(int num) { - copies->setValue(num); - collate->setEnabled(num > 1); -} - - -void QPrintDialog::setFrom(const char * text) { - fromPage->setText(text); -} - - -void QPrintDialog::setTo(const char * text) { - toPage->setText(text); + +void QPrintDialog::fileChanged() +{ + if (!fileED->text().isEmpty()) + fileRB->setChecked(true); + form_->changed(); } -void QPrintDialog::browse_file() +void QPrintDialog::copiesChanged(int i) { - QString d( OnlyPath(tostr(fileName->text())).c_str()); - QString s( QFileDialog::getOpenFileName(d, "PostScript Files (*.ps)", this)); - if (!s.isNull()) - fileName->setText(s); + collateCB->setEnabled(i != 1); + form_->changed(); } -void QPrintDialog::print() +void QPrintDialog::printerChanged() { - form_->print(); - form_->close(); - hide(); + printerRB->setChecked(true); + form_->changed(); } -void QPrintDialog::cancel_adaptor() +void QPrintDialog::pagerangeChanged() { - form_->close(); - hide(); -} - + int from = strToUnsignedInt(fromED->text().latin1()); + int to = strToUnsignedInt(toED->text().latin1()); -void QPrintDialog::set_collate(int copies) -{ - collate->setEnabled(copies > 1); + if (!toED->text().isEmpty() && from > to) + fromED->setText(toED->text()); + + form_->changed(); } diff --git a/src/frontends/qt2/QPrintDialog.h b/src/frontends/qt2/QPrintDialog.h index 6c951f2ad9..524d344aef 100644 --- a/src/frontends/qt2/QPrintDialog.h +++ b/src/frontends/qt2/QPrintDialog.h @@ -22,35 +22,15 @@ class QPrintDialog : public QPrintDialogBase { Q_OBJECT public: - QPrintDialog(QPrint * f, QWidget * parent = 0, const char * name = 0, bool modal = FALSE, WFlags fl = 0); - ~QPrintDialog(); + QPrintDialog(QPrint * f); - // FIXME: these should return std::string ! - const char * getFrom(); - const char * getTo(); - const char * getPrinter(); - const char * getFile(); - const char * getCount(); - PrinterParams::Target getTarget(); - PrinterParams::WhichPages getWhichPages(); - bool getReverse(); - bool getSort(); - void setFrom(const char *); - void setTo(const char *); - void setPrinter(const char *); - void setFile(const char *); - void setCount(int); - void setTarget(PrinterParams::Target); - void setWhichPages(PrinterParams::WhichPages); - void setReverse(bool); - void setSort(bool); - - protected slots: - void cancel_adaptor(); - void browse_file(); - void print(); - void set_collate(int); + virtual void change_adaptor(); + virtual void browseClicked(); + virtual void fileChanged(); + virtual void copiesChanged(int); + virtual void printerChanged(); + virtual void pagerangeChanged(); private: QPrint * form_; diff --git a/src/frontends/qt2/ui/QPrintDialog.ui b/src/frontends/qt2/ui/QPrintDialog.ui index b27f253740..caa594664b 100644 --- a/src/frontends/qt2/ui/QPrintDialog.ui +++ b/src/frontends/qt2/ui/QPrintDialog.ui @@ -13,13 +13,13 @@ 0 0 - 359 + 331 342 caption - Form1 + Print @@ -56,44 +56,60 @@ QRadioButton name - toPrinter + printerRB text - &Printer + P&rinter checked true + + toolTip + Send output to the printer + QRadioButton name - toFile + fileRB text &File + + toolTip + Send output to a file + QLineEdit name - printerName + printerED + + + toolTip + Send output to the given printer QLineEdit name - fileName + fileED enabled - false + true + + + toolTip + Send output to a file @@ -104,11 +120,11 @@ text - &Browse... + &Browse ... enabled - false + true @@ -133,58 +149,55 @@ spacing - 3 + 6 QRadioButton name - allPages + allRB text - All + &All checked true + + toolTip + Print all pages + QRadioButton name - oddPages + oddRB text - Odd + &Odd + + + toolTip + Print odd pages only QRadioButton name - evenPages + evenRB text - Even + &Even - - - QLabel - - name - fromPageL - - - text - Starting range: - - - enabled - false + + toolTip + Print even pages only @@ -195,55 +208,98 @@ text - Last page: + &Last page: enabled - false + true + + + buddy + toED QLineEdit name - toPage + toED enabled - false + true + + + toolTip + Page number to print to QCheckBox name - reverse + reverseCB text - &Reverse order + Re&verse order + + + toolTip + Print in reverse order QLineEdit name - fromPage + fromED enabled - false + true + + + toolTip + Page number to print from - QRadioButton + QLabel name - customPages + rangeLA text - Pages: + Ran&ge + + + buddy + fromED + + + toolTip + Set a range of pages to print + + + + QLabel + + name + fromPageL + + + text + &Starting range: + + + enabled + true + + + buddy + fromED @@ -271,7 +327,7 @@ QSpinBox name - copies + copiesSB minValue @@ -281,21 +337,29 @@ value 1 + + toolTip + Number of copies + QCheckBox name - collate + collateCB text - Co&llate + &Collate enabled false + + toolTip + Collate copies + @@ -371,11 +435,11 @@ QPushButton name - cancelPB + closePB text - &Cancel + Close default @@ -388,75 +452,117 @@ - toFile - toggled(bool) - browsePB - setEnabled(bool) - - - toFile - toggled(bool) - fileName - setEnabled(bool) - - - toFile - toggled(bool) - printerName - setDisabled(bool) - - - printPB - clicked() - QPrintDialogBase - print() - - - cancelPB - clicked() - QPrintDialogBase - cancel_adaptor() - - - copies + copiesSB valueChanged(int) QPrintDialogBase - set_collate(int) + copiesChanged(int) + + + printerED + textChanged(const QString&) + QPrintDialogBase + printerChanged() + + + fileED + textChanged(const QString&) + QPrintDialogBase + fileChanged() browsePB clicked() QPrintDialogBase - browse_file() + browseClicked() - customPages + allRB toggled(bool) - fromPage - setEnabled(bool) + QPrintDialogBase + change_adaptor() - customPages + oddRB toggled(bool) - fromPageL - setEnabled(bool) + QPrintDialogBase + change_adaptor() - customPages + evenRB toggled(bool) - toPage - setEnabled(bool) + QPrintDialogBase + change_adaptor() - customPages + reverseCB toggled(bool) - toPageL - setEnabled(bool) + QPrintDialogBase + change_adaptor() - cancel_adaptor() - enable_pagerange(int) - browse_file() - print() - set_collate(int) + + collateCB + toggled(bool) + QPrintDialogBase + change_adaptor() + + + fromED + textChanged(const QString&) + QPrintDialogBase + pagerangeChanged() + + + fromED + textChanged(const QString&) + QPrintDialogBase + change_adaptor() + + + toED + textChanged(const QString&) + QPrintDialogBase + pagerangeChanged() + + + toED + textChanged(const QString&) + QPrintDialogBase + change_adaptor() + + + fileRB + toggled(bool) + QPrintDialogBase + change_adaptor() + + + printerRB + toggled(bool) + QPrintDialogBase + change_adaptor() + + browseClicked() + change_adaptor() + copiesChanged(int) + fileChanged() + pagerangeChanged() + printerChanged() + + printerRB + printerED + fileRB + fileED + browsePB + allRB + oddRB + evenRB + fromED + toED + reverseCB + copiesSB + collateCB + printPB + closePB +