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"
26 #include "support/gettext.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"
43 #include "insets/InsetListingsParams.h"
45 #include "support/FileName.h"
46 #include "support/filetools.h"
47 #include "support/lstrings.h"
49 #include <boost/bind.hpp>
51 #include <QCloseEvent>
53 #include <QTextCursor>
62 std::vector<typename Pair::second_type> const
63 getSecond(std::vector<Pair> const & pr)
65 std::vector<typename Pair::second_type> tmp(pr.size());
66 std::transform(pr.begin(), pr.end(), tmp.begin(),
67 boost::bind(&Pair::second, _1));
71 char const * const tex_graphics[] =
73 "default", "dvips", "dvitops", "emtex",
74 "ln", "oztex", "textures", "none", ""
78 char const * const tex_graphics_gui[] =
80 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
81 "LN", "OzTeX", "Textures", N_("None"), ""
85 char const * const tex_fonts_roman[] =
87 "default", "cmr", "lmodern", "ae", "times", "palatino",
88 "charter", "newcent", "bookman", "utopia", "beraserif",
89 "ccfonts", "chancery", ""
93 char const * tex_fonts_roman_gui[] =
95 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
96 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
97 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
98 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
103 char const * const tex_fonts_sans[] =
105 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
109 char const * tex_fonts_sans_gui[] =
111 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
112 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
116 char const * const tex_fonts_monospaced[] =
118 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
122 char const * tex_fonts_monospaced_gui[] =
124 N_("Default"), N_("Computer Modern Typewriter"),
125 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
126 N_("LuxiMono"), N_("CM Typewriter Light"), ""
130 vector<pair<string, lyx::docstring> > pagestyles;
136 using support::token;
137 using support::bformat;
138 using support::findToken;
139 using support::getVectorFromString;
141 /////////////////////////////////////////////////////////////////////
145 /////////////////////////////////////////////////////////////////////
147 PreambleModule::PreambleModule(): current_id_(0)
149 // This is not a memory leak. The object will be destroyed
151 (void) new LaTeXHighlighter(preambleTE->document());
152 setFocusProxy(preambleTE);
153 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
157 void PreambleModule::update(BufferParams const & params, BufferId id)
159 QString preamble = toqstr(params.preamble);
160 // Nothing to do if the params and preamble are unchanged.
161 if (id == current_id_
162 && preamble == preambleTE->document()->toPlainText())
165 QTextCursor cur = preambleTE->textCursor();
166 // Save the coords before switching to the new one.
167 preamble_coords_[current_id_] =
168 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
170 // Save the params address for further use.
172 preambleTE->document()->setPlainText(preamble);
173 Coords::const_iterator it = preamble_coords_.find(current_id_);
174 if (it == preamble_coords_.end())
175 // First time we open this one.
176 preamble_coords_[current_id_] = make_pair(0,0);
178 // Restore saved coords.
179 QTextCursor cur = preambleTE->textCursor();
180 cur.setPosition(it->second.first);
181 preambleTE->setTextCursor(cur);
182 preambleTE->verticalScrollBar()->setValue(it->second.second);
187 void PreambleModule::apply(BufferParams & params)
189 params.preamble = fromqstr(preambleTE->document()->toPlainText());
193 void PreambleModule::closeEvent(QCloseEvent * e)
195 // Save the coords before closing.
196 QTextCursor cur = preambleTE->textCursor();
197 preamble_coords_[current_id_] =
198 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
203 /////////////////////////////////////////////////////////////////////
207 /////////////////////////////////////////////////////////////////////
211 GuiDocument::GuiDocument(GuiView & lv)
212 : GuiDialog(lv, "document")
215 setViewTitle(_("Document Settings"));
217 lang_ = getSecond(getLanguageData(false));
219 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
220 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
221 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
222 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
224 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
225 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
227 // Manage the restore, ok, apply, restore and cancel/close buttons
228 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
230 bc().setApply(applyPB);
231 bc().setCancel(closePB);
232 bc().setRestore(restorePB);
234 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
236 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
237 this, SLOT(change_adaptor()));
238 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
239 this, SLOT(setLSpacing(int)));
240 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
241 this, SLOT(change_adaptor()));
242 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
243 this, SLOT(change_adaptor()));
244 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
245 this, SLOT(change_adaptor()));
246 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
247 this, SLOT(change_adaptor()));
248 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
249 this, SLOT(change_adaptor()));
250 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
251 this, SLOT(change_adaptor()));
252 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
253 this, SLOT(setSkip(int)));
254 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
255 this, SLOT(enableSkip(bool)));
256 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
257 this, SLOT(change_adaptor()));
258 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
259 this, SLOT(change_adaptor()));
260 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
261 this, SLOT(change_adaptor()));
262 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
263 this, SLOT(set_listings_msg()));
264 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
265 this, SLOT(set_listings_msg()));
266 textLayoutModule->listingsTB->setPlainText(
267 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
268 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
269 textLayoutModule->lspacingLE));
270 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
271 textLayoutModule->skipLE));
273 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
274 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
275 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
276 textLayoutModule->skipCO->addItem(qt_("Length"));
277 // remove the %-items from the unit choice
278 textLayoutModule->skipLengthCO->noPercents();
279 textLayoutModule->lspacingCO->insertItem(
280 Spacing::Single, qt_("Single"));
281 textLayoutModule->lspacingCO->insertItem(
282 Spacing::Onehalf, qt_("OneHalf"));
283 textLayoutModule->lspacingCO->insertItem(
284 Spacing::Double, qt_("Double"));
285 textLayoutModule->lspacingCO->insertItem(
286 Spacing::Other, qt_("Custom"));
288 // initialize the length validator
289 bc().addCheckedLineEdit(textLayoutModule->skipLE);
291 fontModule = new UiWidget<Ui::FontUi>;
293 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
294 this, SLOT(change_adaptor()));
295 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
296 this, SLOT(romanChanged(int)));
297 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
298 this, SLOT(change_adaptor()));
299 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
300 this, SLOT(sansChanged(int)));
301 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
302 this, SLOT(change_adaptor()));
303 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
304 this, SLOT(ttChanged(int)));
305 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
306 this, SLOT(change_adaptor()));
307 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
308 this, SLOT(change_adaptor()));
309 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
310 this, SLOT(change_adaptor()));
311 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
312 this, SLOT(change_adaptor()));
313 connect(fontModule->fontScCB, SIGNAL(clicked()),
314 this, SLOT(change_adaptor()));
315 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
316 this, SLOT(change_adaptor()));
318 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
319 QString font = qt_(tex_fonts_roman_gui[n]);
320 if (!isFontAvailable(tex_fonts_roman[n]))
321 font += qt_(" (not installed)");
322 fontModule->fontsRomanCO->addItem(font);
324 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
325 QString font = qt_(tex_fonts_sans_gui[n]);
326 if (!isFontAvailable(tex_fonts_sans[n]))
327 font += qt_(" (not installed)");
328 fontModule->fontsSansCO->addItem(font);
330 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
331 QString font = qt_(tex_fonts_monospaced_gui[n]);
332 if (!isFontAvailable(tex_fonts_monospaced[n]))
333 font += qt_(" (not installed)");
334 fontModule->fontsTypewriterCO->addItem(font);
337 fontModule->fontsizeCO->addItem(qt_("Default"));
338 fontModule->fontsizeCO->addItem(qt_("10"));
339 fontModule->fontsizeCO->addItem(qt_("11"));
340 fontModule->fontsizeCO->addItem(qt_("12"));
342 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
343 fontModule->fontsDefaultCO->addItem(
344 qt_(GuiDocument::fontfamilies_gui[n]));
347 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
349 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
350 this, SLOT(setCustomPapersize(int)));
351 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
352 this, SLOT(setCustomPapersize(int)));
353 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
354 this, SLOT(portraitChanged()));
355 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
356 this, SLOT(change_adaptor()));
357 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
358 this, SLOT(change_adaptor()));
359 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
360 this, SLOT(change_adaptor()));
361 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
362 this, SLOT(change_adaptor()));
363 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
364 this, SLOT(change_adaptor()));
365 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
366 this, SLOT(change_adaptor()));
367 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
368 this, SLOT(change_adaptor()));
369 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
370 this, SLOT(change_adaptor()));
371 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
372 this, SLOT(change_adaptor()));
374 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
375 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
376 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
377 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
378 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
379 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
380 pageLayoutModule->paperheightL);
381 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
382 pageLayoutModule->paperwidthL);
385 QComboBox * cb = pageLayoutModule->papersizeCO;
386 cb->addItem(qt_("Default"));
387 cb->addItem(qt_("Custom"));
388 cb->addItem(qt_("US letter"));
389 cb->addItem(qt_("US legal"));
390 cb->addItem(qt_("US executive"));
391 cb->addItem(qt_("A3"));
392 cb->addItem(qt_("A4"));
393 cb->addItem(qt_("A5"));
394 cb->addItem(qt_("B3"));
395 cb->addItem(qt_("B4"));
396 cb->addItem(qt_("B5"));
397 // remove the %-items from the unit choice
398 pageLayoutModule->paperwidthUnitCO->noPercents();
399 pageLayoutModule->paperheightUnitCO->noPercents();
400 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
401 pageLayoutModule->paperheightLE));
402 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
403 pageLayoutModule->paperwidthLE));
406 marginsModule = new UiWidget<Ui::MarginsUi>;
408 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
409 this, SLOT(setCustomMargins(bool)));
410 connect(marginsModule->marginCB, SIGNAL(clicked()),
411 this, SLOT(change_adaptor()));
412 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
413 this, SLOT(change_adaptor()));
414 connect(marginsModule->topUnit, SIGNAL(activated(int)),
415 this, SLOT(change_adaptor()));
416 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
417 this, SLOT(change_adaptor()));
418 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
419 this, SLOT(change_adaptor()));
420 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
421 this, SLOT(change_adaptor()));
422 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
423 this, SLOT(change_adaptor()));
424 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
425 this, SLOT(change_adaptor()));
426 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
427 this, SLOT(change_adaptor()));
428 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
429 this, SLOT(change_adaptor()));
430 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
431 this, SLOT(change_adaptor()));
432 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
433 this, SLOT(change_adaptor()));
434 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
435 this, SLOT(change_adaptor()));
436 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
437 this, SLOT(change_adaptor()));
438 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
439 this, SLOT(change_adaptor()));
440 marginsModule->topLE->setValidator(unsignedLengthValidator(
441 marginsModule->topLE));
442 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
443 marginsModule->bottomLE));
444 marginsModule->innerLE->setValidator(unsignedLengthValidator(
445 marginsModule->innerLE));
446 marginsModule->outerLE->setValidator(unsignedLengthValidator(
447 marginsModule->outerLE));
448 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
449 marginsModule->headsepLE));
450 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
451 marginsModule->headheightLE));
452 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
453 marginsModule->footskipLE));
455 bc().addCheckedLineEdit(marginsModule->topLE,
456 marginsModule->topL);
457 bc().addCheckedLineEdit(marginsModule->bottomLE,
458 marginsModule->bottomL);
459 bc().addCheckedLineEdit(marginsModule->innerLE,
460 marginsModule->innerL);
461 bc().addCheckedLineEdit(marginsModule->outerLE,
462 marginsModule->outerL);
463 bc().addCheckedLineEdit(marginsModule->headsepLE,
464 marginsModule->headsepL);
465 bc().addCheckedLineEdit(marginsModule->headheightLE,
466 marginsModule->headheightL);
467 bc().addCheckedLineEdit(marginsModule->footskipLE,
468 marginsModule->footskipL);
471 langModule = new UiWidget<Ui::LanguageUi>;
473 connect(langModule->languageCO, SIGNAL(activated(int)),
474 this, SLOT(change_adaptor()));
475 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
476 this, SLOT(change_adaptor()));
477 connect(langModule->otherencodingRB, SIGNAL(clicked()),
478 this, SLOT(change_adaptor()));
479 connect(langModule->encodingCO, SIGNAL(activated(int)),
480 this, SLOT(change_adaptor()));
481 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
482 this, SLOT(change_adaptor()));
484 vector<LanguagePair> const langs = getLanguageData(false);
485 vector<LanguagePair>::const_iterator lit = langs.begin();
486 vector<LanguagePair>::const_iterator lend = langs.end();
487 for (; lit != lend; ++lit) {
488 langModule->languageCO->addItem(toqstr(lit->first));
491 // Always put the default encoding in the first position.
492 // It is special because the displayed text is translated.
493 langModule->encodingCO->addItem(qt_("LaTeX default"));
494 Encodings::const_iterator it = encodings.begin();
495 Encodings::const_iterator const end = encodings.end();
496 for (; it != end; ++it)
497 langModule->encodingCO->addItem(toqstr(it->latexName()));
499 langModule->quoteStyleCO->addItem(qt_("``text''"));
500 langModule->quoteStyleCO->addItem(qt_("''text''"));
501 langModule->quoteStyleCO->addItem(qt_(",,text``"));
502 langModule->quoteStyleCO->addItem(qt_(",,text''"));
503 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
504 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
508 numberingModule = new UiWidget<Ui::NumberingUi>;
510 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
511 this, SLOT(change_adaptor()));
512 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
513 this, SLOT(change_adaptor()));
514 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
515 this, SLOT(updateNumbering()));
516 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
517 this, SLOT(updateNumbering()));
518 numberingModule->tocTW->setColumnCount(3);
519 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
520 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
521 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
524 biblioModule = new UiWidget<Ui::BiblioUi>;
525 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
526 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
527 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
528 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
530 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
531 this, SLOT(change_adaptor()));
532 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
533 this, SLOT(change_adaptor()));
534 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
535 this, SLOT(change_adaptor()));
536 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
537 this, SLOT(change_adaptor()));
538 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
539 this, SLOT(change_adaptor()));
541 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
542 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
543 biblioModule->citeStyleCO->setCurrentIndex(0);
546 mathsModule = new UiWidget<Ui::MathsUi>;
547 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
548 mathsModule->amsCB, SLOT(setDisabled(bool)));
549 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
550 mathsModule->esintCB, SLOT(setDisabled(bool)));
552 connect(mathsModule->amsCB, SIGNAL(clicked()),
553 this, SLOT(change_adaptor()));
554 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
555 this, SLOT(change_adaptor()));
556 connect(mathsModule->esintCB, SIGNAL(clicked()),
557 this, SLOT(change_adaptor()));
558 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
559 this, SLOT(change_adaptor()));
561 latexModule = new UiWidget<Ui::LaTeXUi>;
563 connect(latexModule->classCO, SIGNAL(activated(int)),
564 this, SLOT(change_adaptor()));
565 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
566 this, SLOT(change_adaptor()));
567 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
568 this, SLOT(change_adaptor()));
569 connect(latexModule->classCO, SIGNAL(activated(int)),
570 this, SLOT(classChanged()));
573 new GuiSelectionManager(latexModule->availableLV, latexModule->selectedLV,
574 latexModule->addPB, latexModule->deletePB,
575 latexModule->upPB, latexModule->downPB,
576 availableModel(), selectedModel());
577 connect(selectionManager, SIGNAL(updateHook()),
578 this, SLOT(updateModuleInfo()));
579 connect(selectionManager, SIGNAL(updateHook()),
580 this, SLOT(change_adaptor()));
582 // postscript drivers
583 for (int n = 0; tex_graphics[n][0]; ++n) {
584 QString enc = qt_(tex_graphics_gui[n]);
585 latexModule->psdriverCO->addItem(enc);
588 //FIXME This seems too involved with the kernel. Some of this
589 //should be moved to the kernel---which should perhaps just
590 //give us a list of entries or something of the sort.
591 for (TextClassList::const_iterator cit = textclasslist.begin();
592 cit != textclasslist.end(); ++cit) {
593 if (cit->isTeXClassAvailable()) {
594 latexModule->classCO->addItem(toqstr(cit->description()));
597 bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
598 latexModule->classCO->addItem(toqstr(item));
603 branchesModule = new GuiBranches;
604 connect(branchesModule, SIGNAL(changed()),
605 this, SLOT(change_adaptor()));
608 preambleModule = new PreambleModule;
609 connect(preambleModule, SIGNAL(changed()),
610 this, SLOT(change_adaptor()));
613 bulletsModule = new BulletsModule;
614 connect(bulletsModule, SIGNAL(changed()),
615 this, SLOT(change_adaptor()));
618 embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
619 connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
620 this, SLOT(change_adaptor()));
621 connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
622 this, SLOT(change_adaptor()));
623 connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
624 this, SLOT(change_adaptor()));
627 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
629 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
630 this, SLOT(change_adaptor()));
631 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
632 this, SLOT(change_adaptor()));
633 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
634 this, SLOT(change_adaptor()));
635 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
636 this, SLOT(change_adaptor()));
637 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
638 this, SLOT(change_adaptor()));
639 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
640 this, SLOT(change_adaptor()));
641 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
642 this, SLOT(change_adaptor()));
643 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
644 this, SLOT(change_adaptor()));
645 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
646 this, SLOT(change_adaptor()));
647 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
648 this, SLOT(change_adaptor()));
649 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
650 this, SLOT(change_adaptor()));
651 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
652 this, SLOT(change_adaptor()));
653 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
654 this, SLOT(change_adaptor()));
655 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
656 this, SLOT(change_adaptor()));
657 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
658 this, SLOT(change_adaptor()));
659 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
660 this, SLOT(change_adaptor()));
661 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
662 this, SLOT(change_adaptor()));
665 floatModule = new FloatPlacement;
666 connect(floatModule, SIGNAL(changed()),
667 this, SLOT(change_adaptor()));
669 docPS->addPanel(latexModule, _("Document Class"));
670 docPS->addPanel(fontModule, _("Fonts"));
671 docPS->addPanel(textLayoutModule, _("Text Layout"));
672 docPS->addPanel(pageLayoutModule, _("Page Layout"));
673 docPS->addPanel(marginsModule, _("Page Margins"));
674 docPS->addPanel(langModule, _("Language"));
675 docPS->addPanel(numberingModule, _("Numbering & TOC"));
676 docPS->addPanel(biblioModule, _("Bibliography"));
677 docPS->addPanel(pdfSupportModule, _("PDF Properties"));
678 docPS->addPanel(mathsModule, _("Math Options"));
679 docPS->addPanel(floatModule, _("Float Placement"));
680 docPS->addPanel(bulletsModule, _("Bullets"));
681 docPS->addPanel(branchesModule, _("Branches"));
682 docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
683 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
684 docPS->setCurrentPanel(_("Document Class"));
685 // FIXME: hack to work around resizing bug in Qt >= 4.2
686 // bug verified with Qt 4.2.{0-3} (JSpitzm)
687 #if QT_VERSION >= 0x040200
688 docPS->updateGeometry();
693 void GuiDocument::showPreamble()
695 docPS->setCurrentPanel(_("LaTeX Preamble"));
699 void GuiDocument::saveDefaultClicked()
705 void GuiDocument::useDefaultsClicked()
711 void GuiDocument::change_adaptor()
717 docstring GuiDocument::validate_listings_params()
719 // use a cache here to avoid repeated validation
720 // of the same parameters
721 static string param_cache = string();
722 static docstring msg_cache = docstring();
724 if (textLayoutModule->bypassCB->isChecked())
727 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
728 if (params != param_cache) {
729 param_cache = params;
730 msg_cache = InsetListingsParams(params).validate();
736 void GuiDocument::set_listings_msg()
738 static bool isOK = true;
739 docstring msg = validate_listings_params();
744 // listingsTB->setTextColor("black");
745 textLayoutModule->listingsTB->setPlainText(
746 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
749 // listingsTB->setTextColor("red");
750 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
755 void GuiDocument::closeEvent(QCloseEvent * e)
762 void GuiDocument::setLSpacing(int item)
764 textLayoutModule->lspacingLE->setEnabled(item == 3);
768 void GuiDocument::setSkip(int item)
770 bool const enable = (item == 3);
771 textLayoutModule->skipLE->setEnabled(enable);
772 textLayoutModule->skipLengthCO->setEnabled(enable);
776 void GuiDocument::enableSkip(bool skip)
778 textLayoutModule->skipCO->setEnabled(skip);
779 textLayoutModule->skipLE->setEnabled(skip);
780 textLayoutModule->skipLengthCO->setEnabled(skip);
782 setSkip(textLayoutModule->skipCO->currentIndex());
785 void GuiDocument::portraitChanged()
787 setMargins(pageLayoutModule->papersizeCO->currentIndex());
790 void GuiDocument::setMargins(bool custom)
792 marginsModule->marginCB->setChecked(custom);
793 setCustomMargins(custom);
797 void GuiDocument::setCustomPapersize(int papersize)
799 bool const custom = (papersize == 1);
801 pageLayoutModule->paperwidthL->setEnabled(custom);
802 pageLayoutModule->paperwidthLE->setEnabled(custom);
803 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
804 pageLayoutModule->paperheightL->setEnabled(custom);
805 pageLayoutModule->paperheightLE->setEnabled(custom);
806 pageLayoutModule->paperheightLE->setFocus();
807 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
811 void GuiDocument::setCustomMargins(bool custom)
813 marginsModule->topL->setEnabled(!custom);
814 marginsModule->topLE->setEnabled(!custom);
815 marginsModule->topUnit->setEnabled(!custom);
817 marginsModule->bottomL->setEnabled(!custom);
818 marginsModule->bottomLE->setEnabled(!custom);
819 marginsModule->bottomUnit->setEnabled(!custom);
821 marginsModule->innerL->setEnabled(!custom);
822 marginsModule->innerLE->setEnabled(!custom);
823 marginsModule->innerUnit->setEnabled(!custom);
825 marginsModule->outerL->setEnabled(!custom);
826 marginsModule->outerLE->setEnabled(!custom);
827 marginsModule->outerUnit->setEnabled(!custom);
829 marginsModule->headheightL->setEnabled(!custom);
830 marginsModule->headheightLE->setEnabled(!custom);
831 marginsModule->headheightUnit->setEnabled(!custom);
833 marginsModule->headsepL->setEnabled(!custom);
834 marginsModule->headsepLE->setEnabled(!custom);
835 marginsModule->headsepUnit->setEnabled(!custom);
837 marginsModule->footskipL->setEnabled(!custom);
838 marginsModule->footskipLE->setEnabled(!custom);
839 marginsModule->footskipUnit->setEnabled(!custom);
843 void GuiDocument::updateFontsize(string const & items, string const & sel)
845 fontModule->fontsizeCO->clear();
846 fontModule->fontsizeCO->addItem(qt_("Default"));
848 for (int n = 0; !token(items,'|',n).empty(); ++n)
849 fontModule->fontsizeCO->
850 addItem(toqstr(token(items,'|',n)));
852 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
853 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
854 fontModule->fontsizeCO->setCurrentIndex(n);
861 void GuiDocument::romanChanged(int item)
863 string const font = tex_fonts_roman[item];
864 fontModule->fontScCB->setEnabled(providesSC(font));
865 fontModule->fontOsfCB->setEnabled(providesOSF(font));
869 void GuiDocument::sansChanged(int item)
871 string const font = tex_fonts_sans[item];
872 bool scaleable = providesScale(font);
873 fontModule->scaleSansSB->setEnabled(scaleable);
874 fontModule->scaleSansLA->setEnabled(scaleable);
878 void GuiDocument::ttChanged(int item)
880 string const font = tex_fonts_monospaced[item];
881 bool scaleable = providesScale(font);
882 fontModule->scaleTypewriterSB->setEnabled(scaleable);
883 fontModule->scaleTypewriterLA->setEnabled(scaleable);
887 void GuiDocument::updatePagestyle(string const & items, string const & sel)
890 pageLayoutModule->pagestyleCO->clear();
891 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
893 for (int n = 0; !token(items,'|',n).empty(); ++n) {
894 string style = token(items, '|', n);
895 docstring style_gui = _(style);
896 pagestyles.push_back(pair<string, docstring>(style, style_gui));
897 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
900 if (sel == "default") {
901 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
907 for (size_t i = 0; i < pagestyles.size(); ++i)
908 if (pagestyles[i].first == sel)
909 nn = pageLayoutModule->pagestyleCO->findText(
910 toqstr(pagestyles[i].second));
913 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
917 void GuiDocument::classChanged()
919 textclass_type const tc = latexModule->classCO->currentIndex();
920 bp_.setJustBaseClass(tc);
921 if (lyxrc.auto_reset_options)
922 bp_.useClassDefaults();
927 void GuiDocument::updateModuleInfo()
929 selectionManager->update();
931 QListView const * const lv = selectionManager->selectedFocused() ?
932 latexModule->selectedLV :
933 latexModule->availableLV;
934 if (lv->selectionModel()->selectedIndexes().isEmpty())
935 latexModule->infoML->document()->clear();
937 QModelIndex const idx = lv->selectionModel()->currentIndex();
938 string const modName = fromqstr(idx.data().toString());
939 string desc = getModuleDescription(modName);
940 vector<string> pkgList = getPackageList(modName);
942 //this mess formats the package list as "pkg1, pkg2, and pkg3"
943 int const pkgListSize = pkgList.size();
944 for (int i = 0; i < pkgListSize; ++i) {
946 if (i == pkgListSize - 1) //last element
951 if (i == pkgListSize - 1) //last element
956 pkgdesc += pkgList[i];
958 if (!pkgdesc.empty())
959 desc += " Requires " + pkgdesc + ".";
960 latexModule->infoML->document()->setPlainText(toqstr(desc));
965 void GuiDocument::updateEmbeddedFileList()
967 embeddedFilesModule->filesLW->clear();
968 // add current embedded files
969 EmbeddedFiles & files = buffer().embeddedFiles();
971 EmbeddedFiles::EmbeddedFileList::iterator fit = files.begin();
972 EmbeddedFiles::EmbeddedFileList::iterator fit_end = files.end();
973 for (; fit != fit_end; ++fit) {
974 QString label = toqstr(fit->relFilename(buffer().filePath()));
975 if (fit->refCount() > 1)
976 label += " (" + QString::number(fit->refCount()) + ")";
977 QListWidgetItem * item = new QListWidgetItem(label);
978 item->setFlags(item->flags() | Qt::ItemIsSelectable
979 | Qt::ItemIsUserCheckable);
981 item->setCheckState(Qt::Checked);
983 item->setCheckState(Qt::Unchecked);
984 // index of the currently used ParConstIterator
985 embeddedFilesModule->filesLW->addItem(item);
990 void GuiDocument::updateNumbering()
992 TextClass const & tclass = bp_.getTextClass();
994 numberingModule->tocTW->setUpdatesEnabled(false);
995 numberingModule->tocTW->clear();
997 int const depth = numberingModule->depthSL->value();
998 int const toc = numberingModule->tocSL->value();
999 QString const no = qt_("No");
1000 QString const yes = qt_("Yes");
1001 TextClass::const_iterator end = tclass.end();
1002 TextClass::const_iterator cit = tclass.begin();
1003 QTreeWidgetItem * item = 0;
1004 for ( ; cit != end ; ++cit) {
1005 int const toclevel = (*cit)->toclevel;
1006 if (toclevel != Layout::NOT_IN_TOC
1007 && (*cit)->labeltype == LABEL_COUNTER) {
1008 item = new QTreeWidgetItem(numberingModule->tocTW);
1009 item->setText(0, toqstr(translateIfPossible((*cit)->name())));
1010 item->setText(1, (toclevel <= depth) ? yes : no);
1011 item->setText(2, (toclevel <= toc) ? yes : no);
1015 numberingModule->tocTW->setUpdatesEnabled(true);
1016 numberingModule->tocTW->update();
1020 void GuiDocument::apply(BufferParams & params)
1023 preambleModule->apply(params);
1026 params.setCiteEngine(biblio::ENGINE_BASIC);
1028 if (biblioModule->citeNatbibRB->isChecked()) {
1029 bool const use_numerical_citations =
1030 biblioModule->citeStyleCO->currentIndex();
1031 if (use_numerical_citations)
1032 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1034 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1036 } else if (biblioModule->citeJurabibRB->isChecked())
1037 params.setCiteEngine(biblio::ENGINE_JURABIB);
1039 params.use_bibtopic =
1040 biblioModule->bibtopicCB->isChecked();
1042 // language & quotes
1043 if (langModule->defaultencodingRB->isChecked()) {
1044 params.inputenc = "auto";
1046 int i = langModule->encodingCO->currentIndex();
1048 params.inputenc = "default";
1051 fromqstr(langModule->encodingCO->currentText());
1054 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1055 switch (langModule->quoteStyleCO->currentIndex()) {
1057 lga = InsetQuotes::EnglishQ;
1060 lga = InsetQuotes::SwedishQ;
1063 lga = InsetQuotes::GermanQ;
1066 lga = InsetQuotes::PolishQ;
1069 lga = InsetQuotes::FrenchQ;
1072 lga = InsetQuotes::DanishQ;
1075 params.quotes_language = lga;
1077 int const pos = langModule->languageCO->currentIndex();
1078 params.language = lyx::languages.getLanguage(lang_[pos]);
1081 if (params.getTextClass().hasTocLevels()) {
1082 params.tocdepth = numberingModule->tocSL->value();
1083 params.secnumdepth = numberingModule->depthSL->value();
1087 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1088 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1089 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1090 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1093 params.graphicsDriver =
1094 tex_graphics[latexModule->psdriverCO->currentIndex()];
1097 params.clearLayoutModules();
1098 QStringList const selMods = selectedModel()->stringList();
1099 for (int i = 0; i != selMods.size(); ++i)
1100 params.addLayoutModule(lyx::fromqstr(selMods[i]));
1103 if (mathsModule->amsautoCB->isChecked()) {
1104 params.use_amsmath = BufferParams::package_auto;
1106 if (mathsModule->amsCB->isChecked())
1107 params.use_amsmath = BufferParams::package_on;
1109 params.use_amsmath = BufferParams::package_off;
1112 if (mathsModule->esintautoCB->isChecked())
1113 params.use_esint = BufferParams::package_auto;
1115 if (mathsModule->esintCB->isChecked())
1116 params.use_esint = BufferParams::package_on;
1118 params.use_esint = BufferParams::package_off;
1122 params.setJustBaseClass(latexModule->classCO->currentIndex());
1124 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1125 params.pagestyle = "default";
1127 docstring style_gui =
1128 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1129 for (size_t i = 0; i < pagestyles.size(); ++i)
1130 if (pagestyles[i].second == style_gui)
1131 params.pagestyle = pagestyles[i].first;
1134 switch (textLayoutModule->lspacingCO->currentIndex()) {
1136 params.spacing().set(Spacing::Single);
1139 params.spacing().set(Spacing::Onehalf);
1142 params.spacing().set(Spacing::Double);
1145 params.spacing().set(Spacing::Other,
1146 fromqstr(textLayoutModule->lspacingLE->text()));
1150 if (textLayoutModule->twoColumnCB->isChecked())
1155 // text should have passed validation
1156 params.listings_params =
1157 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1159 if (textLayoutModule->indentRB->isChecked())
1160 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1162 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1164 switch (textLayoutModule->skipCO->currentIndex()) {
1166 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1169 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1172 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1177 widgetsToLength(textLayoutModule->skipLE,
1178 textLayoutModule->skipLengthCO)
1180 params.setDefSkip(vs);
1184 // DocumentDefskipCB assures that this never happens
1185 // so Assert then !!! - jbl
1186 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1191 fromqstr(latexModule->optionsLE->text());
1193 params.float_placement = floatModule->get();
1197 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1200 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1202 params.fontsTypewriter =
1203 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1205 params.fontsSansScale = fontModule->scaleSansSB->value();
1207 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1209 params.fontsSC = fontModule->fontScCB->isChecked();
1211 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1213 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1214 fontModule->fontsDefaultCO->currentIndex()];
1216 if (fontModule->fontsizeCO->currentIndex() == 0)
1217 params.fontsize = "default";
1220 fromqstr(fontModule->fontsizeCO->currentText());
1223 params.papersize = PAPER_SIZE(
1224 pageLayoutModule->papersizeCO->currentIndex());
1226 // custom, A3, B3 and B4 paper sizes need geometry
1227 int psize = pageLayoutModule->papersizeCO->currentIndex();
1228 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1230 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1231 pageLayoutModule->paperwidthUnitCO);
1233 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1234 pageLayoutModule->paperheightUnitCO);
1236 if (pageLayoutModule->facingPagesCB->isChecked())
1237 params.sides = TwoSides;
1239 params.sides = OneSide;
1241 if (pageLayoutModule->landscapeRB->isChecked())
1242 params.orientation = ORIENTATION_LANDSCAPE;
1244 params.orientation = ORIENTATION_PORTRAIT;
1247 params.use_geometry =
1248 (!marginsModule->marginCB->isChecked()
1251 Ui::MarginsUi const * m(marginsModule);
1253 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1254 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1255 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1256 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1257 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1258 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1259 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1261 branchesModule->apply(params);
1264 PDFOptions & pdf = params.pdfoptions();
1265 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1266 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1267 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1268 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1269 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1271 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1272 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1273 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1274 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1276 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1277 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1278 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1279 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1280 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1281 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1282 if (pdfSupportModule->fullscreenCB->isChecked())
1283 pdf.pagemode = pdf.pagemode_fullscreen;
1285 pdf.pagemode.clear();
1286 pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1293 /** Return the position of val in the vector if found.
1294 If not found, return 0.
1297 static size_t findPos(std::vector<A> const & vec, A const & val)
1299 typename std::vector<A>::const_iterator it =
1300 std::find(vec.begin(), vec.end(), val);
1301 if (it == vec.end())
1303 return distance(vec.begin(), it);
1307 void GuiDocument::updateParams()
1313 void GuiDocument::updateParams(BufferParams const & params)
1315 // set the default unit
1316 Length::UNIT defaultUnit = Length::CM;
1317 switch (lyxrc.default_papersize) {
1318 case PAPER_DEFAULT: break;
1320 case PAPER_USLETTER:
1322 case PAPER_USEXECUTIVE:
1323 defaultUnit = Length::IN;
1332 defaultUnit = Length::CM;
1339 preambleModule->update(params, id());
1342 biblioModule->citeDefaultRB->setChecked(
1343 params.getEngine() == biblio::ENGINE_BASIC);
1345 biblioModule->citeNatbibRB->setChecked(
1346 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1347 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1349 biblioModule->citeStyleCO->setCurrentIndex(
1350 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1352 biblioModule->citeJurabibRB->setChecked(
1353 params.getEngine() == biblio::ENGINE_JURABIB);
1355 biblioModule->bibtopicCB->setChecked(
1356 params.use_bibtopic);
1358 // language & quotes
1359 int const pos = int(findPos(lang_,
1360 params.language->lang()));
1361 langModule->languageCO->setCurrentIndex(pos);
1363 langModule->quoteStyleCO->setCurrentIndex(
1364 params.quotes_language);
1366 bool default_enc = true;
1367 if (params.inputenc != "auto") {
1368 default_enc = false;
1369 if (params.inputenc == "default") {
1370 langModule->encodingCO->setCurrentIndex(0);
1372 int const i = langModule->encodingCO->findText(
1373 toqstr(params.inputenc));
1375 langModule->encodingCO->setCurrentIndex(i);
1377 // unknown encoding. Set to default.
1381 langModule->defaultencodingRB->setChecked(default_enc);
1382 langModule->otherencodingRB->setChecked(!default_enc);
1385 int const min_toclevel = textClass().min_toclevel();
1386 int const max_toclevel = textClass().max_toclevel();
1387 if (textClass().hasTocLevels()) {
1388 numberingModule->setEnabled(true);
1389 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1390 numberingModule->depthSL->setMaximum(max_toclevel);
1391 numberingModule->depthSL->setValue(params.secnumdepth);
1392 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1393 numberingModule->tocSL->setMaximum(max_toclevel);
1394 numberingModule->tocSL->setValue(params.tocdepth);
1397 numberingModule->setEnabled(false);
1398 numberingModule->tocTW->clear();
1402 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1403 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1404 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1405 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1406 bulletsModule->init();
1409 int nitem = findToken(tex_graphics, params.graphicsDriver);
1411 latexModule->psdriverCO->setCurrentIndex(nitem);
1414 mathsModule->amsCB->setChecked(
1415 params.use_amsmath == BufferParams::package_on);
1416 mathsModule->amsautoCB->setChecked(
1417 params.use_amsmath == BufferParams::package_auto);
1419 mathsModule->esintCB->setChecked(
1420 params.use_esint == BufferParams::package_on);
1421 mathsModule->esintautoCB->setChecked(
1422 params.use_esint == BufferParams::package_auto);
1424 switch (params.spacing().getSpace()) {
1425 case Spacing::Other: nitem = 3; break;
1426 case Spacing::Double: nitem = 2; break;
1427 case Spacing::Onehalf: nitem = 1; break;
1428 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1432 latexModule->classCO->setCurrentIndex(params.getBaseClass());
1434 updatePagestyle(textClass().opt_pagestyle(),
1437 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1438 if (params.spacing().getSpace() == Spacing::Other) {
1439 textLayoutModule->lspacingLE->setText(
1440 toqstr(params.spacing().getValueAsString()));
1444 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1445 textLayoutModule->indentRB->setChecked(true);
1447 textLayoutModule->skipRB->setChecked(true);
1450 switch (params.getDefSkip().kind()) {
1451 case VSpace::SMALLSKIP:
1454 case VSpace::MEDSKIP:
1457 case VSpace::BIGSKIP:
1460 case VSpace::LENGTH:
1463 string const length = params.getDefSkip().asLyXCommand();
1464 lengthToWidgets(textLayoutModule->skipLE,
1465 textLayoutModule->skipLengthCO,
1466 length, defaultUnit);
1473 textLayoutModule->skipCO->setCurrentIndex(skip);
1476 textLayoutModule->twoColumnCB->setChecked(
1477 params.columns == 2);
1479 // break listings_params to multiple lines
1481 InsetListingsParams(params.listings_params).separatedParams();
1482 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1484 if (!params.options.empty()) {
1485 latexModule->optionsLE->setText(
1486 toqstr(params.options));
1488 latexModule->optionsLE->setText(QString());
1491 floatModule->set(params.float_placement);
1494 updateFontsize(textClass().opt_fontsize(),
1497 int n = findToken(tex_fonts_roman, params.fontsRoman);
1499 fontModule->fontsRomanCO->setCurrentIndex(n);
1503 n = findToken(tex_fonts_sans, params.fontsSans);
1505 fontModule->fontsSansCO->setCurrentIndex(n);
1509 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1511 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1515 fontModule->fontScCB->setChecked(params.fontsSC);
1516 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1517 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1518 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1519 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1521 fontModule->fontsDefaultCO->setCurrentIndex(n);
1524 int const psize = params.papersize;
1525 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1526 setCustomPapersize(psize);
1528 bool const landscape =
1529 params.orientation == ORIENTATION_LANDSCAPE;
1530 pageLayoutModule->landscapeRB->setChecked(landscape);
1531 pageLayoutModule->portraitRB->setChecked(!landscape);
1533 pageLayoutModule->facingPagesCB->setChecked(
1534 params.sides == TwoSides);
1537 lengthToWidgets(pageLayoutModule->paperwidthLE,
1538 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1540 lengthToWidgets(pageLayoutModule->paperheightLE,
1541 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1544 Ui::MarginsUi * m = marginsModule;
1546 setMargins(!params.use_geometry);
1548 lengthToWidgets(m->topLE, m->topUnit,
1549 params.topmargin, defaultUnit);
1551 lengthToWidgets(m->bottomLE, m->bottomUnit,
1552 params.bottommargin, defaultUnit);
1554 lengthToWidgets(m->innerLE, m->innerUnit,
1555 params.leftmargin, defaultUnit);
1557 lengthToWidgets(m->outerLE, m->outerUnit,
1558 params.rightmargin, defaultUnit);
1560 lengthToWidgets(m->headheightLE, m->headheightUnit,
1561 params.headheight, defaultUnit);
1563 lengthToWidgets(m->headsepLE, m->headsepUnit,
1564 params.headsep, defaultUnit);
1566 lengthToWidgets(m->footskipLE, m->footskipUnit,
1567 params.footskip, defaultUnit);
1569 branchesModule->update(params);
1572 PDFOptions const & pdf = params.pdfoptions();
1573 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1574 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1575 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1576 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1577 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1579 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1580 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1581 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1583 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1585 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1586 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1587 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
1588 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1589 pdfSupportModule->backrefCB->setChecked(pdf.backref);
1590 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1591 pdfSupportModule->fullscreenCB->setChecked
1592 (pdf.pagemode == pdf.pagemode_fullscreen);
1594 pdfSupportModule->optionsLE->setText(
1595 toqstr(pdf.quoted_options));
1598 updateEmbeddedFileList();
1602 void GuiDocument::applyView()
1608 void GuiDocument::saveDocDefault()
1610 // we have to apply the params first
1616 void GuiDocument::updateContents()
1618 //update list of available modules
1619 QStringList strlist;
1620 vector<string> const modNames = getModuleNames();
1621 vector<string>::const_iterator it = modNames.begin();
1622 for (; it != modNames.end(); ++it)
1623 strlist.push_back(toqstr(*it));
1624 available_model_.setStringList(strlist);
1625 //and selected ones, too
1626 QStringList strlist2;
1627 vector<string> const & selMods = getSelectedModules();
1628 it = selMods.begin();
1629 for (; it != selMods.end(); ++it)
1630 strlist2.push_back(toqstr(*it));
1631 selected_model_.setStringList(strlist2);
1636 void GuiDocument::useClassDefaults()
1638 bp_.setJustBaseClass(latexModule->classCO->currentIndex());
1639 bp_.useClassDefaults();
1644 bool GuiDocument::isValid()
1646 return validate_listings_params().empty();
1650 char const * const GuiDocument::fontfamilies[5] = {
1651 "default", "rmdefault", "sfdefault", "ttdefault", ""
1655 char const * GuiDocument::fontfamilies_gui[5] = {
1656 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
1660 bool GuiDocument::initialiseParams(string const &)
1662 bp_ = buffer().params();
1668 void GuiDocument::clearParams()
1670 bp_ = BufferParams();
1674 BufferId GuiDocument::id() const
1680 vector<string> GuiDocument::getModuleNames()
1682 return moduleNames_;
1686 vector<string> const & GuiDocument::getSelectedModules()
1688 return params().getModules();
1692 string GuiDocument::getModuleDescription(string const & modName) const
1694 LyXModule const * const mod = moduleList[modName];
1696 return string("Module unavailable!");
1697 return mod->description;
1702 GuiDocument::getPackageList(string const & modName) const
1704 LyXModule const * const mod = moduleList[modName];
1706 return vector<string>(); //empty such thing
1707 return mod->packageList;
1711 TextClass const & GuiDocument::textClass() const
1713 return textclasslist[bp_.getBaseClass()];
1717 static void dispatch_bufferparams(Dialog const & dialog,
1718 BufferParams const & bp, kb_action lfun)
1721 ss << "\\begin_header\n";
1723 ss << "\\end_header\n";
1724 dialog.dispatch(FuncRequest(lfun, ss.str()));
1728 void GuiDocument::dispatchParams()
1730 // This must come first so that a language change is correctly noticed
1733 // Apply the BufferParams. Note that this will set the base class
1734 // and then update the buffer's layout.
1735 //FIXME Could this be done last? Then, I think, we'd get the automatic
1736 //update mentioned in the next FIXME...
1737 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
1739 // Generate the colours requested by each new branch.
1740 BranchList & branchlist = params().branchlist();
1741 if (!branchlist.empty()) {
1742 BranchList::const_iterator it = branchlist.begin();
1743 BranchList::const_iterator const end = branchlist.end();
1744 for (; it != end; ++it) {
1745 docstring const & current_branch = it->getBranch();
1746 Branch const * branch = branchlist.find(current_branch);
1747 string const x11hexname = X11hexname(branch->getColor());
1748 // display the new color
1749 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
1750 dispatch(FuncRequest(LFUN_SET_COLOR, str));
1753 // Open insets of selected branches, close deselected ones
1754 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
1757 // FIXME: If we used an LFUN, we would not need those two lines:
1758 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
1762 void GuiDocument::setLanguage() const
1764 Language const * const newL = bp_.language;
1765 if (buffer().params().language == newL)
1768 string const & lang_name = newL->lang();
1769 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
1773 void GuiDocument::saveAsDefault() const
1775 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
1779 bool GuiDocument::isFontAvailable(string const & font) const
1781 if (font == "default" || font == "cmr"
1782 || font == "cmss" || font == "cmtt")
1783 // these are standard
1785 if (font == "lmodern" || font == "lmss" || font == "lmtt")
1786 return LaTeXFeatures::isAvailable("lmodern");
1787 if (font == "times" || font == "palatino"
1788 || font == "helvet" || font == "courier")
1789 return LaTeXFeatures::isAvailable("psnfss");
1790 if (font == "cmbr" || font == "cmtl")
1791 return LaTeXFeatures::isAvailable("cmbright");
1792 if (font == "utopia")
1793 return LaTeXFeatures::isAvailable("utopia")
1794 || LaTeXFeatures::isAvailable("fourier");
1795 if (font == "beraserif" || font == "berasans"
1796 || font == "beramono")
1797 return LaTeXFeatures::isAvailable("bera");
1798 return LaTeXFeatures::isAvailable(font);
1802 bool GuiDocument::providesOSF(string const & font) const
1805 return isFontAvailable("eco");
1806 if (font == "palatino")
1807 return isFontAvailable("mathpazo");
1812 bool GuiDocument::providesSC(string const & font) const
1814 if (font == "palatino")
1815 return isFontAvailable("mathpazo");
1816 if (font == "utopia")
1817 return isFontAvailable("fourier");
1822 bool GuiDocument::providesScale(string const & font) const
1824 return font == "helvet" || font == "luximono"
1825 || font == "berasans" || font == "beramono";
1829 void GuiDocument::loadModuleNames ()
1831 moduleNames_.clear();
1832 LyXModuleList::const_iterator it = moduleList.begin();
1833 for (; it != moduleList.end(); ++it)
1834 moduleNames_.push_back(it->name);
1835 if (!moduleNames_.empty())
1836 sort(moduleNames_.begin(), moduleNames_.end());
1840 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
1843 } // namespace frontend
1846 #include "GuiDocument_moc.cpp"