]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiPrint.cpp
Fix the tab ordering of GuiDocument components.
[lyx.git] / src / frontends / qt4 / GuiPrint.cpp
index 7aea586cce9d7bd51342a5be215f7157347bf2bc..b0fd8718aa2233ea73d627a9b7b921a27f3eae8a 100644 (file)
@@ -5,6 +5,7 @@
  *
  * \author John Levon
  * \author Edwin Leuven
+ * \author Angus Leeming
  *
  * Full author contact details are available in file CREDITS.
  */
 #include <config.h>
 
 #include "GuiPrint.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
 
+#include "qt_helpers.h"
 #include "PrinterParams.h"
 
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "FuncRequest.h"
+#include "LyXRC.h"
+
+#include "support/convert.h"
+#include "support/filetools.h"
 #include "support/os.h"
 
 #include <QLineEdit>
 #include <QSpinBox>
 #include <QPushButton>
 
+using namespace std;
+using namespace lyx::support;
+
 namespace lyx {
 namespace frontend {
 
-GuiPrintDialog::GuiPrintDialog(GuiPrint * f)
-       : form_(f)
+
+GuiPrint::GuiPrint(GuiView & lv)
+       : GuiDialog(lv, "print", qt_("Print Document"))
 {
        setupUi(this);
 
-       connect(printPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
+       connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
 
        connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int)));
-       connect(printerED, SIGNAL(textChanged(const QString&)),
+       connect(printerED, SIGNAL(textChanged(QString)),
                this, SLOT(printerChanged()));
-       connect(fileED, SIGNAL(textChanged(const QString&)),
+       connect(fileED, SIGNAL(textChanged(QString)),
                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&)),
+       connect(fromED, SIGNAL(textChanged(QString)),
                this, SLOT(pagerangeChanged()));
-       connect(fromED, SIGNAL(textChanged(const QString&)),
+       connect(fromED, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
-       connect(toED, SIGNAL(textChanged(const QString&)),
+       connect(toED, SIGNAL(textChanged(QString)),
                this, SLOT(pagerangeChanged()));
-       connect(toED, SIGNAL(textChanged(const QString&)),
+       connect(toED, SIGNAL(textChanged(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)));
+
+       bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
+       bc().setOK(printPB);
+       bc().setCancel(closePB);
 }
 
 
-void GuiPrintDialog::change_adaptor()
+void GuiPrint::change_adaptor()
 {
-       form_->changed();
+       changed();
 }
 
 
-void GuiPrintDialog::browseClicked()
+void GuiPrint::browseClicked()
 {
-       QString file = toqstr(form_->controller().browse(docstring()));
-       if (!file.isNull()) {
+       QString file =
+               browseRelToParent(QString(), bufferFilePath(), qt_("Print to file"),
+                            QStringList(qt_("PostScript files (*.ps)")), true);
+       if (!file.isEmpty()) {
                fileED->setText(file);
-               form_->changed();
+               changed();
        }
 }
 
 
-void GuiPrintDialog::fileChanged()
+void GuiPrint::fileChanged()
 {
        if (!fileED->text().isEmpty())
                fileRB->setChecked(true);
-       form_->changed();
+       changed();
 }
 
 
-void GuiPrintDialog::copiesChanged(int i)
+void GuiPrint::copiesChanged(int i)
 {
        collateCB->setEnabled(i != 1);
-       form_->changed();
+       changed();
 }
 
 
-void GuiPrintDialog::printerChanged()
+void GuiPrint::printerChanged()
 {
        printerRB->setChecked(true);
-       form_->changed();
+       changed();
 }
 
 
-void GuiPrintDialog::pagerangeChanged()
+void GuiPrint::pagerangeChanged()
 {
-       form_->changed();
+       changed();
 }
 
 
-GuiPrint::GuiPrint(Dialog & parent)
-       : GuiView<GuiPrintDialog>(parent, _("Print Document"))
+void GuiPrint::updateContents()
 {
+       // only reset params if a different buffer
+       if (!params_.file_name.empty()
+                       && params_.file_name == fromqstr(fileED->text()))
+               return;
+
+       printerED->setText(toqstr(params_.printer_name));
+       fileED->setText(toqstr(params_.file_name));
+
+       printerRB->setChecked(true);
+       if (params_.target == PrinterParams::FILE)
+               fileRB->setChecked(true);
+
+       reverseCB->setChecked(params_.reverse_order);
+
+       copiesSB->setValue(params_.count_copies);
+
+       oddCB->setChecked(params_.odd_pages);
+       evenCB->setChecked(params_.even_pages);
+
+       collateCB->setChecked(params_.sorted_copies);
+
+       if (params_.all_pages)
+               allRB->setChecked(true);
+       else {
+               rangeRB->setChecked(true);
+               fromED->setText(QString::number(params_.from_page));
+               toED->setText(QString::number(params_.to_page));
+       }
 }
 
 
-void GuiPrint::build_dialog()
+void GuiPrint::applyView()
 {
-       dialog_.reset(new GuiPrintDialog(this));
-
-       bcview().setOK(dialog_->printPB);
-       bcview().setCancel(dialog_->closePB);
+       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();
 }
 
 
-void GuiPrint::update_contents()
+bool GuiPrint::initialiseParams(string const &)
 {
-       PrinterParams & pp = controller().params();
+       /// get global printer parameters
+       params_ = PrinterParams();
+       params_.file_name = support::changeExtension(buffer().absFileName(),
+                                       lyxrc.print_file_extension);
 
-       // only reset params if a different buffer
-       if (!pp.file_name.empty() && pp.file_name == fromqstr(dialog_->fileED->text()))
-               return;
+       setButtonsValid(true); // so that the user can press Ok
+       return true;
+}
 
-       dialog_->printerED->setText(toqstr(pp.printer_name));
-       dialog_->fileED->setText(toqstr(pp.file_name));
 
-       dialog_->printerRB->setChecked(true);
-       if (pp.target == PrinterParams::FILE)
-               dialog_->fileRB->setChecked(true);
+void GuiPrint::clearParams()
+{
+       params_ = PrinterParams();
+}
 
-       dialog_->reverseCB->setChecked(pp.reverse_order);
 
-       dialog_->copiesSB->setValue(pp.count_copies);
+/// print the current buffer
+void GuiPrint::dispatchParams()
+{
+       string command = lyxrc.print_command + ' ';
 
-       dialog_->oddCB->setChecked(pp.odd_pages);
-       dialog_->evenCB->setChecked(pp.even_pages);
+       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 + ' ';
+       }
 
-       dialog_->collateCB->setChecked(pp.sorted_copies);
+       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 (pp.all_pages) {
-               dialog_->allRB->setChecked(true);
-               return;
+       // 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 + ' ';
        }
 
-       dialog_->rangeRB->setChecked(true);
+       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) + ' ';
+       }
 
-       QString s;
-       s.setNum(pp.from_page);
-       dialog_->fromED->setText(s);
-       s.setNum(pp.to_page);
-       dialog_->toED->setText(s);
-}
+       if (params_.reverse_order)
+               command += lyxrc.print_reverse_flag + ' ';
 
+       if (!lyxrc.print_extra_options.empty())
+               command += lyxrc.print_extra_options + ' ';
 
-void GuiPrint::apply()
-{
-       PrinterParams::Target t = PrinterParams::PRINTER;
-       if (dialog_->fileRB->isChecked())
-               t = PrinterParams::FILE;
-
-       PrinterParams const pp(t,
-               fromqstr(dialog_->printerED->text()),
-               support::os::internal_path(fromqstr(dialog_->fileED->text())),
-               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;
+       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(GuiView & lv) { return new GuiPrint(lv); }
+
+
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiPrint_moc.cpp"
+#include "moc_GuiPrint.cpp"