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