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