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