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/lstrings.h"
47 #include <boost/bind.hpp>
49 #include <QCloseEvent>
51 #include <QTextCursor>
61 using std::ostringstream;
66 std::vector<typename Pair::second_type> const
67 getSecond(std::vector<Pair> const & pr)
69 std::vector<typename Pair::second_type> tmp(pr.size());
70 std::transform(pr.begin(), pr.end(), tmp.begin(),
71 boost::bind(&Pair::second, _1));
75 char const * const tex_graphics[] =
77 "default", "dvips", "dvitops", "emtex",
78 "ln", "oztex", "textures", "none", ""
82 char const * const tex_graphics_gui[] =
84 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
85 "LN", "OzTeX", "Textures", N_("None"), ""
89 char const * const tex_fonts_roman[] =
91 "default", "cmr", "lmodern", "ae", "times", "palatino",
92 "charter", "newcent", "bookman", "utopia", "beraserif",
93 "ccfonts", "chancery", ""
97 char const * tex_fonts_roman_gui[] =
99 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
100 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
101 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
102 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
107 char const * const tex_fonts_sans[] =
109 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
113 char const * tex_fonts_sans_gui[] =
115 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
116 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
120 char const * const tex_fonts_monospaced[] =
122 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
126 char const * tex_fonts_monospaced_gui[] =
128 N_("Default"), N_("Computer Modern Typewriter"),
129 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
130 N_("LuxiMono"), N_("CM Typewriter Light"), ""
134 vector<pair<string, lyx::docstring> > pagestyles;
140 using support::token;
141 using support::bformat;
142 using support::findToken;
143 using support::getVectorFromString;
145 /////////////////////////////////////////////////////////////////////
149 /////////////////////////////////////////////////////////////////////
151 PreambleModule::PreambleModule(): current_id_(0)
153 // This is not a memory leak. The object will be destroyed
155 (void) new LaTeXHighlighter(preambleTE->document());
156 setFocusProxy(preambleTE);
157 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
161 void PreambleModule::update(BufferParams const & params, BufferId id)
163 QString preamble = toqstr(params.preamble);
164 // Nothing to do if the params and preamble are unchanged.
165 if (id == current_id_
166 && preamble == preambleTE->document()->toPlainText())
169 QTextCursor cur = preambleTE->textCursor();
170 // Save the coords before switching to the new one.
171 preamble_coords_[current_id_] =
172 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
174 // Save the params address for further use.
176 preambleTE->document()->setPlainText(preamble);
177 Coords::const_iterator it = preamble_coords_.find(current_id_);
178 if (it == preamble_coords_.end())
179 // First time we open this one.
180 preamble_coords_[current_id_] = make_pair(0,0);
182 // Restore saved coords.
183 QTextCursor cur = preambleTE->textCursor();
184 cur.setPosition(it->second.first);
185 preambleTE->setTextCursor(cur);
186 preambleTE->verticalScrollBar()->setValue(it->second.second);
191 void PreambleModule::apply(BufferParams & params)
193 params.preamble = fromqstr(preambleTE->document()->toPlainText());
197 void PreambleModule::closeEvent(QCloseEvent * e)
199 // Save the coords before closing.
200 QTextCursor cur = preambleTE->textCursor();
201 preamble_coords_[current_id_] =
202 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
207 /////////////////////////////////////////////////////////////////////
211 /////////////////////////////////////////////////////////////////////
215 GuiDocument::GuiDocument(GuiView & lv)
216 : GuiDialog(lv, "document")
219 setViewTitle(_("Document Settings"));
221 lang_ = getSecond(getLanguageData(false));
223 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
224 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
225 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
226 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
228 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
229 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
231 // Manage the restore, ok, apply, restore and cancel/close buttons
232 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
234 bc().setApply(applyPB);
235 bc().setCancel(closePB);
236 bc().setRestore(restorePB);
238 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
240 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
241 this, SLOT(change_adaptor()));
242 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
243 this, SLOT(setLSpacing(int)));
244 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
245 this, SLOT(change_adaptor()));
246 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
247 this, SLOT(change_adaptor()));
248 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
249 this, SLOT(change_adaptor()));
250 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
251 this, SLOT(change_adaptor()));
252 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
253 this, SLOT(change_adaptor()));
254 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
255 this, SLOT(change_adaptor()));
256 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
257 this, SLOT(setSkip(int)));
258 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
259 this, SLOT(enableSkip(bool)));
260 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
261 this, SLOT(change_adaptor()));
262 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
263 this, SLOT(change_adaptor()));
264 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
265 this, SLOT(change_adaptor()));
266 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
267 this, SLOT(set_listings_msg()));
268 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
269 this, SLOT(set_listings_msg()));
270 textLayoutModule->listingsTB->setPlainText(
271 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
272 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
273 textLayoutModule->lspacingLE));
274 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
275 textLayoutModule->skipLE));
277 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
278 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
279 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
280 textLayoutModule->skipCO->addItem(qt_("Length"));
281 // remove the %-items from the unit choice
282 textLayoutModule->skipLengthCO->noPercents();
283 textLayoutModule->lspacingCO->insertItem(
284 Spacing::Single, qt_("Single"));
285 textLayoutModule->lspacingCO->insertItem(
286 Spacing::Onehalf, qt_("OneHalf"));
287 textLayoutModule->lspacingCO->insertItem(
288 Spacing::Double, qt_("Double"));
289 textLayoutModule->lspacingCO->insertItem(
290 Spacing::Other, qt_("Custom"));
292 // initialize the length validator
293 bc().addCheckedLineEdit(textLayoutModule->skipLE);
295 fontModule = new UiWidget<Ui::FontUi>;
297 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
298 this, SLOT(change_adaptor()));
299 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
300 this, SLOT(romanChanged(int)));
301 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
302 this, SLOT(change_adaptor()));
303 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
304 this, SLOT(sansChanged(int)));
305 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
306 this, SLOT(change_adaptor()));
307 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
308 this, SLOT(ttChanged(int)));
309 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
310 this, SLOT(change_adaptor()));
311 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
312 this, SLOT(change_adaptor()));
313 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
314 this, SLOT(change_adaptor()));
315 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
316 this, SLOT(change_adaptor()));
317 connect(fontModule->fontScCB, SIGNAL(clicked()),
318 this, SLOT(change_adaptor()));
319 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
320 this, SLOT(change_adaptor()));
322 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
323 QString font = qt_(tex_fonts_roman_gui[n]);
324 if (!isFontAvailable(tex_fonts_roman[n]))
325 font += qt_(" (not installed)");
326 fontModule->fontsRomanCO->addItem(font);
328 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
329 QString font = qt_(tex_fonts_sans_gui[n]);
330 if (!isFontAvailable(tex_fonts_sans[n]))
331 font += qt_(" (not installed)");
332 fontModule->fontsSansCO->addItem(font);
334 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
335 QString font = qt_(tex_fonts_monospaced_gui[n]);
336 if (!isFontAvailable(tex_fonts_monospaced[n]))
337 font += qt_(" (not installed)");
338 fontModule->fontsTypewriterCO->addItem(font);
341 fontModule->fontsizeCO->addItem(qt_("Default"));
342 fontModule->fontsizeCO->addItem(qt_("10"));
343 fontModule->fontsizeCO->addItem(qt_("11"));
344 fontModule->fontsizeCO->addItem(qt_("12"));
346 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
347 fontModule->fontsDefaultCO->addItem(
348 qt_(GuiDocument::fontfamilies_gui[n]));
351 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
353 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
354 this, SLOT(setCustomPapersize(int)));
355 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
356 this, SLOT(setCustomPapersize(int)));
357 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
358 this, SLOT(portraitChanged()));
359 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
360 this, SLOT(change_adaptor()));
361 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
362 this, SLOT(change_adaptor()));
363 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
364 this, SLOT(change_adaptor()));
365 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
366 this, SLOT(change_adaptor()));
367 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
368 this, SLOT(change_adaptor()));
369 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
370 this, SLOT(change_adaptor()));
371 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
372 this, SLOT(change_adaptor()));
373 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
374 this, SLOT(change_adaptor()));
375 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
376 this, SLOT(change_adaptor()));
378 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
379 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
380 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
381 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
382 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
383 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
384 pageLayoutModule->paperheightL);
385 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
386 pageLayoutModule->paperwidthL);
389 QComboBox * cb = pageLayoutModule->papersizeCO;
390 cb->addItem(qt_("Default"));
391 cb->addItem(qt_("Custom"));
392 cb->addItem(qt_("US letter"));
393 cb->addItem(qt_("US legal"));
394 cb->addItem(qt_("US executive"));
395 cb->addItem(qt_("A3"));
396 cb->addItem(qt_("A4"));
397 cb->addItem(qt_("A5"));
398 cb->addItem(qt_("B3"));
399 cb->addItem(qt_("B4"));
400 cb->addItem(qt_("B5"));
401 // remove the %-items from the unit choice
402 pageLayoutModule->paperwidthUnitCO->noPercents();
403 pageLayoutModule->paperheightUnitCO->noPercents();
404 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
405 pageLayoutModule->paperheightLE));
406 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
407 pageLayoutModule->paperwidthLE));
410 marginsModule = new UiWidget<Ui::MarginsUi>;
412 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
413 this, SLOT(setCustomMargins(bool)));
414 connect(marginsModule->marginCB, SIGNAL(clicked()),
415 this, SLOT(change_adaptor()));
416 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
417 this, SLOT(change_adaptor()));
418 connect(marginsModule->topUnit, SIGNAL(activated(int)),
419 this, SLOT(change_adaptor()));
420 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
421 this, SLOT(change_adaptor()));
422 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
423 this, SLOT(change_adaptor()));
424 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
425 this, SLOT(change_adaptor()));
426 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
427 this, SLOT(change_adaptor()));
428 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
429 this, SLOT(change_adaptor()));
430 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
431 this, SLOT(change_adaptor()));
432 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
433 this, SLOT(change_adaptor()));
434 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
435 this, SLOT(change_adaptor()));
436 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
437 this, SLOT(change_adaptor()));
438 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
439 this, SLOT(change_adaptor()));
440 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
441 this, SLOT(change_adaptor()));
442 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
443 this, SLOT(change_adaptor()));
444 marginsModule->topLE->setValidator(unsignedLengthValidator(
445 marginsModule->topLE));
446 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
447 marginsModule->bottomLE));
448 marginsModule->innerLE->setValidator(unsignedLengthValidator(
449 marginsModule->innerLE));
450 marginsModule->outerLE->setValidator(unsignedLengthValidator(
451 marginsModule->outerLE));
452 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
453 marginsModule->headsepLE));
454 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
455 marginsModule->headheightLE));
456 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
457 marginsModule->footskipLE));
459 bc().addCheckedLineEdit(marginsModule->topLE,
460 marginsModule->topL);
461 bc().addCheckedLineEdit(marginsModule->bottomLE,
462 marginsModule->bottomL);
463 bc().addCheckedLineEdit(marginsModule->innerLE,
464 marginsModule->innerL);
465 bc().addCheckedLineEdit(marginsModule->outerLE,
466 marginsModule->outerL);
467 bc().addCheckedLineEdit(marginsModule->headsepLE,
468 marginsModule->headsepL);
469 bc().addCheckedLineEdit(marginsModule->headheightLE,
470 marginsModule->headheightL);
471 bc().addCheckedLineEdit(marginsModule->footskipLE,
472 marginsModule->footskipL);
475 langModule = new UiWidget<Ui::LanguageUi>;
477 connect(langModule->languageCO, SIGNAL(activated(int)),
478 this, SLOT(change_adaptor()));
479 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
480 this, SLOT(change_adaptor()));
481 connect(langModule->otherencodingRB, SIGNAL(clicked()),
482 this, SLOT(change_adaptor()));
483 connect(langModule->encodingCO, SIGNAL(activated(int)),
484 this, SLOT(change_adaptor()));
485 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
486 this, SLOT(change_adaptor()));
488 vector<LanguagePair> const langs = getLanguageData(false);
489 vector<LanguagePair>::const_iterator lit = langs.begin();
490 vector<LanguagePair>::const_iterator lend = langs.end();
491 for (; lit != lend; ++lit) {
492 langModule->languageCO->addItem(toqstr(lit->first));
495 // Always put the default encoding in the first position.
496 // It is special because the displayed text is translated.
497 langModule->encodingCO->addItem(qt_("LaTeX default"));
498 Encodings::const_iterator it = encodings.begin();
499 Encodings::const_iterator const end = encodings.end();
500 for (; it != end; ++it)
501 langModule->encodingCO->addItem(toqstr(it->latexName()));
503 langModule->quoteStyleCO->addItem(qt_("``text''"));
504 langModule->quoteStyleCO->addItem(qt_("''text''"));
505 langModule->quoteStyleCO->addItem(qt_(",,text``"));
506 langModule->quoteStyleCO->addItem(qt_(",,text''"));
507 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
508 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
512 numberingModule = new UiWidget<Ui::NumberingUi>;
514 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
515 this, SLOT(change_adaptor()));
516 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
517 this, SLOT(change_adaptor()));
518 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
519 this, SLOT(updateNumbering()));
520 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
521 this, SLOT(updateNumbering()));
522 numberingModule->tocTW->setColumnCount(3);
523 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
524 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
525 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
528 biblioModule = new UiWidget<Ui::BiblioUi>;
529 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
530 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
531 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
532 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
534 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
535 this, SLOT(change_adaptor()));
536 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
537 this, SLOT(change_adaptor()));
538 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
539 this, SLOT(change_adaptor()));
540 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
541 this, SLOT(change_adaptor()));
542 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
543 this, SLOT(change_adaptor()));
545 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
546 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
547 biblioModule->citeStyleCO->setCurrentIndex(0);
550 mathsModule = new UiWidget<Ui::MathsUi>;
551 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
552 mathsModule->amsCB, SLOT(setDisabled(bool)));
553 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
554 mathsModule->esintCB, SLOT(setDisabled(bool)));
556 connect(mathsModule->amsCB, SIGNAL(clicked()),
557 this, SLOT(change_adaptor()));
558 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
559 this, SLOT(change_adaptor()));
560 connect(mathsModule->esintCB, SIGNAL(clicked()),
561 this, SLOT(change_adaptor()));
562 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
563 this, SLOT(change_adaptor()));
565 latexModule = new UiWidget<Ui::LaTeXUi>;
567 connect(latexModule->classCO, SIGNAL(activated(int)),
568 this, SLOT(change_adaptor()));
569 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
570 this, SLOT(change_adaptor()));
571 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
572 this, SLOT(change_adaptor()));
573 connect(latexModule->classCO, SIGNAL(activated(int)),
574 this, SLOT(classChanged()));
577 new GuiSelectionManager(latexModule->availableLV, latexModule->selectedLV,
578 latexModule->addPB, latexModule->deletePB,
579 latexModule->upPB, latexModule->downPB,
580 availableModel(), selectedModel());
581 connect(selectionManager, SIGNAL(updateHook()),
582 this, SLOT(updateModuleInfo()));
583 connect(selectionManager, SIGNAL(updateHook()),
584 this, SLOT(change_adaptor()));
586 // postscript drivers
587 for (int n = 0; tex_graphics[n][0]; ++n) {
588 QString enc = qt_(tex_graphics_gui[n]);
589 latexModule->psdriverCO->addItem(enc);
592 //FIXME This seems too involved with the kernel. Some of this
593 //should be moved to the kernel---which should perhaps just
594 //give us a list of entries or something of the sort.
595 for (TextClassList::const_iterator cit = textclasslist.begin();
596 cit != textclasslist.end(); ++cit) {
597 if (cit->isTeXClassAvailable()) {
598 latexModule->classCO->addItem(toqstr(cit->description()));
601 bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
602 latexModule->classCO->addItem(toqstr(item));
607 branchesModule = new GuiBranches;
608 connect(branchesModule, SIGNAL(changed()),
609 this, SLOT(change_adaptor()));
612 preambleModule = new PreambleModule;
613 connect(preambleModule, SIGNAL(changed()),
614 this, SLOT(change_adaptor()));
617 bulletsModule = new BulletsModule;
618 connect(bulletsModule, SIGNAL(changed()),
619 this, SLOT(change_adaptor()));
622 embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
623 connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
624 this, SLOT(change_adaptor()));
625 connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
626 this, SLOT(change_adaptor()));
627 connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
628 this, SLOT(change_adaptor()));
631 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
633 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
634 this, SLOT(change_adaptor()));
635 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
636 this, SLOT(change_adaptor()));
637 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
638 this, SLOT(change_adaptor()));
639 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
640 this, SLOT(change_adaptor()));
641 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
642 this, SLOT(change_adaptor()));
643 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
644 this, SLOT(change_adaptor()));
645 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
646 this, SLOT(change_adaptor()));
647 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
648 this, SLOT(change_adaptor()));
649 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
650 this, SLOT(change_adaptor()));
651 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
652 this, SLOT(change_adaptor()));
653 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
654 this, SLOT(change_adaptor()));
655 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
656 this, SLOT(change_adaptor()));
657 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
658 this, SLOT(change_adaptor()));
659 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
660 this, SLOT(change_adaptor()));
661 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
662 this, SLOT(change_adaptor()));
663 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
664 this, SLOT(change_adaptor()));
665 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
666 this, SLOT(change_adaptor()));
669 floatModule = new FloatPlacement;
670 connect(floatModule, SIGNAL(changed()),
671 this, SLOT(change_adaptor()));
673 docPS->addPanel(latexModule, _("Document Class"));
674 docPS->addPanel(fontModule, _("Fonts"));
675 docPS->addPanel(textLayoutModule, _("Text Layout"));
676 docPS->addPanel(pageLayoutModule, _("Page Layout"));
677 docPS->addPanel(marginsModule, _("Page Margins"));
678 docPS->addPanel(langModule, _("Language"));
679 docPS->addPanel(numberingModule, _("Numbering & TOC"));
680 docPS->addPanel(biblioModule, _("Bibliography"));
681 docPS->addPanel(pdfSupportModule, _("PDF Properties"));
682 docPS->addPanel(mathsModule, _("Math Options"));
683 docPS->addPanel(floatModule, _("Float Placement"));
684 docPS->addPanel(bulletsModule, _("Bullets"));
685 docPS->addPanel(branchesModule, _("Branches"));
686 docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
687 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
688 docPS->setCurrentPanel(_("Document Class"));
689 // FIXME: hack to work around resizing bug in Qt >= 4.2
690 // bug verified with Qt 4.2.{0-3} (JSpitzm)
691 #if QT_VERSION >= 0x040200
692 docPS->updateGeometry();
697 void GuiDocument::showPreamble()
699 docPS->setCurrentPanel(_("LaTeX Preamble"));
703 void GuiDocument::saveDefaultClicked()
709 void GuiDocument::useDefaultsClicked()
715 void GuiDocument::change_adaptor()
721 docstring GuiDocument::validate_listings_params()
723 // use a cache here to avoid repeated validation
724 // of the same parameters
725 static string param_cache = string();
726 static docstring msg_cache = docstring();
728 if (textLayoutModule->bypassCB->isChecked())
731 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
732 if (params != param_cache) {
733 param_cache = params;
734 msg_cache = InsetListingsParams(params).validate();
740 void GuiDocument::set_listings_msg()
742 static bool isOK = true;
743 docstring msg = validate_listings_params();
748 // listingsTB->setTextColor("black");
749 textLayoutModule->listingsTB->setPlainText(
750 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
753 // listingsTB->setTextColor("red");
754 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
759 void GuiDocument::closeEvent(QCloseEvent * e)
766 void GuiDocument::setLSpacing(int item)
768 textLayoutModule->lspacingLE->setEnabled(item == 3);
772 void GuiDocument::setSkip(int item)
774 bool const enable = (item == 3);
775 textLayoutModule->skipLE->setEnabled(enable);
776 textLayoutModule->skipLengthCO->setEnabled(enable);
780 void GuiDocument::enableSkip(bool skip)
782 textLayoutModule->skipCO->setEnabled(skip);
783 textLayoutModule->skipLE->setEnabled(skip);
784 textLayoutModule->skipLengthCO->setEnabled(skip);
786 setSkip(textLayoutModule->skipCO->currentIndex());
789 void GuiDocument::portraitChanged()
791 setMargins(pageLayoutModule->papersizeCO->currentIndex());
794 void GuiDocument::setMargins(bool custom)
796 marginsModule->marginCB->setChecked(custom);
797 setCustomMargins(custom);
801 void GuiDocument::setCustomPapersize(int papersize)
803 bool const custom = (papersize == 1);
805 pageLayoutModule->paperwidthL->setEnabled(custom);
806 pageLayoutModule->paperwidthLE->setEnabled(custom);
807 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
808 pageLayoutModule->paperheightL->setEnabled(custom);
809 pageLayoutModule->paperheightLE->setEnabled(custom);
810 pageLayoutModule->paperheightLE->setFocus();
811 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
815 void GuiDocument::setCustomMargins(bool custom)
817 marginsModule->topL->setEnabled(!custom);
818 marginsModule->topLE->setEnabled(!custom);
819 marginsModule->topUnit->setEnabled(!custom);
821 marginsModule->bottomL->setEnabled(!custom);
822 marginsModule->bottomLE->setEnabled(!custom);
823 marginsModule->bottomUnit->setEnabled(!custom);
825 marginsModule->innerL->setEnabled(!custom);
826 marginsModule->innerLE->setEnabled(!custom);
827 marginsModule->innerUnit->setEnabled(!custom);
829 marginsModule->outerL->setEnabled(!custom);
830 marginsModule->outerLE->setEnabled(!custom);
831 marginsModule->outerUnit->setEnabled(!custom);
833 marginsModule->headheightL->setEnabled(!custom);
834 marginsModule->headheightLE->setEnabled(!custom);
835 marginsModule->headheightUnit->setEnabled(!custom);
837 marginsModule->headsepL->setEnabled(!custom);
838 marginsModule->headsepLE->setEnabled(!custom);
839 marginsModule->headsepUnit->setEnabled(!custom);
841 marginsModule->footskipL->setEnabled(!custom);
842 marginsModule->footskipLE->setEnabled(!custom);
843 marginsModule->footskipUnit->setEnabled(!custom);
847 void GuiDocument::updateFontsize(string const & items, string const & sel)
849 fontModule->fontsizeCO->clear();
850 fontModule->fontsizeCO->addItem(qt_("Default"));
852 for (int n = 0; !token(items,'|',n).empty(); ++n)
853 fontModule->fontsizeCO->
854 addItem(toqstr(token(items,'|',n)));
856 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
857 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
858 fontModule->fontsizeCO->setCurrentIndex(n);
865 void GuiDocument::romanChanged(int item)
867 string const font = tex_fonts_roman[item];
868 fontModule->fontScCB->setEnabled(providesSC(font));
869 fontModule->fontOsfCB->setEnabled(providesOSF(font));
873 void GuiDocument::sansChanged(int item)
875 string const font = tex_fonts_sans[item];
876 bool scaleable = providesScale(font);
877 fontModule->scaleSansSB->setEnabled(scaleable);
878 fontModule->scaleSansLA->setEnabled(scaleable);
882 void GuiDocument::ttChanged(int item)
884 string const font = tex_fonts_monospaced[item];
885 bool scaleable = providesScale(font);
886 fontModule->scaleTypewriterSB->setEnabled(scaleable);
887 fontModule->scaleTypewriterLA->setEnabled(scaleable);
891 void GuiDocument::updatePagestyle(string const & items, string const & sel)
894 pageLayoutModule->pagestyleCO->clear();
895 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
897 for (int n = 0; !token(items,'|',n).empty(); ++n) {
898 string style = token(items, '|', n);
899 docstring style_gui = _(style);
900 pagestyles.push_back(pair<string, docstring>(style, style_gui));
901 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
904 if (sel == "default") {
905 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
911 for (size_t i = 0; i < pagestyles.size(); ++i)
912 if (pagestyles[i].first == sel)
913 nn = pageLayoutModule->pagestyleCO->findText(
914 toqstr(pagestyles[i].second));
917 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
921 void GuiDocument::classChanged()
923 textclass_type const tc = latexModule->classCO->currentIndex();
924 bp_.setJustBaseClass(tc);
925 if (lyxrc.auto_reset_options)
926 bp_.useClassDefaults();
931 void GuiDocument::updateModuleInfo()
933 selectionManager->update();
935 QListView const * const lv = selectionManager->selectedFocused() ?
936 latexModule->selectedLV :
937 latexModule->availableLV;
938 if (lv->selectionModel()->selectedIndexes().isEmpty())
939 latexModule->infoML->document()->clear();
941 QModelIndex const idx = lv->selectionModel()->currentIndex();
942 string const modName = fromqstr(idx.data().toString());
943 string desc = getModuleDescription(modName);
944 vector<string> pkgList = getPackageList(modName);
946 //this mess formats the package list as "pkg1, pkg2, and pkg3"
947 int const pkgListSize = pkgList.size();
948 for (int i = 0; i < pkgListSize; ++i) {
950 if (i == pkgListSize - 1) //last element
955 if (i == pkgListSize - 1) //last element
960 pkgdesc += pkgList[i];
962 if (!pkgdesc.empty())
963 desc += " Requires " + pkgdesc + ".";
964 latexModule->infoML->document()->setPlainText(toqstr(desc));
969 void GuiDocument::updateEmbeddedFileList()
971 embeddedFilesModule->filesLW->clear();
972 // add current embedded files
973 EmbeddedFiles & files = buffer().embeddedFiles();
975 EmbeddedFiles::EmbeddedFileList::iterator fit = files.begin();
976 EmbeddedFiles::EmbeddedFileList::iterator fit_end = files.end();
977 for (; fit != fit_end; ++fit) {
978 QString label = toqstr(fit->relFilename(buffer().filePath()));
979 if (fit->refCount() > 1)
980 label += " (" + QString::number(fit->refCount()) + ")";
981 QListWidgetItem * item = new QListWidgetItem(label);
982 item->setFlags(item->flags() | Qt::ItemIsSelectable
983 | Qt::ItemIsUserCheckable);
985 item->setCheckState(Qt::Checked);
987 item->setCheckState(Qt::Unchecked);
988 // index of the currently used ParConstIterator
989 embeddedFilesModule->filesLW->addItem(item);
994 void GuiDocument::updateNumbering()
996 TextClass const & tclass = bp_.getTextClass();
998 numberingModule->tocTW->setUpdatesEnabled(false);
999 numberingModule->tocTW->clear();
1001 int const depth = numberingModule->depthSL->value();
1002 int const toc = numberingModule->tocSL->value();
1003 QString const no = qt_("No");
1004 QString const yes = qt_("Yes");
1005 TextClass::const_iterator end = tclass.end();
1006 TextClass::const_iterator cit = tclass.begin();
1007 QTreeWidgetItem * item = 0;
1008 for ( ; cit != end ; ++cit) {
1009 int const toclevel = (*cit)->toclevel;
1010 if (toclevel != Layout::NOT_IN_TOC
1011 && (*cit)->labeltype == LABEL_COUNTER) {
1012 item = new QTreeWidgetItem(numberingModule->tocTW);
1013 item->setText(0, toqstr(translateIfPossible((*cit)->name())));
1014 item->setText(1, (toclevel <= depth) ? yes : no);
1015 item->setText(2, (toclevel <= toc) ? yes : no);
1019 numberingModule->tocTW->setUpdatesEnabled(true);
1020 numberingModule->tocTW->update();
1024 void GuiDocument::apply(BufferParams & params)
1027 preambleModule->apply(params);
1030 params.setCiteEngine(biblio::ENGINE_BASIC);
1032 if (biblioModule->citeNatbibRB->isChecked()) {
1033 bool const use_numerical_citations =
1034 biblioModule->citeStyleCO->currentIndex();
1035 if (use_numerical_citations)
1036 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1038 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1040 } else if (biblioModule->citeJurabibRB->isChecked())
1041 params.setCiteEngine(biblio::ENGINE_JURABIB);
1043 params.use_bibtopic =
1044 biblioModule->bibtopicCB->isChecked();
1046 // language & quotes
1047 if (langModule->defaultencodingRB->isChecked()) {
1048 params.inputenc = "auto";
1050 int i = langModule->encodingCO->currentIndex();
1052 params.inputenc = "default";
1055 fromqstr(langModule->encodingCO->currentText());
1058 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1059 switch (langModule->quoteStyleCO->currentIndex()) {
1061 lga = InsetQuotes::EnglishQ;
1064 lga = InsetQuotes::SwedishQ;
1067 lga = InsetQuotes::GermanQ;
1070 lga = InsetQuotes::PolishQ;
1073 lga = InsetQuotes::FrenchQ;
1076 lga = InsetQuotes::DanishQ;
1079 params.quotes_language = lga;
1081 int const pos = langModule->languageCO->currentIndex();
1082 params.language = lyx::languages.getLanguage(lang_[pos]);
1085 if (params.getTextClass().hasTocLevels()) {
1086 params.tocdepth = numberingModule->tocSL->value();
1087 params.secnumdepth = numberingModule->depthSL->value();
1091 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1092 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1093 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1094 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1097 params.graphicsDriver =
1098 tex_graphics[latexModule->psdriverCO->currentIndex()];
1101 params.clearLayoutModules();
1102 QStringList const selMods = selectedModel()->stringList();
1103 for (int i = 0; i != selMods.size(); ++i)
1104 params.addLayoutModule(lyx::fromqstr(selMods[i]));
1107 if (mathsModule->amsautoCB->isChecked()) {
1108 params.use_amsmath = BufferParams::package_auto;
1110 if (mathsModule->amsCB->isChecked())
1111 params.use_amsmath = BufferParams::package_on;
1113 params.use_amsmath = BufferParams::package_off;
1116 if (mathsModule->esintautoCB->isChecked())
1117 params.use_esint = BufferParams::package_auto;
1119 if (mathsModule->esintCB->isChecked())
1120 params.use_esint = BufferParams::package_on;
1122 params.use_esint = BufferParams::package_off;
1126 params.setJustBaseClass(latexModule->classCO->currentIndex());
1128 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1129 params.pagestyle = "default";
1131 docstring style_gui =
1132 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1133 for (size_t i = 0; i < pagestyles.size(); ++i)
1134 if (pagestyles[i].second == style_gui)
1135 params.pagestyle = pagestyles[i].first;
1138 switch (textLayoutModule->lspacingCO->currentIndex()) {
1140 params.spacing().set(Spacing::Single);
1143 params.spacing().set(Spacing::Onehalf);
1146 params.spacing().set(Spacing::Double);
1149 params.spacing().set(Spacing::Other,
1150 fromqstr(textLayoutModule->lspacingLE->text()));
1154 if (textLayoutModule->twoColumnCB->isChecked())
1159 // text should have passed validation
1160 params.listings_params =
1161 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1163 if (textLayoutModule->indentRB->isChecked())
1164 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1166 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1168 switch (textLayoutModule->skipCO->currentIndex()) {
1170 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1173 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1176 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1181 widgetsToLength(textLayoutModule->skipLE,
1182 textLayoutModule->skipLengthCO)
1184 params.setDefSkip(vs);
1188 // DocumentDefskipCB assures that this never happens
1189 // so Assert then !!! - jbl
1190 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1195 fromqstr(latexModule->optionsLE->text());
1197 params.float_placement = floatModule->get();
1201 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1204 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1206 params.fontsTypewriter =
1207 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1209 params.fontsSansScale = fontModule->scaleSansSB->value();
1211 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1213 params.fontsSC = fontModule->fontScCB->isChecked();
1215 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1217 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1218 fontModule->fontsDefaultCO->currentIndex()];
1220 if (fontModule->fontsizeCO->currentIndex() == 0)
1221 params.fontsize = "default";
1224 fromqstr(fontModule->fontsizeCO->currentText());
1227 params.papersize = PAPER_SIZE(
1228 pageLayoutModule->papersizeCO->currentIndex());
1230 // custom, A3, B3 and B4 paper sizes need geometry
1231 int psize = pageLayoutModule->papersizeCO->currentIndex();
1232 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1234 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1235 pageLayoutModule->paperwidthUnitCO);
1237 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1238 pageLayoutModule->paperheightUnitCO);
1240 if (pageLayoutModule->facingPagesCB->isChecked())
1241 params.sides = TwoSides;
1243 params.sides = OneSide;
1245 if (pageLayoutModule->landscapeRB->isChecked())
1246 params.orientation = ORIENTATION_LANDSCAPE;
1248 params.orientation = ORIENTATION_PORTRAIT;
1251 params.use_geometry =
1252 (!marginsModule->marginCB->isChecked()
1255 Ui::MarginsUi const * m(marginsModule);
1257 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1258 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1259 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1260 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1261 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1262 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1263 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1265 branchesModule->apply(params);
1268 PDFOptions & pdf = params.pdfoptions();
1269 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1270 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1271 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1272 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1273 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1275 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1276 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1277 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1278 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1280 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1281 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1282 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1283 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1284 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1285 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1286 if (pdfSupportModule->fullscreenCB->isChecked())
1287 pdf.pagemode = pdf.pagemode_fullscreen;
1289 pdf.pagemode.clear();
1290 pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1297 /** Return the position of val in the vector if found.
1298 If not found, return 0.
1301 static size_t findPos(std::vector<A> const & vec, A const & val)
1303 typename std::vector<A>::const_iterator it =
1304 std::find(vec.begin(), vec.end(), val);
1305 if (it == vec.end())
1307 return distance(vec.begin(), it);
1311 void GuiDocument::updateParams()
1317 void GuiDocument::updateParams(BufferParams const & params)
1319 // set the default unit
1320 Length::UNIT defaultUnit = Length::CM;
1321 switch (lyxrc.default_papersize) {
1322 case PAPER_DEFAULT: break;
1324 case PAPER_USLETTER:
1326 case PAPER_USEXECUTIVE:
1327 defaultUnit = Length::IN;
1336 defaultUnit = Length::CM;
1343 preambleModule->update(params, id());
1346 biblioModule->citeDefaultRB->setChecked(
1347 params.getEngine() == biblio::ENGINE_BASIC);
1349 biblioModule->citeNatbibRB->setChecked(
1350 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1351 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1353 biblioModule->citeStyleCO->setCurrentIndex(
1354 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1356 biblioModule->citeJurabibRB->setChecked(
1357 params.getEngine() == biblio::ENGINE_JURABIB);
1359 biblioModule->bibtopicCB->setChecked(
1360 params.use_bibtopic);
1362 // language & quotes
1363 int const pos = int(findPos(lang_,
1364 params.language->lang()));
1365 langModule->languageCO->setCurrentIndex(pos);
1367 langModule->quoteStyleCO->setCurrentIndex(
1368 params.quotes_language);
1370 bool default_enc = true;
1371 if (params.inputenc != "auto") {
1372 default_enc = false;
1373 if (params.inputenc == "default") {
1374 langModule->encodingCO->setCurrentIndex(0);
1376 int const i = langModule->encodingCO->findText(
1377 toqstr(params.inputenc));
1379 langModule->encodingCO->setCurrentIndex(i);
1381 // unknown encoding. Set to default.
1385 langModule->defaultencodingRB->setChecked(default_enc);
1386 langModule->otherencodingRB->setChecked(!default_enc);
1389 int const min_toclevel = textClass().min_toclevel();
1390 int const max_toclevel = textClass().max_toclevel();
1391 if (textClass().hasTocLevels()) {
1392 numberingModule->setEnabled(true);
1393 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1394 numberingModule->depthSL->setMaximum(max_toclevel);
1395 numberingModule->depthSL->setValue(params.secnumdepth);
1396 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1397 numberingModule->tocSL->setMaximum(max_toclevel);
1398 numberingModule->tocSL->setValue(params.tocdepth);
1401 numberingModule->setEnabled(false);
1402 numberingModule->tocTW->clear();
1406 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1407 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1408 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1409 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1410 bulletsModule->init();
1413 int nitem = findToken(tex_graphics, params.graphicsDriver);
1415 latexModule->psdriverCO->setCurrentIndex(nitem);
1418 mathsModule->amsCB->setChecked(
1419 params.use_amsmath == BufferParams::package_on);
1420 mathsModule->amsautoCB->setChecked(
1421 params.use_amsmath == BufferParams::package_auto);
1423 mathsModule->esintCB->setChecked(
1424 params.use_esint == BufferParams::package_on);
1425 mathsModule->esintautoCB->setChecked(
1426 params.use_esint == BufferParams::package_auto);
1428 switch (params.spacing().getSpace()) {
1429 case Spacing::Other: nitem = 3; break;
1430 case Spacing::Double: nitem = 2; break;
1431 case Spacing::Onehalf: nitem = 1; break;
1432 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1436 latexModule->classCO->setCurrentIndex(params.getBaseClass());
1438 updatePagestyle(textClass().opt_pagestyle(),
1441 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1442 if (params.spacing().getSpace() == Spacing::Other) {
1443 textLayoutModule->lspacingLE->setText(
1444 toqstr(params.spacing().getValueAsString()));
1448 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1449 textLayoutModule->indentRB->setChecked(true);
1451 textLayoutModule->skipRB->setChecked(true);
1454 switch (params.getDefSkip().kind()) {
1455 case VSpace::SMALLSKIP:
1458 case VSpace::MEDSKIP:
1461 case VSpace::BIGSKIP:
1464 case VSpace::LENGTH:
1467 string const length = params.getDefSkip().asLyXCommand();
1468 lengthToWidgets(textLayoutModule->skipLE,
1469 textLayoutModule->skipLengthCO,
1470 length, defaultUnit);
1477 textLayoutModule->skipCO->setCurrentIndex(skip);
1480 textLayoutModule->twoColumnCB->setChecked(
1481 params.columns == 2);
1483 // break listings_params to multiple lines
1485 InsetListingsParams(params.listings_params).separatedParams();
1486 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1488 if (!params.options.empty()) {
1489 latexModule->optionsLE->setText(
1490 toqstr(params.options));
1492 latexModule->optionsLE->setText(QString());
1495 floatModule->set(params.float_placement);
1498 updateFontsize(textClass().opt_fontsize(),
1501 int n = findToken(tex_fonts_roman, params.fontsRoman);
1503 fontModule->fontsRomanCO->setCurrentIndex(n);
1507 n = findToken(tex_fonts_sans, params.fontsSans);
1509 fontModule->fontsSansCO->setCurrentIndex(n);
1513 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1515 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1519 fontModule->fontScCB->setChecked(params.fontsSC);
1520 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1521 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1522 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1523 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1525 fontModule->fontsDefaultCO->setCurrentIndex(n);
1528 int const psize = params.papersize;
1529 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1530 setCustomPapersize(psize);
1532 bool const landscape =
1533 params.orientation == ORIENTATION_LANDSCAPE;
1534 pageLayoutModule->landscapeRB->setChecked(landscape);
1535 pageLayoutModule->portraitRB->setChecked(!landscape);
1537 pageLayoutModule->facingPagesCB->setChecked(
1538 params.sides == TwoSides);
1541 lengthToWidgets(pageLayoutModule->paperwidthLE,
1542 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1544 lengthToWidgets(pageLayoutModule->paperheightLE,
1545 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1548 Ui::MarginsUi * m = marginsModule;
1550 setMargins(!params.use_geometry);
1552 lengthToWidgets(m->topLE, m->topUnit,
1553 params.topmargin, defaultUnit);
1555 lengthToWidgets(m->bottomLE, m->bottomUnit,
1556 params.bottommargin, defaultUnit);
1558 lengthToWidgets(m->innerLE, m->innerUnit,
1559 params.leftmargin, defaultUnit);
1561 lengthToWidgets(m->outerLE, m->outerUnit,
1562 params.rightmargin, defaultUnit);
1564 lengthToWidgets(m->headheightLE, m->headheightUnit,
1565 params.headheight, defaultUnit);
1567 lengthToWidgets(m->headsepLE, m->headsepUnit,
1568 params.headsep, defaultUnit);
1570 lengthToWidgets(m->footskipLE, m->footskipUnit,
1571 params.footskip, defaultUnit);
1573 branchesModule->update(params);
1576 PDFOptions const & pdf = params.pdfoptions();
1577 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1578 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1579 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1580 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1581 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1583 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1584 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1585 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1587 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1589 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1590 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1591 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
1592 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1593 pdfSupportModule->backrefCB->setChecked(pdf.backref);
1594 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1595 pdfSupportModule->fullscreenCB->setChecked
1596 (pdf.pagemode == pdf.pagemode_fullscreen);
1598 pdfSupportModule->optionsLE->setText(
1599 toqstr(pdf.quoted_options));
1602 updateEmbeddedFileList();
1606 void GuiDocument::applyView()
1612 void GuiDocument::saveDocDefault()
1614 // we have to apply the params first
1620 void GuiDocument::updateContents()
1622 //update list of available modules
1623 QStringList strlist;
1624 vector<string> const modNames = getModuleNames();
1625 vector<string>::const_iterator it = modNames.begin();
1626 for (; it != modNames.end(); ++it)
1627 strlist.push_back(toqstr(*it));
1628 available_model_.setStringList(strlist);
1629 //and selected ones, too
1630 QStringList strlist2;
1631 vector<string> const & selMods = getSelectedModules();
1632 it = selMods.begin();
1633 for (; it != selMods.end(); ++it)
1634 strlist2.push_back(toqstr(*it));
1635 selected_model_.setStringList(strlist2);
1640 void GuiDocument::useClassDefaults()
1642 bp_.setJustBaseClass(latexModule->classCO->currentIndex());
1643 bp_.useClassDefaults();
1648 bool GuiDocument::isValid()
1650 return validate_listings_params().empty();
1654 char const * const GuiDocument::fontfamilies[5] = {
1655 "default", "rmdefault", "sfdefault", "ttdefault", ""
1659 char const * GuiDocument::fontfamilies_gui[5] = {
1660 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
1664 bool GuiDocument::initialiseParams(string const &)
1666 bp_ = buffer().params();
1672 void GuiDocument::clearParams()
1674 bp_ = BufferParams();
1678 BufferId GuiDocument::id() const
1684 vector<string> GuiDocument::getModuleNames()
1686 return moduleNames_;
1690 vector<string> const & GuiDocument::getSelectedModules()
1692 return params().getModules();
1696 string GuiDocument::getModuleDescription(string const & modName) const
1698 LyXModule const * const mod = moduleList[modName];
1700 return string("Module unavailable!");
1701 return mod->description;
1706 GuiDocument::getPackageList(string const & modName) const
1708 LyXModule const * const mod = moduleList[modName];
1710 return vector<string>(); //empty such thing
1711 return mod->packageList;
1715 TextClass const & GuiDocument::textClass() const
1717 return textclasslist[bp_.getBaseClass()];
1721 static void dispatch_bufferparams(Dialog const & dialog,
1722 BufferParams const & bp, kb_action lfun)
1725 ss << "\\begin_header\n";
1727 ss << "\\end_header\n";
1728 dialog.dispatch(FuncRequest(lfun, ss.str()));
1732 void GuiDocument::dispatchParams()
1734 // This must come first so that a language change is correctly noticed
1737 // Apply the BufferParams. Note that this will set the base class
1738 // and then update the buffer's layout.
1739 //FIXME Could this be done last? Then, I think, we'd get the automatic
1740 //update mentioned in the next FIXME...
1741 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
1743 // Generate the colours requested by each new branch.
1744 BranchList & branchlist = params().branchlist();
1745 if (!branchlist.empty()) {
1746 BranchList::const_iterator it = branchlist.begin();
1747 BranchList::const_iterator const end = branchlist.end();
1748 for (; it != end; ++it) {
1749 docstring const & current_branch = it->getBranch();
1750 Branch const * branch = branchlist.find(current_branch);
1751 string const x11hexname = X11hexname(branch->getColor());
1752 // display the new color
1753 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
1754 dispatch(FuncRequest(LFUN_SET_COLOR, str));
1757 // Open insets of selected branches, close deselected ones
1758 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
1761 // FIXME: If we used an LFUN, we would not need those two lines:
1762 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
1766 void GuiDocument::setLanguage() const
1768 Language const * const newL = bp_.language;
1769 if (buffer().params().language == newL)
1772 string const & lang_name = newL->lang();
1773 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
1777 void GuiDocument::saveAsDefault() const
1779 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
1783 bool GuiDocument::isFontAvailable(string const & font) const
1785 if (font == "default" || font == "cmr"
1786 || font == "cmss" || font == "cmtt")
1787 // these are standard
1789 if (font == "lmodern" || font == "lmss" || font == "lmtt")
1790 return LaTeXFeatures::isAvailable("lmodern");
1791 if (font == "times" || font == "palatino"
1792 || font == "helvet" || font == "courier")
1793 return LaTeXFeatures::isAvailable("psnfss");
1794 if (font == "cmbr" || font == "cmtl")
1795 return LaTeXFeatures::isAvailable("cmbright");
1796 if (font == "utopia")
1797 return LaTeXFeatures::isAvailable("utopia")
1798 || LaTeXFeatures::isAvailable("fourier");
1799 if (font == "beraserif" || font == "berasans"
1800 || font == "beramono")
1801 return LaTeXFeatures::isAvailable("bera");
1802 return LaTeXFeatures::isAvailable(font);
1806 bool GuiDocument::providesOSF(string const & font) const
1809 return isFontAvailable("eco");
1810 if (font == "palatino")
1811 return isFontAvailable("mathpazo");
1816 bool GuiDocument::providesSC(string const & font) const
1818 if (font == "palatino")
1819 return isFontAvailable("mathpazo");
1820 if (font == "utopia")
1821 return isFontAvailable("fourier");
1826 bool GuiDocument::providesScale(string const & font) const
1828 return font == "helvet" || font == "luximono"
1829 || font == "berasans" || font == "beramono";
1833 void GuiDocument::loadModuleNames ()
1835 moduleNames_.clear();
1836 LyXModuleList::const_iterator it = moduleList.begin();
1837 for (; it != moduleList.end(); ++it)
1838 moduleNames_.push_back(it->name);
1839 if (!moduleNames_.empty())
1840 sort(moduleNames_.begin(), moduleNames_.end());
1844 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
1847 } // namespace frontend
1850 #include "GuiDocument_moc.cpp"