]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiPrint.cpp
7aea586cce9d7bd51342a5be215f7157347bf2bc
[features.git] / src / frontends / qt4 / GuiPrint.cpp
1 /**
2  * \file GuiPrint.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Edwin Leuven
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiPrint.h"
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17
18 #include "PrinterParams.h"
19
20 #include "support/os.h"
21
22 #include <QLineEdit>
23 #include <QCheckBox>
24 #include <QRadioButton>
25 #include <QSpinBox>
26 #include <QPushButton>
27
28 namespace lyx {
29 namespace frontend {
30
31 GuiPrintDialog::GuiPrintDialog(GuiPrint * f)
32         : form_(f)
33 {
34         setupUi(this);
35
36         connect(printPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
37         connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
38
39         connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int)));
40         connect(printerED, SIGNAL(textChanged(const QString&)),
41                 this, SLOT(printerChanged()));
42         connect(fileED, SIGNAL(textChanged(const QString&)),
43                 this, SLOT(fileChanged() ));
44         connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
45         connect(allRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
46         connect(reverseCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
47         connect(collateCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
48         connect(fromED, SIGNAL(textChanged(const QString&)),
49                 this, SLOT(pagerangeChanged()));
50         connect(fromED, SIGNAL(textChanged(const QString&)),
51                 this, SLOT(change_adaptor()));
52         connect(toED, SIGNAL(textChanged(const QString&)),
53                 this, SLOT(pagerangeChanged()));
54         connect(toED, SIGNAL(textChanged(const QString&)),
55                 this, SLOT(change_adaptor()));
56         connect(fileRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
57         connect(printerRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
58         connect(rangeRB, SIGNAL(toggled(bool)), fromED, SLOT(setEnabled(bool)));
59         connect(rangeRB, SIGNAL(toggled(bool)), toED, SLOT(setEnabled(bool)));
60 }
61
62
63 void GuiPrintDialog::change_adaptor()
64 {
65         form_->changed();
66 }
67
68
69 void GuiPrintDialog::browseClicked()
70 {
71         QString file = toqstr(form_->controller().browse(docstring()));
72         if (!file.isNull()) {
73                 fileED->setText(file);
74                 form_->changed();
75         }
76 }
77
78
79 void GuiPrintDialog::fileChanged()
80 {
81         if (!fileED->text().isEmpty())
82                 fileRB->setChecked(true);
83         form_->changed();
84 }
85
86
87 void GuiPrintDialog::copiesChanged(int i)
88 {
89         collateCB->setEnabled(i != 1);
90         form_->changed();
91 }
92
93
94 void GuiPrintDialog::printerChanged()
95 {
96         printerRB->setChecked(true);
97         form_->changed();
98 }
99
100
101 void GuiPrintDialog::pagerangeChanged()
102 {
103         form_->changed();
104 }
105
106
107 GuiPrint::GuiPrint(Dialog & parent)
108         : GuiView<GuiPrintDialog>(parent, _("Print Document"))
109 {
110 }
111
112
113 void GuiPrint::build_dialog()
114 {
115         dialog_.reset(new GuiPrintDialog(this));
116
117         bcview().setOK(dialog_->printPB);
118         bcview().setCancel(dialog_->closePB);
119 }
120
121
122 void GuiPrint::update_contents()
123 {
124         PrinterParams & pp = controller().params();
125
126         // only reset params if a different buffer
127         if (!pp.file_name.empty() && pp.file_name == fromqstr(dialog_->fileED->text()))
128                 return;
129
130         dialog_->printerED->setText(toqstr(pp.printer_name));
131         dialog_->fileED->setText(toqstr(pp.file_name));
132
133         dialog_->printerRB->setChecked(true);
134         if (pp.target == PrinterParams::FILE)
135                 dialog_->fileRB->setChecked(true);
136
137         dialog_->reverseCB->setChecked(pp.reverse_order);
138
139         dialog_->copiesSB->setValue(pp.count_copies);
140
141         dialog_->oddCB->setChecked(pp.odd_pages);
142         dialog_->evenCB->setChecked(pp.even_pages);
143
144         dialog_->collateCB->setChecked(pp.sorted_copies);
145
146         if (pp.all_pages) {
147                 dialog_->allRB->setChecked(true);
148                 return;
149         }
150
151         dialog_->rangeRB->setChecked(true);
152
153         QString s;
154         s.setNum(pp.from_page);
155         dialog_->fromED->setText(s);
156         s.setNum(pp.to_page);
157         dialog_->toED->setText(s);
158 }
159
160
161 void GuiPrint::apply()
162 {
163         PrinterParams::Target t = PrinterParams::PRINTER;
164         if (dialog_->fileRB->isChecked())
165                 t = PrinterParams::FILE;
166
167         PrinterParams const pp(t,
168                 fromqstr(dialog_->printerED->text()),
169                 support::os::internal_path(fromqstr(dialog_->fileED->text())),
170                 dialog_->allRB->isChecked(),
171                 dialog_->fromED->text().toUInt(),
172                 dialog_->toED->text().toUInt(),
173                 dialog_->oddCB->isChecked(),
174                 dialog_->evenCB->isChecked(),
175                 dialog_->copiesSB->text().toUInt(),
176                 dialog_->collateCB->isChecked(),
177                 dialog_->reverseCB->isChecked());
178
179         controller().params() = pp;
180 }
181
182 } // namespace frontend
183 } // namespace lyx
184
185 #include "GuiPrint_moc.cpp"