2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "BranchList.h"
17 #include "buffer_funcs.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
23 #include "FloatPlacement.h"
24 #include "frontend_helpers.h"
25 #include "FuncRequest.h"
27 #include "GuiBranches.h"
29 #include "LaTeXFeatures.h"
30 #include "LaTeXHighlighter.h"
32 #include "LengthCombo.h"
33 #include "LyXRC.h" // defaultUnit
34 #include "ModuleList.h"
35 #include "OutputParams.h"
36 #include "PanelStack.h"
37 #include "PDFOptions.h"
38 #include "qt_helpers.h"
40 #include "TextClassList.h"
41 #include "Validator.h"
44 // FIXME: those two headers are needed because of the
45 // WorkArea::redraw() call below.
46 #include "frontends/LyXView.h"
47 #include "frontends/WorkArea.h"
49 #include "insets/InsetListingsParams.h"
51 #include "support/lstrings.h"
53 #include <boost/bind.hpp>
55 #include <QCloseEvent>
57 #include <QTextCursor>
67 using std::ostringstream;
72 std::vector<typename Pair::second_type> const
73 getSecond(std::vector<Pair> const & pr)
75 std::vector<typename Pair::second_type> tmp(pr.size());
76 std::transform(pr.begin(), pr.end(), tmp.begin(),
77 boost::bind(&Pair::second, _1));
81 char const * const tex_graphics[] =
83 "default", "dvips", "dvitops", "emtex",
84 "ln", "oztex", "textures", "none", ""
88 char const * const tex_graphics_gui[] =
90 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
91 "LN", "OzTeX", "Textures", N_("None"), ""
95 char const * const tex_fonts_roman[] =
97 "default", "cmr", "lmodern", "ae", "times", "palatino",
98 "charter", "newcent", "bookman", "utopia", "beraserif",
99 "ccfonts", "chancery", ""
103 char const * tex_fonts_roman_gui[] =
105 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
106 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
107 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
108 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
113 char const * const tex_fonts_sans[] =
115 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
119 char const * tex_fonts_sans_gui[] =
121 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
122 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
126 char const * const tex_fonts_monospaced[] =
128 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
132 char const * tex_fonts_monospaced_gui[] =
134 N_("Default"), N_("Computer Modern Typewriter"),
135 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
136 N_("LuxiMono"), N_("CM Typewriter Light"), ""
140 vector<pair<string, lyx::docstring> > pagestyles;
146 using support::token;
147 using support::bformat;
148 using support::findToken;
149 using support::getVectorFromString;
151 /////////////////////////////////////////////////////////////////////
155 /////////////////////////////////////////////////////////////////////
157 PreambleModule::PreambleModule(): current_id_(0)
159 // This is not a memory leak. The object will be destroyed
161 (void) new LaTeXHighlighter(preambleTE->document());
162 setFocusProxy(preambleTE);
163 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
167 void PreambleModule::update(BufferParams const & params, BufferId id)
169 QString preamble = toqstr(params.preamble);
170 // Nothing to do if the params and preamble are unchanged.
171 if (id == current_id_
172 && preamble == preambleTE->document()->toPlainText())
175 QTextCursor cur = preambleTE->textCursor();
176 // Save the coords before switching to the new one.
177 preamble_coords_[current_id_] =
178 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
180 // Save the params address for further use.
182 preambleTE->document()->setPlainText(preamble);
183 Coords::const_iterator it = preamble_coords_.find(current_id_);
184 if (it == preamble_coords_.end())
185 // First time we open this one.
186 preamble_coords_[current_id_] = make_pair(0,0);
188 // Restore saved coords.
189 QTextCursor cur = preambleTE->textCursor();
190 cur.setPosition(it->second.first);
191 preambleTE->setTextCursor(cur);
192 preambleTE->verticalScrollBar()->setValue(it->second.second);
197 void PreambleModule::apply(BufferParams & params)
199 params.preamble = fromqstr(preambleTE->document()->toPlainText());
203 void PreambleModule::closeEvent(QCloseEvent * e)
205 // Save the coords before closing.
206 QTextCursor cur = preambleTE->textCursor();
207 preamble_coords_[current_id_] =
208 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
213 /////////////////////////////////////////////////////////////////////
217 /////////////////////////////////////////////////////////////////////
221 GuiDocument::GuiDocument(LyXView & lv)
222 : GuiDialog(lv, "document")
225 setViewTitle(_("Document Settings"));
227 lang_ = getSecond(getLanguageData(false));
229 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
230 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
231 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
232 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
234 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
235 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
237 // Manage the restore, ok, apply, restore and cancel/close buttons
238 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
240 bc().setApply(applyPB);
241 bc().setCancel(closePB);
242 bc().setRestore(restorePB);
244 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
246 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
247 this, SLOT(change_adaptor()));
248 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
249 this, SLOT(setLSpacing(int)));
250 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
251 this, SLOT(change_adaptor()));
252 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
253 this, SLOT(change_adaptor()));
254 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
255 this, SLOT(change_adaptor()));
256 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
257 this, SLOT(change_adaptor()));
258 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
259 this, SLOT(change_adaptor()));
260 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
261 this, SLOT(change_adaptor()));
262 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
263 this, SLOT(setSkip(int)));
264 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
265 this, SLOT(enableSkip(bool)));
266 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
267 this, SLOT(change_adaptor()));
268 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
269 this, SLOT(change_adaptor()));
270 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
271 this, SLOT(change_adaptor()));
272 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
273 this, SLOT(set_listings_msg()));
274 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
275 this, SLOT(set_listings_msg()));
276 textLayoutModule->listingsTB->setPlainText(
277 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
278 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
279 textLayoutModule->lspacingLE));
280 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
281 textLayoutModule->skipLE));
283 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
284 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
285 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
286 textLayoutModule->skipCO->addItem(qt_("Length"));
287 // remove the %-items from the unit choice
288 textLayoutModule->skipLengthCO->noPercents();
289 textLayoutModule->lspacingCO->insertItem(
290 Spacing::Single, qt_("Single"));
291 textLayoutModule->lspacingCO->insertItem(
292 Spacing::Onehalf, qt_("OneHalf"));
293 textLayoutModule->lspacingCO->insertItem(
294 Spacing::Double, qt_("Double"));
295 textLayoutModule->lspacingCO->insertItem(
296 Spacing::Other, qt_("Custom"));
298 // initialize the length validator
299 bc().addCheckedLineEdit(textLayoutModule->skipLE);
301 fontModule = new UiWidget<Ui::FontUi>;
303 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
304 this, SLOT(change_adaptor()));
305 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
306 this, SLOT(romanChanged(int)));
307 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
308 this, SLOT(change_adaptor()));
309 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
310 this, SLOT(sansChanged(int)));
311 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
312 this, SLOT(change_adaptor()));
313 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
314 this, SLOT(ttChanged(int)));
315 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
316 this, SLOT(change_adaptor()));
317 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
318 this, SLOT(change_adaptor()));
319 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
320 this, SLOT(change_adaptor()));
321 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
322 this, SLOT(change_adaptor()));
323 connect(fontModule->fontScCB, SIGNAL(clicked()),
324 this, SLOT(change_adaptor()));
325 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
326 this, SLOT(change_adaptor()));
328 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
329 QString font = qt_(tex_fonts_roman_gui[n]);
330 if (!isFontAvailable(tex_fonts_roman[n]))
331 font += qt_(" (not installed)");
332 fontModule->fontsRomanCO->addItem(font);
334 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
335 QString font = qt_(tex_fonts_sans_gui[n]);
336 if (!isFontAvailable(tex_fonts_sans[n]))
337 font += qt_(" (not installed)");
338 fontModule->fontsSansCO->addItem(font);
340 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
341 QString font = qt_(tex_fonts_monospaced_gui[n]);
342 if (!isFontAvailable(tex_fonts_monospaced[n]))
343 font += qt_(" (not installed)");
344 fontModule->fontsTypewriterCO->addItem(font);
347 fontModule->fontsizeCO->addItem(qt_("Default"));
348 fontModule->fontsizeCO->addItem(qt_("10"));
349 fontModule->fontsizeCO->addItem(qt_("11"));
350 fontModule->fontsizeCO->addItem(qt_("12"));
352 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
353 fontModule->fontsDefaultCO->addItem(
354 qt_(GuiDocument::fontfamilies_gui[n]));
357 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
359 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
360 this, SLOT(setCustomPapersize(int)));
361 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
362 this, SLOT(setCustomPapersize(int)));
363 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
364 this, SLOT(portraitChanged()));
365 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
366 this, SLOT(change_adaptor()));
367 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
368 this, SLOT(change_adaptor()));
369 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
370 this, SLOT(change_adaptor()));
371 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
372 this, SLOT(change_adaptor()));
373 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
374 this, SLOT(change_adaptor()));
375 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
376 this, SLOT(change_adaptor()));
377 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
378 this, SLOT(change_adaptor()));
379 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
380 this, SLOT(change_adaptor()));
381 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
382 this, SLOT(change_adaptor()));
384 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
385 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
386 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
387 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
388 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
389 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
390 pageLayoutModule->paperheightL);
391 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
392 pageLayoutModule->paperwidthL);
395 QComboBox * cb = pageLayoutModule->papersizeCO;
396 cb->addItem(qt_("Default"));
397 cb->addItem(qt_("Custom"));
398 cb->addItem(qt_("US letter"));
399 cb->addItem(qt_("US legal"));
400 cb->addItem(qt_("US executive"));
401 cb->addItem(qt_("A3"));
402 cb->addItem(qt_("A4"));
403 cb->addItem(qt_("A5"));
404 cb->addItem(qt_("B3"));
405 cb->addItem(qt_("B4"));
406 cb->addItem(qt_("B5"));
407 // remove the %-items from the unit choice
408 pageLayoutModule->paperwidthUnitCO->noPercents();
409 pageLayoutModule->paperheightUnitCO->noPercents();
410 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
411 pageLayoutModule->paperheightLE));
412 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
413 pageLayoutModule->paperwidthLE));
416 marginsModule = new UiWidget<Ui::MarginsUi>;
418 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
419 this, SLOT(setCustomMargins(bool)));
420 connect(marginsModule->marginCB, SIGNAL(clicked()),
421 this, SLOT(change_adaptor()));
422 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
423 this, SLOT(change_adaptor()));
424 connect(marginsModule->topUnit, SIGNAL(activated(int)),
425 this, SLOT(change_adaptor()));
426 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
427 this, SLOT(change_adaptor()));
428 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
429 this, SLOT(change_adaptor()));
430 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
431 this, SLOT(change_adaptor()));
432 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
433 this, SLOT(change_adaptor()));
434 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
435 this, SLOT(change_adaptor()));
436 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
437 this, SLOT(change_adaptor()));
438 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
439 this, SLOT(change_adaptor()));
440 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
441 this, SLOT(change_adaptor()));
442 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
443 this, SLOT(change_adaptor()));
444 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
445 this, SLOT(change_adaptor()));
446 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
447 this, SLOT(change_adaptor()));
448 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
449 this, SLOT(change_adaptor()));
450 marginsModule->topLE->setValidator(unsignedLengthValidator(
451 marginsModule->topLE));
452 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
453 marginsModule->bottomLE));
454 marginsModule->innerLE->setValidator(unsignedLengthValidator(
455 marginsModule->innerLE));
456 marginsModule->outerLE->setValidator(unsignedLengthValidator(
457 marginsModule->outerLE));
458 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
459 marginsModule->headsepLE));
460 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
461 marginsModule->headheightLE));
462 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
463 marginsModule->footskipLE));
465 bc().addCheckedLineEdit(marginsModule->topLE,
466 marginsModule->topL);
467 bc().addCheckedLineEdit(marginsModule->bottomLE,
468 marginsModule->bottomL);
469 bc().addCheckedLineEdit(marginsModule->innerLE,
470 marginsModule->innerL);
471 bc().addCheckedLineEdit(marginsModule->outerLE,
472 marginsModule->outerL);
473 bc().addCheckedLineEdit(marginsModule->headsepLE,
474 marginsModule->headsepL);
475 bc().addCheckedLineEdit(marginsModule->headheightLE,
476 marginsModule->headheightL);
477 bc().addCheckedLineEdit(marginsModule->footskipLE,
478 marginsModule->footskipL);
481 langModule = new UiWidget<Ui::LanguageUi>;
483 connect(langModule->languageCO, SIGNAL(activated(int)),
484 this, SLOT(change_adaptor()));
485 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
486 this, SLOT(change_adaptor()));
487 connect(langModule->otherencodingRB, SIGNAL(clicked()),
488 this, SLOT(change_adaptor()));
489 connect(langModule->encodingCO, SIGNAL(activated(int)),
490 this, SLOT(change_adaptor()));
491 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
492 this, SLOT(change_adaptor()));
494 vector<LanguagePair> const langs = getLanguageData(false);
495 vector<LanguagePair>::const_iterator lit = langs.begin();
496 vector<LanguagePair>::const_iterator lend = langs.end();
497 for (; lit != lend; ++lit) {
498 langModule->languageCO->addItem(toqstr(lit->first));
501 // Always put the default encoding in the first position.
502 // It is special because the displayed text is translated.
503 langModule->encodingCO->addItem(qt_("LaTeX default"));
504 Encodings::const_iterator it = encodings.begin();
505 Encodings::const_iterator const end = encodings.end();
506 for (; it != end; ++it)
507 langModule->encodingCO->addItem(toqstr(it->latexName()));
509 langModule->quoteStyleCO->addItem(qt_("``text''"));
510 langModule->quoteStyleCO->addItem(qt_("''text''"));
511 langModule->quoteStyleCO->addItem(qt_(",,text``"));
512 langModule->quoteStyleCO->addItem(qt_(",,text''"));
513 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
514 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
518 numberingModule = new UiWidget<Ui::NumberingUi>;
520 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
521 this, SLOT(change_adaptor()));
522 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
523 this, SLOT(change_adaptor()));
524 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
525 this, SLOT(updateNumbering()));
526 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
527 this, SLOT(updateNumbering()));
528 numberingModule->tocTW->setColumnCount(3);
529 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
530 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
531 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
534 biblioModule = new UiWidget<Ui::BiblioUi>;
535 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
536 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
537 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
538 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
540 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
541 this, SLOT(change_adaptor()));
542 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
543 this, SLOT(change_adaptor()));
544 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
545 this, SLOT(change_adaptor()));
546 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
547 this, SLOT(change_adaptor()));
548 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
549 this, SLOT(change_adaptor()));
551 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
552 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
553 biblioModule->citeStyleCO->setCurrentIndex(0);
556 mathsModule = new UiWidget<Ui::MathsUi>;
557 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
558 mathsModule->amsCB, SLOT(setDisabled(bool)));
559 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
560 mathsModule->esintCB, SLOT(setDisabled(bool)));
562 connect(mathsModule->amsCB, SIGNAL(clicked()),
563 this, SLOT(change_adaptor()));
564 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
565 this, SLOT(change_adaptor()));
566 connect(mathsModule->esintCB, SIGNAL(clicked()),
567 this, SLOT(change_adaptor()));
568 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
569 this, SLOT(change_adaptor()));
571 latexModule = new UiWidget<Ui::LaTeXUi>;
573 connect(latexModule->classCO, SIGNAL(activated(int)),
574 this, SLOT(change_adaptor()));
575 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
576 this, SLOT(change_adaptor()));
577 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
578 this, SLOT(change_adaptor()));
579 connect(latexModule->classCO, SIGNAL(activated(int)),
580 this, SLOT(classChanged()));
583 new GuiSelectionManager(latexModule->availableLV, latexModule->selectedLV,
584 latexModule->addPB, latexModule->deletePB,
585 latexModule->upPB, latexModule->downPB,
586 availableModel(), selectedModel());
587 connect(selectionManager, SIGNAL(updateHook()),
588 this, SLOT(updateModuleInfo()));
589 connect(selectionManager, SIGNAL(updateHook()),
590 this, SLOT(change_adaptor()));
592 // postscript drivers
593 for (int n = 0; tex_graphics[n][0]; ++n) {
594 QString enc = qt_(tex_graphics_gui[n]);
595 latexModule->psdriverCO->addItem(enc);
598 //FIXME This seems too involved with the kernel. Some of this
599 //should be moved to the kernel---which should perhaps just
600 //give us a list of entries or something of the sort.
601 for (TextClassList::const_iterator cit = textclasslist.begin();
602 cit != textclasslist.end(); ++cit) {
603 if (cit->isTeXClassAvailable()) {
604 latexModule->classCO->addItem(toqstr(cit->description()));
607 bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
608 latexModule->classCO->addItem(toqstr(item));
613 branchesModule = new GuiBranches;
614 connect(branchesModule, SIGNAL(changed()),
615 this, SLOT(change_adaptor()));
618 preambleModule = new PreambleModule;
619 connect(preambleModule, SIGNAL(changed()),
620 this, SLOT(change_adaptor()));
623 bulletsModule = new BulletsModule;
624 connect(bulletsModule, SIGNAL(changed()),
625 this, SLOT(change_adaptor()));
628 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
630 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
631 this, SLOT(change_adaptor()));
632 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
633 this, SLOT(change_adaptor()));
634 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
635 this, SLOT(change_adaptor()));
636 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
637 this, SLOT(change_adaptor()));
638 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
639 this, SLOT(change_adaptor()));
640 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
641 this, SLOT(change_adaptor()));
642 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
643 this, SLOT(change_adaptor()));
644 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
645 this, SLOT(change_adaptor()));
646 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
647 this, SLOT(change_adaptor()));
648 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
649 this, SLOT(change_adaptor()));
650 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
651 this, SLOT(change_adaptor()));
652 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
653 this, SLOT(change_adaptor()));
654 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
655 this, SLOT(change_adaptor()));
656 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
657 this, SLOT(change_adaptor()));
658 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
659 this, SLOT(change_adaptor()));
660 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
661 this, SLOT(change_adaptor()));
664 floatModule = new FloatPlacement;
665 connect(floatModule, SIGNAL(changed()),
666 this, SLOT(change_adaptor()));
668 docPS->addPanel(latexModule, _("Document Class"));
669 docPS->addPanel(fontModule, _("Fonts"));
670 docPS->addPanel(textLayoutModule, _("Text Layout"));
671 docPS->addPanel(pageLayoutModule, _("Page Layout"));
672 docPS->addPanel(marginsModule, _("Page Margins"));
673 docPS->addPanel(langModule, _("Language"));
674 docPS->addPanel(numberingModule, _("Numbering & TOC"));
675 docPS->addPanel(biblioModule, _("Bibliography"));
676 docPS->addPanel(pdfSupportModule, _("PDF Properties"));
677 docPS->addPanel(mathsModule, _("Math Options"));
678 docPS->addPanel(floatModule, _("Float Placement"));
679 docPS->addPanel(bulletsModule, _("Bullets"));
680 docPS->addPanel(branchesModule, _("Branches"));
681 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
682 docPS->setCurrentPanel(_("Document Class"));
683 // FIXME: hack to work around resizing bug in Qt >= 4.2
684 // bug verified with Qt 4.2.{0-3} (JSpitzm)
685 #if QT_VERSION >= 0x040200
686 docPS->updateGeometry();
691 void GuiDocument::showPreamble()
693 docPS->setCurrentPanel(_("LaTeX Preamble"));
697 void GuiDocument::saveDefaultClicked()
703 void GuiDocument::useDefaultsClicked()
709 void GuiDocument::change_adaptor()
715 docstring GuiDocument::validate_listings_params()
717 // use a cache here to avoid repeated validation
718 // of the same parameters
719 static string param_cache = string();
720 static docstring msg_cache = docstring();
722 if (textLayoutModule->bypassCB->isChecked())
725 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
726 if (params != param_cache) {
727 param_cache = params;
728 msg_cache = InsetListingsParams(params).validate();
734 void GuiDocument::set_listings_msg()
736 static bool isOK = true;
737 docstring msg = validate_listings_params();
742 // listingsTB->setTextColor("black");
743 textLayoutModule->listingsTB->setPlainText(
744 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
747 // listingsTB->setTextColor("red");
748 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
753 void GuiDocument::closeEvent(QCloseEvent * e)
760 void GuiDocument::setLSpacing(int item)
762 textLayoutModule->lspacingLE->setEnabled(item == 3);
766 void GuiDocument::setSkip(int item)
768 bool const enable = (item == 3);
769 textLayoutModule->skipLE->setEnabled(enable);
770 textLayoutModule->skipLengthCO->setEnabled(enable);
774 void GuiDocument::enableSkip(bool skip)
776 textLayoutModule->skipCO->setEnabled(skip);
777 textLayoutModule->skipLE->setEnabled(skip);
778 textLayoutModule->skipLengthCO->setEnabled(skip);
780 setSkip(textLayoutModule->skipCO->currentIndex());
783 void GuiDocument::portraitChanged()
785 setMargins(pageLayoutModule->papersizeCO->currentIndex());
788 void GuiDocument::setMargins(bool custom)
790 marginsModule->marginCB->setChecked(custom);
791 setCustomMargins(custom);
795 void GuiDocument::setCustomPapersize(int papersize)
797 bool const custom = (papersize == 1);
799 pageLayoutModule->paperwidthL->setEnabled(custom);
800 pageLayoutModule->paperwidthLE->setEnabled(custom);
801 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
802 pageLayoutModule->paperheightL->setEnabled(custom);
803 pageLayoutModule->paperheightLE->setEnabled(custom);
804 pageLayoutModule->paperheightLE->setFocus();
805 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
809 void GuiDocument::setCustomMargins(bool custom)
811 marginsModule->topL->setEnabled(!custom);
812 marginsModule->topLE->setEnabled(!custom);
813 marginsModule->topUnit->setEnabled(!custom);
815 marginsModule->bottomL->setEnabled(!custom);
816 marginsModule->bottomLE->setEnabled(!custom);
817 marginsModule->bottomUnit->setEnabled(!custom);
819 marginsModule->innerL->setEnabled(!custom);
820 marginsModule->innerLE->setEnabled(!custom);
821 marginsModule->innerUnit->setEnabled(!custom);
823 marginsModule->outerL->setEnabled(!custom);
824 marginsModule->outerLE->setEnabled(!custom);
825 marginsModule->outerUnit->setEnabled(!custom);
827 marginsModule->headheightL->setEnabled(!custom);
828 marginsModule->headheightLE->setEnabled(!custom);
829 marginsModule->headheightUnit->setEnabled(!custom);
831 marginsModule->headsepL->setEnabled(!custom);
832 marginsModule->headsepLE->setEnabled(!custom);
833 marginsModule->headsepUnit->setEnabled(!custom);
835 marginsModule->footskipL->setEnabled(!custom);
836 marginsModule->footskipLE->setEnabled(!custom);
837 marginsModule->footskipUnit->setEnabled(!custom);
841 void GuiDocument::updateFontsize(string const & items, string const & sel)
843 fontModule->fontsizeCO->clear();
844 fontModule->fontsizeCO->addItem(qt_("Default"));
846 for (int n = 0; !token(items,'|',n).empty(); ++n)
847 fontModule->fontsizeCO->
848 addItem(toqstr(token(items,'|',n)));
850 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
851 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
852 fontModule->fontsizeCO->setCurrentIndex(n);
859 void GuiDocument::romanChanged(int item)
861 string const font = tex_fonts_roman[item];
862 fontModule->fontScCB->setEnabled(providesSC(font));
863 fontModule->fontOsfCB->setEnabled(providesOSF(font));
867 void GuiDocument::sansChanged(int item)
869 string const font = tex_fonts_sans[item];
870 bool scaleable = providesScale(font);
871 fontModule->scaleSansSB->setEnabled(scaleable);
872 fontModule->scaleSansLA->setEnabled(scaleable);
876 void GuiDocument::ttChanged(int item)
878 string const font = tex_fonts_monospaced[item];
879 bool scaleable = providesScale(font);
880 fontModule->scaleTypewriterSB->setEnabled(scaleable);
881 fontModule->scaleTypewriterLA->setEnabled(scaleable);
885 void GuiDocument::updatePagestyle(string const & items, string const & sel)
888 pageLayoutModule->pagestyleCO->clear();
889 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
891 for (int n = 0; !token(items,'|',n).empty(); ++n) {
892 string style = token(items, '|', n);
893 docstring style_gui = _(style);
894 pagestyles.push_back(pair<string, docstring>(style, style_gui));
895 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
898 if (sel == "default") {
899 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
905 for (size_t i = 0; i < pagestyles.size(); ++i)
906 if (pagestyles[i].first == sel)
907 nn = pageLayoutModule->pagestyleCO->findText(
908 toqstr(pagestyles[i].second));
911 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
915 void GuiDocument::classChanged()
917 textclass_type const tc = latexModule->classCO->currentIndex();
918 bp_.setJustBaseClass(tc);
919 if (lyxrc.auto_reset_options)
920 bp_.useClassDefaults();
925 void GuiDocument::updateModuleInfo()
927 selectionManager->update();
929 QListView const * const lv = selectionManager->selectedFocused() ?
930 latexModule->selectedLV :
931 latexModule->availableLV;
932 if (lv->selectionModel()->selectedIndexes().isEmpty())
933 latexModule->infoML->document()->clear();
935 QModelIndex const idx = lv->selectionModel()->currentIndex();
936 string const modName = fromqstr(idx.data().toString());
937 string desc = getModuleDescription(modName);
938 vector<string> pkgList = getPackageList(modName);
940 //this mess formats the package list as "pkg1, pkg2, and pkg3"
941 int const pkgListSize = pkgList.size();
942 for (int i = 0; i < pkgListSize; ++i) {
944 if (i == pkgListSize - 1) //last element
949 if (i == pkgListSize - 1) //last element
954 pkgdesc += pkgList[i];
956 if (!pkgdesc.empty())
957 desc += " Requires " + pkgdesc + ".";
958 latexModule->infoML->document()->setPlainText(toqstr(desc));
963 void GuiDocument::updateNumbering()
965 TextClass const & tclass = bp_.getTextClass();
967 numberingModule->tocTW->setUpdatesEnabled(false);
968 numberingModule->tocTW->clear();
970 int const depth = numberingModule->depthSL->value();
971 int const toc = numberingModule->tocSL->value();
972 QString const no = qt_("No");
973 QString const yes = qt_("Yes");
974 TextClass::const_iterator end = tclass.end();
975 TextClass::const_iterator cit = tclass.begin();
976 QTreeWidgetItem * item = 0;
977 for ( ; cit != end ; ++cit) {
978 int const toclevel = (*cit)->toclevel;
979 if (toclevel != Layout::NOT_IN_TOC
980 && (*cit)->labeltype == LABEL_COUNTER) {
981 item = new QTreeWidgetItem(numberingModule->tocTW);
982 item->setText(0, toqstr(translateIfPossible((*cit)->name())));
983 item->setText(1, (toclevel <= depth) ? yes : no);
984 item->setText(2, (toclevel <= toc) ? yes : no);
988 numberingModule->tocTW->setUpdatesEnabled(true);
989 numberingModule->tocTW->update();
993 void GuiDocument::apply(BufferParams & params)
996 preambleModule->apply(params);
999 params.setCiteEngine(biblio::ENGINE_BASIC);
1001 if (biblioModule->citeNatbibRB->isChecked()) {
1002 bool const use_numerical_citations =
1003 biblioModule->citeStyleCO->currentIndex();
1004 if (use_numerical_citations)
1005 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1007 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1009 } else if (biblioModule->citeJurabibRB->isChecked())
1010 params.setCiteEngine(biblio::ENGINE_JURABIB);
1012 params.use_bibtopic =
1013 biblioModule->bibtopicCB->isChecked();
1015 // language & quotes
1016 if (langModule->defaultencodingRB->isChecked()) {
1017 params.inputenc = "auto";
1019 int i = langModule->encodingCO->currentIndex();
1021 params.inputenc = "default";
1024 fromqstr(langModule->encodingCO->currentText());
1027 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1028 switch (langModule->quoteStyleCO->currentIndex()) {
1030 lga = InsetQuotes::EnglishQ;
1033 lga = InsetQuotes::SwedishQ;
1036 lga = InsetQuotes::GermanQ;
1039 lga = InsetQuotes::PolishQ;
1042 lga = InsetQuotes::FrenchQ;
1045 lga = InsetQuotes::DanishQ;
1048 params.quotes_language = lga;
1050 int const pos = langModule->languageCO->currentIndex();
1051 params.language = lyx::languages.getLanguage(lang_[pos]);
1054 if (params.getTextClass().hasTocLevels()) {
1055 params.tocdepth = numberingModule->tocSL->value();
1056 params.secnumdepth = numberingModule->depthSL->value();
1060 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1061 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1062 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1063 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1066 params.graphicsDriver =
1067 tex_graphics[latexModule->psdriverCO->currentIndex()];
1070 params.clearLayoutModules();
1071 QStringList const selMods = selectedModel()->stringList();
1072 for (int i = 0; i != selMods.size(); ++i)
1073 params.addLayoutModule(lyx::fromqstr(selMods[i]));
1076 if (mathsModule->amsautoCB->isChecked()) {
1077 params.use_amsmath = BufferParams::package_auto;
1079 if (mathsModule->amsCB->isChecked())
1080 params.use_amsmath = BufferParams::package_on;
1082 params.use_amsmath = BufferParams::package_off;
1085 if (mathsModule->esintautoCB->isChecked())
1086 params.use_esint = BufferParams::package_auto;
1088 if (mathsModule->esintCB->isChecked())
1089 params.use_esint = BufferParams::package_on;
1091 params.use_esint = BufferParams::package_off;
1095 params.setJustBaseClass(latexModule->classCO->currentIndex());
1097 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1098 params.pagestyle = "default";
1100 docstring style_gui =
1101 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1102 for (size_t i = 0; i < pagestyles.size(); ++i)
1103 if (pagestyles[i].second == style_gui)
1104 params.pagestyle = pagestyles[i].first;
1107 switch (textLayoutModule->lspacingCO->currentIndex()) {
1109 params.spacing().set(Spacing::Single);
1112 params.spacing().set(Spacing::Onehalf);
1115 params.spacing().set(Spacing::Double);
1118 params.spacing().set(Spacing::Other,
1119 fromqstr(textLayoutModule->lspacingLE->text()));
1123 if (textLayoutModule->twoColumnCB->isChecked())
1128 // text should have passed validation
1129 params.listings_params =
1130 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1132 if (textLayoutModule->indentRB->isChecked())
1133 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1135 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1137 switch (textLayoutModule->skipCO->currentIndex()) {
1139 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1142 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1145 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1150 widgetsToLength(textLayoutModule->skipLE,
1151 textLayoutModule->skipLengthCO)
1153 params.setDefSkip(vs);
1157 // DocumentDefskipCB assures that this never happens
1158 // so Assert then !!! - jbl
1159 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1164 fromqstr(latexModule->optionsLE->text());
1166 params.float_placement = floatModule->get();
1170 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1173 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1175 params.fontsTypewriter =
1176 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1178 params.fontsSansScale = fontModule->scaleSansSB->value();
1180 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1182 params.fontsSC = fontModule->fontScCB->isChecked();
1184 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1186 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1187 fontModule->fontsDefaultCO->currentIndex()];
1189 if (fontModule->fontsizeCO->currentIndex() == 0)
1190 params.fontsize = "default";
1193 fromqstr(fontModule->fontsizeCO->currentText());
1196 params.papersize = PAPER_SIZE(
1197 pageLayoutModule->papersizeCO->currentIndex());
1199 // custom, A3, B3 and B4 paper sizes need geometry
1200 int psize = pageLayoutModule->papersizeCO->currentIndex();
1201 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1203 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1204 pageLayoutModule->paperwidthUnitCO);
1206 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1207 pageLayoutModule->paperheightUnitCO);
1209 if (pageLayoutModule->facingPagesCB->isChecked())
1210 params.sides = TextClass::TwoSides;
1212 params.sides = TextClass::OneSide;
1214 if (pageLayoutModule->landscapeRB->isChecked())
1215 params.orientation = ORIENTATION_LANDSCAPE;
1217 params.orientation = ORIENTATION_PORTRAIT;
1220 params.use_geometry =
1221 (!marginsModule->marginCB->isChecked()
1224 Ui::MarginsUi const * m(marginsModule);
1226 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1227 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1228 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1229 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1230 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1231 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1232 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1234 branchesModule->apply(params);
1237 PDFOptions & pdf = params.pdfoptions();
1238 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1239 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1240 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1241 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1242 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1244 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1245 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1246 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1247 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1249 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1250 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1251 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1252 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1253 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1254 if (pdfSupportModule->fullscreenCB->isChecked())
1255 pdf.pagemode = pdf.pagemode_fullscreen;
1257 pdf.pagemode.clear();
1258 pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1259 if (pdf.use_hyperref || !pdf.empty())
1260 pdf.store_options = true;
1264 /** Return the position of val in the vector if found.
1265 If not found, return 0.
1268 static size_t findPos(std::vector<A> const & vec, A const & val)
1270 typename std::vector<A>::const_iterator it =
1271 std::find(vec.begin(), vec.end(), val);
1272 if (it == vec.end())
1274 return distance(vec.begin(), it);
1278 void GuiDocument::updateParams()
1284 void GuiDocument::updateParams(BufferParams const & params)
1286 // set the default unit
1287 Length::UNIT defaultUnit = Length::CM;
1288 switch (lyxrc.default_papersize) {
1289 case PAPER_DEFAULT: break;
1291 case PAPER_USLETTER:
1293 case PAPER_USEXECUTIVE:
1294 defaultUnit = Length::IN;
1303 defaultUnit = Length::CM;
1310 preambleModule->update(params, id());
1313 biblioModule->citeDefaultRB->setChecked(
1314 params.getEngine() == biblio::ENGINE_BASIC);
1316 biblioModule->citeNatbibRB->setChecked(
1317 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1318 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1320 biblioModule->citeStyleCO->setCurrentIndex(
1321 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1323 biblioModule->citeJurabibRB->setChecked(
1324 params.getEngine() == biblio::ENGINE_JURABIB);
1326 biblioModule->bibtopicCB->setChecked(
1327 params.use_bibtopic);
1329 // language & quotes
1330 int const pos = int(findPos(lang_,
1331 params.language->lang()));
1332 langModule->languageCO->setCurrentIndex(pos);
1334 langModule->quoteStyleCO->setCurrentIndex(
1335 params.quotes_language);
1337 bool default_enc = true;
1338 if (params.inputenc != "auto") {
1339 default_enc = false;
1340 if (params.inputenc == "default") {
1341 langModule->encodingCO->setCurrentIndex(0);
1343 int const i = langModule->encodingCO->findText(
1344 toqstr(params.inputenc));
1346 langModule->encodingCO->setCurrentIndex(i);
1348 // unknown encoding. Set to default.
1352 langModule->defaultencodingRB->setChecked(default_enc);
1353 langModule->otherencodingRB->setChecked(!default_enc);
1356 int const min_toclevel = textClass().min_toclevel();
1357 int const max_toclevel = textClass().max_toclevel();
1358 if (textClass().hasTocLevels()) {
1359 numberingModule->setEnabled(true);
1360 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1361 numberingModule->depthSL->setMaximum(max_toclevel);
1362 numberingModule->depthSL->setValue(params.secnumdepth);
1363 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1364 numberingModule->tocSL->setMaximum(max_toclevel);
1365 numberingModule->tocSL->setValue(params.tocdepth);
1368 numberingModule->setEnabled(false);
1369 numberingModule->tocTW->clear();
1373 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1374 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1375 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1376 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1377 bulletsModule->init();
1380 int nitem = findToken(tex_graphics, params.graphicsDriver);
1382 latexModule->psdriverCO->setCurrentIndex(nitem);
1385 mathsModule->amsCB->setChecked(
1386 params.use_amsmath == BufferParams::package_on);
1387 mathsModule->amsautoCB->setChecked(
1388 params.use_amsmath == BufferParams::package_auto);
1390 mathsModule->esintCB->setChecked(
1391 params.use_esint == BufferParams::package_on);
1392 mathsModule->esintautoCB->setChecked(
1393 params.use_esint == BufferParams::package_auto);
1395 switch (params.spacing().getSpace()) {
1396 case Spacing::Other: nitem = 3; break;
1397 case Spacing::Double: nitem = 2; break;
1398 case Spacing::Onehalf: nitem = 1; break;
1399 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1403 latexModule->classCO->setCurrentIndex(params.getBaseClass());
1405 updatePagestyle(textClass().opt_pagestyle(),
1408 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1409 if (params.spacing().getSpace() == Spacing::Other) {
1410 textLayoutModule->lspacingLE->setText(
1411 toqstr(params.spacing().getValueAsString()));
1415 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1416 textLayoutModule->indentRB->setChecked(true);
1418 textLayoutModule->skipRB->setChecked(true);
1421 switch (params.getDefSkip().kind()) {
1422 case VSpace::SMALLSKIP:
1425 case VSpace::MEDSKIP:
1428 case VSpace::BIGSKIP:
1431 case VSpace::LENGTH:
1434 string const length = params.getDefSkip().asLyXCommand();
1435 lengthToWidgets(textLayoutModule->skipLE,
1436 textLayoutModule->skipLengthCO,
1437 length, defaultUnit);
1444 textLayoutModule->skipCO->setCurrentIndex(skip);
1447 textLayoutModule->twoColumnCB->setChecked(
1448 params.columns == 2);
1450 // break listings_params to multiple lines
1452 InsetListingsParams(params.listings_params).separatedParams();
1453 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1455 if (!params.options.empty()) {
1456 latexModule->optionsLE->setText(
1457 toqstr(params.options));
1459 latexModule->optionsLE->setText(QString());
1462 floatModule->set(params.float_placement);
1465 updateFontsize(textClass().opt_fontsize(),
1468 int n = findToken(tex_fonts_roman, params.fontsRoman);
1470 fontModule->fontsRomanCO->setCurrentIndex(n);
1474 n = findToken(tex_fonts_sans, params.fontsSans);
1476 fontModule->fontsSansCO->setCurrentIndex(n);
1480 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1482 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1486 fontModule->fontScCB->setChecked(params.fontsSC);
1487 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1488 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1489 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1490 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1492 fontModule->fontsDefaultCO->setCurrentIndex(n);
1495 int const psize = params.papersize;
1496 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1497 setCustomPapersize(psize);
1499 bool const landscape =
1500 params.orientation == ORIENTATION_LANDSCAPE;
1501 pageLayoutModule->landscapeRB->setChecked(landscape);
1502 pageLayoutModule->portraitRB->setChecked(!landscape);
1504 pageLayoutModule->facingPagesCB->setChecked(
1505 params.sides == TextClass::TwoSides);
1508 lengthToWidgets(pageLayoutModule->paperwidthLE,
1509 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1511 lengthToWidgets(pageLayoutModule->paperheightLE,
1512 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1515 Ui::MarginsUi * m = marginsModule;
1517 setMargins(!params.use_geometry);
1519 lengthToWidgets(m->topLE, m->topUnit,
1520 params.topmargin, defaultUnit);
1522 lengthToWidgets(m->bottomLE, m->bottomUnit,
1523 params.bottommargin, defaultUnit);
1525 lengthToWidgets(m->innerLE, m->innerUnit,
1526 params.leftmargin, defaultUnit);
1528 lengthToWidgets(m->outerLE, m->outerUnit,
1529 params.rightmargin, defaultUnit);
1531 lengthToWidgets(m->headheightLE, m->headheightUnit,
1532 params.headheight, defaultUnit);
1534 lengthToWidgets(m->headsepLE, m->headsepUnit,
1535 params.headsep, defaultUnit);
1537 lengthToWidgets(m->footskipLE, m->footskipUnit,
1538 params.footskip, defaultUnit);
1540 branchesModule->update(params);
1543 PDFOptions const & pdf = params.pdfoptions();
1544 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1545 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1546 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1547 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1548 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1550 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1551 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1552 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1554 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1556 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1557 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1558 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1559 pdfSupportModule->backrefCB->setChecked(pdf.backref);
1560 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1561 pdfSupportModule->fullscreenCB->setChecked
1562 (pdf.pagemode == pdf.pagemode_fullscreen);
1564 pdfSupportModule->optionsLE->setText(
1565 toqstr(pdf.quoted_options));
1569 void GuiDocument::applyView()
1575 void GuiDocument::saveDocDefault()
1577 // we have to apply the params first
1583 void GuiDocument::updateContents()
1585 //update list of available modules
1586 QStringList strlist;
1587 vector<string> const modNames = getModuleNames();
1588 vector<string>::const_iterator it = modNames.begin();
1589 for (; it != modNames.end(); ++it)
1590 strlist.push_back(toqstr(*it));
1591 available_model_.setStringList(strlist);
1592 //and selected ones, too
1593 QStringList strlist2;
1594 vector<string> const & selMods = getSelectedModules();
1595 it = selMods.begin();
1596 for (; it != selMods.end(); ++it)
1597 strlist2.push_back(toqstr(*it));
1598 selected_model_.setStringList(strlist2);
1603 void GuiDocument::useClassDefaults()
1605 bp_.setJustBaseClass(latexModule->classCO->currentIndex());
1606 bp_.useClassDefaults();
1611 bool GuiDocument::isValid()
1613 return validate_listings_params().empty();
1617 char const * const GuiDocument::fontfamilies[5] = {
1618 "default", "rmdefault", "sfdefault", "ttdefault", ""
1622 char const * GuiDocument::fontfamilies_gui[5] = {
1623 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
1627 bool GuiDocument::initialiseParams(string const &)
1629 bp_ = buffer().params();
1635 void GuiDocument::clearParams()
1637 bp_ = BufferParams();
1641 BufferId GuiDocument::id() const
1647 vector<string> GuiDocument::getModuleNames()
1649 return moduleNames_;
1653 vector<string> const & GuiDocument::getSelectedModules()
1655 return params().getModules();
1659 string GuiDocument::getModuleDescription(string const & modName) const
1661 LyXModule const * const mod = moduleList[modName];
1663 return string("Module unavailable!");
1664 return mod->description;
1669 GuiDocument::getPackageList(string const & modName) const
1671 LyXModule const * const mod = moduleList[modName];
1673 return vector<string>(); //empty such thing
1674 return mod->packageList;
1678 TextClass const & GuiDocument::textClass() const
1680 return textclasslist[bp_.getBaseClass()];
1684 static void dispatch_bufferparams(Controller const & controller,
1685 BufferParams const & bp, kb_action lfun)
1688 ss << "\\begin_header\n";
1690 ss << "\\end_header\n";
1691 controller.dispatch(FuncRequest(lfun, ss.str()));
1695 void GuiDocument::dispatchParams()
1697 // This must come first so that a language change is correctly noticed
1700 // Apply the BufferParams. Note that this will set the base class
1701 // and then update the buffer's layout.
1702 //FIXME Could this be done last? Then, I think, we'd get the automatic
1703 //update mentioned in the next FIXME...
1704 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
1706 // Generate the colours requested by each new branch.
1707 BranchList & branchlist = params().branchlist();
1708 if (!branchlist.empty()) {
1709 BranchList::const_iterator it = branchlist.begin();
1710 BranchList::const_iterator const end = branchlist.end();
1711 for (; it != end; ++it) {
1712 docstring const & current_branch = it->getBranch();
1713 Branch const * branch = branchlist.find(current_branch);
1714 string const x11hexname =
1715 lyx::X11hexname(branch->getColor());
1716 // display the new color
1717 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
1718 dispatch(FuncRequest(LFUN_SET_COLOR, str));
1721 // Open insets of selected branches, close deselected ones
1722 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
1725 // FIXME: If we used an LFUN, we would not need those two lines:
1726 bufferview()->update();
1727 lyxview().currentWorkArea()->redraw();
1731 void GuiDocument::setLanguage() const
1733 Language const * const newL = bp_.language;
1734 if (buffer().params().language == newL)
1737 string const & lang_name = newL->lang();
1738 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
1742 void GuiDocument::saveAsDefault() const
1744 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
1748 bool GuiDocument::isFontAvailable(string const & font) const
1750 if (font == "default" || font == "cmr"
1751 || font == "cmss" || font == "cmtt")
1752 // these are standard
1754 if (font == "lmodern" || font == "lmss" || font == "lmtt")
1755 return LaTeXFeatures::isAvailable("lmodern");
1756 if (font == "times" || font == "palatino"
1757 || font == "helvet" || font == "courier")
1758 return LaTeXFeatures::isAvailable("psnfss");
1759 if (font == "cmbr" || font == "cmtl")
1760 return LaTeXFeatures::isAvailable("cmbright");
1761 if (font == "utopia")
1762 return LaTeXFeatures::isAvailable("utopia")
1763 || LaTeXFeatures::isAvailable("fourier");
1764 if (font == "beraserif" || font == "berasans"
1765 || font == "beramono")
1766 return LaTeXFeatures::isAvailable("bera");
1767 return LaTeXFeatures::isAvailable(font);
1771 bool GuiDocument::providesOSF(string const & font) const
1774 return isFontAvailable("eco");
1775 if (font == "palatino")
1776 return isFontAvailable("mathpazo");
1781 bool GuiDocument::providesSC(string const & font) const
1783 if (font == "palatino")
1784 return isFontAvailable("mathpazo");
1785 if (font == "utopia")
1786 return isFontAvailable("fourier");
1791 bool GuiDocument::providesScale(string const & font) const
1793 return font == "helvet" || font == "luximono"
1794 || font == "berasans" || font == "beramono";
1798 void GuiDocument::loadModuleNames ()
1800 moduleNames_.clear();
1801 LyXModuleList::const_iterator it = moduleList.begin();
1802 for (; it != moduleList.end(); ++it)
1803 moduleNames_.push_back(it->name);
1804 if (!moduleNames_.empty())
1805 sort(moduleNames_.begin(), moduleNames_.end());
1809 Dialog * createGuiDocument(LyXView & lv) { return new GuiDocument(lv); }
1812 } // namespace frontend
1815 #include "GuiDocument_moc.cpp"