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