]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QPrint.C
The initial merge of the Qt frontend, and the necessary compile fixes.
[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 "LyXView.h"
17 #include "ControlPrint.h"
18 #include "support/lstrings.h"
19 #include "gettext.h"
20
21 #include "QPrint.h"
22 #include "QPrintDialog.h"
23 #include "Qt2BC.h"
24
25 #include <qlineedit.h>
26 #include <qcheckbox.h>
27 #include <qradiobutton.h>
28 #include <qspinbox.h>
29 #include <qpushbutton.h>
30
31 // FIXME FIXME QPrintDialog is getting destructed twice !!!!
32  
33 typedef Qt2CB<ControlPrint, Qt2DB<QPrintDialog> > base_class;
34
35 QPrint::QPrint(ControlPrint & c)
36         : base_class(c, _("Print"))
37 {
38 }
39
40
41 void QPrint::build_dialog()
42 {
43         dialog_.reset(new QPrintDialog(this));
44
45         bc().setOK(dialog_->printPB);
46         bc().setCancel(dialog_->closePB);
47 }
48
49
50 void QPrint::update_contents()
51 {
52         PrinterParams & pp = controller().params();
53
54         dialog_->printerED->setText(pp.printer_name.c_str());
55         dialog_->fileED->setText(pp.file_name.c_str());
56
57         dialog_->printerRB->setChecked(true);
58         if (pp.target == PrinterParams::FILE)
59                 dialog_->fileRB->setChecked(true);
60
61         dialog_->reverseCB->setChecked(pp.reverse_order);
62
63         QRadioButton * button;
64         switch (pp.which_pages) {
65                 case PrinterParams::ALL: button = dialog_->allRB; break;
66                 case PrinterParams::ODD: button = dialog_->oddRB; break;
67                 case PrinterParams::EVEN: button = dialog_->evenRB; break;
68         }
69         button->setChecked(true);
70
71         // hmmm... maybe a bit weird but maybe not
72         // we might just be remembering the last
73         // time this was printed.
74         if (!pp.from_page.empty()) {
75                 dialog_->fromED->setText(pp.from_page.c_str());
76
77                 dialog_->toED->setText("");
78                 if (pp.to_page)
79                         dialog_->toED->setText(tostr(pp.to_page).c_str());
80         } else {
81                 dialog_->fromED->setText("");
82                 dialog_->toED->setText("");
83         }
84
85         dialog_->copiesSB->setValue(pp.count_copies);
86 }
87
88
89 void QPrint::apply()
90 {
91         PrinterParams::WhichPages wp;
92
93         if (dialog_->allRB->isChecked())
94                 wp = PrinterParams::ALL;
95         else if (dialog_->oddRB->isChecked())
96                 wp = PrinterParams::ODD;
97         else
98                 wp = PrinterParams::EVEN;
99
100         string from;
101         int to(0);
102         if (!dialog_->fromED->text().isEmpty()) {
103                 // we have at least one page requested
104                 from = dialog_->fromED->text().latin1();
105                 if (!dialog_->toED->text().isEmpty())
106                         to = strToInt(dialog_->toED->text().latin1());
107         }
108
109         PrinterParams::Target t = PrinterParams::PRINTER;
110         if (dialog_->fileRB->isChecked())
111                 t = PrinterParams::FILE;
112
113         PrinterParams const pp(t,
114                 dialog_->printerED->text().latin1(),
115                 dialog_->fileED->text().latin1(),
116                 wp, from, to,
117                 dialog_->reverseCB->isChecked(),
118                 !dialog_->collateCB->isChecked(),
119                 strToInt(dialog_->copiesSB->text().latin1()));
120
121         controller().params() = pp;
122 }