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"
18 #include "BranchList.h"
19 #include "buffer_funcs.h"
21 #include "BufferParams.h"
22 #include "BufferView.h"
24 #include "EmbeddedFiles.h"
26 #include "FloatPlacement.h"
27 #include "FuncRequest.h"
28 #include "support/gettext.h"
29 #include "GuiBranches.h"
31 #include "LaTeXFeatures.h"
32 #include "LaTeXHighlighter.h"
34 #include "LengthCombo.h"
35 #include "LyXRC.h" // defaultUnit
36 #include "ModuleList.h"
37 #include "OutputParams.h"
38 #include "PanelStack.h"
39 #include "PDFOptions.h"
40 #include "qt_helpers.h"
42 #include "TextClassList.h"
43 #include "Validator.h"
45 #include "insets/InsetListingsParams.h"
47 #include "support/FileName.h"
48 #include "support/filetools.h"
49 #include "support/lstrings.h"
51 #include <boost/bind.hpp>
53 #include <QCloseEvent>
55 #include <QTextCursor>
65 using std::ostringstream;
70 std::vector<typename Pair::second_type> const
71 getSecond(std::vector<Pair> const & pr)
73 std::vector<typename Pair::second_type> tmp(pr.size());
74 std::transform(pr.begin(), pr.end(), tmp.begin(),
75 boost::bind(&Pair::second, _1));
79 char const * const tex_graphics[] =
81 "default", "dvips", "dvitops", "emtex",
82 "ln", "oztex", "textures", "none", ""
86 char const * const tex_graphics_gui[] =
88 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
89 "LN", "OzTeX", "Textures", N_("None"), ""
93 char const * const tex_fonts_roman[] =
95 "default", "cmr", "lmodern", "ae", "times", "palatino",
96 "charter", "newcent", "bookman", "utopia", "beraserif",
97 "ccfonts", "chancery", ""
101 char const * tex_fonts_roman_gui[] =
103 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
104 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
105 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
106 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
111 char const * const tex_fonts_sans[] =
113 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
117 char const * tex_fonts_sans_gui[] =
119 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
120 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
124 char const * const tex_fonts_monospaced[] =
126 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
130 char const * tex_fonts_monospaced_gui[] =
132 N_("Default"), N_("Computer Modern Typewriter"),
133 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
134 N_("LuxiMono"), N_("CM Typewriter Light"), ""
138 vector<pair<string, lyx::docstring> > pagestyles;
144 using support::token;
145 using support::bformat;
146 using support::findToken;
147 using support::getVectorFromString;
149 /////////////////////////////////////////////////////////////////////
153 /////////////////////////////////////////////////////////////////////
155 PreambleModule::PreambleModule(): current_id_(0)
157 // This is not a memory leak. The object will be destroyed
159 (void) new LaTeXHighlighter(preambleTE->document());
160 setFocusProxy(preambleTE);
161 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
165 void PreambleModule::update(BufferParams const & params, BufferId id)
167 QString preamble = toqstr(params.preamble);
168 // Nothing to do if the params and preamble are unchanged.
169 if (id == current_id_
170 && preamble == preambleTE->document()->toPlainText())
173 QTextCursor cur = preambleTE->textCursor();
174 // Save the coords before switching to the new one.
175 preamble_coords_[current_id_] =
176 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
178 // Save the params address for further use.
180 preambleTE->document()->setPlainText(preamble);
181 Coords::const_iterator it = preamble_coords_.find(current_id_);
182 if (it == preamble_coords_.end())
183 // First time we open this one.
184 preamble_coords_[current_id_] = make_pair(0,0);
186 // Restore saved coords.
187 QTextCursor cur = preambleTE->textCursor();
188 cur.setPosition(it->second.first);
189 preambleTE->setTextCursor(cur);
190 preambleTE->verticalScrollBar()->setValue(it->second.second);
195 void PreambleModule::apply(BufferParams & params)
197 params.preamble = fromqstr(preambleTE->document()->toPlainText());
201 void PreambleModule::closeEvent(QCloseEvent * e)
203 // Save the coords before closing.
204 QTextCursor cur = preambleTE->textCursor();
205 preamble_coords_[current_id_] =
206 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
211 /////////////////////////////////////////////////////////////////////
215 /////////////////////////////////////////////////////////////////////
219 GuiDocument::GuiDocument(GuiView & lv)
220 : GuiDialog(lv, "document")
223 setViewTitle(_("Document Settings"));
225 lang_ = getSecond(getLanguageData(false));
227 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
228 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
229 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
230 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
232 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
233 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
235 // Manage the restore, ok, apply, restore and cancel/close buttons
236 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
238 bc().setApply(applyPB);
239 bc().setCancel(closePB);
240 bc().setRestore(restorePB);
242 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
244 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
245 this, SLOT(change_adaptor()));
246 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
247 this, SLOT(setLSpacing(int)));
248 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
249 this, SLOT(change_adaptor()));
250 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
251 this, SLOT(change_adaptor()));
252 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
253 this, SLOT(change_adaptor()));
254 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
255 this, SLOT(change_adaptor()));
256 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
257 this, SLOT(change_adaptor()));
258 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
259 this, SLOT(change_adaptor()));
260 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
261 this, SLOT(setSkip(int)));
262 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
263 this, SLOT(enableSkip(bool)));
264 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
265 this, SLOT(change_adaptor()));
266 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
267 this, SLOT(change_adaptor()));
268 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
269 this, SLOT(change_adaptor()));
270 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
271 this, SLOT(set_listings_msg()));
272 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
273 this, SLOT(set_listings_msg()));
274 textLayoutModule->listingsTB->setPlainText(
275 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
276 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
277 textLayoutModule->lspacingLE));
278 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
279 textLayoutModule->skipLE));
281 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
282 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
283 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
284 textLayoutModule->skipCO->addItem(qt_("Length"));
285 // remove the %-items from the unit choice
286 textLayoutModule->skipLengthCO->noPercents();
287 textLayoutModule->lspacingCO->insertItem(
288 Spacing::Single, qt_("Single"));
289 textLayoutModule->lspacingCO->insertItem(
290 Spacing::Onehalf, qt_("OneHalf"));
291 textLayoutModule->lspacingCO->insertItem(
292 Spacing::Double, qt_("Double"));
293 textLayoutModule->lspacingCO->insertItem(
294 Spacing::Other, qt_("Custom"));
296 // initialize the length validator
297 bc().addCheckedLineEdit(textLayoutModule->skipLE);
299 fontModule = new UiWidget<Ui::FontUi>;
301 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
302 this, SLOT(change_adaptor()));
303 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
304 this, SLOT(romanChanged(int)));
305 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
306 this, SLOT(change_adaptor()));
307 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
308 this, SLOT(sansChanged(int)));
309 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
310 this, SLOT(change_adaptor()));
311 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
312 this, SLOT(ttChanged(int)));
313 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
314 this, SLOT(change_adaptor()));
315 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
316 this, SLOT(change_adaptor()));
317 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
318 this, SLOT(change_adaptor()));
319 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
320 this, SLOT(change_adaptor()));
321 connect(fontModule->fontScCB, SIGNAL(clicked()),
322 this, SLOT(change_adaptor()));
323 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
324 this, SLOT(change_adaptor()));
326 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
327 QString font = qt_(tex_fonts_roman_gui[n]);
328 if (!isFontAvailable(tex_fonts_roman[n]))
329 font += qt_(" (not installed)");
330 fontModule->fontsRomanCO->addItem(font);
332 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
333 QString font = qt_(tex_fonts_sans_gui[n]);
334 if (!isFontAvailable(tex_fonts_sans[n]))
335 font += qt_(" (not installed)");
336 fontModule->fontsSansCO->addItem(font);
338 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
339 QString font = qt_(tex_fonts_monospaced_gui[n]);
340 if (!isFontAvailable(tex_fonts_monospaced[n]))
341 font += qt_(" (not installed)");
342 fontModule->fontsTypewriterCO->addItem(font);
345 fontModule->fontsizeCO->addItem(qt_("Default"));
346 fontModule->fontsizeCO->addItem(qt_("10"));
347 fontModule->fontsizeCO->addItem(qt_("11"));
348 fontModule->fontsizeCO->addItem(qt_("12"));
350 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
351 fontModule->fontsDefaultCO->addItem(
352 qt_(GuiDocument::fontfamilies_gui[n]));
355 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
357 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
358 this, SLOT(setCustomPapersize(int)));
359 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
360 this, SLOT(setCustomPapersize(int)));
361 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
362 this, SLOT(portraitChanged()));
363 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
364 this, SLOT(change_adaptor()));
365 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
366 this, SLOT(change_adaptor()));
367 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
368 this, SLOT(change_adaptor()));
369 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
370 this, SLOT(change_adaptor()));
371 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
372 this, SLOT(change_adaptor()));
373 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
374 this, SLOT(change_adaptor()));
375 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
376 this, SLOT(change_adaptor()));
377 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
378 this, SLOT(change_adaptor()));
379 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
380 this, SLOT(change_adaptor()));
382 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
383 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
384 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
385 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
386 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
387 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
388 pageLayoutModule->paperheightL);
389 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
390 pageLayoutModule->paperwidthL);
393 QComboBox * cb = pageLayoutModule->papersizeCO;
394 cb->addItem(qt_("Default"));
395 cb->addItem(qt_("Custom"));
396 cb->addItem(qt_("US letter"));
397 cb->addItem(qt_("US legal"));
398 cb->addItem(qt_("US executive"));
399 cb->addItem(qt_("A3"));
400 cb->addItem(qt_("A4"));
401 cb->addItem(qt_("A5"));
402 cb->addItem(qt_("B3"));
403 cb->addItem(qt_("B4"));
404 cb->addItem(qt_("B5"));
405 // remove the %-items from the unit choice
406 pageLayoutModule->paperwidthUnitCO->noPercents();
407 pageLayoutModule->paperheightUnitCO->noPercents();
408 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
409 pageLayoutModule->paperheightLE));
410 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
411 pageLayoutModule->paperwidthLE));
414 marginsModule = new UiWidget<Ui::MarginsUi>;
416 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
417 this, SLOT(setCustomMargins(bool)));
418 connect(marginsModule->marginCB, SIGNAL(clicked()),
419 this, SLOT(change_adaptor()));
420 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
421 this, SLOT(change_adaptor()));
422 connect(marginsModule->topUnit, SIGNAL(activated(int)),
423 this, SLOT(change_adaptor()));
424 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
425 this, SLOT(change_adaptor()));
426 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
427 this, SLOT(change_adaptor()));
428 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
429 this, SLOT(change_adaptor()));
430 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
431 this, SLOT(change_adaptor()));
432 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
433 this, SLOT(change_adaptor()));
434 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
435 this, SLOT(change_adaptor()));
436 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
437 this, SLOT(change_adaptor()));
438 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
439 this, SLOT(change_adaptor()));
440 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
441 this, SLOT(change_adaptor()));
442 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
443 this, SLOT(change_adaptor()));
444 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
445 this, SLOT(change_adaptor()));
446 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
447 this, SLOT(change_adaptor()));
448 marginsModule->topLE->setValidator(unsignedLengthValidator(
449 marginsModule->topLE));
450 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
451 marginsModule->bottomLE));
452 marginsModule->innerLE->setValidator(unsignedLengthValidator(
453 marginsModule->innerLE));
454 marginsModule->outerLE->setValidator(unsignedLengthValidator(
455 marginsModule->outerLE));
456 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
457 marginsModule->headsepLE));
458 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
459 marginsModule->headheightLE));
460 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
461 marginsModule->footskipLE));
463 bc().addCheckedLineEdit(marginsModule->topLE,
464 marginsModule->topL);
465 bc().addCheckedLineEdit(marginsModule->bottomLE,
466 marginsModule->bottomL);
467 bc().addCheckedLineEdit(marginsModule->innerLE,
468 marginsModule->innerL);
469 bc().addCheckedLineEdit(marginsModule->outerLE,
470 marginsModule->outerL);
471 bc().addCheckedLineEdit(marginsModule->headsepLE,
472 marginsModule->headsepL);
473 bc().addCheckedLineEdit(marginsModule->headheightLE,
474 marginsModule->headheightL);
475 bc().addCheckedLineEdit(marginsModule->footskipLE,
476 marginsModule->footskipL);
479 langModule = new UiWidget<Ui::LanguageUi>;
481 connect(langModule->languageCO, SIGNAL(activated(int)),
482 this, SLOT(change_adaptor()));
483 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
484 this, SLOT(change_adaptor()));
485 connect(langModule->otherencodingRB, SIGNAL(clicked()),
486 this, SLOT(change_adaptor()));
487 connect(langModule->encodingCO, SIGNAL(activated(int)),
488 this, SLOT(change_adaptor()));
489 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
490 this, SLOT(change_adaptor()));
492 vector<LanguagePair> const langs = getLanguageData(false);
493 vector<LanguagePair>::const_iterator lit = langs.begin();
494 vector<LanguagePair>::const_iterator lend = langs.end();
495 for (; lit != lend; ++lit) {
496 langModule->languageCO->addItem(toqstr(lit->first));
499 // Always put the default encoding in the first position.
500 // It is special because the displayed text is translated.
501 langModule->encodingCO->addItem(qt_("LaTeX default"));
502 Encodings::const_iterator it = encodings.begin();
503 Encodings::const_iterator const end = encodings.end();
504 for (; it != end; ++it)
505 langModule->encodingCO->addItem(toqstr(it->latexName()));
507 langModule->quoteStyleCO->addItem(qt_("``text''"));
508 langModule->quoteStyleCO->addItem(qt_("''text''"));
509 langModule->quoteStyleCO->addItem(qt_(",,text``"));
510 langModule->quoteStyleCO->addItem(qt_(",,text''"));
511 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
512 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
516 numberingModule = new UiWidget<Ui::NumberingUi>;
518 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
519 this, SLOT(change_adaptor()));
520 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
521 this, SLOT(change_adaptor()));
522 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
523 this, SLOT(updateNumbering()));
524 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
525 this, SLOT(updateNumbering()));
526 numberingModule->tocTW->setColumnCount(3);
527 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
528 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
529 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
532 biblioModule = new UiWidget<Ui::BiblioUi>;
533 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
534 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
535 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
536 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
538 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
539 this, SLOT(change_adaptor()));
540 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
541 this, SLOT(change_adaptor()));
542 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
543 this, SLOT(change_adaptor()));
544 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
545 this, SLOT(change_adaptor()));
546 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
547 this, SLOT(change_adaptor()));
549 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
550 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
551 biblioModule->citeStyleCO->setCurrentIndex(0);
554 mathsModule = new UiWidget<Ui::MathsUi>;
555 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
556 mathsModule->amsCB, SLOT(setDisabled(bool)));
557 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
558 mathsModule->esintCB, SLOT(setDisabled(bool)));
560 connect(mathsModule->amsCB, SIGNAL(clicked()),
561 this, SLOT(change_adaptor()));
562 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
563 this, SLOT(change_adaptor()));
564 connect(mathsModule->esintCB, SIGNAL(clicked()),
565 this, SLOT(change_adaptor()));
566 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
567 this, SLOT(change_adaptor()));
569 latexModule = new UiWidget<Ui::LaTeXUi>;
571 connect(latexModule->classCO, SIGNAL(activated(int)),
572 this, SLOT(change_adaptor()));
573 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
574 this, SLOT(change_adaptor()));
575 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
576 this, SLOT(change_adaptor()));
577 connect(latexModule->classCO, SIGNAL(activated(int)),
578 this, SLOT(classChanged()));
581 new GuiSelectionManager(latexModule->availableLV, latexModule->selectedLV,
582 latexModule->addPB, latexModule->deletePB,
583 latexModule->upPB, latexModule->downPB,
584 availableModel(), selectedModel());
585 connect(selectionManager, SIGNAL(updateHook()),
586 this, SLOT(updateModuleInfo()));
587 connect(selectionManager, SIGNAL(updateHook()),
588 this, SLOT(change_adaptor()));
590 // postscript drivers
591 for (int n = 0; tex_graphics[n][0]; ++n) {
592 QString enc = qt_(tex_graphics_gui[n]);
593 latexModule->psdriverCO->addItem(enc);
596 //FIXME This seems too involved with the kernel. Some of this
597 //should be moved to the kernel---which should perhaps just
598 //give us a list of entries or something of the sort.
599 for (TextClassList::const_iterator cit = textclasslist.begin();
600 cit != textclasslist.end(); ++cit) {
601 if (cit->isTeXClassAvailable()) {
602 latexModule->classCO->addItem(toqstr(cit->description()));
605 bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
606 latexModule->classCO->addItem(toqstr(item));
611 branchesModule = new GuiBranches;
612 connect(branchesModule, SIGNAL(changed()),
613 this, SLOT(change_adaptor()));
616 preambleModule = new PreambleModule;
617 connect(preambleModule, SIGNAL(changed()),
618 this, SLOT(change_adaptor()));
621 bulletsModule = new BulletsModule;
622 connect(bulletsModule, SIGNAL(changed()),
623 this, SLOT(change_adaptor()));
626 embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
627 connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
628 this, SLOT(change_adaptor()));
629 connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
630 this, SLOT(change_adaptor()));
631 connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
632 this, SLOT(change_adaptor()));
635 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
637 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
638 this, SLOT(change_adaptor()));
639 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
640 this, SLOT(change_adaptor()));
641 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
642 this, SLOT(change_adaptor()));
643 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
644 this, SLOT(change_adaptor()));
645 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
646 this, SLOT(change_adaptor()));
647 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
648 this, SLOT(change_adaptor()));
649 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
650 this, SLOT(change_adaptor()));
651 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
652 this, SLOT(change_adaptor()));
653 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
654 this, SLOT(change_adaptor()));
655 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
656 this, SLOT(change_adaptor()));
657 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
658 this, SLOT(change_adaptor()));
659 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
660 this, SLOT(change_adaptor()));
661 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
662 this, SLOT(change_adaptor()));
663 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
664 this, SLOT(change_adaptor()));
665 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
666 this, SLOT(change_adaptor()));
667 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
668 this, SLOT(change_adaptor()));
669 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
670 this, SLOT(change_adaptor()));
673 floatModule = new FloatPlacement;
674 connect(floatModule, SIGNAL(changed()),
675 this, SLOT(change_adaptor()));
677 docPS->addPanel(latexModule, _("Document Class"));
678 docPS->addPanel(fontModule, _("Fonts"));
679 docPS->addPanel(textLayoutModule, _("Text Layout"));
680 docPS->addPanel(pageLayoutModule, _("Page Layout"));
681 docPS->addPanel(marginsModule, _("Page Margins"));
682 docPS->addPanel(langModule, _("Language"));
683 docPS->addPanel(numberingModule, _("Numbering & TOC"));
684 docPS->addPanel(biblioModule, _("Bibliography"));
685 docPS->addPanel(pdfSupportModule, _("PDF Properties"));
686 docPS->addPanel(mathsModule, _("Math Options"));
687 docPS->addPanel(floatModule, _("Float Placement"));
688 docPS->addPanel(bulletsModule, _("Bullets"));
689 docPS->addPanel(branchesModule, _("Branches"));
690 docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
691 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
692 docPS->setCurrentPanel(_("Document Class"));
693 // FIXME: hack to work around resizing bug in Qt >= 4.2
694 // bug verified with Qt 4.2.{0-3} (JSpitzm)
695 #if QT_VERSION >= 0x040200
696 docPS->updateGeometry();
701 void GuiDocument::showPreamble()
703 docPS->setCurrentPanel(_("LaTeX Preamble"));
707 void GuiDocument::saveDefaultClicked()
713 void GuiDocument::useDefaultsClicked()
719 void GuiDocument::change_adaptor()
725 docstring GuiDocument::validate_listings_params()
727 // use a cache here to avoid repeated validation
728 // of the same parameters
729 static string param_cache = string();
730 static docstring msg_cache = docstring();
732 if (textLayoutModule->bypassCB->isChecked())
735 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
736 if (params != param_cache) {
737 param_cache = params;
738 msg_cache = InsetListingsParams(params).validate();
744 void GuiDocument::set_listings_msg()
746 static bool isOK = true;
747 docstring msg = validate_listings_params();
752 // listingsTB->setTextColor("black");
753 textLayoutModule->listingsTB->setPlainText(
754 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
757 // listingsTB->setTextColor("red");
758 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
763 void GuiDocument::closeEvent(QCloseEvent * e)
770 void GuiDocument::setLSpacing(int item)
772 textLayoutModule->lspacingLE->setEnabled(item == 3);
776 void GuiDocument::setSkip(int item)
778 bool const enable = (item == 3);
779 textLayoutModule->skipLE->setEnabled(enable);
780 textLayoutModule->skipLengthCO->setEnabled(enable);
784 void GuiDocument::enableSkip(bool skip)
786 textLayoutModule->skipCO->setEnabled(skip);
787 textLayoutModule->skipLE->setEnabled(skip);
788 textLayoutModule->skipLengthCO->setEnabled(skip);
790 setSkip(textLayoutModule->skipCO->currentIndex());
793 void GuiDocument::portraitChanged()
795 setMargins(pageLayoutModule->papersizeCO->currentIndex());
798 void GuiDocument::setMargins(bool custom)
800 marginsModule->marginCB->setChecked(custom);
801 setCustomMargins(custom);
805 void GuiDocument::setCustomPapersize(int papersize)
807 bool const custom = (papersize == 1);
809 pageLayoutModule->paperwidthL->setEnabled(custom);
810 pageLayoutModule->paperwidthLE->setEnabled(custom);
811 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
812 pageLayoutModule->paperheightL->setEnabled(custom);
813 pageLayoutModule->paperheightLE->setEnabled(custom);
814 pageLayoutModule->paperheightLE->setFocus();
815 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
819 void GuiDocument::setCustomMargins(bool custom)
821 marginsModule->topL->setEnabled(!custom);
822 marginsModule->topLE->setEnabled(!custom);
823 marginsModule->topUnit->setEnabled(!custom);
825 marginsModule->bottomL->setEnabled(!custom);
826 marginsModule->bottomLE->setEnabled(!custom);
827 marginsModule->bottomUnit->setEnabled(!custom);
829 marginsModule->innerL->setEnabled(!custom);
830 marginsModule->innerLE->setEnabled(!custom);
831 marginsModule->innerUnit->setEnabled(!custom);
833 marginsModule->outerL->setEnabled(!custom);
834 marginsModule->outerLE->setEnabled(!custom);
835 marginsModule->outerUnit->setEnabled(!custom);
837 marginsModule->headheightL->setEnabled(!custom);
838 marginsModule->headheightLE->setEnabled(!custom);
839 marginsModule->headheightUnit->setEnabled(!custom);
841 marginsModule->headsepL->setEnabled(!custom);
842 marginsModule->headsepLE->setEnabled(!custom);
843 marginsModule->headsepUnit->setEnabled(!custom);
845 marginsModule->footskipL->setEnabled(!custom);
846 marginsModule->footskipLE->setEnabled(!custom);
847 marginsModule->footskipUnit->setEnabled(!custom);
851 void GuiDocument::updateFontsize(string const & items, string const & sel)
853 fontModule->fontsizeCO->clear();
854 fontModule->fontsizeCO->addItem(qt_("Default"));
856 for (int n = 0; !token(items,'|',n).empty(); ++n)
857 fontModule->fontsizeCO->
858 addItem(toqstr(token(items,'|',n)));
860 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
861 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
862 fontModule->fontsizeCO->setCurrentIndex(n);
869 void GuiDocument::romanChanged(int item)
871 string const font = tex_fonts_roman[item];
872 fontModule->fontScCB->setEnabled(providesSC(font));
873 fontModule->fontOsfCB->setEnabled(providesOSF(font));
877 void GuiDocument::sansChanged(int item)
879 string const font = tex_fonts_sans[item];
880 bool scaleable = providesScale(font);
881 fontModule->scaleSansSB->setEnabled(scaleable);
882 fontModule->scaleSansLA->setEnabled(scaleable);
886 void GuiDocument::ttChanged(int item)
888 string const font = tex_fonts_monospaced[item];
889 bool scaleable = providesScale(font);
890 fontModule->scaleTypewriterSB->setEnabled(scaleable);
891 fontModule->scaleTypewriterLA->setEnabled(scaleable);
895 void GuiDocument::updatePagestyle(string const & items, string const & sel)
898 pageLayoutModule->pagestyleCO->clear();
899 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
901 for (int n = 0; !token(items,'|',n).empty(); ++n) {
902 string style = token(items, '|', n);
903 docstring style_gui = _(style);
904 pagestyles.push_back(pair<string, docstring>(style, style_gui));
905 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
908 if (sel == "default") {
909 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
915 for (size_t i = 0; i < pagestyles.size(); ++i)
916 if (pagestyles[i].first == sel)
917 nn = pageLayoutModule->pagestyleCO->findText(
918 toqstr(pagestyles[i].second));
921 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
925 void GuiDocument::classChanged()
927 textclass_type const tc = latexModule->classCO->currentIndex();
928 bp_.setJustBaseClass(tc);
929 if (lyxrc.auto_reset_options)
930 bp_.useClassDefaults();
935 void GuiDocument::updateModuleInfo()
937 selectionManager->update();
939 QListView const * const lv = selectionManager->selectedFocused() ?
940 latexModule->selectedLV :
941 latexModule->availableLV;
942 if (lv->selectionModel()->selectedIndexes().isEmpty())
943 latexModule->infoML->document()->clear();
945 QModelIndex const idx = lv->selectionModel()->currentIndex();
946 string const modName = fromqstr(idx.data().toString());
947 string desc = getModuleDescription(modName);
948 vector<string> pkgList = getPackageList(modName);
950 //this mess formats the package list as "pkg1, pkg2, and pkg3"
951 int const pkgListSize = pkgList.size();
952 for (int i = 0; i < pkgListSize; ++i) {
954 if (i == pkgListSize - 1) //last element
959 if (i == pkgListSize - 1) //last element
964 pkgdesc += pkgList[i];
966 if (!pkgdesc.empty())
967 desc += " Requires " + pkgdesc + ".";
968 latexModule->infoML->document()->setPlainText(toqstr(desc));
973 void GuiDocument::updateEmbeddedFileList()
975 embeddedFilesModule->filesLW->clear();
976 // add current embedded files
977 EmbeddedFiles & files = buffer().embeddedFiles();
979 EmbeddedFiles::EmbeddedFileList::iterator fit = files.begin();
980 EmbeddedFiles::EmbeddedFileList::iterator fit_end = files.end();
981 for (; fit != fit_end; ++fit) {
982 QString label = toqstr(fit->relFilename(buffer().filePath()));
983 if (fit->refCount() > 1)
984 label += " (" + QString::number(fit->refCount()) + ")";
985 QListWidgetItem * item = new QListWidgetItem(label);
986 item->setFlags(item->flags() | Qt::ItemIsSelectable
987 | Qt::ItemIsUserCheckable);
989 item->setCheckState(Qt::Checked);
991 item->setCheckState(Qt::Unchecked);
992 // index of the currently used ParConstIterator
993 embeddedFilesModule->filesLW->addItem(item);
998 void GuiDocument::updateNumbering()
1000 TextClass const & tclass = bp_.getTextClass();
1002 numberingModule->tocTW->setUpdatesEnabled(false);
1003 numberingModule->tocTW->clear();
1005 int const depth = numberingModule->depthSL->value();
1006 int const toc = numberingModule->tocSL->value();
1007 QString const no = qt_("No");
1008 QString const yes = qt_("Yes");
1009 TextClass::const_iterator end = tclass.end();
1010 TextClass::const_iterator cit = tclass.begin();
1011 QTreeWidgetItem * item = 0;
1012 for ( ; cit != end ; ++cit) {
1013 int const toclevel = (*cit)->toclevel;
1014 if (toclevel != Layout::NOT_IN_TOC
1015 && (*cit)->labeltype == LABEL_COUNTER) {
1016 item = new QTreeWidgetItem(numberingModule->tocTW);
1017 item->setText(0, toqstr(translateIfPossible((*cit)->name())));
1018 item->setText(1, (toclevel <= depth) ? yes : no);
1019 item->setText(2, (toclevel <= toc) ? yes : no);
1023 numberingModule->tocTW->setUpdatesEnabled(true);
1024 numberingModule->tocTW->update();
1028 void GuiDocument::apply(BufferParams & params)
1031 preambleModule->apply(params);
1034 params.setCiteEngine(biblio::ENGINE_BASIC);
1036 if (biblioModule->citeNatbibRB->isChecked()) {
1037 bool const use_numerical_citations =
1038 biblioModule->citeStyleCO->currentIndex();
1039 if (use_numerical_citations)
1040 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1042 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1044 } else if (biblioModule->citeJurabibRB->isChecked())
1045 params.setCiteEngine(biblio::ENGINE_JURABIB);
1047 params.use_bibtopic =
1048 biblioModule->bibtopicCB->isChecked();
1050 // language & quotes
1051 if (langModule->defaultencodingRB->isChecked()) {
1052 params.inputenc = "auto";
1054 int i = langModule->encodingCO->currentIndex();
1056 params.inputenc = "default";
1059 fromqstr(langModule->encodingCO->currentText());
1062 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1063 switch (langModule->quoteStyleCO->currentIndex()) {
1065 lga = InsetQuotes::EnglishQ;
1068 lga = InsetQuotes::SwedishQ;
1071 lga = InsetQuotes::GermanQ;
1074 lga = InsetQuotes::PolishQ;
1077 lga = InsetQuotes::FrenchQ;
1080 lga = InsetQuotes::DanishQ;
1083 params.quotes_language = lga;
1085 int const pos = langModule->languageCO->currentIndex();
1086 params.language = lyx::languages.getLanguage(lang_[pos]);
1089 if (params.getTextClass().hasTocLevels()) {
1090 params.tocdepth = numberingModule->tocSL->value();
1091 params.secnumdepth = numberingModule->depthSL->value();
1095 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1096 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1097 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1098 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1101 params.graphicsDriver =
1102 tex_graphics[latexModule->psdriverCO->currentIndex()];
1105 params.clearLayoutModules();
1106 QStringList const selMods = selectedModel()->stringList();
1107 for (int i = 0; i != selMods.size(); ++i)
1108 params.addLayoutModule(lyx::fromqstr(selMods[i]));
1111 if (mathsModule->amsautoCB->isChecked()) {
1112 params.use_amsmath = BufferParams::package_auto;
1114 if (mathsModule->amsCB->isChecked())
1115 params.use_amsmath = BufferParams::package_on;
1117 params.use_amsmath = BufferParams::package_off;
1120 if (mathsModule->esintautoCB->isChecked())
1121 params.use_esint = BufferParams::package_auto;
1123 if (mathsModule->esintCB->isChecked())
1124 params.use_esint = BufferParams::package_on;
1126 params.use_esint = BufferParams::package_off;
1130 params.setJustBaseClass(latexModule->classCO->currentIndex());
1132 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1133 params.pagestyle = "default";
1135 docstring style_gui =
1136 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1137 for (size_t i = 0; i < pagestyles.size(); ++i)
1138 if (pagestyles[i].second == style_gui)
1139 params.pagestyle = pagestyles[i].first;
1142 switch (textLayoutModule->lspacingCO->currentIndex()) {
1144 params.spacing().set(Spacing::Single);
1147 params.spacing().set(Spacing::Onehalf);
1150 params.spacing().set(Spacing::Double);
1153 params.spacing().set(Spacing::Other,
1154 fromqstr(textLayoutModule->lspacingLE->text()));
1158 if (textLayoutModule->twoColumnCB->isChecked())
1163 // text should have passed validation
1164 params.listings_params =
1165 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1167 if (textLayoutModule->indentRB->isChecked())
1168 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1170 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1172 switch (textLayoutModule->skipCO->currentIndex()) {
1174 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1177 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1180 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1185 widgetsToLength(textLayoutModule->skipLE,
1186 textLayoutModule->skipLengthCO)
1188 params.setDefSkip(vs);
1192 // DocumentDefskipCB assures that this never happens
1193 // so Assert then !!! - jbl
1194 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1199 fromqstr(latexModule->optionsLE->text());
1201 params.float_placement = floatModule->get();
1205 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1208 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1210 params.fontsTypewriter =
1211 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1213 params.fontsSansScale = fontModule->scaleSansSB->value();
1215 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1217 params.fontsSC = fontModule->fontScCB->isChecked();
1219 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1221 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1222 fontModule->fontsDefaultCO->currentIndex()];
1224 if (fontModule->fontsizeCO->currentIndex() == 0)
1225 params.fontsize = "default";
1228 fromqstr(fontModule->fontsizeCO->currentText());
1231 params.papersize = PAPER_SIZE(
1232 pageLayoutModule->papersizeCO->currentIndex());
1234 // custom, A3, B3 and B4 paper sizes need geometry
1235 int psize = pageLayoutModule->papersizeCO->currentIndex();
1236 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1238 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1239 pageLayoutModule->paperwidthUnitCO);
1241 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1242 pageLayoutModule->paperheightUnitCO);
1244 if (pageLayoutModule->facingPagesCB->isChecked())
1245 params.sides = TwoSides;
1247 params.sides = OneSide;
1249 if (pageLayoutModule->landscapeRB->isChecked())
1250 params.orientation = ORIENTATION_LANDSCAPE;
1252 params.orientation = ORIENTATION_PORTRAIT;
1255 params.use_geometry =
1256 (!marginsModule->marginCB->isChecked()
1259 Ui::MarginsUi const * m(marginsModule);
1261 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1262 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1263 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1264 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1265 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1266 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1267 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1269 branchesModule->apply(params);
1272 PDFOptions & pdf = params.pdfoptions();
1273 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1274 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1275 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1276 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1277 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1279 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1280 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1281 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1282 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1284 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1285 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1286 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1287 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1288 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1289 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1290 if (pdfSupportModule->fullscreenCB->isChecked())
1291 pdf.pagemode = pdf.pagemode_fullscreen;
1293 pdf.pagemode.clear();
1294 pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1299 // GuiDocument is special because some change in there might affect other
1300 // dialogs. It is then better to make sure that all dialogs are in sync
1301 // with current document settings.
1302 lyxview().updateBufferDependent(true);
1303 lyxview().updateLayoutList();
1304 lyxview().updateToolbars();
1308 /** Return the position of val in the vector if found.
1309 If not found, return 0.
1312 static size_t findPos(std::vector<A> const & vec, A const & val)
1314 typename std::vector<A>::const_iterator it =
1315 std::find(vec.begin(), vec.end(), val);
1316 if (it == vec.end())
1318 return distance(vec.begin(), it);
1322 void GuiDocument::updateParams()
1328 void GuiDocument::updateParams(BufferParams const & params)
1330 // set the default unit
1331 Length::UNIT defaultUnit = Length::CM;
1332 switch (lyxrc.default_papersize) {
1333 case PAPER_DEFAULT: break;
1335 case PAPER_USLETTER:
1337 case PAPER_USEXECUTIVE:
1338 defaultUnit = Length::IN;
1347 defaultUnit = Length::CM;
1354 preambleModule->update(params, id());
1357 biblioModule->citeDefaultRB->setChecked(
1358 params.getEngine() == biblio::ENGINE_BASIC);
1360 biblioModule->citeNatbibRB->setChecked(
1361 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1362 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1364 biblioModule->citeStyleCO->setCurrentIndex(
1365 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1367 biblioModule->citeJurabibRB->setChecked(
1368 params.getEngine() == biblio::ENGINE_JURABIB);
1370 biblioModule->bibtopicCB->setChecked(
1371 params.use_bibtopic);
1373 // language & quotes
1374 int const pos = int(findPos(lang_,
1375 params.language->lang()));
1376 langModule->languageCO->setCurrentIndex(pos);
1378 langModule->quoteStyleCO->setCurrentIndex(
1379 params.quotes_language);
1381 bool default_enc = true;
1382 if (params.inputenc != "auto") {
1383 default_enc = false;
1384 if (params.inputenc == "default") {
1385 langModule->encodingCO->setCurrentIndex(0);
1387 int const i = langModule->encodingCO->findText(
1388 toqstr(params.inputenc));
1390 langModule->encodingCO->setCurrentIndex(i);
1392 // unknown encoding. Set to default.
1396 langModule->defaultencodingRB->setChecked(default_enc);
1397 langModule->otherencodingRB->setChecked(!default_enc);
1400 int const min_toclevel = textClass().min_toclevel();
1401 int const max_toclevel = textClass().max_toclevel();
1402 if (textClass().hasTocLevels()) {
1403 numberingModule->setEnabled(true);
1404 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1405 numberingModule->depthSL->setMaximum(max_toclevel);
1406 numberingModule->depthSL->setValue(params.secnumdepth);
1407 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1408 numberingModule->tocSL->setMaximum(max_toclevel);
1409 numberingModule->tocSL->setValue(params.tocdepth);
1412 numberingModule->setEnabled(false);
1413 numberingModule->tocTW->clear();
1417 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1418 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1419 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1420 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1421 bulletsModule->init();
1424 int nitem = findToken(tex_graphics, params.graphicsDriver);
1426 latexModule->psdriverCO->setCurrentIndex(nitem);
1429 mathsModule->amsCB->setChecked(
1430 params.use_amsmath == BufferParams::package_on);
1431 mathsModule->amsautoCB->setChecked(
1432 params.use_amsmath == BufferParams::package_auto);
1434 mathsModule->esintCB->setChecked(
1435 params.use_esint == BufferParams::package_on);
1436 mathsModule->esintautoCB->setChecked(
1437 params.use_esint == BufferParams::package_auto);
1439 switch (params.spacing().getSpace()) {
1440 case Spacing::Other: nitem = 3; break;
1441 case Spacing::Double: nitem = 2; break;
1442 case Spacing::Onehalf: nitem = 1; break;
1443 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1447 latexModule->classCO->setCurrentIndex(params.getBaseClass());
1449 updatePagestyle(textClass().opt_pagestyle(),
1452 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1453 if (params.spacing().getSpace() == Spacing::Other) {
1454 textLayoutModule->lspacingLE->setText(
1455 toqstr(params.spacing().getValueAsString()));
1459 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1460 textLayoutModule->indentRB->setChecked(true);
1462 textLayoutModule->skipRB->setChecked(true);
1465 switch (params.getDefSkip().kind()) {
1466 case VSpace::SMALLSKIP:
1469 case VSpace::MEDSKIP:
1472 case VSpace::BIGSKIP:
1475 case VSpace::LENGTH:
1478 string const length = params.getDefSkip().asLyXCommand();
1479 lengthToWidgets(textLayoutModule->skipLE,
1480 textLayoutModule->skipLengthCO,
1481 length, defaultUnit);
1488 textLayoutModule->skipCO->setCurrentIndex(skip);
1491 textLayoutModule->twoColumnCB->setChecked(
1492 params.columns == 2);
1494 // break listings_params to multiple lines
1496 InsetListingsParams(params.listings_params).separatedParams();
1497 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1499 if (!params.options.empty()) {
1500 latexModule->optionsLE->setText(
1501 toqstr(params.options));
1503 latexModule->optionsLE->setText(QString());
1506 floatModule->set(params.float_placement);
1509 updateFontsize(textClass().opt_fontsize(),
1512 int n = findToken(tex_fonts_roman, params.fontsRoman);
1514 fontModule->fontsRomanCO->setCurrentIndex(n);
1518 n = findToken(tex_fonts_sans, params.fontsSans);
1520 fontModule->fontsSansCO->setCurrentIndex(n);
1524 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1526 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1530 fontModule->fontScCB->setChecked(params.fontsSC);
1531 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1532 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1533 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1534 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1536 fontModule->fontsDefaultCO->setCurrentIndex(n);
1539 int const psize = params.papersize;
1540 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1541 setCustomPapersize(psize);
1543 bool const landscape =
1544 params.orientation == ORIENTATION_LANDSCAPE;
1545 pageLayoutModule->landscapeRB->setChecked(landscape);
1546 pageLayoutModule->portraitRB->setChecked(!landscape);
1548 pageLayoutModule->facingPagesCB->setChecked(
1549 params.sides == TwoSides);
1552 lengthToWidgets(pageLayoutModule->paperwidthLE,
1553 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1555 lengthToWidgets(pageLayoutModule->paperheightLE,
1556 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1559 Ui::MarginsUi * m = marginsModule;
1561 setMargins(!params.use_geometry);
1563 lengthToWidgets(m->topLE, m->topUnit,
1564 params.topmargin, defaultUnit);
1566 lengthToWidgets(m->bottomLE, m->bottomUnit,
1567 params.bottommargin, defaultUnit);
1569 lengthToWidgets(m->innerLE, m->innerUnit,
1570 params.leftmargin, defaultUnit);
1572 lengthToWidgets(m->outerLE, m->outerUnit,
1573 params.rightmargin, defaultUnit);
1575 lengthToWidgets(m->headheightLE, m->headheightUnit,
1576 params.headheight, defaultUnit);
1578 lengthToWidgets(m->headsepLE, m->headsepUnit,
1579 params.headsep, defaultUnit);
1581 lengthToWidgets(m->footskipLE, m->footskipUnit,
1582 params.footskip, defaultUnit);
1584 branchesModule->update(params);
1587 PDFOptions const & pdf = params.pdfoptions();
1588 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1589 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1590 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1591 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1592 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1594 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1595 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1596 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1598 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1600 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1601 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1602 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
1603 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1604 pdfSupportModule->backrefCB->setChecked(pdf.backref);
1605 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1606 pdfSupportModule->fullscreenCB->setChecked
1607 (pdf.pagemode == pdf.pagemode_fullscreen);
1609 pdfSupportModule->optionsLE->setText(
1610 toqstr(pdf.quoted_options));
1613 updateEmbeddedFileList();
1617 void GuiDocument::applyView()
1623 void GuiDocument::saveDocDefault()
1625 // we have to apply the params first
1631 void GuiDocument::updateContents()
1633 //update list of available modules
1634 QStringList strlist;
1635 vector<string> const modNames = getModuleNames();
1636 vector<string>::const_iterator it = modNames.begin();
1637 for (; it != modNames.end(); ++it)
1638 strlist.push_back(toqstr(*it));
1639 available_model_.setStringList(strlist);
1640 //and selected ones, too
1641 QStringList strlist2;
1642 vector<string> const & selMods = getSelectedModules();
1643 it = selMods.begin();
1644 for (; it != selMods.end(); ++it)
1645 strlist2.push_back(toqstr(*it));
1646 selected_model_.setStringList(strlist2);
1651 void GuiDocument::useClassDefaults()
1653 bp_.setJustBaseClass(latexModule->classCO->currentIndex());
1654 bp_.useClassDefaults();
1659 bool GuiDocument::isValid()
1661 return validate_listings_params().empty();
1665 char const * const GuiDocument::fontfamilies[5] = {
1666 "default", "rmdefault", "sfdefault", "ttdefault", ""
1670 char const * GuiDocument::fontfamilies_gui[5] = {
1671 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
1675 bool GuiDocument::initialiseParams(string const &)
1677 bp_ = buffer().params();
1683 void GuiDocument::clearParams()
1685 bp_ = BufferParams();
1689 BufferId GuiDocument::id() const
1695 vector<string> GuiDocument::getModuleNames()
1697 return moduleNames_;
1701 vector<string> const & GuiDocument::getSelectedModules()
1703 return params().getModules();
1707 string GuiDocument::getModuleDescription(string const & modName) const
1709 LyXModule const * const mod = moduleList[modName];
1711 return string("Module unavailable!");
1712 return mod->description;
1717 GuiDocument::getPackageList(string const & modName) const
1719 LyXModule const * const mod = moduleList[modName];
1721 return vector<string>(); //empty such thing
1722 return mod->packageList;
1726 TextClass const & GuiDocument::textClass() const
1728 return textclasslist[bp_.getBaseClass()];
1732 static void dispatch_bufferparams(Dialog const & dialog,
1733 BufferParams const & bp, kb_action lfun)
1736 ss << "\\begin_header\n";
1738 ss << "\\end_header\n";
1739 dialog.dispatch(FuncRequest(lfun, ss.str()));
1743 void GuiDocument::dispatchParams()
1745 // This must come first so that a language change is correctly noticed
1748 // Apply the BufferParams. Note that this will set the base class
1749 // and then update the buffer's layout.
1750 //FIXME Could this be done last? Then, I think, we'd get the automatic
1751 //update mentioned in the next FIXME...
1752 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
1754 // Generate the colours requested by each new branch.
1755 BranchList & branchlist = params().branchlist();
1756 if (!branchlist.empty()) {
1757 BranchList::const_iterator it = branchlist.begin();
1758 BranchList::const_iterator const end = branchlist.end();
1759 for (; it != end; ++it) {
1760 docstring const & current_branch = it->getBranch();
1761 Branch const * branch = branchlist.find(current_branch);
1762 string const x11hexname = X11hexname(branch->getColor());
1763 // display the new color
1764 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
1765 dispatch(FuncRequest(LFUN_SET_COLOR, str));
1768 // Open insets of selected branches, close deselected ones
1769 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
1772 // FIXME: If we used an LFUN, we would not need those two lines:
1773 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
1777 void GuiDocument::setLanguage() const
1779 Language const * const newL = bp_.language;
1780 if (buffer().params().language == newL)
1783 string const & lang_name = newL->lang();
1784 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
1788 void GuiDocument::saveAsDefault() const
1790 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
1794 bool GuiDocument::isFontAvailable(string const & font) const
1796 if (font == "default" || font == "cmr"
1797 || font == "cmss" || font == "cmtt")
1798 // these are standard
1800 if (font == "lmodern" || font == "lmss" || font == "lmtt")
1801 return LaTeXFeatures::isAvailable("lmodern");
1802 if (font == "times" || font == "palatino"
1803 || font == "helvet" || font == "courier")
1804 return LaTeXFeatures::isAvailable("psnfss");
1805 if (font == "cmbr" || font == "cmtl")
1806 return LaTeXFeatures::isAvailable("cmbright");
1807 if (font == "utopia")
1808 return LaTeXFeatures::isAvailable("utopia")
1809 || LaTeXFeatures::isAvailable("fourier");
1810 if (font == "beraserif" || font == "berasans"
1811 || font == "beramono")
1812 return LaTeXFeatures::isAvailable("bera");
1813 return LaTeXFeatures::isAvailable(font);
1817 bool GuiDocument::providesOSF(string const & font) const
1820 return isFontAvailable("eco");
1821 if (font == "palatino")
1822 return isFontAvailable("mathpazo");
1827 bool GuiDocument::providesSC(string const & font) const
1829 if (font == "palatino")
1830 return isFontAvailable("mathpazo");
1831 if (font == "utopia")
1832 return isFontAvailable("fourier");
1837 bool GuiDocument::providesScale(string const & font) const
1839 return font == "helvet" || font == "luximono"
1840 || font == "berasans" || font == "beramono";
1844 void GuiDocument::loadModuleNames ()
1846 moduleNames_.clear();
1847 LyXModuleList::const_iterator it = moduleList.begin();
1848 for (; it != moduleList.end(); ++it)
1849 moduleNames_.push_back(it->name);
1850 if (!moduleNames_.empty())
1851 sort(moduleNames_.begin(), moduleNames_.end());
1855 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
1858 } // namespace frontend
1861 #include "GuiDocument_moc.cpp"