2 * \file QDocumentDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "QDocument.h"
14 #include "QDocumentDialog.h"
16 #include "floatplacement.h"
17 #include "lcolorcache.h"
18 #include "lengthcombo.h"
19 #include "validators.h"
20 #include "panelstack.h"
21 #include "qt_helpers.h"
23 #include "bufferparams.h"
26 #include "tex-strings.h"
28 #include "controllers/ControlDocument.h"
30 #include "support/lstrings.h"
33 #include <qmultilineedit.h>
34 #include <qlineedit.h>
35 #include <qlistview.h>
36 #include <qpushbutton.h>
37 #include <qradiobutton.h>
38 #include <qcheckbox.h>
43 #include <qcolordialog.h>
44 #include <qvalidator.h>
46 using lyx::support::token;
54 QDocumentDialog::QDocumentDialog(QDocument * form)
55 : QDocumentDialogBase(0, 0, false, 0), form_(form)
57 connect(okPB, SIGNAL(clicked()),
58 form, SLOT(slotOK()));
59 connect(applyPB, SIGNAL(clicked()),
60 form, SLOT(slotApply()));
61 connect(closePB, SIGNAL(clicked()),
62 form, SLOT(slotClose()));
63 connect(restorePB, SIGNAL(clicked()),
64 form, SLOT(slotRestore()));
66 fontModule = new FontModuleBase(this);
67 textLayoutModule = new TextLayoutModuleBase(this);
68 pageLayoutModule = new PageLayoutModuleBase(this);
69 marginsModule = new MarginsModuleBase(this);
70 langModule = new LanguageModuleBase(this);
71 bulletsModule = new BulletsModule(this);
72 numberingModule = new NumberingModuleBase(this);
73 biblioModule = new BiblioModuleBase(this);
74 mathsModule = new MathsModuleBase(this);
75 floatModule = new FloatPlacement(this, "floatplacement");
76 latexModule = new LaTeXModuleBase(this);
77 branchesModule = new BranchesModuleBase(this);
78 preambleModule = new PreambleModuleBase(this);
80 docPS->addPanel(latexModule, _("Document Class"));
81 docPS->addPanel(fontModule, _("Fonts"));
82 docPS->addPanel(textLayoutModule, _("Text Layout"));
83 docPS->addPanel(pageLayoutModule, _("Page Layout"));
84 docPS->addPanel(marginsModule, _("Page Margins"));
85 docPS->addPanel(langModule, _("Language"));
86 docPS->addPanel(numberingModule, _("Numbering & TOC"));
87 docPS->addPanel(biblioModule, _("Bibliography"));
88 docPS->addPanel(mathsModule, _("Math Options"));
89 docPS->addPanel(floatModule, _("Float Placement"));
90 docPS->addPanel(bulletsModule, _("Bullets"));
91 docPS->addPanel(branchesModule, _("Branches"));
92 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
93 docPS->setCurrentPanel(_("Document Class"));
96 connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
98 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
99 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
100 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
101 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
102 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
104 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
105 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
106 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
107 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
109 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
110 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
111 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
112 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
113 numberingModule->tocLV->setSorting(-1);
115 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
116 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
118 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
120 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
121 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
122 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
123 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
125 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
126 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
127 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
128 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
129 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
130 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
131 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
132 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
133 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
134 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
135 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
138 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
139 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(romanChanged(int)));
140 connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
141 connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(sansChanged(int)));
142 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
143 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(ttChanged(int)));
144 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
145 connect(fontModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
146 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
147 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
148 connect(fontModule->fontScCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
149 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
152 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool)));
153 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
154 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
155 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
156 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
157 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
158 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
159 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
160 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
161 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
162 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
163 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
164 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
165 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
166 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
167 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
170 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
171 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
172 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
173 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
174 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
175 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
176 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
177 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
178 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
179 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
180 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
181 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
184 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
187 connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed()));
188 connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed()));
189 connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed()));
190 connect(branchesModule->branchesLV, SIGNAL(doubleClicked(QListViewItem *)), this,
191 SLOT(branchDoubleClicked(QListViewItem *)));
192 connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
193 branchesModule->branchesLV->setSorting(0);
195 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
196 textLayoutModule->lspacingLE));
198 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
199 textLayoutModule->skipLE));
200 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
201 pageLayoutModule->paperheightLE));
202 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
203 pageLayoutModule->paperwidthLE));
204 marginsModule->topLE->setValidator(unsignedLengthValidator(
205 marginsModule->topLE));
206 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
207 marginsModule->bottomLE));
208 marginsModule->innerLE->setValidator(unsignedLengthValidator(
209 marginsModule->innerLE));
210 marginsModule->outerLE->setValidator(unsignedLengthValidator(
211 marginsModule->outerLE));
212 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
213 marginsModule->headsepLE));
214 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
215 marginsModule->headheightLE));
216 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
217 marginsModule->footskipLE));
221 QDocumentDialog::~QDocumentDialog()
226 void QDocumentDialog::showPreamble()
228 docPS->setCurrentPanel(_("LaTeX Preamble"));
232 void QDocumentDialog::saveDefaultClicked()
234 form_->saveDocDefault();
238 void QDocumentDialog::useDefaultsClicked()
240 form_->useClassDefaults();
244 void QDocumentDialog::change_adaptor()
250 void QDocumentDialog::closeEvent(QCloseEvent * e)
257 void QDocumentDialog::setLSpacing(int item)
259 textLayoutModule->lspacingLE->setEnabled(item == 3);
263 void QDocumentDialog::setSkip(int item)
265 bool const enable = (item == 3);
266 textLayoutModule->skipLE->setEnabled(enable);
267 textLayoutModule->skipLengthCO->setEnabled(enable);
271 void QDocumentDialog::enableSkip(bool skip)
273 textLayoutModule->skipCO->setEnabled(skip);
274 textLayoutModule->skipLE->setEnabled(skip);
275 textLayoutModule->skipLengthCO->setEnabled(skip);
277 setSkip(textLayoutModule->skipCO->currentItem());
280 void QDocumentDialog::portraitChanged()
282 setMargins(pageLayoutModule->papersizeCO->currentItem());
285 void QDocumentDialog::setMargins(bool custom)
287 marginsModule->marginCB->setChecked(custom);
288 setCustomMargins(custom);
292 void QDocumentDialog::setCustomPapersize(int papersize)
294 bool const custom = (papersize == 1);
296 pageLayoutModule->paperwidthL->setEnabled(custom);
297 pageLayoutModule->paperwidthLE->setEnabled(custom);
298 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
299 pageLayoutModule->paperheightL->setEnabled(custom);
300 pageLayoutModule->paperheightLE->setEnabled(custom);
301 pageLayoutModule->paperheightLE->setFocus();
302 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
306 void QDocumentDialog::setCustomMargins(bool custom)
308 marginsModule->topL->setEnabled(!custom);
309 marginsModule->topLE->setEnabled(!custom);
310 marginsModule->topUnit->setEnabled(!custom);
312 marginsModule->bottomL->setEnabled(!custom);
313 marginsModule->bottomLE->setEnabled(!custom);
314 marginsModule->bottomUnit->setEnabled(!custom);
316 marginsModule->innerL->setEnabled(!custom);
317 marginsModule->innerLE->setEnabled(!custom);
318 marginsModule->innerUnit->setEnabled(!custom);
320 marginsModule->outerL->setEnabled(!custom);
321 marginsModule->outerLE->setEnabled(!custom);
322 marginsModule->outerUnit->setEnabled(!custom);
324 marginsModule->headheightL->setEnabled(!custom);
325 marginsModule->headheightLE->setEnabled(!custom);
326 marginsModule->headheightUnit->setEnabled(!custom);
328 marginsModule->headsepL->setEnabled(!custom);
329 marginsModule->headsepLE->setEnabled(!custom);
330 marginsModule->headsepUnit->setEnabled(!custom);
332 marginsModule->footskipL->setEnabled(!custom);
333 marginsModule->footskipLE->setEnabled(!custom);
334 marginsModule->footskipUnit->setEnabled(!custom);
338 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
340 fontModule->fontsizeCO->clear();
341 fontModule->fontsizeCO->insertItem(qt_("default"));
343 for (int n = 0; !token(items,'|',n).empty(); ++n)
344 fontModule->fontsizeCO->
345 insertItem(toqstr(token(items,'|',n)));
347 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
348 if (fromqstr(fontModule->fontsizeCO->text(n)) == sel) {
349 fontModule->fontsizeCO->setCurrentItem(n);
356 void QDocumentDialog::romanChanged(int item)
358 string const font = tex_fonts_roman[item];
360 fontModule->fontScCB->setEnabled(
361 form_->controller().providesSC(font));
362 fontModule->fontOsfCB->setEnabled(
363 form_->controller().providesOSF(font));
367 void QDocumentDialog::sansChanged(int item)
369 string const font = tex_fonts_sans[item];
371 fontModule->scaleSansSB->setEnabled(
372 form_->controller().providesScale(font));
376 void QDocumentDialog::ttChanged(int item)
378 string const font = tex_fonts_monospaced[item];
380 fontModule->scaleTypewriterSB->setEnabled(
381 form_->controller().providesScale(font));
385 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
387 pageLayoutModule->pagestyleCO->clear();
388 pageLayoutModule->pagestyleCO->insertItem("default");
390 for (int n=0; !token(items,'|',n).empty(); ++n)
391 pageLayoutModule->pagestyleCO->
392 insertItem(toqstr(token(items,'|',n)));
394 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
395 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
396 pageLayoutModule->pagestyleCO->setCurrentItem(n);
403 void QDocumentDialog::classChanged()
405 ControlDocument & cntrl = form_->controller();
406 BufferParams & params = cntrl.params();
408 lyx::textclass_type const tc = latexModule->classCO->currentItem();
410 if (form_->controller().loadTextclass(tc)) {
411 params.textclass = tc;
412 if (lyxrc.auto_reset_options)
413 params.useClassDefaults();
414 form_->update_contents();
416 latexModule->classCO->setCurrentItem(params.textclass);
421 void QDocumentDialog::updateNumbering()
423 LyXTextClass const & tclass =
424 form_->controller().params().getLyXTextClass();
426 //numberingModule->tocLV->setUpdatesEnabled(false);
428 // Update the example QListView
429 int const depth = numberingModule->depthSL->value();
430 int const toc = numberingModule->tocSL->value();
431 QString const no = qt_("No");
432 QString const yes = qt_("Yes");
433 LyXTextClass::const_iterator end = tclass.end();
434 LyXTextClass::const_iterator cit = tclass.begin();
435 numberingModule->tocLV->clear();
436 QListViewItem * item = 0;
437 for ( ; cit != end ; ++cit) {
438 int const toclevel = (*cit)->toclevel;
439 if (toclevel != LyXLayout::NOT_IN_TOC) {
440 item = new QListViewItem(numberingModule->tocLV,
441 item, qt_((*cit)->name()));
442 item->setText(1, (toclevel <= depth) ? yes : no);
443 item->setText(2, (toclevel <= toc) ? yes : no);
447 //numberingModule->tocLV->setUpdatesEnabled(true);
448 //numberingModule->tocLV->update();
452 void QDocumentDialog::updateBranchView()
454 // store the selected branch
455 QListViewItem * selItem =
456 branchesModule->branchesLV->selectedItem();
459 sel_branch = selItem->text(0);
461 branchesModule->branchesLV->clear();
463 BranchList::const_iterator it = form_->branchlist_.begin();
464 BranchList::const_iterator const end = form_->branchlist_.end();
465 for (; it != end; ++it) {
466 QString const bname = toqstr(it->getBranch());
467 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
468 QListViewItem * newItem =
469 new QListViewItem(branchesModule->branchesLV, bname, sel);
470 QColor const itemcolor = rgb2qcolor(it->getColor());
471 if (itemcolor.isValid()) {
472 QPixmap coloritem(30, 10);
473 coloritem.fill(itemcolor);
474 newItem->setPixmap(2, coloritem);
476 // restore selected branch
477 if (bname == sel_branch)
478 branchesModule->branchesLV->setSelected(newItem, true);
484 void QDocumentDialog::addBranchPressed()
486 QString const new_branch = branchesModule->newBranchLE->text();
487 if (!new_branch.isEmpty()) {
488 form_->branchlist_.add(fromqstr(new_branch));
489 branchesModule->newBranchLE->clear();
495 void QDocumentDialog::deleteBranchPressed()
497 QListViewItem * selItem =
498 branchesModule->branchesLV->selectedItem();
501 sel_branch = selItem->text(0);
503 form_->branchlist_.remove(fromqstr(sel_branch));
504 branchesModule->newBranchLE->clear();
510 void QDocumentDialog::toggleBranchPressed()
512 QListViewItem * selItem =
513 branchesModule->branchesLV->selectedItem();
514 toggleBranch(selItem);
518 void QDocumentDialog::branchDoubleClicked(QListViewItem * selItem)
520 toggleBranch(selItem);
524 void QDocumentDialog::toggleBranch(QListViewItem * selItem)
529 QString sel_branch = selItem->text(0);
531 bool const selected = selItem->text(1) == qt_("Yes");
532 Branch * branch = form_->branchlist_.find(fromqstr(sel_branch));
533 if (branch && branch->setSelected(!selected)) {
534 branchesModule->newBranchLE->clear();
541 void QDocumentDialog::toggleBranchColor()
543 QListViewItem * selItem =
544 branchesModule->branchesLV->selectedItem();
547 sel_branch = selItem->text(0);
549 string current_branch = fromqstr(sel_branch);
551 form_->branchlist_.find(current_branch);
555 QColor const initial = rgb2qcolor(branch->getColor());
556 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
558 // add the color to the branchlist
559 branch->setColor(fromqstr(ncol.name()));
560 branchesModule->newBranchLE->clear();
566 } // namespace frontend