2 * \file QDocumentDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "buffer.h" //*here* because of braindead qt headers's #define signals
15 #include "qt_helpers.h"
17 #include "ControlDocument.h"
18 #include "QDocument.h"
21 #include "QDocumentDialog.h"
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"
38 #include "support/lstrings.h"
42 #include <qwidgetstack.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>
53 #include "lengthcombo.h"
55 using namespace lyx::support;
57 QDocumentDialog::QDocumentDialog(QDocument * form)
58 : QDocumentDialogBase(0, 0, false, 0), form_(form)
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()));
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);
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"));
95 connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
97 connect(biblioModule->natbibCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
98 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
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()));
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);
113 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
114 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
116 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
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()));
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()));
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()));
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()));
171 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
175 QDocumentDialog::~QDocumentDialog()
180 void QDocumentDialog::showPreamble()
182 docPS->setCurrentPanel(_("LaTeX Preamble"));
186 void QDocumentDialog::saveDefaultClicked()
188 form_->saveDocDefault();
192 void QDocumentDialog::useDefaultsClicked()
194 form_->useClassDefaults();
198 void QDocumentDialog::change_adaptor()
204 void QDocumentDialog::closeEvent(QCloseEvent * e)
211 void QDocumentDialog::setLSpacing(int item)
213 textLayoutModule->lspacingLE->setEnabled(item == 3);
217 void QDocumentDialog::setSkip(int item)
219 bool const enable = (item == 3);
220 textLayoutModule->skipLE->setEnabled(enable);
221 textLayoutModule->skipLengthCO->setEnabled(enable);
225 void QDocumentDialog::enableSkip(bool skip)
227 textLayoutModule->skipCO->setEnabled(skip);
228 textLayoutModule->skipLE->setEnabled(skip);
229 textLayoutModule->skipLengthCO->setEnabled(skip);
231 setSkip(textLayoutModule->skipCO->currentItem());
234 void QDocumentDialog::portraitChanged()
236 setMargins(pageLayoutModule->papersizeCO->currentItem());
239 void QDocumentDialog::setMargins(int papersize)
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) {
254 marginsModule->marginCO->setCurrentItem(olditem);
255 setCustomMargins(olditem);
259 void QDocumentDialog::setCustomPapersize(int papersize)
261 bool const custom = (papersize == 1);
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);
273 void QDocumentDialog::setCustomMargins(int margin)
275 bool const custom = (margin == 1);
277 marginsModule->topL->setEnabled(custom);
278 marginsModule->topLE->setEnabled(custom);
279 marginsModule->topUnit->setEnabled(custom);
281 marginsModule->bottomL->setEnabled(custom);
282 marginsModule->bottomLE->setEnabled(custom);
283 marginsModule->bottomUnit->setEnabled(custom);
285 marginsModule->innerL->setEnabled(custom);
286 marginsModule->innerLE->setEnabled(custom);
287 marginsModule->innerUnit->setEnabled(custom);
289 marginsModule->outerL->setEnabled(custom);
290 marginsModule->outerLE->setEnabled(custom);
291 marginsModule->outerUnit->setEnabled(custom);
293 marginsModule->headheightL->setEnabled(custom);
294 marginsModule->headheightLE->setEnabled(custom);
295 marginsModule->headheightUnit->setEnabled(custom);
297 marginsModule->headsepL->setEnabled(custom);
298 marginsModule->headsepLE->setEnabled(custom);
299 marginsModule->headsepUnit->setEnabled(custom);
301 marginsModule->footskipL->setEnabled(custom);
302 marginsModule->footskipLE->setEnabled(custom);
303 marginsModule->footskipUnit->setEnabled(custom);
308 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
310 textLayoutModule->fontsizeCO->clear();
311 textLayoutModule->fontsizeCO->insertItem("default");
313 for (int n = 0; !token(items,'|',n).empty(); ++n)
314 textLayoutModule->fontsizeCO->
315 insertItem(toqstr(token(items,'|',n)));
317 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
318 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
319 textLayoutModule->fontsizeCO->setCurrentItem(n);
326 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
328 pageLayoutModule->pagestyleCO->clear();
329 pageLayoutModule->pagestyleCO->insertItem("default");
331 for (int n=0; !token(items,'|',n).empty(); ++n)
332 pageLayoutModule->pagestyleCO->
333 insertItem(toqstr(token(items,'|',n)));
335 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
336 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
337 pageLayoutModule->pagestyleCO->setCurrentItem(n);
344 void QDocumentDialog::classChanged()
346 ControlDocument & cntrl = form_->controller();
347 BufferParams & params = cntrl.params();
349 lyx::textclass_type const tc = latexModule->classCO->currentItem();
351 if (form_->controller().loadTextclass(tc)) {
352 params.textclass = tc;
354 if (lyxrc.auto_reset_options) {
355 params.useClassDefaults();
356 form_->update_contents();
358 updateFontsize(cntrl.textClass().opt_fontsize(),
361 updatePagestyle(cntrl.textClass().opt_pagestyle(),
365 latexModule->classCO->setCurrentItem(params.textclass);
370 void QDocumentDialog::updateNumbering()
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();
382 QString const no = qt_("No");
383 QString const yes = qt_("Yes");
385 //numberingModule->tocLV->setUpdatesEnabled(false);
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);
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);
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);
419 //numberingModule->tocLV->setUpdatesEnabled(true);
420 //numberingModule->tocLV->update();