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>
63 using std::ostringstream;
68 std::vector<typename Pair::second_type> const
69 getSecond(std::vector<Pair> const & pr)
71 std::vector<typename Pair::second_type> tmp(pr.size());
72 std::transform(pr.begin(), pr.end(), tmp.begin(),
73 boost::bind(&Pair::second, _1));
77 char const * const tex_graphics[] =
79 "default", "dvips", "dvitops", "emtex",
80 "ln", "oztex", "textures", "none", ""
84 char const * const tex_graphics_gui[] =
86 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
87 "LN", "OzTeX", "Textures", N_("None"), ""
91 char const * const tex_fonts_roman[] =
93 "default", "cmr", "lmodern", "ae", "times", "palatino",
94 "charter", "newcent", "bookman", "utopia", "beraserif",
95 "ccfonts", "chancery", ""
99 char const * tex_fonts_roman_gui[] =
101 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
102 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
103 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
104 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
109 char const * const tex_fonts_sans[] =
111 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
115 char const * tex_fonts_sans_gui[] =
117 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
118 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
122 char const * const tex_fonts_monospaced[] =
124 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
128 char const * tex_fonts_monospaced_gui[] =
130 N_("Default"), N_("Computer Modern Typewriter"),
131 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
132 N_("LuxiMono"), N_("CM Typewriter Light"), ""
136 vector<pair<string, lyx::docstring> > pagestyles;
142 using support::token;
143 using support::bformat;
144 using support::findToken;
145 using support::getVectorFromString;
147 /////////////////////////////////////////////////////////////////////
151 /////////////////////////////////////////////////////////////////////
153 PreambleModule::PreambleModule(): current_id_(0)
155 // This is not a memory leak. The object will be destroyed
157 (void) new LaTeXHighlighter(preambleTE->document());
158 setFocusProxy(preambleTE);
159 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
163 void PreambleModule::update(BufferParams const & params, BufferId id)
165 QString preamble = toqstr(params.preamble);
166 // Nothing to do if the params and preamble are unchanged.
167 if (id == current_id_
168 && preamble == preambleTE->document()->toPlainText())
171 QTextCursor cur = preambleTE->textCursor();
172 // Save the coords before switching to the new one.
173 preamble_coords_[current_id_] =
174 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
176 // Save the params address for further use.
178 preambleTE->document()->setPlainText(preamble);
179 Coords::const_iterator it = preamble_coords_.find(current_id_);
180 if (it == preamble_coords_.end())
181 // First time we open this one.
182 preamble_coords_[current_id_] = make_pair(0,0);
184 // Restore saved coords.
185 QTextCursor cur = preambleTE->textCursor();
186 cur.setPosition(it->second.first);
187 preambleTE->setTextCursor(cur);
188 preambleTE->verticalScrollBar()->setValue(it->second.second);
193 void PreambleModule::apply(BufferParams & params)
195 params.preamble = fromqstr(preambleTE->document()->toPlainText());
199 void PreambleModule::closeEvent(QCloseEvent * e)
201 // Save the coords before closing.
202 QTextCursor cur = preambleTE->textCursor();
203 preamble_coords_[current_id_] =
204 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
209 /////////////////////////////////////////////////////////////////////
213 /////////////////////////////////////////////////////////////////////
217 GuiDocument::GuiDocument(GuiView & lv)
218 : GuiDialog(lv, "document")
221 setViewTitle(_("Document Settings"));
223 lang_ = getSecond(getLanguageData(false));
225 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
226 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
227 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
228 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
230 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
231 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
233 // Manage the restore, ok, apply, restore and cancel/close buttons
234 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
236 bc().setApply(applyPB);
237 bc().setCancel(closePB);
238 bc().setRestore(restorePB);
240 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
242 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
243 this, SLOT(change_adaptor()));
244 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
245 this, SLOT(setLSpacing(int)));
246 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
247 this, SLOT(change_adaptor()));
248 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
249 this, SLOT(change_adaptor()));
250 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
251 this, SLOT(change_adaptor()));
252 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
253 this, SLOT(change_adaptor()));
254 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
255 this, SLOT(change_adaptor()));
256 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
257 this, SLOT(change_adaptor()));
258 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
259 this, SLOT(setSkip(int)));
260 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
261 this, SLOT(enableSkip(bool)));
262 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
263 this, SLOT(change_adaptor()));
264 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
265 this, SLOT(change_adaptor()));
266 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
267 this, SLOT(change_adaptor()));
268 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
269 this, SLOT(set_listings_msg()));
270 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
271 this, SLOT(set_listings_msg()));
272 textLayoutModule->listingsTB->setPlainText(
273 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
274 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
275 textLayoutModule->lspacingLE));
276 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
277 textLayoutModule->skipLE));
279 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
280 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
281 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
282 textLayoutModule->skipCO->addItem(qt_("Length"));
283 // remove the %-items from the unit choice
284 textLayoutModule->skipLengthCO->noPercents();
285 textLayoutModule->lspacingCO->insertItem(
286 Spacing::Single, qt_("Single"));
287 textLayoutModule->lspacingCO->insertItem(
288 Spacing::Onehalf, qt_("OneHalf"));
289 textLayoutModule->lspacingCO->insertItem(
290 Spacing::Double, qt_("Double"));
291 textLayoutModule->lspacingCO->insertItem(
292 Spacing::Other, qt_("Custom"));
294 // initialize the length validator
295 bc().addCheckedLineEdit(textLayoutModule->skipLE);
297 fontModule = new UiWidget<Ui::FontUi>;
299 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
300 this, SLOT(change_adaptor()));
301 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
302 this, SLOT(romanChanged(int)));
303 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
304 this, SLOT(change_adaptor()));
305 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
306 this, SLOT(sansChanged(int)));
307 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
308 this, SLOT(change_adaptor()));
309 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
310 this, SLOT(ttChanged(int)));
311 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
312 this, SLOT(change_adaptor()));
313 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
314 this, SLOT(change_adaptor()));
315 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
316 this, SLOT(change_adaptor()));
317 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
318 this, SLOT(change_adaptor()));
319 connect(fontModule->fontScCB, SIGNAL(clicked()),
320 this, SLOT(change_adaptor()));
321 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
322 this, SLOT(change_adaptor()));
324 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
325 QString font = qt_(tex_fonts_roman_gui[n]);
326 if (!isFontAvailable(tex_fonts_roman[n]))
327 font += qt_(" (not installed)");
328 fontModule->fontsRomanCO->addItem(font);
330 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
331 QString font = qt_(tex_fonts_sans_gui[n]);
332 if (!isFontAvailable(tex_fonts_sans[n]))
333 font += qt_(" (not installed)");
334 fontModule->fontsSansCO->addItem(font);
336 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
337 QString font = qt_(tex_fonts_monospaced_gui[n]);
338 if (!isFontAvailable(tex_fonts_monospaced[n]))
339 font += qt_(" (not installed)");
340 fontModule->fontsTypewriterCO->addItem(font);
343 fontModule->fontsizeCO->addItem(qt_("Default"));
344 fontModule->fontsizeCO->addItem(qt_("10"));
345 fontModule->fontsizeCO->addItem(qt_("11"));
346 fontModule->fontsizeCO->addItem(qt_("12"));
348 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
349 fontModule->fontsDefaultCO->addItem(
350 qt_(GuiDocument::fontfamilies_gui[n]));
353 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
355 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
356 this, SLOT(setCustomPapersize(int)));
357 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
358 this, SLOT(setCustomPapersize(int)));
359 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
360 this, SLOT(portraitChanged()));
361 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
362 this, SLOT(change_adaptor()));
363 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
364 this, SLOT(change_adaptor()));
365 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
366 this, SLOT(change_adaptor()));
367 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
368 this, SLOT(change_adaptor()));
369 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
370 this, SLOT(change_adaptor()));
371 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
372 this, SLOT(change_adaptor()));
373 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
374 this, SLOT(change_adaptor()));
375 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
376 this, SLOT(change_adaptor()));
377 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
378 this, SLOT(change_adaptor()));
380 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
381 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
382 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
383 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
384 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
385 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
386 pageLayoutModule->paperheightL);
387 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
388 pageLayoutModule->paperwidthL);
391 QComboBox * cb = pageLayoutModule->papersizeCO;
392 cb->addItem(qt_("Default"));
393 cb->addItem(qt_("Custom"));
394 cb->addItem(qt_("US letter"));
395 cb->addItem(qt_("US legal"));
396 cb->addItem(qt_("US executive"));
397 cb->addItem(qt_("A3"));
398 cb->addItem(qt_("A4"));
399 cb->addItem(qt_("A5"));
400 cb->addItem(qt_("B3"));
401 cb->addItem(qt_("B4"));
402 cb->addItem(qt_("B5"));
403 // remove the %-items from the unit choice
404 pageLayoutModule->paperwidthUnitCO->noPercents();
405 pageLayoutModule->paperheightUnitCO->noPercents();
406 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
407 pageLayoutModule->paperheightLE));
408 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
409 pageLayoutModule->paperwidthLE));
412 marginsModule = new UiWidget<Ui::MarginsUi>;
414 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
415 this, SLOT(setCustomMargins(bool)));
416 connect(marginsModule->marginCB, SIGNAL(clicked()),
417 this, SLOT(change_adaptor()));
418 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
419 this, SLOT(change_adaptor()));
420 connect(marginsModule->topUnit, SIGNAL(activated(int)),
421 this, SLOT(change_adaptor()));
422 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
423 this, SLOT(change_adaptor()));
424 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
425 this, SLOT(change_adaptor()));
426 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
427 this, SLOT(change_adaptor()));
428 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
429 this, SLOT(change_adaptor()));
430 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
431 this, SLOT(change_adaptor()));
432 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
433 this, SLOT(change_adaptor()));
434 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
435 this, SLOT(change_adaptor()));
436 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
437 this, SLOT(change_adaptor()));
438 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
439 this, SLOT(change_adaptor()));
440 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
441 this, SLOT(change_adaptor()));
442 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
443 this, SLOT(change_adaptor()));
444 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
445 this, SLOT(change_adaptor()));
446 marginsModule->topLE->setValidator(unsignedLengthValidator(
447 marginsModule->topLE));
448 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
449 marginsModule->bottomLE));
450 marginsModule->innerLE->setValidator(unsignedLengthValidator(
451 marginsModule->innerLE));
452 marginsModule->outerLE->setValidator(unsignedLengthValidator(
453 marginsModule->outerLE));
454 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
455 marginsModule->headsepLE));
456 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
457 marginsModule->headheightLE));
458 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
459 marginsModule->footskipLE));
461 bc().addCheckedLineEdit(marginsModule->topLE,
462 marginsModule->topL);
463 bc().addCheckedLineEdit(marginsModule->bottomLE,
464 marginsModule->bottomL);
465 bc().addCheckedLineEdit(marginsModule->innerLE,
466 marginsModule->innerL);
467 bc().addCheckedLineEdit(marginsModule->outerLE,
468 marginsModule->outerL);
469 bc().addCheckedLineEdit(marginsModule->headsepLE,
470 marginsModule->headsepL);
471 bc().addCheckedLineEdit(marginsModule->headheightLE,
472 marginsModule->headheightL);
473 bc().addCheckedLineEdit(marginsModule->footskipLE,
474 marginsModule->footskipL);
477 langModule = new UiWidget<Ui::LanguageUi>;
479 connect(langModule->languageCO, SIGNAL(activated(int)),
480 this, SLOT(change_adaptor()));
481 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
482 this, SLOT(change_adaptor()));
483 connect(langModule->otherencodingRB, SIGNAL(clicked()),
484 this, SLOT(change_adaptor()));
485 connect(langModule->encodingCO, SIGNAL(activated(int)),
486 this, SLOT(change_adaptor()));
487 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
488 this, SLOT(change_adaptor()));
490 vector<LanguagePair> const langs = getLanguageData(false);
491 vector<LanguagePair>::const_iterator lit = langs.begin();
492 vector<LanguagePair>::const_iterator lend = langs.end();
493 for (; lit != lend; ++lit) {
494 langModule->languageCO->addItem(toqstr(lit->first));
497 // Always put the default encoding in the first position.
498 // It is special because the displayed text is translated.
499 langModule->encodingCO->addItem(qt_("LaTeX default"));
500 Encodings::const_iterator it = encodings.begin();
501 Encodings::const_iterator const end = encodings.end();
502 for (; it != end; ++it)
503 langModule->encodingCO->addItem(toqstr(it->latexName()));
505 langModule->quoteStyleCO->addItem(qt_("``text''"));
506 langModule->quoteStyleCO->addItem(qt_("''text''"));
507 langModule->quoteStyleCO->addItem(qt_(",,text``"));
508 langModule->quoteStyleCO->addItem(qt_(",,text''"));
509 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
510 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
514 numberingModule = new UiWidget<Ui::NumberingUi>;
516 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
517 this, SLOT(change_adaptor()));
518 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
519 this, SLOT(change_adaptor()));
520 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
521 this, SLOT(updateNumbering()));
522 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
523 this, SLOT(updateNumbering()));
524 numberingModule->tocTW->setColumnCount(3);
525 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
526 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
527 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
530 biblioModule = new UiWidget<Ui::BiblioUi>;
531 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
532 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
533 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
534 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
536 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
537 this, SLOT(change_adaptor()));
538 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
539 this, SLOT(change_adaptor()));
540 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
541 this, SLOT(change_adaptor()));
542 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
543 this, SLOT(change_adaptor()));
544 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
545 this, SLOT(change_adaptor()));
547 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
548 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
549 biblioModule->citeStyleCO->setCurrentIndex(0);
552 mathsModule = new UiWidget<Ui::MathsUi>;
553 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
554 mathsModule->amsCB, SLOT(setDisabled(bool)));
555 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
556 mathsModule->esintCB, SLOT(setDisabled(bool)));
558 connect(mathsModule->amsCB, SIGNAL(clicked()),
559 this, SLOT(change_adaptor()));
560 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
561 this, SLOT(change_adaptor()));
562 connect(mathsModule->esintCB, SIGNAL(clicked()),
563 this, SLOT(change_adaptor()));
564 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
565 this, SLOT(change_adaptor()));
567 latexModule = new UiWidget<Ui::LaTeXUi>;
569 connect(latexModule->classCO, SIGNAL(activated(int)),
570 this, SLOT(change_adaptor()));
571 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
572 this, SLOT(change_adaptor()));
573 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
574 this, SLOT(change_adaptor()));
575 connect(latexModule->classCO, SIGNAL(activated(int)),
576 this, SLOT(classChanged()));
579 new GuiSelectionManager(latexModule->availableLV, latexModule->selectedLV,
580 latexModule->addPB, latexModule->deletePB,
581 latexModule->upPB, latexModule->downPB,
582 availableModel(), selectedModel());
583 connect(selectionManager, SIGNAL(updateHook()),
584 this, SLOT(updateModuleInfo()));
585 connect(selectionManager, SIGNAL(updateHook()),
586 this, SLOT(change_adaptor()));
588 // postscript drivers
589 for (int n = 0; tex_graphics[n][0]; ++n) {
590 QString enc = qt_(tex_graphics_gui[n]);
591 latexModule->psdriverCO->addItem(enc);
594 //FIXME This seems too involved with the kernel. Some of this
595 //should be moved to the kernel---which should perhaps just
596 //give us a list of entries or something of the sort.
597 for (TextClassList::const_iterator cit = textclasslist.begin();
598 cit != textclasslist.end(); ++cit) {
599 if (cit->isTeXClassAvailable()) {
600 latexModule->classCO->addItem(toqstr(cit->description()));
603 bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
604 latexModule->classCO->addItem(toqstr(item));
609 branchesModule = new GuiBranches;
610 connect(branchesModule, SIGNAL(changed()),
611 this, SLOT(change_adaptor()));
614 preambleModule = new PreambleModule;
615 connect(preambleModule, SIGNAL(changed()),
616 this, SLOT(change_adaptor()));
619 bulletsModule = new BulletsModule;
620 connect(bulletsModule, SIGNAL(changed()),
621 this, SLOT(change_adaptor()));
624 embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
625 connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
626 this, SLOT(change_adaptor()));
627 connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
628 this, SLOT(change_adaptor()));
629 connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
630 this, SLOT(change_adaptor()));
633 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
635 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
636 this, SLOT(change_adaptor()));
637 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
638 this, SLOT(change_adaptor()));
639 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
640 this, SLOT(change_adaptor()));
641 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
642 this, SLOT(change_adaptor()));
643 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
644 this, SLOT(change_adaptor()));
645 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
646 this, SLOT(change_adaptor()));
647 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
648 this, SLOT(change_adaptor()));
649 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
650 this, SLOT(change_adaptor()));
651 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
652 this, SLOT(change_adaptor()));
653 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
654 this, SLOT(change_adaptor()));
655 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
656 this, SLOT(change_adaptor()));
657 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
658 this, SLOT(change_adaptor()));
659 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
660 this, SLOT(change_adaptor()));
661 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
662 this, SLOT(change_adaptor()));
663 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
664 this, SLOT(change_adaptor()));
665 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
666 this, SLOT(change_adaptor()));
667 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
668 this, SLOT(change_adaptor()));
671 floatModule = new FloatPlacement;
672 connect(floatModule, SIGNAL(changed()),
673 this, SLOT(change_adaptor()));
675 docPS->addPanel(latexModule, _("Document Class"));
676 docPS->addPanel(fontModule, _("Fonts"));
677 docPS->addPanel(textLayoutModule, _("Text Layout"));
678 docPS->addPanel(pageLayoutModule, _("Page Layout"));
679 docPS->addPanel(marginsModule, _("Page Margins"));
680 docPS->addPanel(langModule, _("Language"));
681 docPS->addPanel(numberingModule, _("Numbering & TOC"));
682 docPS->addPanel(biblioModule, _("Bibliography"));
683 docPS->addPanel(pdfSupportModule, _("PDF Properties"));
684 docPS->addPanel(mathsModule, _("Math Options"));
685 docPS->addPanel(floatModule, _("Float Placement"));
686 docPS->addPanel(bulletsModule, _("Bullets"));
687 docPS->addPanel(branchesModule, _("Branches"));
688 docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
689 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
690 docPS->setCurrentPanel(_("Document Class"));
691 // FIXME: hack to work around resizing bug in Qt >= 4.2
692 // bug verified with Qt 4.2.{0-3} (JSpitzm)
693 #if QT_VERSION >= 0x040200
694 docPS->updateGeometry();
699 void GuiDocument::showPreamble()
701 docPS->setCurrentPanel(_("LaTeX Preamble"));
705 void GuiDocument::saveDefaultClicked()
711 void GuiDocument::useDefaultsClicked()
717 void GuiDocument::change_adaptor()
723 docstring GuiDocument::validate_listings_params()
725 // use a cache here to avoid repeated validation
726 // of the same parameters
727 static string param_cache = string();
728 static docstring msg_cache = docstring();
730 if (textLayoutModule->bypassCB->isChecked())
733 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
734 if (params != param_cache) {
735 param_cache = params;
736 msg_cache = InsetListingsParams(params).validate();
742 void GuiDocument::set_listings_msg()
744 static bool isOK = true;
745 docstring msg = validate_listings_params();
750 // listingsTB->setTextColor("black");
751 textLayoutModule->listingsTB->setPlainText(
752 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
755 // listingsTB->setTextColor("red");
756 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
761 void GuiDocument::closeEvent(QCloseEvent * e)
768 void GuiDocument::setLSpacing(int item)
770 textLayoutModule->lspacingLE->setEnabled(item == 3);
774 void GuiDocument::setSkip(int item)
776 bool const enable = (item == 3);
777 textLayoutModule->skipLE->setEnabled(enable);
778 textLayoutModule->skipLengthCO->setEnabled(enable);
782 void GuiDocument::enableSkip(bool skip)
784 textLayoutModule->skipCO->setEnabled(skip);
785 textLayoutModule->skipLE->setEnabled(skip);
786 textLayoutModule->skipLengthCO->setEnabled(skip);
788 setSkip(textLayoutModule->skipCO->currentIndex());
791 void GuiDocument::portraitChanged()
793 setMargins(pageLayoutModule->papersizeCO->currentIndex());
796 void GuiDocument::setMargins(bool custom)
798 marginsModule->marginCB->setChecked(custom);
799 setCustomMargins(custom);
803 void GuiDocument::setCustomPapersize(int papersize)
805 bool const custom = (papersize == 1);
807 pageLayoutModule->paperwidthL->setEnabled(custom);
808 pageLayoutModule->paperwidthLE->setEnabled(custom);
809 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
810 pageLayoutModule->paperheightL->setEnabled(custom);
811 pageLayoutModule->paperheightLE->setEnabled(custom);
812 pageLayoutModule->paperheightLE->setFocus();
813 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
817 void GuiDocument::setCustomMargins(bool custom)
819 marginsModule->topL->setEnabled(!custom);
820 marginsModule->topLE->setEnabled(!custom);
821 marginsModule->topUnit->setEnabled(!custom);
823 marginsModule->bottomL->setEnabled(!custom);
824 marginsModule->bottomLE->setEnabled(!custom);
825 marginsModule->bottomUnit->setEnabled(!custom);
827 marginsModule->innerL->setEnabled(!custom);
828 marginsModule->innerLE->setEnabled(!custom);
829 marginsModule->innerUnit->setEnabled(!custom);
831 marginsModule->outerL->setEnabled(!custom);
832 marginsModule->outerLE->setEnabled(!custom);
833 marginsModule->outerUnit->setEnabled(!custom);
835 marginsModule->headheightL->setEnabled(!custom);
836 marginsModule->headheightLE->setEnabled(!custom);
837 marginsModule->headheightUnit->setEnabled(!custom);
839 marginsModule->headsepL->setEnabled(!custom);
840 marginsModule->headsepLE->setEnabled(!custom);
841 marginsModule->headsepUnit->setEnabled(!custom);
843 marginsModule->footskipL->setEnabled(!custom);
844 marginsModule->footskipLE->setEnabled(!custom);
845 marginsModule->footskipUnit->setEnabled(!custom);
849 void GuiDocument::updateFontsize(string const & items, string const & sel)
851 fontModule->fontsizeCO->clear();
852 fontModule->fontsizeCO->addItem(qt_("Default"));
854 for (int n = 0; !token(items,'|',n).empty(); ++n)
855 fontModule->fontsizeCO->
856 addItem(toqstr(token(items,'|',n)));
858 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
859 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
860 fontModule->fontsizeCO->setCurrentIndex(n);
867 void GuiDocument::romanChanged(int item)
869 string const font = tex_fonts_roman[item];
870 fontModule->fontScCB->setEnabled(providesSC(font));
871 fontModule->fontOsfCB->setEnabled(providesOSF(font));
875 void GuiDocument::sansChanged(int item)
877 string const font = tex_fonts_sans[item];
878 bool scaleable = providesScale(font);
879 fontModule->scaleSansSB->setEnabled(scaleable);
880 fontModule->scaleSansLA->setEnabled(scaleable);
884 void GuiDocument::ttChanged(int item)
886 string const font = tex_fonts_monospaced[item];
887 bool scaleable = providesScale(font);
888 fontModule->scaleTypewriterSB->setEnabled(scaleable);
889 fontModule->scaleTypewriterLA->setEnabled(scaleable);
893 void GuiDocument::updatePagestyle(string const & items, string const & sel)
896 pageLayoutModule->pagestyleCO->clear();
897 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
899 for (int n = 0; !token(items,'|',n).empty(); ++n) {
900 string style = token(items, '|', n);
901 docstring style_gui = _(style);
902 pagestyles.push_back(pair<string, docstring>(style, style_gui));
903 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
906 if (sel == "default") {
907 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
913 for (size_t i = 0; i < pagestyles.size(); ++i)
914 if (pagestyles[i].first == sel)
915 nn = pageLayoutModule->pagestyleCO->findText(
916 toqstr(pagestyles[i].second));
919 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
923 void GuiDocument::classChanged()
925 textclass_type const tc = latexModule->classCO->currentIndex();
926 bp_.setJustBaseClass(tc);
927 if (lyxrc.auto_reset_options)
928 bp_.useClassDefaults();
933 void GuiDocument::updateModuleInfo()
935 selectionManager->update();
937 QListView const * const lv = selectionManager->selectedFocused() ?
938 latexModule->selectedLV :
939 latexModule->availableLV;
940 if (lv->selectionModel()->selectedIndexes().isEmpty())
941 latexModule->infoML->document()->clear();
943 QModelIndex const idx = lv->selectionModel()->currentIndex();
944 string const modName = fromqstr(idx.data().toString());
945 string desc = getModuleDescription(modName);
946 vector<string> pkgList = getPackageList(modName);
948 //this mess formats the package list as "pkg1, pkg2, and pkg3"
949 int const pkgListSize = pkgList.size();
950 for (int i = 0; i < pkgListSize; ++i) {
952 if (i == pkgListSize - 1) //last element
957 if (i == pkgListSize - 1) //last element
962 pkgdesc += pkgList[i];
964 if (!pkgdesc.empty())
965 desc += " Requires " + pkgdesc + ".";
966 latexModule->infoML->document()->setPlainText(toqstr(desc));
971 void GuiDocument::updateEmbeddedFileList()
973 embeddedFilesModule->filesLW->clear();
974 // add current embedded files
975 EmbeddedFiles & files = buffer().embeddedFiles();
977 EmbeddedFiles::EmbeddedFileList::iterator fit = files.begin();
978 EmbeddedFiles::EmbeddedFileList::iterator fit_end = files.end();
979 for (; fit != fit_end; ++fit) {
980 QString label = toqstr(fit->relFilename(buffer().filePath()));
981 if (fit->refCount() > 1)
982 label += " (" + QString::number(fit->refCount()) + ")";
983 QListWidgetItem * item = new QListWidgetItem(label);
984 item->setFlags(item->flags() | Qt::ItemIsSelectable
985 | Qt::ItemIsUserCheckable);
987 item->setCheckState(Qt::Checked);
989 item->setCheckState(Qt::Unchecked);
990 // index of the currently used ParConstIterator
991 embeddedFilesModule->filesLW->addItem(item);
996 void GuiDocument::updateNumbering()
998 TextClass const & tclass = bp_.getTextClass();
1000 numberingModule->tocTW->setUpdatesEnabled(false);
1001 numberingModule->tocTW->clear();
1003 int const depth = numberingModule->depthSL->value();
1004 int const toc = numberingModule->tocSL->value();
1005 QString const no = qt_("No");
1006 QString const yes = qt_("Yes");
1007 TextClass::const_iterator end = tclass.end();
1008 TextClass::const_iterator cit = tclass.begin();
1009 QTreeWidgetItem * item = 0;
1010 for ( ; cit != end ; ++cit) {
1011 int const toclevel = (*cit)->toclevel;
1012 if (toclevel != Layout::NOT_IN_TOC
1013 && (*cit)->labeltype == LABEL_COUNTER) {
1014 item = new QTreeWidgetItem(numberingModule->tocTW);
1015 item->setText(0, toqstr(translateIfPossible((*cit)->name())));
1016 item->setText(1, (toclevel <= depth) ? yes : no);
1017 item->setText(2, (toclevel <= toc) ? yes : no);
1021 numberingModule->tocTW->setUpdatesEnabled(true);
1022 numberingModule->tocTW->update();
1026 void GuiDocument::apply(BufferParams & params)
1029 preambleModule->apply(params);
1032 params.setCiteEngine(biblio::ENGINE_BASIC);
1034 if (biblioModule->citeNatbibRB->isChecked()) {
1035 bool const use_numerical_citations =
1036 biblioModule->citeStyleCO->currentIndex();
1037 if (use_numerical_citations)
1038 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1040 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1042 } else if (biblioModule->citeJurabibRB->isChecked())
1043 params.setCiteEngine(biblio::ENGINE_JURABIB);
1045 params.use_bibtopic =
1046 biblioModule->bibtopicCB->isChecked();
1048 // language & quotes
1049 if (langModule->defaultencodingRB->isChecked()) {
1050 params.inputenc = "auto";
1052 int i = langModule->encodingCO->currentIndex();
1054 params.inputenc = "default";
1057 fromqstr(langModule->encodingCO->currentText());
1060 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1061 switch (langModule->quoteStyleCO->currentIndex()) {
1063 lga = InsetQuotes::EnglishQ;
1066 lga = InsetQuotes::SwedishQ;
1069 lga = InsetQuotes::GermanQ;
1072 lga = InsetQuotes::PolishQ;
1075 lga = InsetQuotes::FrenchQ;
1078 lga = InsetQuotes::DanishQ;
1081 params.quotes_language = lga;
1083 int const pos = langModule->languageCO->currentIndex();
1084 params.language = lyx::languages.getLanguage(lang_[pos]);
1087 if (params.getTextClass().hasTocLevels()) {
1088 params.tocdepth = numberingModule->tocSL->value();
1089 params.secnumdepth = numberingModule->depthSL->value();
1093 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1094 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1095 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1096 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1099 params.graphicsDriver =
1100 tex_graphics[latexModule->psdriverCO->currentIndex()];
1103 params.clearLayoutModules();
1104 QStringList const selMods = selectedModel()->stringList();
1105 for (int i = 0; i != selMods.size(); ++i)
1106 params.addLayoutModule(lyx::fromqstr(selMods[i]));
1109 if (mathsModule->amsautoCB->isChecked()) {
1110 params.use_amsmath = BufferParams::package_auto;
1112 if (mathsModule->amsCB->isChecked())
1113 params.use_amsmath = BufferParams::package_on;
1115 params.use_amsmath = BufferParams::package_off;
1118 if (mathsModule->esintautoCB->isChecked())
1119 params.use_esint = BufferParams::package_auto;
1121 if (mathsModule->esintCB->isChecked())
1122 params.use_esint = BufferParams::package_on;
1124 params.use_esint = BufferParams::package_off;
1128 params.setJustBaseClass(latexModule->classCO->currentIndex());
1130 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1131 params.pagestyle = "default";
1133 docstring style_gui =
1134 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1135 for (size_t i = 0; i < pagestyles.size(); ++i)
1136 if (pagestyles[i].second == style_gui)
1137 params.pagestyle = pagestyles[i].first;
1140 switch (textLayoutModule->lspacingCO->currentIndex()) {
1142 params.spacing().set(Spacing::Single);
1145 params.spacing().set(Spacing::Onehalf);
1148 params.spacing().set(Spacing::Double);
1151 params.spacing().set(Spacing::Other,
1152 fromqstr(textLayoutModule->lspacingLE->text()));
1156 if (textLayoutModule->twoColumnCB->isChecked())
1161 // text should have passed validation
1162 params.listings_params =
1163 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1165 if (textLayoutModule->indentRB->isChecked())
1166 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1168 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1170 switch (textLayoutModule->skipCO->currentIndex()) {
1172 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1175 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1178 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1183 widgetsToLength(textLayoutModule->skipLE,
1184 textLayoutModule->skipLengthCO)
1186 params.setDefSkip(vs);
1190 // DocumentDefskipCB assures that this never happens
1191 // so Assert then !!! - jbl
1192 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1197 fromqstr(latexModule->optionsLE->text());
1199 params.float_placement = floatModule->get();
1203 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1206 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1208 params.fontsTypewriter =
1209 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1211 params.fontsSansScale = fontModule->scaleSansSB->value();
1213 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1215 params.fontsSC = fontModule->fontScCB->isChecked();
1217 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1219 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1220 fontModule->fontsDefaultCO->currentIndex()];
1222 if (fontModule->fontsizeCO->currentIndex() == 0)
1223 params.fontsize = "default";
1226 fromqstr(fontModule->fontsizeCO->currentText());
1229 params.papersize = PAPER_SIZE(
1230 pageLayoutModule->papersizeCO->currentIndex());
1232 // custom, A3, B3 and B4 paper sizes need geometry
1233 int psize = pageLayoutModule->papersizeCO->currentIndex();
1234 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1236 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1237 pageLayoutModule->paperwidthUnitCO);
1239 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1240 pageLayoutModule->paperheightUnitCO);
1242 if (pageLayoutModule->facingPagesCB->isChecked())
1243 params.sides = TwoSides;
1245 params.sides = OneSide;
1247 if (pageLayoutModule->landscapeRB->isChecked())
1248 params.orientation = ORIENTATION_LANDSCAPE;
1250 params.orientation = ORIENTATION_PORTRAIT;
1253 params.use_geometry =
1254 (!marginsModule->marginCB->isChecked()
1257 Ui::MarginsUi const * m(marginsModule);
1259 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1260 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1261 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1262 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1263 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1264 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1265 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1267 branchesModule->apply(params);
1270 PDFOptions & pdf = params.pdfoptions();
1271 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1272 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1273 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1274 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1275 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1277 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1278 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1279 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1280 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1282 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1283 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1284 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1285 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1286 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1287 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1288 if (pdfSupportModule->fullscreenCB->isChecked())
1289 pdf.pagemode = pdf.pagemode_fullscreen;
1291 pdf.pagemode.clear();
1292 pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1299 /** Return the position of val in the vector if found.
1300 If not found, return 0.
1303 static size_t findPos(std::vector<A> const & vec, A const & val)
1305 typename std::vector<A>::const_iterator it =
1306 std::find(vec.begin(), vec.end(), val);
1307 if (it == vec.end())
1309 return distance(vec.begin(), it);
1313 void GuiDocument::updateParams()
1319 void GuiDocument::updateParams(BufferParams const & params)
1321 // set the default unit
1322 Length::UNIT defaultUnit = Length::CM;
1323 switch (lyxrc.default_papersize) {
1324 case PAPER_DEFAULT: break;
1326 case PAPER_USLETTER:
1328 case PAPER_USEXECUTIVE:
1329 defaultUnit = Length::IN;
1338 defaultUnit = Length::CM;
1345 preambleModule->update(params, id());
1348 biblioModule->citeDefaultRB->setChecked(
1349 params.getEngine() == biblio::ENGINE_BASIC);
1351 biblioModule->citeNatbibRB->setChecked(
1352 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1353 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1355 biblioModule->citeStyleCO->setCurrentIndex(
1356 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1358 biblioModule->citeJurabibRB->setChecked(
1359 params.getEngine() == biblio::ENGINE_JURABIB);
1361 biblioModule->bibtopicCB->setChecked(
1362 params.use_bibtopic);
1364 // language & quotes
1365 int const pos = int(findPos(lang_,
1366 params.language->lang()));
1367 langModule->languageCO->setCurrentIndex(pos);
1369 langModule->quoteStyleCO->setCurrentIndex(
1370 params.quotes_language);
1372 bool default_enc = true;
1373 if (params.inputenc != "auto") {
1374 default_enc = false;
1375 if (params.inputenc == "default") {
1376 langModule->encodingCO->setCurrentIndex(0);
1378 int const i = langModule->encodingCO->findText(
1379 toqstr(params.inputenc));
1381 langModule->encodingCO->setCurrentIndex(i);
1383 // unknown encoding. Set to default.
1387 langModule->defaultencodingRB->setChecked(default_enc);
1388 langModule->otherencodingRB->setChecked(!default_enc);
1391 int const min_toclevel = textClass().min_toclevel();
1392 int const max_toclevel = textClass().max_toclevel();
1393 if (textClass().hasTocLevels()) {
1394 numberingModule->setEnabled(true);
1395 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1396 numberingModule->depthSL->setMaximum(max_toclevel);
1397 numberingModule->depthSL->setValue(params.secnumdepth);
1398 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1399 numberingModule->tocSL->setMaximum(max_toclevel);
1400 numberingModule->tocSL->setValue(params.tocdepth);
1403 numberingModule->setEnabled(false);
1404 numberingModule->tocTW->clear();
1408 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1409 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1410 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1411 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1412 bulletsModule->init();
1415 int nitem = findToken(tex_graphics, params.graphicsDriver);
1417 latexModule->psdriverCO->setCurrentIndex(nitem);
1420 mathsModule->amsCB->setChecked(
1421 params.use_amsmath == BufferParams::package_on);
1422 mathsModule->amsautoCB->setChecked(
1423 params.use_amsmath == BufferParams::package_auto);
1425 mathsModule->esintCB->setChecked(
1426 params.use_esint == BufferParams::package_on);
1427 mathsModule->esintautoCB->setChecked(
1428 params.use_esint == BufferParams::package_auto);
1430 switch (params.spacing().getSpace()) {
1431 case Spacing::Other: nitem = 3; break;
1432 case Spacing::Double: nitem = 2; break;
1433 case Spacing::Onehalf: nitem = 1; break;
1434 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1438 latexModule->classCO->setCurrentIndex(params.getBaseClass());
1440 updatePagestyle(textClass().opt_pagestyle(),
1443 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1444 if (params.spacing().getSpace() == Spacing::Other) {
1445 textLayoutModule->lspacingLE->setText(
1446 toqstr(params.spacing().getValueAsString()));
1450 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1451 textLayoutModule->indentRB->setChecked(true);
1453 textLayoutModule->skipRB->setChecked(true);
1456 switch (params.getDefSkip().kind()) {
1457 case VSpace::SMALLSKIP:
1460 case VSpace::MEDSKIP:
1463 case VSpace::BIGSKIP:
1466 case VSpace::LENGTH:
1469 string const length = params.getDefSkip().asLyXCommand();
1470 lengthToWidgets(textLayoutModule->skipLE,
1471 textLayoutModule->skipLengthCO,
1472 length, defaultUnit);
1479 textLayoutModule->skipCO->setCurrentIndex(skip);
1482 textLayoutModule->twoColumnCB->setChecked(
1483 params.columns == 2);
1485 // break listings_params to multiple lines
1487 InsetListingsParams(params.listings_params).separatedParams();
1488 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1490 if (!params.options.empty()) {
1491 latexModule->optionsLE->setText(
1492 toqstr(params.options));
1494 latexModule->optionsLE->setText(QString());
1497 floatModule->set(params.float_placement);
1500 updateFontsize(textClass().opt_fontsize(),
1503 int n = findToken(tex_fonts_roman, params.fontsRoman);
1505 fontModule->fontsRomanCO->setCurrentIndex(n);
1509 n = findToken(tex_fonts_sans, params.fontsSans);
1511 fontModule->fontsSansCO->setCurrentIndex(n);
1515 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1517 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1521 fontModule->fontScCB->setChecked(params.fontsSC);
1522 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1523 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1524 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1525 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1527 fontModule->fontsDefaultCO->setCurrentIndex(n);
1530 int const psize = params.papersize;
1531 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1532 setCustomPapersize(psize);
1534 bool const landscape =
1535 params.orientation == ORIENTATION_LANDSCAPE;
1536 pageLayoutModule->landscapeRB->setChecked(landscape);
1537 pageLayoutModule->portraitRB->setChecked(!landscape);
1539 pageLayoutModule->facingPagesCB->setChecked(
1540 params.sides == TwoSides);
1543 lengthToWidgets(pageLayoutModule->paperwidthLE,
1544 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1546 lengthToWidgets(pageLayoutModule->paperheightLE,
1547 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1550 Ui::MarginsUi * m = marginsModule;
1552 setMargins(!params.use_geometry);
1554 lengthToWidgets(m->topLE, m->topUnit,
1555 params.topmargin, defaultUnit);
1557 lengthToWidgets(m->bottomLE, m->bottomUnit,
1558 params.bottommargin, defaultUnit);
1560 lengthToWidgets(m->innerLE, m->innerUnit,
1561 params.leftmargin, defaultUnit);
1563 lengthToWidgets(m->outerLE, m->outerUnit,
1564 params.rightmargin, defaultUnit);
1566 lengthToWidgets(m->headheightLE, m->headheightUnit,
1567 params.headheight, defaultUnit);
1569 lengthToWidgets(m->headsepLE, m->headsepUnit,
1570 params.headsep, defaultUnit);
1572 lengthToWidgets(m->footskipLE, m->footskipUnit,
1573 params.footskip, defaultUnit);
1575 branchesModule->update(params);
1578 PDFOptions const & pdf = params.pdfoptions();
1579 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1580 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1581 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1582 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1583 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1585 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1586 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1587 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1589 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1591 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1592 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1593 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
1594 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1595 pdfSupportModule->backrefCB->setChecked(pdf.backref);
1596 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1597 pdfSupportModule->fullscreenCB->setChecked
1598 (pdf.pagemode == pdf.pagemode_fullscreen);
1600 pdfSupportModule->optionsLE->setText(
1601 toqstr(pdf.quoted_options));
1604 updateEmbeddedFileList();
1608 void GuiDocument::applyView()
1614 void GuiDocument::saveDocDefault()
1616 // we have to apply the params first
1622 void GuiDocument::updateContents()
1624 //update list of available modules
1625 QStringList strlist;
1626 vector<string> const modNames = getModuleNames();
1627 vector<string>::const_iterator it = modNames.begin();
1628 for (; it != modNames.end(); ++it)
1629 strlist.push_back(toqstr(*it));
1630 available_model_.setStringList(strlist);
1631 //and selected ones, too
1632 QStringList strlist2;
1633 vector<string> const & selMods = getSelectedModules();
1634 it = selMods.begin();
1635 for (; it != selMods.end(); ++it)
1636 strlist2.push_back(toqstr(*it));
1637 selected_model_.setStringList(strlist2);
1642 void GuiDocument::useClassDefaults()
1644 bp_.setJustBaseClass(latexModule->classCO->currentIndex());
1645 bp_.useClassDefaults();
1650 bool GuiDocument::isValid()
1652 return validate_listings_params().empty();
1656 char const * const GuiDocument::fontfamilies[5] = {
1657 "default", "rmdefault", "sfdefault", "ttdefault", ""
1661 char const * GuiDocument::fontfamilies_gui[5] = {
1662 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
1666 bool GuiDocument::initialiseParams(string const &)
1668 bp_ = buffer().params();
1674 void GuiDocument::clearParams()
1676 bp_ = BufferParams();
1680 BufferId GuiDocument::id() const
1686 vector<string> GuiDocument::getModuleNames()
1688 return moduleNames_;
1692 vector<string> const & GuiDocument::getSelectedModules()
1694 return params().getModules();
1698 string GuiDocument::getModuleDescription(string const & modName) const
1700 LyXModule const * const mod = moduleList[modName];
1702 return string("Module unavailable!");
1703 return mod->description;
1708 GuiDocument::getPackageList(string const & modName) const
1710 LyXModule const * const mod = moduleList[modName];
1712 return vector<string>(); //empty such thing
1713 return mod->packageList;
1717 TextClass const & GuiDocument::textClass() const
1719 return textclasslist[bp_.getBaseClass()];
1723 static void dispatch_bufferparams(Dialog const & dialog,
1724 BufferParams const & bp, kb_action lfun)
1727 ss << "\\begin_header\n";
1729 ss << "\\end_header\n";
1730 dialog.dispatch(FuncRequest(lfun, ss.str()));
1734 void GuiDocument::dispatchParams()
1736 // This must come first so that a language change is correctly noticed
1739 // Apply the BufferParams. Note that this will set the base class
1740 // and then update the buffer's layout.
1741 //FIXME Could this be done last? Then, I think, we'd get the automatic
1742 //update mentioned in the next FIXME...
1743 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
1745 // Generate the colours requested by each new branch.
1746 BranchList & branchlist = params().branchlist();
1747 if (!branchlist.empty()) {
1748 BranchList::const_iterator it = branchlist.begin();
1749 BranchList::const_iterator const end = branchlist.end();
1750 for (; it != end; ++it) {
1751 docstring const & current_branch = it->getBranch();
1752 Branch const * branch = branchlist.find(current_branch);
1753 string const x11hexname = X11hexname(branch->getColor());
1754 // display the new color
1755 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
1756 dispatch(FuncRequest(LFUN_SET_COLOR, str));
1759 // Open insets of selected branches, close deselected ones
1760 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
1763 // FIXME: If we used an LFUN, we would not need those two lines:
1764 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
1768 void GuiDocument::setLanguage() const
1770 Language const * const newL = bp_.language;
1771 if (buffer().params().language == newL)
1774 string const & lang_name = newL->lang();
1775 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
1779 void GuiDocument::saveAsDefault() const
1781 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
1785 bool GuiDocument::isFontAvailable(string const & font) const
1787 if (font == "default" || font == "cmr"
1788 || font == "cmss" || font == "cmtt")
1789 // these are standard
1791 if (font == "lmodern" || font == "lmss" || font == "lmtt")
1792 return LaTeXFeatures::isAvailable("lmodern");
1793 if (font == "times" || font == "palatino"
1794 || font == "helvet" || font == "courier")
1795 return LaTeXFeatures::isAvailable("psnfss");
1796 if (font == "cmbr" || font == "cmtl")
1797 return LaTeXFeatures::isAvailable("cmbright");
1798 if (font == "utopia")
1799 return LaTeXFeatures::isAvailable("utopia")
1800 || LaTeXFeatures::isAvailable("fourier");
1801 if (font == "beraserif" || font == "berasans"
1802 || font == "beramono")
1803 return LaTeXFeatures::isAvailable("bera");
1804 return LaTeXFeatures::isAvailable(font);
1808 bool GuiDocument::providesOSF(string const & font) const
1811 return isFontAvailable("eco");
1812 if (font == "palatino")
1813 return isFontAvailable("mathpazo");
1818 bool GuiDocument::providesSC(string const & font) const
1820 if (font == "palatino")
1821 return isFontAvailable("mathpazo");
1822 if (font == "utopia")
1823 return isFontAvailable("fourier");
1828 bool GuiDocument::providesScale(string const & font) const
1830 return font == "helvet" || font == "luximono"
1831 || font == "berasans" || font == "beramono";
1835 void GuiDocument::loadModuleNames ()
1837 moduleNames_.clear();
1838 LyXModuleList::const_iterator it = moduleList.begin();
1839 for (; it != moduleList.end(); ++it)
1840 moduleNames_.push_back(it->name);
1841 if (!moduleNames_.empty())
1842 sort(moduleNames_.begin(), moduleNames_.end());
1846 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
1849 } // namespace frontend
1852 #include "GuiDocument_moc.cpp"