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"
22 #include "EmbeddedFiles.h"
24 #include "FloatPlacement.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 embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
629 connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
630 this, SLOT(change_adaptor()));
631 connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
632 this, SLOT(change_adaptor()));
633 connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
634 this, SLOT(change_adaptor()));
637 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
639 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
640 this, SLOT(change_adaptor()));
641 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
642 this, SLOT(change_adaptor()));
643 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
644 this, SLOT(change_adaptor()));
645 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
646 this, SLOT(change_adaptor()));
647 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
648 this, SLOT(change_adaptor()));
649 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
650 this, SLOT(change_adaptor()));
651 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
652 this, SLOT(change_adaptor()));
653 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
654 this, SLOT(change_adaptor()));
655 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
656 this, SLOT(change_adaptor()));
657 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
658 this, SLOT(change_adaptor()));
659 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
660 this, SLOT(change_adaptor()));
661 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
662 this, SLOT(change_adaptor()));
663 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
664 this, SLOT(change_adaptor()));
665 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
666 this, SLOT(change_adaptor()));
667 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
668 this, SLOT(change_adaptor()));
669 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
670 this, SLOT(change_adaptor()));
671 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
672 this, SLOT(change_adaptor()));
675 floatModule = new FloatPlacement;
676 connect(floatModule, SIGNAL(changed()),
677 this, SLOT(change_adaptor()));
679 docPS->addPanel(latexModule, _("Document Class"));
680 docPS->addPanel(fontModule, _("Fonts"));
681 docPS->addPanel(textLayoutModule, _("Text Layout"));
682 docPS->addPanel(pageLayoutModule, _("Page Layout"));
683 docPS->addPanel(marginsModule, _("Page Margins"));
684 docPS->addPanel(langModule, _("Language"));
685 docPS->addPanel(numberingModule, _("Numbering & TOC"));
686 docPS->addPanel(biblioModule, _("Bibliography"));
687 docPS->addPanel(pdfSupportModule, _("PDF Properties"));
688 docPS->addPanel(mathsModule, _("Math Options"));
689 docPS->addPanel(floatModule, _("Float Placement"));
690 docPS->addPanel(bulletsModule, _("Bullets"));
691 docPS->addPanel(branchesModule, _("Branches"));
692 docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
693 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
694 docPS->setCurrentPanel(_("Document Class"));
695 // FIXME: hack to work around resizing bug in Qt >= 4.2
696 // bug verified with Qt 4.2.{0-3} (JSpitzm)
697 #if QT_VERSION >= 0x040200
698 docPS->updateGeometry();
703 void GuiDocument::showPreamble()
705 docPS->setCurrentPanel(_("LaTeX Preamble"));
709 void GuiDocument::saveDefaultClicked()
715 void GuiDocument::useDefaultsClicked()
721 void GuiDocument::change_adaptor()
727 docstring GuiDocument::validate_listings_params()
729 // use a cache here to avoid repeated validation
730 // of the same parameters
731 static string param_cache = string();
732 static docstring msg_cache = docstring();
734 if (textLayoutModule->bypassCB->isChecked())
737 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
738 if (params != param_cache) {
739 param_cache = params;
740 msg_cache = InsetListingsParams(params).validate();
746 void GuiDocument::set_listings_msg()
748 static bool isOK = true;
749 docstring msg = validate_listings_params();
754 // listingsTB->setTextColor("black");
755 textLayoutModule->listingsTB->setPlainText(
756 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
759 // listingsTB->setTextColor("red");
760 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
765 void GuiDocument::closeEvent(QCloseEvent * e)
772 void GuiDocument::setLSpacing(int item)
774 textLayoutModule->lspacingLE->setEnabled(item == 3);
778 void GuiDocument::setSkip(int item)
780 bool const enable = (item == 3);
781 textLayoutModule->skipLE->setEnabled(enable);
782 textLayoutModule->skipLengthCO->setEnabled(enable);
786 void GuiDocument::enableSkip(bool skip)
788 textLayoutModule->skipCO->setEnabled(skip);
789 textLayoutModule->skipLE->setEnabled(skip);
790 textLayoutModule->skipLengthCO->setEnabled(skip);
792 setSkip(textLayoutModule->skipCO->currentIndex());
795 void GuiDocument::portraitChanged()
797 setMargins(pageLayoutModule->papersizeCO->currentIndex());
800 void GuiDocument::setMargins(bool custom)
802 marginsModule->marginCB->setChecked(custom);
803 setCustomMargins(custom);
807 void GuiDocument::setCustomPapersize(int papersize)
809 bool const custom = (papersize == 1);
811 pageLayoutModule->paperwidthL->setEnabled(custom);
812 pageLayoutModule->paperwidthLE->setEnabled(custom);
813 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
814 pageLayoutModule->paperheightL->setEnabled(custom);
815 pageLayoutModule->paperheightLE->setEnabled(custom);
816 pageLayoutModule->paperheightLE->setFocus();
817 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
821 void GuiDocument::setCustomMargins(bool custom)
823 marginsModule->topL->setEnabled(!custom);
824 marginsModule->topLE->setEnabled(!custom);
825 marginsModule->topUnit->setEnabled(!custom);
827 marginsModule->bottomL->setEnabled(!custom);
828 marginsModule->bottomLE->setEnabled(!custom);
829 marginsModule->bottomUnit->setEnabled(!custom);
831 marginsModule->innerL->setEnabled(!custom);
832 marginsModule->innerLE->setEnabled(!custom);
833 marginsModule->innerUnit->setEnabled(!custom);
835 marginsModule->outerL->setEnabled(!custom);
836 marginsModule->outerLE->setEnabled(!custom);
837 marginsModule->outerUnit->setEnabled(!custom);
839 marginsModule->headheightL->setEnabled(!custom);
840 marginsModule->headheightLE->setEnabled(!custom);
841 marginsModule->headheightUnit->setEnabled(!custom);
843 marginsModule->headsepL->setEnabled(!custom);
844 marginsModule->headsepLE->setEnabled(!custom);
845 marginsModule->headsepUnit->setEnabled(!custom);
847 marginsModule->footskipL->setEnabled(!custom);
848 marginsModule->footskipLE->setEnabled(!custom);
849 marginsModule->footskipUnit->setEnabled(!custom);
853 void GuiDocument::updateFontsize(string const & items, string const & sel)
855 fontModule->fontsizeCO->clear();
856 fontModule->fontsizeCO->addItem(qt_("Default"));
858 for (int n = 0; !token(items,'|',n).empty(); ++n)
859 fontModule->fontsizeCO->
860 addItem(toqstr(token(items,'|',n)));
862 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
863 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
864 fontModule->fontsizeCO->setCurrentIndex(n);
871 void GuiDocument::romanChanged(int item)
873 string const font = tex_fonts_roman[item];
874 fontModule->fontScCB->setEnabled(providesSC(font));
875 fontModule->fontOsfCB->setEnabled(providesOSF(font));
879 void GuiDocument::sansChanged(int item)
881 string const font = tex_fonts_sans[item];
882 bool scaleable = providesScale(font);
883 fontModule->scaleSansSB->setEnabled(scaleable);
884 fontModule->scaleSansLA->setEnabled(scaleable);
888 void GuiDocument::ttChanged(int item)
890 string const font = tex_fonts_monospaced[item];
891 bool scaleable = providesScale(font);
892 fontModule->scaleTypewriterSB->setEnabled(scaleable);
893 fontModule->scaleTypewriterLA->setEnabled(scaleable);
897 void GuiDocument::updatePagestyle(string const & items, string const & sel)
900 pageLayoutModule->pagestyleCO->clear();
901 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
903 for (int n = 0; !token(items,'|',n).empty(); ++n) {
904 string style = token(items, '|', n);
905 docstring style_gui = _(style);
906 pagestyles.push_back(pair<string, docstring>(style, style_gui));
907 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
910 if (sel == "default") {
911 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
917 for (size_t i = 0; i < pagestyles.size(); ++i)
918 if (pagestyles[i].first == sel)
919 nn = pageLayoutModule->pagestyleCO->findText(
920 toqstr(pagestyles[i].second));
923 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
927 void GuiDocument::classChanged()
929 textclass_type const tc = latexModule->classCO->currentIndex();
930 bp_.setJustBaseClass(tc);
931 if (lyxrc.auto_reset_options)
932 bp_.useClassDefaults();
937 void GuiDocument::updateModuleInfo()
939 selectionManager->update();
941 QListView const * const lv = selectionManager->selectedFocused() ?
942 latexModule->selectedLV :
943 latexModule->availableLV;
944 if (lv->selectionModel()->selectedIndexes().isEmpty())
945 latexModule->infoML->document()->clear();
947 QModelIndex const idx = lv->selectionModel()->currentIndex();
948 string const modName = fromqstr(idx.data().toString());
949 string desc = getModuleDescription(modName);
950 vector<string> pkgList = getPackageList(modName);
952 //this mess formats the package list as "pkg1, pkg2, and pkg3"
953 int const pkgListSize = pkgList.size();
954 for (int i = 0; i < pkgListSize; ++i) {
956 if (i == pkgListSize - 1) //last element
961 if (i == pkgListSize - 1) //last element
966 pkgdesc += pkgList[i];
968 if (!pkgdesc.empty())
969 desc += " Requires " + pkgdesc + ".";
970 latexModule->infoML->document()->setPlainText(toqstr(desc));
975 void GuiDocument::updateEmbeddedFileList()
977 embeddedFilesModule->filesLW->clear();
978 // add current embedded files
979 EmbeddedFiles & files = buffer().embeddedFiles();
981 EmbeddedFiles::EmbeddedFileList::iterator fit = files.begin();
982 EmbeddedFiles::EmbeddedFileList::iterator fit_end = files.end();
983 for (; fit != fit_end; ++fit) {
984 QString label = toqstr(fit->relFilename(buffer().filePath()));
985 if (fit->refCount() > 1)
986 label += " (" + QString::number(fit->refCount()) + ")";
987 QListWidgetItem * item = new QListWidgetItem(label);
988 item->setFlags(item->flags() | Qt::ItemIsSelectable
989 | Qt::ItemIsUserCheckable);
991 item->setCheckState(Qt::Checked);
993 item->setCheckState(Qt::Unchecked);
994 // index of the currently used ParConstIterator
995 embeddedFilesModule->filesLW->addItem(item);
1000 void GuiDocument::updateNumbering()
1002 TextClass const & tclass = bp_.getTextClass();
1004 numberingModule->tocTW->setUpdatesEnabled(false);
1005 numberingModule->tocTW->clear();
1007 int const depth = numberingModule->depthSL->value();
1008 int const toc = numberingModule->tocSL->value();
1009 QString const no = qt_("No");
1010 QString const yes = qt_("Yes");
1011 TextClass::const_iterator end = tclass.end();
1012 TextClass::const_iterator cit = tclass.begin();
1013 QTreeWidgetItem * item = 0;
1014 for ( ; cit != end ; ++cit) {
1015 int const toclevel = (*cit)->toclevel;
1016 if (toclevel != Layout::NOT_IN_TOC
1017 && (*cit)->labeltype == LABEL_COUNTER) {
1018 item = new QTreeWidgetItem(numberingModule->tocTW);
1019 item->setText(0, toqstr(translateIfPossible((*cit)->name())));
1020 item->setText(1, (toclevel <= depth) ? yes : no);
1021 item->setText(2, (toclevel <= toc) ? yes : no);
1025 numberingModule->tocTW->setUpdatesEnabled(true);
1026 numberingModule->tocTW->update();
1030 void GuiDocument::apply(BufferParams & params)
1033 preambleModule->apply(params);
1036 params.setCiteEngine(biblio::ENGINE_BASIC);
1038 if (biblioModule->citeNatbibRB->isChecked()) {
1039 bool const use_numerical_citations =
1040 biblioModule->citeStyleCO->currentIndex();
1041 if (use_numerical_citations)
1042 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1044 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1046 } else if (biblioModule->citeJurabibRB->isChecked())
1047 params.setCiteEngine(biblio::ENGINE_JURABIB);
1049 params.use_bibtopic =
1050 biblioModule->bibtopicCB->isChecked();
1052 // language & quotes
1053 if (langModule->defaultencodingRB->isChecked()) {
1054 params.inputenc = "auto";
1056 int i = langModule->encodingCO->currentIndex();
1058 params.inputenc = "default";
1061 fromqstr(langModule->encodingCO->currentText());
1064 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1065 switch (langModule->quoteStyleCO->currentIndex()) {
1067 lga = InsetQuotes::EnglishQ;
1070 lga = InsetQuotes::SwedishQ;
1073 lga = InsetQuotes::GermanQ;
1076 lga = InsetQuotes::PolishQ;
1079 lga = InsetQuotes::FrenchQ;
1082 lga = InsetQuotes::DanishQ;
1085 params.quotes_language = lga;
1087 int const pos = langModule->languageCO->currentIndex();
1088 params.language = lyx::languages.getLanguage(lang_[pos]);
1091 if (params.getTextClass().hasTocLevels()) {
1092 params.tocdepth = numberingModule->tocSL->value();
1093 params.secnumdepth = numberingModule->depthSL->value();
1097 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1098 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1099 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1100 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1103 params.graphicsDriver =
1104 tex_graphics[latexModule->psdriverCO->currentIndex()];
1107 params.clearLayoutModules();
1108 QStringList const selMods = selectedModel()->stringList();
1109 for (int i = 0; i != selMods.size(); ++i)
1110 params.addLayoutModule(lyx::fromqstr(selMods[i]));
1113 if (mathsModule->amsautoCB->isChecked()) {
1114 params.use_amsmath = BufferParams::package_auto;
1116 if (mathsModule->amsCB->isChecked())
1117 params.use_amsmath = BufferParams::package_on;
1119 params.use_amsmath = BufferParams::package_off;
1122 if (mathsModule->esintautoCB->isChecked())
1123 params.use_esint = BufferParams::package_auto;
1125 if (mathsModule->esintCB->isChecked())
1126 params.use_esint = BufferParams::package_on;
1128 params.use_esint = BufferParams::package_off;
1132 params.setJustBaseClass(latexModule->classCO->currentIndex());
1134 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1135 params.pagestyle = "default";
1137 docstring style_gui =
1138 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1139 for (size_t i = 0; i < pagestyles.size(); ++i)
1140 if (pagestyles[i].second == style_gui)
1141 params.pagestyle = pagestyles[i].first;
1144 switch (textLayoutModule->lspacingCO->currentIndex()) {
1146 params.spacing().set(Spacing::Single);
1149 params.spacing().set(Spacing::Onehalf);
1152 params.spacing().set(Spacing::Double);
1155 params.spacing().set(Spacing::Other,
1156 fromqstr(textLayoutModule->lspacingLE->text()));
1160 if (textLayoutModule->twoColumnCB->isChecked())
1165 // text should have passed validation
1166 params.listings_params =
1167 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1169 if (textLayoutModule->indentRB->isChecked())
1170 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1172 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1174 switch (textLayoutModule->skipCO->currentIndex()) {
1176 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1179 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1182 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1187 widgetsToLength(textLayoutModule->skipLE,
1188 textLayoutModule->skipLengthCO)
1190 params.setDefSkip(vs);
1194 // DocumentDefskipCB assures that this never happens
1195 // so Assert then !!! - jbl
1196 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1201 fromqstr(latexModule->optionsLE->text());
1203 params.float_placement = floatModule->get();
1207 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1210 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1212 params.fontsTypewriter =
1213 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1215 params.fontsSansScale = fontModule->scaleSansSB->value();
1217 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1219 params.fontsSC = fontModule->fontScCB->isChecked();
1221 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1223 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1224 fontModule->fontsDefaultCO->currentIndex()];
1226 if (fontModule->fontsizeCO->currentIndex() == 0)
1227 params.fontsize = "default";
1230 fromqstr(fontModule->fontsizeCO->currentText());
1233 params.papersize = PAPER_SIZE(
1234 pageLayoutModule->papersizeCO->currentIndex());
1236 // custom, A3, B3 and B4 paper sizes need geometry
1237 int psize = pageLayoutModule->papersizeCO->currentIndex();
1238 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1240 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1241 pageLayoutModule->paperwidthUnitCO);
1243 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1244 pageLayoutModule->paperheightUnitCO);
1246 if (pageLayoutModule->facingPagesCB->isChecked())
1247 params.sides = TextClass::TwoSides;
1249 params.sides = TextClass::OneSide;
1251 if (pageLayoutModule->landscapeRB->isChecked())
1252 params.orientation = ORIENTATION_LANDSCAPE;
1254 params.orientation = ORIENTATION_PORTRAIT;
1257 params.use_geometry =
1258 (!marginsModule->marginCB->isChecked()
1261 Ui::MarginsUi const * m(marginsModule);
1263 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1264 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1265 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1266 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1267 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1268 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1269 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1271 branchesModule->apply(params);
1274 PDFOptions & pdf = params.pdfoptions();
1275 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1276 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1277 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1278 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1279 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1281 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1282 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1283 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1284 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1286 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1287 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1288 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1289 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1290 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1291 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1292 if (pdfSupportModule->fullscreenCB->isChecked())
1293 pdf.pagemode = pdf.pagemode_fullscreen;
1295 pdf.pagemode.clear();
1296 pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1303 /** Return the position of val in the vector if found.
1304 If not found, return 0.
1307 static size_t findPos(std::vector<A> const & vec, A const & val)
1309 typename std::vector<A>::const_iterator it =
1310 std::find(vec.begin(), vec.end(), val);
1311 if (it == vec.end())
1313 return distance(vec.begin(), it);
1317 void GuiDocument::updateParams()
1323 void GuiDocument::updateParams(BufferParams const & params)
1325 // set the default unit
1326 Length::UNIT defaultUnit = Length::CM;
1327 switch (lyxrc.default_papersize) {
1328 case PAPER_DEFAULT: break;
1330 case PAPER_USLETTER:
1332 case PAPER_USEXECUTIVE:
1333 defaultUnit = Length::IN;
1342 defaultUnit = Length::CM;
1349 preambleModule->update(params, id());
1352 biblioModule->citeDefaultRB->setChecked(
1353 params.getEngine() == biblio::ENGINE_BASIC);
1355 biblioModule->citeNatbibRB->setChecked(
1356 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1357 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1359 biblioModule->citeStyleCO->setCurrentIndex(
1360 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1362 biblioModule->citeJurabibRB->setChecked(
1363 params.getEngine() == biblio::ENGINE_JURABIB);
1365 biblioModule->bibtopicCB->setChecked(
1366 params.use_bibtopic);
1368 // language & quotes
1369 int const pos = int(findPos(lang_,
1370 params.language->lang()));
1371 langModule->languageCO->setCurrentIndex(pos);
1373 langModule->quoteStyleCO->setCurrentIndex(
1374 params.quotes_language);
1376 bool default_enc = true;
1377 if (params.inputenc != "auto") {
1378 default_enc = false;
1379 if (params.inputenc == "default") {
1380 langModule->encodingCO->setCurrentIndex(0);
1382 int const i = langModule->encodingCO->findText(
1383 toqstr(params.inputenc));
1385 langModule->encodingCO->setCurrentIndex(i);
1387 // unknown encoding. Set to default.
1391 langModule->defaultencodingRB->setChecked(default_enc);
1392 langModule->otherencodingRB->setChecked(!default_enc);
1395 int const min_toclevel = textClass().min_toclevel();
1396 int const max_toclevel = textClass().max_toclevel();
1397 if (textClass().hasTocLevels()) {
1398 numberingModule->setEnabled(true);
1399 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1400 numberingModule->depthSL->setMaximum(max_toclevel);
1401 numberingModule->depthSL->setValue(params.secnumdepth);
1402 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1403 numberingModule->tocSL->setMaximum(max_toclevel);
1404 numberingModule->tocSL->setValue(params.tocdepth);
1407 numberingModule->setEnabled(false);
1408 numberingModule->tocTW->clear();
1412 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1413 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1414 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1415 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1416 bulletsModule->init();
1419 int nitem = findToken(tex_graphics, params.graphicsDriver);
1421 latexModule->psdriverCO->setCurrentIndex(nitem);
1424 mathsModule->amsCB->setChecked(
1425 params.use_amsmath == BufferParams::package_on);
1426 mathsModule->amsautoCB->setChecked(
1427 params.use_amsmath == BufferParams::package_auto);
1429 mathsModule->esintCB->setChecked(
1430 params.use_esint == BufferParams::package_on);
1431 mathsModule->esintautoCB->setChecked(
1432 params.use_esint == BufferParams::package_auto);
1434 switch (params.spacing().getSpace()) {
1435 case Spacing::Other: nitem = 3; break;
1436 case Spacing::Double: nitem = 2; break;
1437 case Spacing::Onehalf: nitem = 1; break;
1438 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1442 latexModule->classCO->setCurrentIndex(params.getBaseClass());
1444 updatePagestyle(textClass().opt_pagestyle(),
1447 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1448 if (params.spacing().getSpace() == Spacing::Other) {
1449 textLayoutModule->lspacingLE->setText(
1450 toqstr(params.spacing().getValueAsString()));
1454 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1455 textLayoutModule->indentRB->setChecked(true);
1457 textLayoutModule->skipRB->setChecked(true);
1460 switch (params.getDefSkip().kind()) {
1461 case VSpace::SMALLSKIP:
1464 case VSpace::MEDSKIP:
1467 case VSpace::BIGSKIP:
1470 case VSpace::LENGTH:
1473 string const length = params.getDefSkip().asLyXCommand();
1474 lengthToWidgets(textLayoutModule->skipLE,
1475 textLayoutModule->skipLengthCO,
1476 length, defaultUnit);
1483 textLayoutModule->skipCO->setCurrentIndex(skip);
1486 textLayoutModule->twoColumnCB->setChecked(
1487 params.columns == 2);
1489 // break listings_params to multiple lines
1491 InsetListingsParams(params.listings_params).separatedParams();
1492 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1494 if (!params.options.empty()) {
1495 latexModule->optionsLE->setText(
1496 toqstr(params.options));
1498 latexModule->optionsLE->setText(QString());
1501 floatModule->set(params.float_placement);
1504 updateFontsize(textClass().opt_fontsize(),
1507 int n = findToken(tex_fonts_roman, params.fontsRoman);
1509 fontModule->fontsRomanCO->setCurrentIndex(n);
1513 n = findToken(tex_fonts_sans, params.fontsSans);
1515 fontModule->fontsSansCO->setCurrentIndex(n);
1519 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1521 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1525 fontModule->fontScCB->setChecked(params.fontsSC);
1526 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1527 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1528 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1529 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1531 fontModule->fontsDefaultCO->setCurrentIndex(n);
1534 int const psize = params.papersize;
1535 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1536 setCustomPapersize(psize);
1538 bool const landscape =
1539 params.orientation == ORIENTATION_LANDSCAPE;
1540 pageLayoutModule->landscapeRB->setChecked(landscape);
1541 pageLayoutModule->portraitRB->setChecked(!landscape);
1543 pageLayoutModule->facingPagesCB->setChecked(
1544 params.sides == TextClass::TwoSides);
1547 lengthToWidgets(pageLayoutModule->paperwidthLE,
1548 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1550 lengthToWidgets(pageLayoutModule->paperheightLE,
1551 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1554 Ui::MarginsUi * m = marginsModule;
1556 setMargins(!params.use_geometry);
1558 lengthToWidgets(m->topLE, m->topUnit,
1559 params.topmargin, defaultUnit);
1561 lengthToWidgets(m->bottomLE, m->bottomUnit,
1562 params.bottommargin, defaultUnit);
1564 lengthToWidgets(m->innerLE, m->innerUnit,
1565 params.leftmargin, defaultUnit);
1567 lengthToWidgets(m->outerLE, m->outerUnit,
1568 params.rightmargin, defaultUnit);
1570 lengthToWidgets(m->headheightLE, m->headheightUnit,
1571 params.headheight, defaultUnit);
1573 lengthToWidgets(m->headsepLE, m->headsepUnit,
1574 params.headsep, defaultUnit);
1576 lengthToWidgets(m->footskipLE, m->footskipUnit,
1577 params.footskip, defaultUnit);
1579 branchesModule->update(params);
1582 PDFOptions const & pdf = params.pdfoptions();
1583 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1584 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1585 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1586 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1587 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1589 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1590 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1591 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1593 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1595 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1596 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1597 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
1598 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1599 pdfSupportModule->backrefCB->setChecked(pdf.backref);
1600 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1601 pdfSupportModule->fullscreenCB->setChecked
1602 (pdf.pagemode == pdf.pagemode_fullscreen);
1604 pdfSupportModule->optionsLE->setText(
1605 toqstr(pdf.quoted_options));
1608 updateEmbeddedFileList();
1612 void GuiDocument::applyView()
1618 void GuiDocument::saveDocDefault()
1620 // we have to apply the params first
1626 void GuiDocument::updateContents()
1628 //update list of available modules
1629 QStringList strlist;
1630 vector<string> const modNames = getModuleNames();
1631 vector<string>::const_iterator it = modNames.begin();
1632 for (; it != modNames.end(); ++it)
1633 strlist.push_back(toqstr(*it));
1634 available_model_.setStringList(strlist);
1635 //and selected ones, too
1636 QStringList strlist2;
1637 vector<string> const & selMods = getSelectedModules();
1638 it = selMods.begin();
1639 for (; it != selMods.end(); ++it)
1640 strlist2.push_back(toqstr(*it));
1641 selected_model_.setStringList(strlist2);
1646 void GuiDocument::useClassDefaults()
1648 bp_.setJustBaseClass(latexModule->classCO->currentIndex());
1649 bp_.useClassDefaults();
1654 bool GuiDocument::isValid()
1656 return validate_listings_params().empty();
1660 char const * const GuiDocument::fontfamilies[5] = {
1661 "default", "rmdefault", "sfdefault", "ttdefault", ""
1665 char const * GuiDocument::fontfamilies_gui[5] = {
1666 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
1670 bool GuiDocument::initialiseParams(string const &)
1672 bp_ = buffer().params();
1678 void GuiDocument::clearParams()
1680 bp_ = BufferParams();
1684 BufferId GuiDocument::id() const
1690 vector<string> GuiDocument::getModuleNames()
1692 return moduleNames_;
1696 vector<string> const & GuiDocument::getSelectedModules()
1698 return params().getModules();
1702 string GuiDocument::getModuleDescription(string const & modName) const
1704 LyXModule const * const mod = moduleList[modName];
1706 return string("Module unavailable!");
1707 return mod->description;
1712 GuiDocument::getPackageList(string const & modName) const
1714 LyXModule const * const mod = moduleList[modName];
1716 return vector<string>(); //empty such thing
1717 return mod->packageList;
1721 TextClass const & GuiDocument::textClass() const
1723 return textclasslist[bp_.getBaseClass()];
1727 static void dispatch_bufferparams(Dialog const & dialog,
1728 BufferParams const & bp, kb_action lfun)
1731 ss << "\\begin_header\n";
1733 ss << "\\end_header\n";
1734 dialog.dispatch(FuncRequest(lfun, ss.str()));
1738 void GuiDocument::dispatchParams()
1740 // This must come first so that a language change is correctly noticed
1743 // Apply the BufferParams. Note that this will set the base class
1744 // and then update the buffer's layout.
1745 //FIXME Could this be done last? Then, I think, we'd get the automatic
1746 //update mentioned in the next FIXME...
1747 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
1749 // Generate the colours requested by each new branch.
1750 BranchList & branchlist = params().branchlist();
1751 if (!branchlist.empty()) {
1752 BranchList::const_iterator it = branchlist.begin();
1753 BranchList::const_iterator const end = branchlist.end();
1754 for (; it != end; ++it) {
1755 docstring const & current_branch = it->getBranch();
1756 Branch const * branch = branchlist.find(current_branch);
1757 string const x11hexname = X11hexname(branch->getColor());
1758 // display the new color
1759 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
1760 dispatch(FuncRequest(LFUN_SET_COLOR, str));
1763 // Open insets of selected branches, close deselected ones
1764 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
1767 // FIXME: If we used an LFUN, we would not need those two lines:
1768 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
1772 void GuiDocument::setLanguage() const
1774 Language const * const newL = bp_.language;
1775 if (buffer().params().language == newL)
1778 string const & lang_name = newL->lang();
1779 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
1783 void GuiDocument::saveAsDefault() const
1785 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
1789 bool GuiDocument::isFontAvailable(string const & font) const
1791 if (font == "default" || font == "cmr"
1792 || font == "cmss" || font == "cmtt")
1793 // these are standard
1795 if (font == "lmodern" || font == "lmss" || font == "lmtt")
1796 return LaTeXFeatures::isAvailable("lmodern");
1797 if (font == "times" || font == "palatino"
1798 || font == "helvet" || font == "courier")
1799 return LaTeXFeatures::isAvailable("psnfss");
1800 if (font == "cmbr" || font == "cmtl")
1801 return LaTeXFeatures::isAvailable("cmbright");
1802 if (font == "utopia")
1803 return LaTeXFeatures::isAvailable("utopia")
1804 || LaTeXFeatures::isAvailable("fourier");
1805 if (font == "beraserif" || font == "berasans"
1806 || font == "beramono")
1807 return LaTeXFeatures::isAvailable("bera");
1808 return LaTeXFeatures::isAvailable(font);
1812 bool GuiDocument::providesOSF(string const & font) const
1815 return isFontAvailable("eco");
1816 if (font == "palatino")
1817 return isFontAvailable("mathpazo");
1822 bool GuiDocument::providesSC(string const & font) const
1824 if (font == "palatino")
1825 return isFontAvailable("mathpazo");
1826 if (font == "utopia")
1827 return isFontAvailable("fourier");
1832 bool GuiDocument::providesScale(string const & font) const
1834 return font == "helvet" || font == "luximono"
1835 || font == "berasans" || font == "beramono";
1839 void GuiDocument::loadModuleNames ()
1841 moduleNames_.clear();
1842 LyXModuleList::const_iterator it = moduleList.begin();
1843 for (; it != moduleList.end(); ++it)
1844 moduleNames_.push_back(it->name);
1845 if (!moduleNames_.empty())
1846 sort(moduleNames_.begin(), moduleNames_.end());
1850 Dialog * createGuiDocument(LyXView & lv) { return new GuiDocument(lv); }
1853 } // namespace frontend
1856 #include "GuiDocument_moc.cpp"