]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDocumentDialog.C
Get rid of the static_casts.
[lyx.git] / src / frontends / qt2 / QDocumentDialog.C
1 /**
2  * \file QDocumentDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12 #include "qt_helpers.h"
13
14 #include "ControlDocument.h"
15 #include "QDocument.h"
16
17
18 #include "QDocumentDialog.h"
19
20 #include "ui/TextLayoutModuleBase.h"
21 #include "ui/MathsModuleBase.h"
22 #include "ui/LaTeXModuleBase.h"
23 #include "ui/PageLayoutModuleBase.h"
24 #include "ui/LanguageModuleBase.h"
25 #include "ui/BulletsModuleBase.h"
26 #include "BulletsModule.h"
27 #include "ui/BiblioModuleBase.h"
28 #include "ui/NumberingModuleBase.h"
29 #include "ui/MarginsModuleBase.h"
30 #include "ui/PreambleModuleBase.h"
31 #include "panelstack.h"
32 #include "floatplacement.h"
33
34 #include "Spacing.h"
35 #include "support/lstrings.h"
36 #include "lyxrc.h"
37 #include "buffer.h"
38
39 #include <qwidgetstack.h>
40 #include <qlistbox.h>
41 #include <qlabel.h>
42 #include <qmultilineedit.h>
43 #include <qlineedit.h>
44 #include <qlistview.h>
45 #include <qpushbutton.h>
46 #include <qcombobox.h>
47 #include <qradiobutton.h>
48 #include <qcheckbox.h>
49 #include <qslider.h>
50 #include "lengthcombo.h"
51
52
53 QDocumentDialog::QDocumentDialog(QDocument * form)
54         : QDocumentDialogBase(0, 0, false, 0), form_(form)
55 {
56         connect(okPB, SIGNAL(clicked()),
57                 form, SLOT(slotOK()));
58         connect(applyPB, SIGNAL(clicked()),
59                 form, SLOT(slotApply()));
60         connect(closePB, SIGNAL(clicked()),
61                 form, SLOT(slotClose()));
62         connect(restorePB, SIGNAL(clicked()),
63                 form, SLOT(slotRestore()));
64
65         textLayoutModule = new TextLayoutModuleBase(this);
66         pageLayoutModule = new PageLayoutModuleBase(this);
67         marginsModule = new MarginsModuleBase(this);
68         langModule = new LanguageModuleBase(this);
69         bulletsModule = new BulletsModule(this);
70         numberingModule = new NumberingModuleBase(this);
71         biblioModule = new BiblioModuleBase(this);
72         mathsModule = new MathsModuleBase(this);
73         floatModule = new FloatPlacement(this, "floatplacement");
74         latexModule = new LaTeXModuleBase(this);
75         preambleModule = new PreambleModuleBase(this);
76
77         docPS->addPanel(latexModule, _("Document Class"));
78         docPS->addPanel(textLayoutModule, _("Text Layout"));
79         docPS->addPanel(pageLayoutModule, _("Page Layout"));
80         docPS->addPanel(marginsModule, _("Page Margins"));
81         docPS->addPanel(langModule, _("Language"));
82         docPS->addPanel(numberingModule, _("Numbering & TOC"));
83         docPS->addPanel(biblioModule, _("Bibliography"));
84         docPS->addPanel(mathsModule, _("Math options"));
85         docPS->addPanel(floatModule, _("Float Placement"));
86         docPS->addPanel(bulletsModule, _("Bullets"));
87         docPS->addPanel(preambleModule, _("LaTeX Preamble"));
88         docPS->setCurrentPanel(_("Document Class"));
89
90         // preamble
91         connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
92         // biblio
93         connect(biblioModule->natbibCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
94         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
95         // language & quote
96         connect(langModule->singleQuoteRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
97         connect(langModule->doubleQuoteRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
98         connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
99         connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
100         connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
101         connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
102         // numbering
103         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
104         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
105         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
106         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
107         numberingModule->tocLV->setSorting(-1);
108         // maths
109         connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
110         connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
111         // float
112         connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
113         // latex class
114         connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
115         connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
116         connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
117         connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
118         // text layout
119         connect(textLayoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
120         connect(textLayoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
121         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
122         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
123         connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
124         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
125         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
126         connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
127         connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
128         connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
129         connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
130         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
131         connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
132
133         // margins
134         connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(setCustomMargins(int)));
135         connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
136         connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
137         connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
138         connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
139         connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
140         connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
141         connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
142         connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
143         connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
144         connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
145         connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
146         connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
147         connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
148         connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
149         connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
150
151         // page layout
152         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setMargins(int)));
153         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
154         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
155         connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
156         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
157         connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
158         connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
159         connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
160         connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
161         connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
162         connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
163         connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
164         connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
165
166         // bullets
167         connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
168 }
169
170
171 QDocumentDialog::~QDocumentDialog()
172 {
173 }
174
175
176 void QDocumentDialog::showPreamble()
177 {
178         docPS->setCurrentPanel(_("LaTeX Preamble"));
179 }
180
181
182 void QDocumentDialog::saveDefaultClicked()
183 {
184         form_->saveDocDefault();
185 }
186
187
188 void QDocumentDialog::useDefaultsClicked()
189 {
190     form_->useClassDefaults();
191 }
192
193
194 void QDocumentDialog::change_adaptor()
195 {
196         form_->changed();
197 }
198
199
200 void QDocumentDialog::closeEvent(QCloseEvent * e)
201 {
202         form_->slotWMHide();
203         e->accept();
204 }
205
206
207 void QDocumentDialog::setLSpacing(int item)
208 {
209         textLayoutModule->lspacingLE->setEnabled(item == 3);
210 }
211
212
213 void QDocumentDialog::setSkip(int item)
214 {
215         bool const enable = (item == 3);
216         textLayoutModule->skipLE->setEnabled(enable);
217         textLayoutModule->skipLengthCO->setEnabled(enable);
218 }
219
220
221 void QDocumentDialog::enableSkip(bool skip)
222 {
223         textLayoutModule->skipCO->setEnabled(skip);
224         textLayoutModule->skipLE->setEnabled(skip);
225         textLayoutModule->skipLengthCO->setEnabled(skip);
226         if (skip)
227                 setSkip(textLayoutModule->skipCO->currentItem());
228 }
229
230 void QDocumentDialog::portraitChanged()
231 {
232         setMargins(pageLayoutModule->papersizeCO->currentItem());
233 }
234
235 void QDocumentDialog::setMargins(int papersize)
236 {
237         int olditem = marginsModule->marginCO->currentItem();
238         marginsModule->marginCO->clear();
239         marginsModule->marginCO->insertItem(qt_("Default"));
240         marginsModule->marginCO->insertItem(qt_("Custom"));
241         bool a4size = (papersize == 6 || papersize == 0
242                         && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER);
243         if (a4size && pageLayoutModule->portraitRB->isChecked()) {
244                 marginsModule->marginCO->insertItem(qt_("Small margins"));
245                 marginsModule->marginCO->insertItem(qt_("Very small margins"));
246                 marginsModule->marginCO->insertItem(qt_("Very wide margins"));
247         } else if (olditem > 1) {
248                 olditem = 0;
249         }
250         marginsModule->marginCO->setCurrentItem(olditem);
251         setCustomMargins(olditem);
252 }
253
254
255 void QDocumentDialog::setCustomPapersize(int papersize)
256 {
257         bool const custom = (papersize == 1);
258
259         pageLayoutModule->paperwidthL->setEnabled(custom);
260         pageLayoutModule->paperwidthLE->setEnabled(custom);
261         pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
262         pageLayoutModule->paperheightL->setEnabled(custom);
263         pageLayoutModule->paperheightLE->setEnabled(custom);
264         pageLayoutModule->paperheightLE->setFocus();
265         pageLayoutModule->paperheightUnitCO->setEnabled(custom);
266 }
267
268
269 void QDocumentDialog::setCustomMargins(int margin)
270 {
271         bool const custom = (margin == 1);
272
273         marginsModule->topL->setEnabled(custom);
274         marginsModule->topLE->setEnabled(custom);
275         marginsModule->topUnit->setEnabled(custom);
276
277         marginsModule->bottomL->setEnabled(custom);
278         marginsModule->bottomLE->setEnabled(custom);
279         marginsModule->bottomUnit->setEnabled(custom);
280
281         marginsModule->innerL->setEnabled(custom);
282         marginsModule->innerLE->setEnabled(custom);
283         marginsModule->innerUnit->setEnabled(custom);
284
285         marginsModule->outerL->setEnabled(custom);
286         marginsModule->outerLE->setEnabled(custom);
287         marginsModule->outerUnit->setEnabled(custom);
288
289         marginsModule->headheightL->setEnabled(custom);
290         marginsModule->headheightLE->setEnabled(custom);
291         marginsModule->headheightUnit->setEnabled(custom);
292
293         marginsModule->headsepL->setEnabled(custom);
294         marginsModule->headsepLE->setEnabled(custom);
295         marginsModule->headsepUnit->setEnabled(custom);
296
297         marginsModule->footskipL->setEnabled(custom);
298         marginsModule->footskipLE->setEnabled(custom);
299         marginsModule->footskipUnit->setEnabled(custom);
300
301 }
302
303
304 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
305 {
306         textLayoutModule->fontsizeCO->clear();
307         textLayoutModule->fontsizeCO->insertItem("default");
308
309         for (int n=0; !token(items,'|',n).empty(); ++n)
310                 textLayoutModule->fontsizeCO->
311                         insertItem(toqstr(token(items,'|',n)));
312
313         for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
314                 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
315                         textLayoutModule->fontsizeCO->setCurrentItem(n);
316                         break;
317                 }
318         }
319 }
320
321
322 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
323 {
324         pageLayoutModule->pagestyleCO->clear();
325         pageLayoutModule->pagestyleCO->insertItem("default");
326
327         for (int n=0; !token(items,'|',n).empty(); ++n)
328                 pageLayoutModule->pagestyleCO->
329                         insertItem(toqstr(token(items,'|',n)));
330
331         for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
332                 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
333                         pageLayoutModule->pagestyleCO->setCurrentItem(n);
334                         break;
335                 }
336         }
337 }
338
339
340 void QDocumentDialog::classChanged()
341 {
342         ControlDocument & cntrl = form_->controller();
343         BufferParams & params = cntrl.params();
344
345         lyx::textclass_type const tc = latexModule->classCO->currentItem();
346
347         if (form_->controller().loadTextclass(tc)) {
348                 params.textclass = tc;
349
350                 if (lyxrc.auto_reset_options) {
351                         params.useClassDefaults();
352                         form_->update_contents();
353                 } else {
354                         updateFontsize(cntrl.textClass().opt_fontsize(),
355                                        params.fontsize);
356
357                         updatePagestyle(cntrl.textClass().opt_pagestyle(),
358                                         params.pagestyle);
359                 }
360         } else {
361                 latexModule->classCO->setCurrentItem(params.textclass);
362         }
363 }
364
365
366 void QDocumentDialog::updateNumbering()
367 {
368         int const depth = numberingModule->depthSL->value();
369         int const toc = numberingModule->tocSL->value();
370         QListViewItem * partitem = numberingModule->tocLV->firstChild();
371         QListViewItem * chapteritem = partitem->nextSibling();
372         QListViewItem * sectionitem = chapteritem->nextSibling();
373         QListViewItem * subsectionitem = sectionitem->nextSibling();
374         QListViewItem * subsubsectionitem = subsectionitem->nextSibling();
375         QListViewItem * paragraphitem = subsubsectionitem->nextSibling();
376         QListViewItem * subparagraphitem = paragraphitem->nextSibling();
377
378         QString const no = qt_("No");
379         QString const yes = qt_("Yes");
380
381         //numberingModule->tocLV->setUpdatesEnabled(false);
382
383         partitem->setText(1, yes);
384         chapteritem->setText(1, yes);
385         sectionitem->setText(1, yes);
386         subsectionitem->setText(1, yes);
387         subsubsectionitem->setText(1, yes);
388         paragraphitem->setText(1, yes);
389         subparagraphitem->setText(1, yes);
390         partitem->setText(2, yes);
391         chapteritem->setText(2, yes);
392         sectionitem->setText(2, yes);
393         subsectionitem->setText(2, yes);
394         subsubsectionitem->setText(2, yes);
395         paragraphitem->setText(2, yes);
396         subparagraphitem->setText(2, yes);
397
398         // numbering
399         if (depth < -1) partitem->setText(1, no);
400         if (depth < 0) chapteritem->setText(1, no);
401         if (depth < 1) sectionitem->setText(1, no);
402         if (depth < 2) subsectionitem->setText(1, no);
403         if (depth < 3) subsubsectionitem->setText(1, no);
404         if (depth < 4) paragraphitem->setText(1, no);
405         if (depth < 5) subparagraphitem->setText(1, no);
406
407         // in toc
408         if (toc < 0) chapteritem->setText(2, no);
409         if (toc < 1) sectionitem->setText(2, no);
410         if (toc < 2) subsectionitem->setText(2, no);
411         if (toc < 3) subsubsectionitem->setText(2, no);
412         if (toc < 4) paragraphitem->setText(2, no);
413         if (toc < 5) subparagraphitem->setText(2, no);
414
415         //numberingModule->tocLV->setUpdatesEnabled(true);
416         //numberingModule->tocLV->update();
417 }