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