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
12 #include "qt_helpers.h"
14 #include "ControlDocument.h"
15 #include "QDocument.h"
18 #include "QDocumentDialog.h"
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"
35 #include "support/lstrings.h"
39 #include <qwidgetstack.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>
50 #include "lengthcombo.h"
53 QDocumentDialog::QDocumentDialog(QDocument * form)
54 : QDocumentDialogBase(0, 0, false, 0), form_(form)
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()));
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);
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"));
91 connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
93 connect(biblioModule->natbibCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
94 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
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()));
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);
109 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
110 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
112 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
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()));
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()));
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()));
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()));
167 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
171 QDocumentDialog::~QDocumentDialog()
176 void QDocumentDialog::showPreamble()
178 docPS->setCurrentPanel(_("LaTeX Preamble"));
182 void QDocumentDialog::saveDefaultClicked()
184 form_->saveDocDefault();
188 void QDocumentDialog::useDefaultsClicked()
190 form_->useClassDefaults();
194 void QDocumentDialog::change_adaptor()
200 void QDocumentDialog::closeEvent(QCloseEvent * e)
207 void QDocumentDialog::setLSpacing(int item)
209 textLayoutModule->lspacingLE->setEnabled(item == 3);
213 void QDocumentDialog::setSkip(int item)
215 bool const enable = (item == 3);
216 textLayoutModule->skipLE->setEnabled(enable);
217 textLayoutModule->skipLengthCO->setEnabled(enable);
221 void QDocumentDialog::enableSkip(bool skip)
223 textLayoutModule->skipCO->setEnabled(skip);
224 textLayoutModule->skipLE->setEnabled(skip);
225 textLayoutModule->skipLengthCO->setEnabled(skip);
227 setSkip(textLayoutModule->skipCO->currentItem());
230 void QDocumentDialog::portraitChanged()
232 setMargins(pageLayoutModule->papersizeCO->currentItem());
235 void QDocumentDialog::setMargins(int papersize)
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) {
250 marginsModule->marginCO->setCurrentItem(olditem);
251 setCustomMargins(olditem);
255 void QDocumentDialog::setCustomPapersize(int papersize)
257 bool const custom = (papersize == 1);
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);
269 void QDocumentDialog::setCustomMargins(int margin)
271 bool const custom = (margin == 1);
273 marginsModule->topL->setEnabled(custom);
274 marginsModule->topLE->setEnabled(custom);
275 marginsModule->topUnit->setEnabled(custom);
277 marginsModule->bottomL->setEnabled(custom);
278 marginsModule->bottomLE->setEnabled(custom);
279 marginsModule->bottomUnit->setEnabled(custom);
281 marginsModule->innerL->setEnabled(custom);
282 marginsModule->innerLE->setEnabled(custom);
283 marginsModule->innerUnit->setEnabled(custom);
285 marginsModule->outerL->setEnabled(custom);
286 marginsModule->outerLE->setEnabled(custom);
287 marginsModule->outerUnit->setEnabled(custom);
289 marginsModule->headheightL->setEnabled(custom);
290 marginsModule->headheightLE->setEnabled(custom);
291 marginsModule->headheightUnit->setEnabled(custom);
293 marginsModule->headsepL->setEnabled(custom);
294 marginsModule->headsepLE->setEnabled(custom);
295 marginsModule->headsepUnit->setEnabled(custom);
297 marginsModule->footskipL->setEnabled(custom);
298 marginsModule->footskipLE->setEnabled(custom);
299 marginsModule->footskipUnit->setEnabled(custom);
304 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
306 textLayoutModule->fontsizeCO->clear();
307 textLayoutModule->fontsizeCO->insertItem("default");
309 for (int n=0; !token(items,'|',n).empty(); ++n)
310 textLayoutModule->fontsizeCO->
311 insertItem(toqstr(token(items,'|',n)));
313 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
314 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
315 textLayoutModule->fontsizeCO->setCurrentItem(n);
322 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
324 pageLayoutModule->pagestyleCO->clear();
325 pageLayoutModule->pagestyleCO->insertItem("default");
327 for (int n=0; !token(items,'|',n).empty(); ++n)
328 pageLayoutModule->pagestyleCO->
329 insertItem(toqstr(token(items,'|',n)));
331 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
332 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
333 pageLayoutModule->pagestyleCO->setCurrentItem(n);
340 void QDocumentDialog::classChanged()
342 ControlDocument & cntrl = form_->controller();
343 BufferParams & params = cntrl.params();
345 lyx::textclass_type const tc = latexModule->classCO->currentItem();
347 if (form_->controller().loadTextclass(tc)) {
348 params.textclass = tc;
350 if (lyxrc.auto_reset_options) {
351 params.useClassDefaults();
352 form_->update_contents();
354 updateFontsize(cntrl.textClass().opt_fontsize(),
357 updatePagestyle(cntrl.textClass().opt_pagestyle(),
361 latexModule->classCO->setCurrentItem(params.textclass);
366 void QDocumentDialog::updateNumbering()
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();
378 QString const no = qt_("No");
379 QString const yes = qt_("Yes");
381 //numberingModule->tocLV->setUpdatesEnabled(false);
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);
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);
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);
415 //numberingModule->tocLV->setUpdatesEnabled(true);
416 //numberingModule->tocLV->update();