]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QTabularDialog.C
* LyXView::updateInset(): schedule a redraw instead of redraw immediately.
[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/ButtonController.h"
21 #include "controllers/ControlTabular.h"
22
23 #include <QCloseEvent>
24 #include <QCheckBox>
25 #include <QPushButton>
26 #include <QRadioButton>
27 #include <QLineEdit>
28
29 using std::string;
30
31 namespace lyx {
32 namespace frontend {
33
34
35 QTabularDialog::QTabularDialog(QTabular * form)
36         : form_(form)
37 {
38         setupUi(this);
39
40         widthED->setValidator(unsignedLengthValidator(widthED));
41         topspaceED->setValidator(new LengthValidator(topspaceED));
42         bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
43         interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
44
45         connect(topspaceED, SIGNAL(returnPressed()),
46                 this, SLOT(topspace_changed()));
47         connect(topspaceUnit, SIGNAL(selectionChanged(lyx::LyXLength::UNIT)),
48                 this, SLOT(topspace_changed()));
49         connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed()));
50         connect(bottomspaceED, SIGNAL(returnPressed()),
51                 this, SLOT(bottomspace_changed()));
52         connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::LyXLength::UNIT)),
53                 this, SLOT(bottomspace_changed()));
54         connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed()));
55         connect(interlinespaceED, SIGNAL(returnPressed()),
56                 this, SLOT(interlinespace_changed()));
57         connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::LyXLength::UNIT)),
58                 this, SLOT(interlinespace_changed()));
59         connect(interlinespaceCO, SIGNAL(activated(int)), this, SLOT(interlinespace_changed()));
60         connect(booktabsRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
61         connect(borderDefaultRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
62         connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked()));
63         connect(borderUnsetPB, SIGNAL(clicked()), this, SLOT(borderUnset_clicked()));
64         connect(longTabularCB, SIGNAL(toggled(bool)), longtableGB, SLOT(setEnabled(bool)));
65         connect(longTabularCB, SIGNAL(toggled(bool)), newpageCB, SLOT(setEnabled(bool)));
66         connect(hAlignCB, SIGNAL(activated(int)), this, SLOT(hAlign_changed(int)));
67         connect(vAlignCB, SIGNAL(activated(int)), this, SLOT(vAlign_changed(int)));
68         connect(multicolumnCB, SIGNAL(clicked()), this, SLOT(multicolumn_clicked()));
69         connect(newpageCB, SIGNAL(clicked()), this, SLOT(ltNewpage_clicked()));
70         connect(headerStatusCB, SIGNAL(clicked()), this, SLOT(ltHeaderStatus_clicked()));
71         connect(headerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderAbove_clicked()));
72         connect(headerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderBelow_clicked()));
73         connect(firstheaderStatusCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderStatus_clicked()));
74         connect(firstheaderBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderAbove_clicked()));
75         connect(firstheaderBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderBelow_clicked()));
76         connect(firstheaderNoContentsCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderEmpty_clicked()));
77         connect(footerStatusCB, SIGNAL(clicked()), this, SLOT(ltFooterStatus_clicked()));
78         connect(footerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderAbove_clicked()));
79         connect(footerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderBelow_clicked()));
80         connect(lastfooterStatusCB, SIGNAL(clicked()), this, SLOT(ltLastFooterStatus_clicked()));
81         connect(lastfooterBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderAbove_clicked()));
82         connect(lastfooterBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderBelow_clicked()));
83         connect(lastfooterNoContentsCB, SIGNAL(clicked()), this, SLOT(ltLastFooterEmpty_clicked()));
84         connect(specialAlignmentED, SIGNAL(returnPressed()), this, SLOT(specialAlignment_changed()));
85         connect(widthED, SIGNAL(returnPressed()), this, SLOT(width_changed()));
86         connect(widthUnit, SIGNAL(selectionChanged(lyx::LyXLength::UNIT)), this, SLOT(width_changed()));
87         connect(closePB, SIGNAL(clicked()), this, SLOT(close_clicked()));
88         connect(borders, SIGNAL(topSet(bool)), this, SLOT(topBorder_changed()));
89         connect(borders, SIGNAL(bottomSet(bool)), this, SLOT(bottomBorder_changed()));
90         connect(borders, SIGNAL(rightSet(bool)), this, SLOT(rightBorder_changed()));
91         connect(borders, SIGNAL(leftSet(bool)), this, SLOT(leftBorder_changed()));
92         connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
93         connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
94         connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
95 }
96
97
98 void QTabularDialog::change_adaptor()
99 {
100         form_->changed();
101 }
102
103
104 void QTabularDialog::closeEvent(QCloseEvent * e)
105 {
106         form_->slotWMHide();
107         e->accept();
108 }
109
110
111 void QTabularDialog::booktabsChanged(bool)
112 {
113         form_->changed();
114         form_->controller().booktabs(booktabsRB->isChecked());
115         form_->update_borders();
116 }
117
118
119 void QTabularDialog::topspace_changed()
120 {
121         switch(topspaceCO->currentIndex()) {
122                 case 0: {
123                         form_->controller().set(LyXTabular::SET_TOP_SPACE, "");
124                                 topspaceED->setEnabled(false);
125                                 topspaceUnit->setEnabled(false);
126                         break;
127                 }
128                 case 1: {
129                         form_->controller().set(LyXTabular::SET_TOP_SPACE, "default");
130                         topspaceED->setEnabled(false);
131                         topspaceUnit->setEnabled(false);
132                         break;
133                 }
134                 case 2: {
135                         if (!topspaceED->text().isEmpty())
136                                 form_->controller().set(LyXTabular::SET_TOP_SPACE,
137                                         widgetsToLength(topspaceED, topspaceUnit));
138                         if (!form_->bc().bp().isReadOnly()) {
139                                 topspaceED->setEnabled(true);
140                                 topspaceUnit->setEnabled(true);
141                         }
142                         break;
143                 }
144         }
145         form_->changed();
146 }
147
148
149 void QTabularDialog::bottomspace_changed()
150 {
151         switch(bottomspaceCO->currentIndex()) {
152                 case 0: {
153                         form_->controller().set(LyXTabular::SET_BOTTOM_SPACE, "");
154                                 bottomspaceED->setEnabled(false);
155                                 bottomspaceUnit->setEnabled(false);
156                         break;
157                 }
158                 case 1: {
159                         form_->controller().set(LyXTabular::SET_BOTTOM_SPACE, "default");
160                         bottomspaceED->setEnabled(false);
161                         bottomspaceUnit->setEnabled(false);
162                         break;
163                 }
164                 case 2: {
165                         if (!bottomspaceED->text().isEmpty())
166                                 form_->controller().set(LyXTabular::SET_BOTTOM_SPACE,
167                                         widgetsToLength(bottomspaceED, bottomspaceUnit));
168                         if (!form_->bc().bp().isReadOnly()) {
169                                 bottomspaceED->setEnabled(true);
170                                 bottomspaceUnit->setEnabled(true);
171                         }
172                         break;
173                 }
174         }
175         form_->changed();
176 }
177
178
179 void QTabularDialog::interlinespace_changed()
180 {
181         switch(interlinespaceCO->currentIndex()) {
182                 case 0: {
183                         form_->controller().set(LyXTabular::SET_INTERLINE_SPACE, "");
184                                 interlinespaceED->setEnabled(false);
185                                 interlinespaceUnit->setEnabled(false);
186                         break;
187                 }
188                 case 1: {
189                         form_->controller().set(LyXTabular::SET_INTERLINE_SPACE, "default");
190                         interlinespaceED->setEnabled(false);
191                         interlinespaceUnit->setEnabled(false);
192                         break;
193                 }
194                 case 2: {
195                         if (!interlinespaceED->text().isEmpty())
196                                 form_->controller().set(LyXTabular::SET_INTERLINE_SPACE,
197                                         widgetsToLength(interlinespaceED, interlinespaceUnit));
198                         if (!form_->bc().bp().isReadOnly()) {
199                                 interlinespaceED->setEnabled(true);
200                                 interlinespaceUnit->setEnabled(true);
201                         }
202                         break;
203                 }
204         }
205         form_->changed();
206 }
207
208
209 void QTabularDialog::close_clicked()
210 {
211         form_->closeGUI();
212         form_->slotClose();
213 }
214
215
216 void QTabularDialog::borderSet_clicked()
217 {
218         form_->controller().set(LyXTabular::SET_ALL_LINES);
219         form_->update_borders();
220         form_->changed();
221 }
222
223
224 void QTabularDialog::borderUnset_clicked()
225 {
226         form_->controller().set(LyXTabular::UNSET_ALL_LINES);
227         form_->update_borders();
228         form_->changed();
229 }
230
231
232 void QTabularDialog::leftBorder_changed()
233 {
234         form_->controller().toggleLeftLine();
235         form_->changed();
236 }
237
238
239 void QTabularDialog::rightBorder_changed()
240 {
241         form_->controller().toggleRightLine();
242         form_->changed();
243 }
244
245
246 void QTabularDialog::topBorder_changed()
247 {
248         form_->controller().toggleTopLine();
249         form_->changed();
250 }
251
252
253 void QTabularDialog::bottomBorder_changed()
254 {
255         form_->controller().toggleBottomLine();
256         form_->changed();
257 }
258
259
260 void QTabularDialog::specialAlignment_changed()
261 {
262         string special = fromqstr(specialAlignmentED->text());
263         form_->controller().setSpecial(special);
264         form_->changed();
265 }
266
267
268 void QTabularDialog::width_changed()
269 {
270         form_->changed();
271         string const width = widgetsToLength(widthED, widthUnit);
272         form_->controller().setWidth(width);
273 }
274
275
276 void QTabularDialog::multicolumn_clicked()
277 {
278         form_->controller().toggleMultiColumn();
279         form_->changed();
280 }
281
282
283 void QTabularDialog::rotateTabular()
284 {
285         form_->controller().rotateTabular(rotateTabularCB->isChecked());
286         form_->changed();
287 }
288
289
290 void QTabularDialog::rotateCell()
291 {
292         form_->controller().rotateCell(rotateCellCB->isChecked());
293         form_->changed();
294 }
295
296
297 void QTabularDialog::hAlign_changed(int align)
298 {
299         ControlTabular::HALIGN h = ControlTabular::LEFT;
300
301         switch (align) {
302                 case 0: h = ControlTabular::LEFT; break;
303                 case 1: h = ControlTabular::CENTER; break;
304                 case 2: h = ControlTabular::RIGHT; break;
305                 case 3: h = ControlTabular::BLOCK; break;
306         }
307
308         form_->controller().halign(h);
309 }
310
311
312 void QTabularDialog::vAlign_changed(int align)
313 {
314         ControlTabular::VALIGN v = ControlTabular::TOP;
315
316         switch (align) {
317                 case 0: v = ControlTabular::TOP; break;
318                 case 1: v = ControlTabular::MIDDLE; break;
319                 case 2: v = ControlTabular::BOTTOM; break;
320         }
321
322         form_->controller().valign(v);
323 }
324
325
326 void QTabularDialog::longTabular()
327 {
328         form_->controller().longTabular(longTabularCB->isChecked());
329         form_->changed();
330 }
331
332
333 void QTabularDialog::ltNewpage_clicked()
334 {
335         form_->controller().set(LyXTabular::SET_LTNEWPAGE);
336         form_->changed();
337 }
338
339
340 void QTabularDialog::ltHeaderStatus_clicked()
341 {
342         bool enable(headerStatusCB->isChecked());
343         if (enable)
344                 form_->controller().set(LyXTabular::SET_LTHEAD, "");
345         else
346                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
347         headerBorderAboveCB->setEnabled(enable);
348         headerBorderBelowCB->setEnabled(enable);
349         firstheaderNoContentsCB->setEnabled(enable);
350         form_->changed();
351 }
352
353
354 void QTabularDialog::ltHeaderBorderAbove_clicked()
355 {
356         if (headerBorderAboveCB->isChecked())
357                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_above");
358         else
359                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_above");
360         form_->changed();
361 }
362
363
364 void QTabularDialog::ltHeaderBorderBelow_clicked()
365 {
366         if (headerBorderBelowCB->isChecked())
367                 form_->controller().set(LyXTabular::SET_LTHEAD, "dl_below");
368         else
369                 form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_below");
370         form_->changed();
371 }
372
373
374 void QTabularDialog::ltFirstHeaderBorderAbove_clicked()
375 {
376         if (firstheaderBorderAboveCB->isChecked())
377                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_above");
378         else
379                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_above");
380         form_->changed();
381 }
382
383
384 void QTabularDialog::ltFirstHeaderBorderBelow_clicked()
385 {
386         if (firstheaderBorderBelowCB->isChecked())
387                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_below");
388         else
389                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_below");
390         form_->changed();
391 }
392
393
394 void QTabularDialog::ltFirstHeaderStatus_clicked()
395 {
396         bool enable(firstheaderStatusCB->isChecked());
397         if (enable)
398                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "");
399         else
400                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
401         firstheaderBorderAboveCB->setEnabled(enable);
402         firstheaderBorderBelowCB->setEnabled(enable);
403         form_->changed();
404 }
405
406
407 void QTabularDialog::ltFirstHeaderEmpty_clicked()
408 {
409         bool enable(firstheaderNoContentsCB->isChecked());
410         if (enable)
411                 form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "empty");
412         else
413                 form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "empty");
414         firstheaderStatusCB->setEnabled(!enable);
415         firstheaderBorderAboveCB->setEnabled(!enable);
416         firstheaderBorderBelowCB->setEnabled(!enable);
417         form_->changed();
418 }
419
420
421 void QTabularDialog::ltFooterStatus_clicked()
422 {
423         bool enable(footerStatusCB->isChecked());
424         if (enable)
425                 form_->controller().set(LyXTabular::SET_LTFOOT, "");
426         else
427                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
428         footerBorderAboveCB->setEnabled(enable);
429         footerBorderBelowCB->setEnabled(enable);
430         lastfooterNoContentsCB->setEnabled(enable);
431         form_->changed();
432 }
433
434
435 void QTabularDialog::ltFooterBorderAbove_clicked()
436 {
437         if (footerBorderAboveCB->isChecked())
438                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_above");
439         else
440                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_above");
441         form_->changed();
442 }
443
444
445 void QTabularDialog::ltFooterBorderBelow_clicked()
446 {
447         if (footerBorderBelowCB->isChecked())
448                 form_->controller().set(LyXTabular::SET_LTFOOT, "dl_below");
449         else
450                 form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_below");
451         form_->changed();
452 }
453
454
455 void QTabularDialog::ltLastFooterStatus_clicked()
456 {
457         bool enable(lastfooterStatusCB->isChecked());
458         if (enable)
459                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "");
460         else
461                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
462         lastfooterBorderAboveCB->setEnabled(enable);
463         lastfooterBorderBelowCB->setEnabled(enable);
464         form_->changed();
465 }
466
467
468 void QTabularDialog::ltLastFooterBorderAbove_clicked()
469 {
470         if (lastfooterBorderAboveCB->isChecked())
471                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_above");
472         else
473                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_above");
474         form_->changed();
475 }
476
477
478 void QTabularDialog::ltLastFooterBorderBelow_clicked()
479 {
480         if (lastfooterBorderBelowCB->isChecked())
481                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_below");
482         else
483                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_below");
484         form_->changed();
485 }
486
487
488 void QTabularDialog::ltLastFooterEmpty_clicked()
489 {
490         bool enable(lastfooterNoContentsCB->isChecked());
491         if (enable)
492                 form_->controller().set(LyXTabular::SET_LTLASTFOOT, "empty");
493         else
494                 form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "empty");
495         lastfooterStatusCB->setEnabled(!enable);
496         lastfooterBorderAboveCB->setEnabled(!enable);
497         lastfooterBorderBelowCB->setEnabled(!enable);
498         form_->changed();
499 }
500
501 } // namespace frontend
502 } // namespace lyx
503
504 #include "QTabularDialog_moc.cpp"