]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QTabularDialog.C
Qt4 compilation speedup patch by Bo Peng and me.
[lyx.git] / src / frontends / qt4 / QTabularDialog.C
1 /**
2  * \file QTabularDialog.C
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 Jürgen Spitzmüller
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "QTabularDialog.h"
16 #include "QTabular.h"
17 //Added by qt3to4:
18 #include <QCloseEvent>
19 #include "validators.h"
20 #include "qt_helpers.h"
21
22 #include "controllers/ControlTabular.h"
23
24 #include <QCheckBox>
25 #include <QPushButton>
26 #include <QLineEdit>
27
28 using std::string;
29
30 namespace lyx {
31 namespace frontend {
32
33
34 QTabularDialog::QTabularDialog(QTabular * form)
35         : form_(form)
36 {
37         setupUi(this);
38
39         connect(closePB, SIGNAL(clicked()),
40                 form, SLOT(slotClose()));
41
42         widthED->setValidator(unsignedLengthValidator(widthED));
43
44     connect( borderSetPB, SIGNAL( clicked() ), this, SLOT( borderSet_clicked() ) );
45     connect( borderUnsetPB, SIGNAL( clicked() ), this, SLOT( borderUnset_clicked() ) );
46     connect( longTabularCB, SIGNAL( toggled(bool) ), longtableGB, SLOT( setEnabled(bool) ) );
47     connect( longTabularCB, SIGNAL( toggled(bool) ), newpageCB, SLOT( setEnabled(bool) ) );
48     connect( hAlignCB, SIGNAL( activated(int) ), this, SLOT( hAlign_changed(int) ) );
49     connect( vAlignCB, SIGNAL( activated(int) ), this, SLOT( vAlign_changed(int) ) );
50     connect( multicolumnCB, SIGNAL( clicked() ), this, SLOT( multicolumn_clicked() ) );
51     connect( newpageCB, SIGNAL( clicked() ), this, SLOT( ltNewpage_clicked() ) );
52     connect( headerStatusCB, SIGNAL( clicked() ), this, SLOT( ltHeaderStatus_clicked() ) );
53     connect( headerBorderAboveCB, SIGNAL( clicked() ), this, SLOT( ltHeaderBorderAbove_clicked() ) );
54     connect( headerBorderBelowCB, SIGNAL( clicked() ), this, SLOT( ltHeaderBorderBelow_clicked() ) );
55     connect( firstheaderStatusCB, SIGNAL( clicked() ), this, SLOT( ltFirstHeaderStatus_clicked() ) );
56     connect( firstheaderBorderAboveCB, SIGNAL( clicked() ), this, SLOT( ltFirstHeaderBorderAbove_clicked() ) );
57     connect( firstheaderBorderBelowCB, SIGNAL( clicked() ), this, SLOT( ltFirstHeaderBorderBelow_clicked() ) );
58     connect( firstheaderNoContentsCB, SIGNAL( clicked() ), this, SLOT( ltFirstHeaderEmpty_clicked() ) );
59     connect( footerStatusCB, SIGNAL( clicked() ), this, SLOT( ltFooterStatus_clicked() ) );
60     connect( footerBorderAboveCB, SIGNAL( clicked() ), this, SLOT( ltFooterBorderAbove_clicked() ) );
61     connect( footerBorderBelowCB, SIGNAL( clicked() ), this, SLOT( ltFooterBorderBelow_clicked() ) );
62     connect( lastfooterStatusCB, SIGNAL( clicked() ), this, SLOT( ltLastFooterStatus_clicked() ) );
63     connect( lastfooterBorderAboveCB, SIGNAL( clicked() ), this, SLOT( ltLastFooterBorderAbove_clicked() ) );
64     connect( lastfooterBorderBelowCB, SIGNAL( clicked() ), this, SLOT( ltLastFooterBorderBelow_clicked() ) );
65     connect( lastfooterNoContentsCB, SIGNAL( clicked() ), this, SLOT( ltLastFooterEmpty_clicked() ) );
66     connect( specialAlignmentED, SIGNAL( returnPressed() ), this, SLOT( specialAlignment_changed() ) );
67     connect( widthED, SIGNAL( returnPressed() ), this, SLOT( width_changed() ) );
68     connect( widthUnit, SIGNAL( selectionChanged(LyXLength::UNIT) ), this, SLOT( width_changed() ) );
69     connect( closePB, SIGNAL( clicked() ), this, SLOT( close_clicked() ) );
70     connect( borders, SIGNAL( topSet(bool) ), this, SLOT( topBorder_changed() ) );
71     connect( borders, SIGNAL( bottomSet(bool) ), this, SLOT( bottomBorder_changed() ) );
72     connect( borders, SIGNAL( rightSet(bool) ), this, SLOT( rightBorder_changed() ) );
73     connect( borders, SIGNAL( leftSet(bool) ), this, SLOT( leftBorder_changed() ) );
74     connect( rotateTabularCB, SIGNAL( clicked() ), this, SLOT( rotateTabular() ) );
75     connect( rotateCellCB, SIGNAL( clicked() ), this, SLOT( rotateCell() ) );
76     connect( longTabularCB, SIGNAL( clicked() ), this, SLOT( longTabular() ) );
77 }
78
79
80 void QTabularDialog::change_adaptor()
81 {
82         form_->changed();
83 }
84
85
86 void QTabularDialog::closeEvent(QCloseEvent * e)
87 {
88         form_->slotWMHide();
89         e->accept();
90 }
91
92
93 void QTabularDialog::close_clicked()
94 {
95         form_->closeGUI();
96 }
97
98
99 void QTabularDialog::borderSet_clicked()
100 {
101         form_->controller().set(LyXTabular::SET_ALL_LINES);
102         form_->update_borders();
103         form_->changed();
104 }
105
106
107 void QTabularDialog::borderUnset_clicked()
108 {
109         form_->controller().set(LyXTabular::UNSET_ALL_LINES);
110         form_->update_borders();
111         form_->changed();
112 }
113
114
115 void QTabularDialog::leftBorder_changed()
116 {
117         form_->controller().toggleLeftLine();
118         form_->changed();
119 }
120
121
122 void QTabularDialog::rightBorder_changed()
123 {
124         form_->controller().toggleRightLine();
125         form_->changed();
126 }
127
128
129 void QTabularDialog::topBorder_changed()
130 {
131         form_->controller().toggleTopLine();
132         form_->changed();
133 }
134
135
136 void QTabularDialog::bottomBorder_changed()
137 {
138         form_->controller().toggleBottomLine();
139         form_->changed();
140 }
141
142
143 void QTabularDialog::specialAlignment_changed()
144 {
145         string special = fromqstr(specialAlignmentED->text());
146         form_->controller().setSpecial(special);
147         form_->changed();
148 }
149
150
151 void QTabularDialog::width_changed()
152 {
153         form_->changed();
154         string const width = widgetsToLength(widthED, widthUnit);
155         form_->controller().setWidth(width);
156 }
157
158
159 void QTabularDialog::multicolumn_clicked()
160 {
161         form_->controller().toggleMultiColumn();
162         form_->changed();
163 }
164
165
166 void QTabularDialog::rotateTabular()
167 {
168         form_->controller().rotateTabular(rotateTabularCB->isChecked());
169         form_->changed();
170 }
171
172
173 void QTabularDialog::rotateCell()
174 {
175         form_->controller().rotateCell(rotateCellCB->isChecked());
176         form_->changed();
177 }
178
179
180 void QTabularDialog::hAlign_changed(int align)
181 {
182         ControlTabular::HALIGN h = ControlTabular::LEFT;
183
184         switch (align) {
185                 case 0: h = ControlTabular::LEFT; break;
186                 case 1: h = ControlTabular::CENTER; break;
187                 case 2: h = ControlTabular::RIGHT; break;
188                 case 3: h = ControlTabular::BLOCK; break;
189         }
190
191         form_->controller().halign(h);
192 }
193
194
195 void QTabularDialog::vAlign_changed(int align)
196 {
197         ControlTabular::VALIGN v = ControlTabular::TOP;
198
199         switch (align) {
200                 case 0: v = ControlTabular::TOP; break;
201                 case 1: v = ControlTabular::MIDDLE; break;
202                 case 2: v = ControlTabular::BOTTOM; break;
203         }
204
205         form_->controller().valign(v);
206 }
207
208
209 void QTabularDialog::longTabular()
210 {
211         form_->controller().longTabular(longTabularCB->isChecked());
212         form_->changed();
213 }
214
215
216 void QTabularDialog::ltNewpage_clicked()
217 {
218         form_->controller().set(LyXTabular::SET_LTNEWPAGE);
219         form_->changed();
220 }
221
222
223 void QTabularDialog::ltHeaderStatus_clicked()
224 {
225         bool enable(headerStatusCB->isChecked());
226         if (enable)
227                 form_->controller().set(LyXTabular::SET_LTHEAD, "");
228         else
229                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
230         headerBorderAboveCB->setEnabled(enable);
231         headerBorderBelowCB->setEnabled(enable);
232         firstheaderNoContentsCB->setEnabled(enable);
233         form_->changed();
234 }
235
236
237 void QTabularDialog::ltHeaderBorderAbove_clicked()
238 {
239         if (headerBorderAboveCB->isChecked())
240                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_above");
241         else
242                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_above");
243         form_->changed();
244 }
245
246
247 void QTabularDialog::ltHeaderBorderBelow_clicked()
248 {
249         if (headerBorderBelowCB->isChecked())
250                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_below");
251         else
252                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_below");
253         form_->changed();
254 }
255
256
257 void QTabularDialog::ltFirstHeaderBorderAbove_clicked()
258 {
259         if (firstheaderBorderAboveCB->isChecked())
260                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_above");
261         else
262                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_above");
263         form_->changed();
264 }
265
266
267 void QTabularDialog::ltFirstHeaderBorderBelow_clicked()
268 {
269         if (firstheaderBorderBelowCB->isChecked())
270                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_below");
271         else
272                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_below");
273         form_->changed();
274 }
275
276
277 void QTabularDialog::ltFirstHeaderStatus_clicked()
278 {
279         bool enable(firstheaderStatusCB->isChecked());
280         if (enable)
281                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "");
282         else
283                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
284         firstheaderBorderAboveCB->setEnabled(enable);
285         firstheaderBorderBelowCB->setEnabled(enable);
286         form_->changed();
287 }
288
289
290 void QTabularDialog::ltFirstHeaderEmpty_clicked()
291 {
292         bool enable(firstheaderNoContentsCB->isChecked());
293         if (enable)
294                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "empty");
295         else
296                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "empty");
297         firstheaderStatusCB->setEnabled(!enable);
298         firstheaderBorderAboveCB->setEnabled(!enable);
299         firstheaderBorderBelowCB->setEnabled(!enable);
300         form_->changed();
301 }
302
303
304 void QTabularDialog::ltFooterStatus_clicked()
305 {
306         bool enable(footerStatusCB->isChecked());
307         if (enable)
308                 form_->controller().set(LyXTabular::SET_LTFOOT, "");
309         else
310                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
311         footerBorderAboveCB->setEnabled(enable);
312         footerBorderBelowCB->setEnabled(enable);
313         lastfooterNoContentsCB->setEnabled(enable);
314         form_->changed();
315 }
316
317
318 void QTabularDialog::ltFooterBorderAbove_clicked()
319 {
320         if (footerBorderAboveCB->isChecked())
321                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_above");
322         else
323                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_above");
324         form_->changed();
325 }
326
327
328 void QTabularDialog::ltFooterBorderBelow_clicked()
329 {
330         if (footerBorderBelowCB->isChecked())
331                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_below");
332         else
333                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_below");
334         form_->changed();
335 }
336
337
338 void QTabularDialog::ltLastFooterStatus_clicked()
339 {
340         bool enable(lastfooterStatusCB->isChecked());
341         if (enable)
342                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "");
343         else
344                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
345         lastfooterBorderAboveCB->setEnabled(enable);
346         lastfooterBorderBelowCB->setEnabled(enable);
347         form_->changed();
348 }
349
350
351 void QTabularDialog::ltLastFooterBorderAbove_clicked()
352 {
353         if (lastfooterBorderAboveCB->isChecked())
354                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_above");
355         else
356                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_above");
357         form_->changed();
358 }
359
360
361 void QTabularDialog::ltLastFooterBorderBelow_clicked()
362 {
363         if (lastfooterBorderBelowCB->isChecked())
364                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_below");
365         else
366                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_below");
367         form_->changed();
368 }
369
370
371 void QTabularDialog::ltLastFooterEmpty_clicked()
372 {
373         bool enable(lastfooterNoContentsCB->isChecked());
374         if (enable)
375                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "empty");
376         else
377                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "empty");
378         lastfooterStatusCB->setEnabled(!enable);
379         lastfooterBorderAboveCB->setEnabled(!enable);
380         lastfooterBorderBelowCB->setEnabled(!enable);
381         form_->changed();
382 }
383
384 } // namespace frontend
385 } // namespace lyx
386
387 #include "QTabularDialog_moc.cpp"