]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QPrint.C
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / QPrint.C
index 52a3080333ad42761cd9c7feff940bc76541cff3..07f721d0f39b3bbca1c2d5f9a35229d579831d47 100644 (file)
 /**
  * \file QPrint.C
- * Copyright 2001 LyX Team
- * see the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author John Levon, moz@compsoc.man.ac.uk
+ * \author John Levon
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 
-#include "QPrintDialog.h"
-#include "QPrint.h"
-#include "Dialogs.h"
-#include "gettext.h"
-#include "buffer.h"
-#include "lyxrc.h" 
-#include "QtLyXView.h" 
+#ifdef __GNUG__
+#pragma implementation
+#endif
 
-#include "PrinterParams.h" 
-#include "Liason.h" 
-#include "BufferView.h" 
+#include "LyXView.h"
+#include "PrinterParams.h"
+#include "ControlPrint.h"
 #include "support/lstrings.h"
-#include "qmessagebox.h"
+#include "gettext.h"
 
-using Liason::printBuffer;
-using Liason::getPrinterParams;
-using std::max;
+#include "QPrint.h"
+#include "QLPrintDialog.h"
+#include "Qt2BC.h"
 
-QPrint::QPrint(LyXView *v, Dialogs *d)
-       : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
-{
-       d->showPrint.connect(SigC::slot(this, &QPrint::show));
-}
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qradiobutton.h>
+#include <qspinbox.h>
+#include <qpushbutton.h>
+
+
+typedef Qt2CB<ControlPrint, Qt2DB<QLPrintDialog> > base_class;
 
 
-QPrint::~QPrint()
+QPrint::QPrint()
+       : base_class(_("Print"))
 {
-       delete dialog_;
 }
 
 
-// we can safely ignore the parameter because we can always update
-void QPrint::update(bool)
+void QPrint::build_dialog()
 {
-       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("");
-       }
+       dialog_.reset(new QLPrintDialog(this));
+
+       bc().setOK(dialog_->printPB);
+       bc().setCancel(dialog_->closePB);
 }
 
-void QPrint::print()
+
+void QPrint::update_contents()
 {
-       if (!lv_->view()->available())
-              return;
+       PrinterParams & pp = controller().params();
 
-       string from;
-       int to(0);
+       // only reset params if a different buffer
+       if (!pp.file_name.empty() && pp.file_name == dialog_->fileED->text().latin1())
+               return;
 
-       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();
-       }
-}
+       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);
 
-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));
-       }
+       dialog_->reverseCB->setChecked(pp.reverse_order);
 
-       dialog_->raise();
-       dialog_->setActiveWindow();
-       update();
-       dialog_->show();
-}
+       dialog_->copiesSB->setValue(pp.count_copies);
 
+       dialog_->oddCB->setChecked(pp.odd_pages);
+       dialog_->evenCB->setChecked(pp.even_pages);
 
-void QPrint::close()
-{
-       h_.disconnect();
-       u_.disconnect();
+       dialog_->collateCB->setChecked(pp.sorted_copies);
+
+       if (pp.all_pages) {
+               dialog_->allRB->setChecked(true);
+               return;
+       }
+
+       dialog_->rangeRB->setChecked(true);
+
+       QString s;
+       s.setNum(pp.from_page);
+       dialog_->fromED->setText(s);
+       s.setNum(pp.to_page);
+       dialog_->toED->setText(s);
 }
 
-void QPrint::hide()
+
+void QPrint::apply()
 {
-       dialog_->hide();
-       close();
+       PrinterParams::Target t = PrinterParams::PRINTER;
+       if (dialog_->fileRB->isChecked())
+               t = PrinterParams::FILE;
+
+       PrinterParams const pp(t,
+               dialog_->printerED->text().latin1(),
+               dialog_->fileED->text().latin1(),
+               dialog_->allRB->isChecked(),
+               dialog_->fromED->text().toUInt(),
+               dialog_->toED->text().toUInt(),
+               dialog_->oddCB->isChecked(),
+               dialog_->evenCB->isChecked(),
+               dialog_->copiesSB->text().toUInt(),
+               dialog_->collateCB->isChecked(),
+               dialog_->reverseCB->isChecked());
+
+       controller().params() = pp;
 }