2 * \file QDocumentDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "QDocument.h"
15 #include "QDocumentDialog.h"
17 #include <QCloseEvent>
19 #include "FloatPlacement.h"
20 #include "lengthcombo.h"
21 #include "validators.h"
22 #include "panelstack.h"
24 #include "checkedwidgets.h"
25 #include "qt_helpers.h"
27 #include "bufferparams.h"
30 #include "helper_funcs.h" // getSecond()
32 #include "lyxrc.h" // defaultUnit
33 #include "lyxtextclasslist.h"
34 #include "tex-strings.h" // tex_graphics
37 #include "controllers/ControlDocument.h"
38 #include "controllers/frnt_lang.h"
40 #include "support/lstrings.h"
42 #include "controllers/ControlDocument.h"
43 #include "controllers/frnt_lang.h"
46 using lyx::support::token;
47 using lyx::support::bformat;
48 using lyx::support::findToken;
49 using lyx::support::getVectorFromString;
60 QDocumentDialog::QDocumentDialog(QDocument * form)
62 lang_(getSecond(getLanguageData(false)))
66 connect(okPB, SIGNAL(clicked()),
67 form, SLOT(slotOK()));
68 connect(applyPB, SIGNAL(clicked()),
69 form, SLOT(slotApply()));
70 connect(closePB, SIGNAL(clicked()),
71 form, SLOT(slotClose()));
72 connect(restorePB, SIGNAL(clicked()),
73 form, SLOT(slotRestore()));
76 connect(savePB, SIGNAL( clicked() ),
77 this, SLOT( saveDefaultClicked() ) );
78 connect(defaultPB, SIGNAL( clicked() ),
79 this, SLOT( useDefaultsClicked() ) );
81 // Manage the restore, ok, apply, restore and cancel/close buttons
82 form_->bcview().setOK(okPB);
83 form_->bcview().setApply(applyPB);
84 form_->bcview().setCancel(closePB);
85 form_->bcview().setRestore(restorePB);
88 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
90 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
91 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
92 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
93 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
94 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
95 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
96 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
97 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
98 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
99 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
100 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
101 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
102 textLayoutModule->lspacingLE));
103 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
104 textLayoutModule->skipLE));
106 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
107 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
108 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
109 textLayoutModule->skipCO->addItem(qt_("Length"));
110 // remove the %-items from the unit choice
111 textLayoutModule->skipLengthCO->noPercents();
112 textLayoutModule->lspacingCO->insertItem(
113 Spacing::Single, qt_("Single"));
114 textLayoutModule->lspacingCO->insertItem(
115 Spacing::Onehalf, qt_("OneHalf"));
116 textLayoutModule->lspacingCO->insertItem(
117 Spacing::Double, qt_("Double"));
118 textLayoutModule->lspacingCO->insertItem(
119 Spacing::Other, qt_("Custom"));
121 // initialize the length validator
122 addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
127 fontModule = new UiWidget<Ui::FontUi>;
129 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
130 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(romanChanged(int)));
131 connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
132 connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(sansChanged(int)));
133 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
134 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(ttChanged(int)));
135 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
136 connect(fontModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
137 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
138 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
139 connect(fontModule->fontScCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
140 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
142 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
143 QString font = toqstr(tex_fonts_roman_gui[n]);
144 if (!form_->controller().isFontAvailable(tex_fonts_roman[n]))
145 font += qt_(" (not installed)");
146 fontModule->fontsRomanCO->addItem(font);
148 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
149 QString font = toqstr(tex_fonts_sans_gui[n]);
150 if (!form_->controller().isFontAvailable(tex_fonts_sans[n]))
151 font += qt_(" (not installed)");
152 fontModule->fontsSansCO->addItem(font);
154 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
155 QString font = toqstr(tex_fonts_monospaced_gui[n]);
156 if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n]))
157 font += qt_(" (not installed)");
158 fontModule->fontsTypewriterCO->addItem(font);
161 fontModule->fontsizeCO->addItem(qt_("default"));
162 fontModule->fontsizeCO->addItem(qt_("10"));
163 fontModule->fontsizeCO->addItem(qt_("11"));
164 fontModule->fontsizeCO->addItem(qt_("12"));
166 for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
167 fontModule->fontsDefaultCO->addItem(
168 qt_(ControlDocument::fontfamilies_gui[n]));
173 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
175 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
176 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
177 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
178 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
179 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
180 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
181 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
182 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
183 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
184 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
185 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
186 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
187 pageLayoutModule->pagestyleCO->addItem(qt_("default"));
188 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
189 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
190 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
191 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
192 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
193 pageLayoutModule->paperheightL);
194 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
195 pageLayoutModule->paperwidthL);
198 QComboBox * cb = pageLayoutModule->papersizeCO;
199 cb->addItem(qt_("Default"));
200 cb->addItem(qt_("Custom"));
201 cb->addItem(qt_("US letter"));
202 cb->addItem(qt_("US legal"));
203 cb->addItem(qt_("US executive"));
204 cb->addItem(qt_("A3"));
205 cb->addItem(qt_("A4"));
206 cb->addItem(qt_("A5"));
207 cb->addItem(qt_("B3"));
208 cb->addItem(qt_("B4"));
209 cb->addItem(qt_("B5"));
210 // remove the %-items from the unit choice
211 pageLayoutModule->paperwidthUnitCO->noPercents();
212 pageLayoutModule->paperheightUnitCO->noPercents();
213 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
214 pageLayoutModule->paperheightLE));
215 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
216 pageLayoutModule->paperwidthLE));
221 marginsModule = new UiWidget<Ui::MarginsUi>;
223 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool)));
224 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
225 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
226 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
227 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
228 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
229 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
230 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
231 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
232 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
233 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
234 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
235 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
236 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
237 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
238 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
239 marginsModule->topLE->setValidator(unsignedLengthValidator(
240 marginsModule->topLE));
241 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
242 marginsModule->bottomLE));
243 marginsModule->innerLE->setValidator(unsignedLengthValidator(
244 marginsModule->innerLE));
245 marginsModule->outerLE->setValidator(unsignedLengthValidator(
246 marginsModule->outerLE));
247 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
248 marginsModule->headsepLE));
249 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
250 marginsModule->headheightLE));
251 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
252 marginsModule->footskipLE));
254 addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
255 marginsModule->topL);
256 addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
257 marginsModule->bottomL);
258 addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
259 marginsModule->innerL);
260 addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
261 marginsModule->outerL);
262 addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
263 marginsModule->headsepL);
264 addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
265 marginsModule->headheightL);
266 addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
267 marginsModule->footskipL);
273 langModule = new UiWidget<Ui::LanguageUi>;
274 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), langModule->encodingL, SLOT(setDisabled(bool)));
275 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), langModule->encodingCO, SLOT(setDisabled(bool)));
277 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
278 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
279 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
280 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
282 vector<LanguagePair> const langs = getLanguageData(false);
283 vector<LanguagePair>::const_iterator lit = langs.begin();
284 vector<LanguagePair>::const_iterator lend = langs.end();
285 for (; lit != lend; ++lit) {
286 langModule->languageCO->addItem(
290 // Always put the default encoding in the first position.
291 // It is special because the displayed text is translated.
292 langModule->encodingCO->addItem(qt_("LaTeX default"));
293 Encodings::const_iterator it = encodings.begin();
294 Encodings::const_iterator const end = encodings.end();
295 for (; it != end; ++it)
296 langModule->encodingCO->addItem(toqstr(it->latexName()));
298 langModule->quoteStyleCO->addItem(qt_("``text''"));
299 langModule->quoteStyleCO->addItem(qt_("''text''"));
300 langModule->quoteStyleCO->addItem(qt_(",,text``"));
301 langModule->quoteStyleCO->addItem(qt_(",,text''"));
302 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
303 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
307 numberingModule = new UiWidget<Ui::NumberingUi>;
309 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
310 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
311 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
312 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
313 numberingModule->tocTW->setColumnCount(3);
314 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
315 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
316 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
319 biblioModule = new UiWidget<Ui::BiblioUi>;
320 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citationStyleL, SLOT( setEnabled(bool) ) );
321 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citeStyleCO, SLOT( setEnabled(bool) ) );
323 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
324 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
325 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
326 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
327 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
329 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
330 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
331 biblioModule->citeStyleCO->setCurrentIndex(0);
335 mathsModule = new UiWidget<Ui::MathsUi>;
336 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), mathsModule->amsCB, SLOT(setDisabled(bool)));
337 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)), mathsModule->esintCB, SLOT(setDisabled(bool)));
339 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
340 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
341 connect(mathsModule->esintCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
342 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
344 latexModule = new UiWidget<Ui::LaTeXUi>;
346 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
347 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
348 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
349 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
351 for (int n = 0; tex_graphics[n][0]; ++n) {
352 QString enc = tex_graphics[n];
353 latexModule->psdriverCO->addItem(enc);
356 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
357 cit != textclasslist.end(); ++cit) {
358 if (cit->isTeXClassAvailable()) {
359 latexModule->classCO->addItem(toqstr(cit->description()));
362 bformat(_("Unavailable: %1$s"), lyx::from_utf8(cit->description()));
363 latexModule->classCO->addItem(toqstr(item));
368 branchesModule = new QBranches;
369 connect(branchesModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
372 preambleModule = new UiWidget<Ui::PreambleUi>;
373 connect(preambleModule->preambleTE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
377 bulletsModule = new BulletsModule;
378 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
382 floatModule = new FloatPlacement;
383 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
385 docPS->addPanel(latexModule, _("Document Class"));
386 docPS->addPanel(fontModule, _("Fonts"));
387 docPS->addPanel(textLayoutModule, _("Text Layout"));
388 docPS->addPanel(pageLayoutModule, _("Page Layout"));
389 docPS->addPanel(marginsModule, _("Page Margins"));
390 docPS->addPanel(langModule, _("Language"));
391 docPS->addPanel(numberingModule, _("Numbering & TOC"));
392 docPS->addPanel(biblioModule, _("Bibliography"));
393 docPS->addPanel(mathsModule, _("Math Options"));
394 docPS->addPanel(floatModule, _("Float Placement"));
395 docPS->addPanel(bulletsModule, _("Bullets"));
396 docPS->addPanel(branchesModule, _("Branches"));
397 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
398 docPS->setCurrentPanel(_("Document Class"));
399 // FIXME: hack to work around resizing bug in Qt >= 4.2
400 // bug verified with Qt 4.2.{0-2} (JSpitzm)
401 #if QT_VERSION >= 0x040200
402 docPS->updateGeometry();
407 QDocumentDialog::~QDocumentDialog()
412 void QDocumentDialog::showPreamble()
414 docPS->setCurrentPanel(_("LaTeX Preamble"));
418 void QDocumentDialog::saveDefaultClicked()
420 form_->saveDocDefault();
424 void QDocumentDialog::useDefaultsClicked()
426 form_->useClassDefaults();
430 void QDocumentDialog::change_adaptor()
436 void QDocumentDialog::closeEvent(QCloseEvent * e)
443 void QDocumentDialog::setLSpacing(int item)
445 textLayoutModule->lspacingLE->setEnabled(item == 3);
449 void QDocumentDialog::setSkip(int item)
451 bool const enable = (item == 3);
452 textLayoutModule->skipLE->setEnabled(enable);
453 textLayoutModule->skipLengthCO->setEnabled(enable);
457 void QDocumentDialog::enableSkip(bool skip)
459 textLayoutModule->skipCO->setEnabled(skip);
460 textLayoutModule->skipLE->setEnabled(skip);
461 textLayoutModule->skipLengthCO->setEnabled(skip);
463 setSkip(textLayoutModule->skipCO->currentIndex());
466 void QDocumentDialog::portraitChanged()
468 setMargins(pageLayoutModule->papersizeCO->currentIndex());
471 void QDocumentDialog::setMargins(bool custom)
473 marginsModule->marginCB->setChecked(custom);
474 setCustomMargins(custom);
478 void QDocumentDialog::setCustomPapersize(int papersize)
480 bool const custom = (papersize == 1);
482 pageLayoutModule->paperwidthL->setEnabled(custom);
483 pageLayoutModule->paperwidthLE->setEnabled(custom);
484 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
485 pageLayoutModule->paperheightL->setEnabled(custom);
486 pageLayoutModule->paperheightLE->setEnabled(custom);
487 pageLayoutModule->paperheightLE->setFocus();
488 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
492 void QDocumentDialog::setCustomMargins(bool custom)
494 marginsModule->topL->setEnabled(!custom);
495 marginsModule->topLE->setEnabled(!custom);
496 marginsModule->topUnit->setEnabled(!custom);
498 marginsModule->bottomL->setEnabled(!custom);
499 marginsModule->bottomLE->setEnabled(!custom);
500 marginsModule->bottomUnit->setEnabled(!custom);
502 marginsModule->innerL->setEnabled(!custom);
503 marginsModule->innerLE->setEnabled(!custom);
504 marginsModule->innerUnit->setEnabled(!custom);
506 marginsModule->outerL->setEnabled(!custom);
507 marginsModule->outerLE->setEnabled(!custom);
508 marginsModule->outerUnit->setEnabled(!custom);
510 marginsModule->headheightL->setEnabled(!custom);
511 marginsModule->headheightLE->setEnabled(!custom);
512 marginsModule->headheightUnit->setEnabled(!custom);
514 marginsModule->headsepL->setEnabled(!custom);
515 marginsModule->headsepLE->setEnabled(!custom);
516 marginsModule->headsepUnit->setEnabled(!custom);
518 marginsModule->footskipL->setEnabled(!custom);
519 marginsModule->footskipLE->setEnabled(!custom);
520 marginsModule->footskipUnit->setEnabled(!custom);
524 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
526 fontModule->fontsizeCO->clear();
527 fontModule->fontsizeCO->addItem(qt_("default"));
529 for (int n = 0; !token(items,'|',n).empty(); ++n)
530 fontModule->fontsizeCO->
531 addItem(toqstr(token(items,'|',n)));
533 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
534 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
535 fontModule->fontsizeCO->setCurrentIndex(n);
542 void QDocumentDialog::romanChanged(int item)
544 string const font = tex_fonts_roman[item];
546 fontModule->fontScCB->setEnabled(
547 form_->controller().providesSC(font));
548 fontModule->fontOsfCB->setEnabled(
549 form_->controller().providesOSF(font));
553 void QDocumentDialog::sansChanged(int item)
555 string const font = tex_fonts_sans[item];
556 bool scaleable = form_->controller().providesScale(font);
557 fontModule->scaleSansSB->setEnabled(scaleable);
558 fontModule->scaleSansLA->setEnabled(scaleable);
562 void QDocumentDialog::ttChanged(int item)
564 string const font = tex_fonts_monospaced[item];
565 bool scaleable = form_->controller().providesScale(font);
566 fontModule->scaleTypewriterSB->setEnabled(scaleable);
567 fontModule->scaleTypewriterLA->setEnabled(scaleable);
571 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
573 pageLayoutModule->pagestyleCO->clear();
574 pageLayoutModule->pagestyleCO->addItem("default");
576 for (int n=0; !token(items,'|',n).empty(); ++n)
577 pageLayoutModule->pagestyleCO->
578 addItem(toqstr(token(items,'|',n)));
580 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
581 if (fromqstr(pageLayoutModule->pagestyleCO->itemText(n))==sel) {
582 pageLayoutModule->pagestyleCO->setCurrentIndex(n);
589 void QDocumentDialog::classChanged()
591 ControlDocument & cntrl = form_->controller();
592 BufferParams & params = cntrl.params();
594 lyx::textclass_type const tc = latexModule->classCO->currentIndex();
596 if (form_->controller().loadTextclass(tc)) {
597 params.textclass = tc;
598 if (lyxrc.auto_reset_options)
599 params.useClassDefaults();
600 form_->update_contents();
602 latexModule->classCO->setCurrentIndex(params.textclass);
607 void QDocumentDialog::updateNumbering()
609 LyXTextClass const & tclass =
610 form_->controller().params().getLyXTextClass();
612 numberingModule->tocTW->setUpdatesEnabled(false);
613 numberingModule->tocTW->clear();
615 int const depth = numberingModule->depthSL->value();
616 int const toc = numberingModule->tocSL->value();
617 QString const no = qt_("No");
618 QString const yes = qt_("Yes");
619 LyXTextClass::const_iterator end = tclass.end();
620 LyXTextClass::const_iterator cit = tclass.begin();
621 QTreeWidgetItem * item = 0;
622 for ( ; cit != end ; ++cit) {
623 int const toclevel = (*cit)->toclevel;
624 if (toclevel != LyXLayout::NOT_IN_TOC
625 && (*cit)->labeltype == LABEL_COUNTER) {
626 item = new QTreeWidgetItem(numberingModule->tocTW);
627 item->setText(0, qt_((*cit)->name()));
628 item->setText(1, (toclevel <= depth) ? yes : no);
629 item->setText(2, (toclevel <= toc) ? yes : no);
633 numberingModule->tocTW->setUpdatesEnabled(true);
634 numberingModule->tocTW->update();
637 void QDocumentDialog::apply(BufferParams & params)
641 fromqstr(preambleModule->preambleTE->document()->toPlainText());
644 params.cite_engine = biblio::ENGINE_BASIC;
646 if (biblioModule->citeNatbibRB->isChecked()) {
647 bool const use_numerical_citations =
648 biblioModule->citeStyleCO->currentIndex();
649 if (use_numerical_citations)
650 params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
652 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
654 } else if (biblioModule->citeJurabibRB->isChecked())
655 params.cite_engine = biblio::ENGINE_JURABIB;
657 params.use_bibtopic =
658 biblioModule->bibtopicCB->isChecked();
661 if (langModule->defaultencodingCB->isChecked()) {
662 params.inputenc = "auto";
664 int i = langModule->encodingCO->currentIndex();
666 params.inputenc = "default";
669 fromqstr(langModule->encodingCO->currentText());
672 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
673 switch (langModule->quoteStyleCO->currentIndex()) {
675 lga = InsetQuotes::EnglishQ;
678 lga = InsetQuotes::SwedishQ;
681 lga = InsetQuotes::GermanQ;
684 lga = InsetQuotes::PolishQ;
687 lga = InsetQuotes::FrenchQ;
690 lga = InsetQuotes::DanishQ;
693 params.quotes_language = lga;
695 int const pos = langModule->languageCO->currentIndex();
696 params.language = languages.getLanguage(lang_[pos]);
699 if (params.getLyXTextClass().hasTocLevels()) {
700 params.tocdepth = numberingModule->tocSL->value();
701 params.secnumdepth = numberingModule->depthSL->value();
705 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
706 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
707 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
708 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
711 params.graphicsDriver =
712 fromqstr(latexModule->psdriverCO->currentText());
714 if (mathsModule->amsautoCB->isChecked()) {
715 params.use_amsmath = BufferParams::package_auto;
717 if (mathsModule->amsCB->isChecked())
718 params.use_amsmath = BufferParams::package_on;
720 params.use_amsmath = BufferParams::package_off;
723 if (mathsModule->esintautoCB->isChecked())
724 params.use_esint = BufferParams::package_auto;
726 if (mathsModule->esintCB->isChecked())
727 params.use_esint = BufferParams::package_on;
729 params.use_esint = BufferParams::package_off;
734 latexModule->classCO->currentIndex();
737 fromqstr(pageLayoutModule->pagestyleCO->currentText());
739 switch (textLayoutModule->lspacingCO->currentIndex()) {
741 params.spacing().set(Spacing::Single);
744 params.spacing().set(Spacing::Onehalf);
747 params.spacing().set(Spacing::Double);
750 params.spacing().set(Spacing::Other,
751 fromqstr(textLayoutModule->lspacingLE->text()));
755 if (textLayoutModule->twoColumnCB->isChecked())
760 if (textLayoutModule->indentRB->isChecked())
761 params.paragraph_separation = BufferParams::PARSEP_INDENT;
763 params.paragraph_separation = BufferParams::PARSEP_SKIP;
765 switch (textLayoutModule->skipCO->currentIndex()) {
767 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
770 params.setDefSkip(VSpace(VSpace::MEDSKIP));
773 params.setDefSkip(VSpace(VSpace::BIGSKIP));
778 widgetsToLength(textLayoutModule->skipLE,
779 textLayoutModule->skipLengthCO)
781 params.setDefSkip(vs);
785 // DocumentDefskipCB assures that this never happens
786 // so Assert then !!! - jbl
787 params.setDefSkip(VSpace(VSpace::MEDSKIP));
792 fromqstr(latexModule->optionsLE->text());
794 params.float_placement = floatModule->get();
798 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
801 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
803 params.fontsTypewriter =
804 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
806 params.fontsSansScale = fontModule->scaleSansSB->value();
808 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
810 params.fontsSC = fontModule->fontScCB->isChecked();
812 params.fontsOSF = fontModule->fontOsfCB->isChecked();
814 params.fontsDefaultFamily = ControlDocument::fontfamilies[
815 fontModule->fontsDefaultCO->currentIndex()];
817 if (fontModule->fontsizeCO->currentIndex() == 0)
818 params.fontsize = "default";
821 fromqstr(fontModule->fontsizeCO->currentText());
824 params.papersize = PAPER_SIZE(
825 pageLayoutModule->papersizeCO->currentIndex());
827 // custom, A3, B3 and B4 paper sizes need geometry
828 int psize = pageLayoutModule->papersizeCO->currentIndex();
829 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
831 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
832 pageLayoutModule->paperwidthUnitCO);
834 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
835 pageLayoutModule->paperheightUnitCO);
837 if (pageLayoutModule->facingPagesCB->isChecked())
838 params.sides = LyXTextClass::TwoSides;
840 params.sides = LyXTextClass::OneSide;
842 if (pageLayoutModule->landscapeRB->isChecked())
843 params.orientation = ORIENTATION_LANDSCAPE;
845 params.orientation = ORIENTATION_PORTRAIT;
848 params.use_geometry =
849 (!marginsModule->marginCB->isChecked()
852 Ui::MarginsUi const * m(marginsModule);
854 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
856 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
858 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
860 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
862 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
864 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
866 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
868 branchesModule->apply(params);
873 /** Return the position of val in the vector if found.
874 If not found, return 0.
877 typename std::vector<A>::size_type
878 findPos(std::vector<A> const & vec, A const & val)
880 typename std::vector<A>::const_iterator it =
881 std::find(vec.begin(), vec.end(), val);
884 return distance(vec.begin(), it);
890 void QDocumentDialog::update(BufferParams const & params)
892 // set the default unit
893 // FIXME: move to controller
894 LyXLength::UNIT defaultUnit = LyXLength::CM;
895 switch (lyxrc.default_papersize) {
896 case PAPER_DEFAULT: break;
900 case PAPER_USEXECUTIVE:
901 defaultUnit = LyXLength::IN;
910 defaultUnit = LyXLength::CM;
917 QString preamble = toqstr(params.preamble);
918 preambleModule->preambleTE->document()->setPlainText(preamble);
921 biblioModule->citeDefaultRB->setChecked(
922 params.cite_engine == biblio::ENGINE_BASIC);
924 biblioModule->citeNatbibRB->setChecked(
925 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
926 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
928 biblioModule->citeStyleCO->setCurrentIndex(
929 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
931 biblioModule->citeJurabibRB->setChecked(
932 params.cite_engine == biblio::ENGINE_JURABIB);
934 biblioModule->bibtopicCB->setChecked(
935 params.use_bibtopic);
938 int const pos = int(findPos(lang_,
939 params.language->lang()));
940 langModule->languageCO->setCurrentIndex(pos);
942 langModule->quoteStyleCO->setCurrentIndex(
943 params.quotes_language);
945 langModule->defaultencodingCB->setChecked(true);
947 if (params.inputenc != "auto") {
948 langModule->defaultencodingCB->setChecked(false);
949 if (params.inputenc == "default") {
950 langModule->encodingCO->setCurrentIndex(0);
952 int const i = langModule->encodingCO->findText(
953 toqstr(params.inputenc));
955 langModule->encodingCO->setCurrentIndex(i);
957 // unknown encoding. Set to default.
958 langModule->defaultencodingCB->setChecked(true);
963 int const min_toclevel = form_->controller().textClass().min_toclevel();
964 int const max_toclevel = form_->controller().textClass().max_toclevel();
965 if (form_->controller().textClass().hasTocLevels()) {
966 numberingModule->setEnabled(true);
967 numberingModule->depthSL->setMinimum(min_toclevel - 1);
968 numberingModule->depthSL->setMaximum(max_toclevel);
969 numberingModule->depthSL->setValue(params.secnumdepth);
970 numberingModule->tocSL->setMaximum(min_toclevel - 1);
971 numberingModule->tocSL->setMaximum(max_toclevel);
972 numberingModule->tocSL->setValue(params.tocdepth);
975 numberingModule->setEnabled(false);
976 numberingModule->tocTW->clear();
980 bulletsModule->setBullet(0, params.user_defined_bullet(0));
981 bulletsModule->setBullet(1, params.user_defined_bullet(1));
982 bulletsModule->setBullet(2, params.user_defined_bullet(2));
983 bulletsModule->setBullet(3, params.user_defined_bullet(3));
984 bulletsModule->init();
987 QString text = toqstr(params.graphicsDriver);
988 int nitem = latexModule->psdriverCO->count();
989 for (int n = 0; n < nitem ; ++n) {
990 QString enc = tex_graphics[n];
992 latexModule->psdriverCO->setCurrentIndex(n);
997 mathsModule->amsCB->setChecked(
998 params.use_amsmath == BufferParams::package_on);
999 mathsModule->amsautoCB->setChecked(
1000 params.use_amsmath == BufferParams::package_auto);
1002 mathsModule->esintCB->setChecked(
1003 params.use_esint == BufferParams::package_on);
1004 mathsModule->esintautoCB->setChecked(
1005 params.use_esint == BufferParams::package_auto);
1007 switch (params.spacing().getSpace()) {
1008 case Spacing::Other: nitem = 3; break;
1009 case Spacing::Double: nitem = 2; break;
1010 case Spacing::Onehalf: nitem = 1; break;
1011 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1015 latexModule->classCO->setCurrentIndex(params.textclass);
1017 updatePagestyle(form_->controller().textClass().opt_pagestyle(),
1020 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1021 if (params.spacing().getSpace() == Spacing::Other) {
1022 textLayoutModule->lspacingLE->setText(
1023 toqstr(params.spacing().getValueAsString()));
1027 if (params.paragraph_separation
1028 == BufferParams::PARSEP_INDENT) {
1029 textLayoutModule->indentRB->setChecked(true);
1031 textLayoutModule->skipRB->setChecked(true);
1035 switch (params.getDefSkip().kind()) {
1036 case VSpace::SMALLSKIP:
1039 case VSpace::MEDSKIP:
1042 case VSpace::BIGSKIP:
1045 case VSpace::LENGTH:
1048 string const length = params.getDefSkip().asLyXCommand();
1049 lengthToWidgets(textLayoutModule->skipLE,
1050 textLayoutModule->skipLengthCO,
1051 length, defaultUnit);
1058 textLayoutModule->skipCO->setCurrentIndex(skip);
1061 textLayoutModule->twoColumnCB->setChecked(
1062 params.columns == 2);
1064 if (!params.options.empty()) {
1065 latexModule->optionsLE->setText(
1066 toqstr(params.options));
1068 latexModule->optionsLE->setText("");
1071 floatModule->set(params.float_placement);
1074 updateFontsize(form_->controller().textClass().opt_fontsize(),
1077 int n = findToken(tex_fonts_roman, params.fontsRoman);
1079 fontModule->fontsRomanCO->setCurrentIndex(n);
1083 n = findToken(tex_fonts_sans, params.fontsSans);
1085 fontModule->fontsSansCO->setCurrentIndex(n);
1089 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1091 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1095 fontModule->fontScCB->setChecked(params.fontsSC);
1096 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1097 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1098 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1099 n = findToken(ControlDocument::fontfamilies, params.fontsDefaultFamily);
1101 fontModule->fontsDefaultCO->setCurrentIndex(n);
1104 int const psize = params.papersize;
1105 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1106 setCustomPapersize(psize);
1108 bool const landscape =
1109 params.orientation == ORIENTATION_LANDSCAPE;
1110 pageLayoutModule->landscapeRB->setChecked(landscape);
1111 pageLayoutModule->portraitRB->setChecked(!landscape);
1113 pageLayoutModule->facingPagesCB->setChecked(
1114 params.sides == LyXTextClass::TwoSides);
1117 lengthToWidgets(pageLayoutModule->paperwidthLE,
1118 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1120 lengthToWidgets(pageLayoutModule->paperheightLE,
1121 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1124 Ui::MarginsUi * m = marginsModule;
1126 setMargins(!params.use_geometry);
1128 lengthToWidgets(m->topLE, m->topUnit,
1129 params.topmargin, defaultUnit);
1131 lengthToWidgets(m->bottomLE, m->bottomUnit,
1132 params.bottommargin, defaultUnit);
1134 lengthToWidgets(m->innerLE, m->innerUnit,
1135 params.leftmargin, defaultUnit);
1137 lengthToWidgets(m->outerLE, m->outerUnit,
1138 params.rightmargin, defaultUnit);
1140 lengthToWidgets(m->headheightLE, m->headheightUnit,
1141 params.headheight, defaultUnit);
1143 lengthToWidgets(m->headsepLE, m->headsepUnit,
1144 params.headsep, defaultUnit);
1146 lengthToWidgets(m->footskipLE, m->footskipUnit,
1147 params.footskip, defaultUnit);
1149 branchesModule->update(params);
1155 } // namespace frontend
1158 #include "QDocumentDialog_moc.cpp"