]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QPrint.C
add print dialog back
[lyx.git] / src / frontends / qt2 / QPrint.C
1 /**
2  * \file QPrint.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  * \author Edwin Leuven, leuven@fee.uva.nl
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <qlineedit.h>
17 #include <qcheckbox.h>
18 #include <qradiobutton.h>
19 #include <qspinbox.h>
20 #include <qpushbutton.h>
21  
22 #include "QPrintDialog.h"
23 #include "QPrint.h"
24 #include "Qt2BC.h"
25 #include "gettext.h"
26  
27 #include "QtLyXView.h"
28 #include "ControlPrint.h"
29
30 #include "support/lstrings.h"
31  
32 typedef Qt2CB<ControlPrint, Qt2DB<QPrintDialog> > base_class;
33
34 QPrint::QPrint(ControlPrint & c)
35         : base_class(c, _("Print"))
36 {
37 }
38
39
40 void QPrint::build_dialog()
41 {
42         dialog_.reset(new QPrintDialog(this));
43
44         bc().setOK(dialog_->printPB); 
45         bc().setCancel(dialog_->closePB);
46 }
47
48
49 void QPrint::update_contents()
50 {
51         PrinterParams & pp = controller().params();
52
53         dialog_->printerED->setText(pp.printer_name.c_str());
54         dialog_->fileED->setText(pp.file_name.c_str());
55  
56         dialog_->printerRB->setChecked(true);
57         if (pp.target == PrinterParams::FILE)
58                 dialog_->fileRB->setChecked(true);
59  
60         dialog_->reverseCB->setChecked(pp.reverse_order);
61
62         QRadioButton * button;
63         switch (pp.which_pages) {
64                 case PrinterParams::ALL: button = dialog_->allRB; break;
65                 case PrinterParams::ODD: button = dialog_->oddRB; break;
66                 case PrinterParams::EVEN: button = dialog_->evenRB; break;
67         }
68         button->setChecked(true);
69  
70         // hmmm... maybe a bit weird but maybe not
71         // we might just be remembering the last
72         // time this was printed.
73         if (!pp.from_page.empty()) {
74                 dialog_->fromED->setText(pp.from_page.c_str());
75
76                 dialog_->toED->setText("");
77                 if (pp.to_page) 
78                         dialog_->toED->setText(tostr(pp.to_page).c_str());
79         } else {
80                 dialog_->fromED->setText("");
81                 dialog_->toED->setText("");
82         }
83
84         dialog_->copiesSB->setValue(pp.count_copies);
85 }
86
87
88 void QPrint::apply()
89 {
90         PrinterParams::WhichPages wp;
91
92         if (dialog_->allRB->isChecked())
93                 wp = PrinterParams::ALL;
94         else if (dialog_->oddRB->isChecked())
95                 wp = PrinterParams::ODD;
96         else
97                 wp = PrinterParams::EVEN;
98
99         string from;
100         int to(0);
101         if (!dialog_->fromED->text().isEmpty()) {
102                 // we have at least one page requested
103                 from = dialog_->fromED->text().latin1();
104                 if (!dialog_->toED->text().isEmpty())
105                         to = strToInt(dialog_->toED->text().latin1());
106         }
107
108         PrinterParams::Target t = PrinterParams::PRINTER;
109         if (dialog_->fileRB->isChecked())
110                 t = PrinterParams::FILE;
111
112         PrinterParams const pp(t,
113                 dialog_->printerED->text().latin1(),
114                 dialog_->fileED->text().latin1(),
115                 wp, from, to,
116                 dialog_->reverseCB->isChecked(),
117                 !dialog_->collateCB->isChecked(),
118                 strToInt(dialog_->copiesSB->text().latin1()));
119  
120         controller().params() = pp;
121 }