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 "bufferparams.h"
17 #include "controllers/ControlDocument.h"
19 #include "support/lstrings.h"
21 #include "QDocument.h"
22 #include "QDocumentDialog.h"
24 #include "floatplacement.h"
25 #include "lengthcombo.h"
26 #include "panelstack.h"
27 #include "qt_helpers.h"
30 #include <qmultilineedit.h>
31 #include <qlineedit.h>
32 #include <qlistview.h>
33 #include <qpushbutton.h>
34 #include <qradiobutton.h>
35 #include <qcheckbox.h>
39 #include <qcolordialog.h>
41 using lyx::support::token;
46 QDocumentDialog::QDocumentDialog(QDocument * form)
47 : QDocumentDialogBase(0, 0, false, 0), form_(form)
49 connect(okPB, SIGNAL(clicked()),
50 form, SLOT(slotOK()));
51 connect(applyPB, SIGNAL(clicked()),
52 form, SLOT(slotApply()));
53 connect(closePB, SIGNAL(clicked()),
54 form, SLOT(slotClose()));
55 connect(restorePB, SIGNAL(clicked()),
56 form, SLOT(slotRestore()));
58 textLayoutModule = new TextLayoutModuleBase(this);
59 pageLayoutModule = new PageLayoutModuleBase(this);
60 marginsModule = new MarginsModuleBase(this);
61 langModule = new LanguageModuleBase(this);
62 bulletsModule = new BulletsModule(this);
63 numberingModule = new NumberingModuleBase(this);
64 biblioModule = new BiblioModuleBase(this);
65 mathsModule = new MathsModuleBase(this);
66 floatModule = new FloatPlacement(this, "floatplacement");
67 latexModule = new LaTeXModuleBase(this);
68 branchesModule = new BranchesModuleBase(this);
69 preambleModule = new PreambleModuleBase(this);
71 docPS->addPanel(latexModule, _("Document Class"));
72 docPS->addPanel(textLayoutModule, _("Text Layout"));
73 docPS->addPanel(pageLayoutModule, _("Page Layout"));
74 docPS->addPanel(marginsModule, _("Page Margins"));
75 docPS->addPanel(langModule, _("Language"));
76 docPS->addPanel(numberingModule, _("Numbering & TOC"));
77 docPS->addPanel(biblioModule, _("Bibliography"));
78 docPS->addPanel(mathsModule, _("Math options"));
79 docPS->addPanel(floatModule, _("Float Placement"));
80 docPS->addPanel(bulletsModule, _("Bullets"));
81 docPS->addPanel(branchesModule, _("Branches"));
82 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
83 docPS->setCurrentPanel(_("Document Class"));
86 connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
88 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
89 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
90 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
91 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
93 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
94 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
95 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
96 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
98 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
99 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
100 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
101 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
102 numberingModule->tocLV->setSorting(-1);
104 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
105 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
107 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
109 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
110 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
111 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
112 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
114 connect(textLayoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
115 connect(textLayoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
116 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
117 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
118 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
119 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
120 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
121 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
122 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
123 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
124 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
125 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
126 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
129 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(setCustomMargins(int)));
130 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
131 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
132 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
133 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
134 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
135 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
136 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
137 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
138 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
139 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
140 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
141 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
142 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
143 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
144 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
147 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setMargins(int)));
148 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
149 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
150 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
151 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
152 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
153 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
154 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
155 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
156 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
157 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
158 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
159 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
162 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
165 connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed()));
166 connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed()));
167 connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed()));
168 connect(branchesModule->branchesLV, SIGNAL(doubleClicked(QListViewItem *)), this,
169 SLOT(branchDoubleClicked(QListViewItem *)));
170 connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
171 branchesModule->branchesLV->setSorting(0);
175 QDocumentDialog::~QDocumentDialog()
180 void QDocumentDialog::showPreamble()
182 docPS->setCurrentPanel(_("LaTeX Preamble"));
186 void QDocumentDialog::saveDefaultClicked()
188 form_->saveDocDefault();
192 void QDocumentDialog::useDefaultsClicked()
194 form_->useClassDefaults();
198 void QDocumentDialog::change_adaptor()
204 void QDocumentDialog::closeEvent(QCloseEvent * e)
211 void QDocumentDialog::setLSpacing(int item)
213 textLayoutModule->lspacingLE->setEnabled(item == 3);
217 void QDocumentDialog::setSkip(int item)
219 bool const enable = (item == 3);
220 textLayoutModule->skipLE->setEnabled(enable);
221 textLayoutModule->skipLengthCO->setEnabled(enable);
225 void QDocumentDialog::enableSkip(bool skip)
227 textLayoutModule->skipCO->setEnabled(skip);
228 textLayoutModule->skipLE->setEnabled(skip);
229 textLayoutModule->skipLengthCO->setEnabled(skip);
231 setSkip(textLayoutModule->skipCO->currentItem());
234 void QDocumentDialog::portraitChanged()
236 setMargins(pageLayoutModule->papersizeCO->currentItem());
239 void QDocumentDialog::setMargins(int papersize)
241 int olditem = marginsModule->marginCO->currentItem();
242 marginsModule->marginCO->clear();
243 marginsModule->marginCO->insertItem(qt_("Default"));
244 marginsModule->marginCO->insertItem(qt_("Custom"));
245 bool a4size = (papersize == 6 || papersize == 0
246 && lyxrc.default_papersize == PAPER_A4PAPER);
247 if (a4size && pageLayoutModule->portraitRB->isChecked()) {
248 marginsModule->marginCO->insertItem(qt_("Small margins"));
249 marginsModule->marginCO->insertItem(qt_("Very small margins"));
250 marginsModule->marginCO->insertItem(qt_("Very wide margins"));
251 } else if (olditem > 1) {
254 marginsModule->marginCO->setCurrentItem(olditem);
255 setCustomMargins(olditem);
259 void QDocumentDialog::setCustomPapersize(int papersize)
261 bool const custom = (papersize == 1);
263 pageLayoutModule->paperwidthL->setEnabled(custom);
264 pageLayoutModule->paperwidthLE->setEnabled(custom);
265 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
266 pageLayoutModule->paperheightL->setEnabled(custom);
267 pageLayoutModule->paperheightLE->setEnabled(custom);
268 pageLayoutModule->paperheightLE->setFocus();
269 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
273 void QDocumentDialog::setCustomMargins(int margin)
275 bool const custom = (margin == 1);
277 marginsModule->topL->setEnabled(custom);
278 marginsModule->topLE->setEnabled(custom);
279 marginsModule->topUnit->setEnabled(custom);
281 marginsModule->bottomL->setEnabled(custom);
282 marginsModule->bottomLE->setEnabled(custom);
283 marginsModule->bottomUnit->setEnabled(custom);
285 marginsModule->innerL->setEnabled(custom);
286 marginsModule->innerLE->setEnabled(custom);
287 marginsModule->innerUnit->setEnabled(custom);
289 marginsModule->outerL->setEnabled(custom);
290 marginsModule->outerLE->setEnabled(custom);
291 marginsModule->outerUnit->setEnabled(custom);
293 marginsModule->headheightL->setEnabled(custom);
294 marginsModule->headheightLE->setEnabled(custom);
295 marginsModule->headheightUnit->setEnabled(custom);
297 marginsModule->headsepL->setEnabled(custom);
298 marginsModule->headsepLE->setEnabled(custom);
299 marginsModule->headsepUnit->setEnabled(custom);
301 marginsModule->footskipL->setEnabled(custom);
302 marginsModule->footskipLE->setEnabled(custom);
303 marginsModule->footskipUnit->setEnabled(custom);
307 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
309 textLayoutModule->fontsizeCO->clear();
310 textLayoutModule->fontsizeCO->insertItem("default");
312 for (int n = 0; !token(items,'|',n).empty(); ++n)
313 textLayoutModule->fontsizeCO->
314 insertItem(toqstr(token(items,'|',n)));
316 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
317 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
318 textLayoutModule->fontsizeCO->setCurrentItem(n);
325 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
327 pageLayoutModule->pagestyleCO->clear();
328 pageLayoutModule->pagestyleCO->insertItem("default");
330 for (int n=0; !token(items,'|',n).empty(); ++n)
331 pageLayoutModule->pagestyleCO->
332 insertItem(toqstr(token(items,'|',n)));
334 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
335 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
336 pageLayoutModule->pagestyleCO->setCurrentItem(n);
343 void QDocumentDialog::classChanged()
345 ControlDocument & cntrl = form_->controller();
346 BufferParams & params = cntrl.params();
348 lyx::textclass_type const tc = latexModule->classCO->currentItem();
350 if (form_->controller().loadTextclass(tc)) {
351 params.textclass = tc;
353 if (lyxrc.auto_reset_options) {
354 params.useClassDefaults();
355 form_->update_contents();
357 updateFontsize(cntrl.textClass().opt_fontsize(),
360 updatePagestyle(cntrl.textClass().opt_pagestyle(),
364 latexModule->classCO->setCurrentItem(params.textclass);
369 void QDocumentDialog::updateNumbering()
371 int const depth = numberingModule->depthSL->value();
372 int const toc = numberingModule->tocSL->value();
373 QListViewItem * partitem = numberingModule->tocLV->firstChild();
374 QListViewItem * chapteritem = partitem->nextSibling();
375 QListViewItem * sectionitem = chapteritem->nextSibling();
376 QListViewItem * subsectionitem = sectionitem->nextSibling();
377 QListViewItem * subsubsectionitem = subsectionitem->nextSibling();
378 QListViewItem * paragraphitem = subsubsectionitem->nextSibling();
379 QListViewItem * subparagraphitem = paragraphitem->nextSibling();
381 QString const no = qt_("No");
382 QString const yes = qt_("Yes");
384 //numberingModule->tocLV->setUpdatesEnabled(false);
386 partitem->setText(1, yes);
387 chapteritem->setText(1, yes);
388 sectionitem->setText(1, yes);
389 subsectionitem->setText(1, yes);
390 subsubsectionitem->setText(1, yes);
391 paragraphitem->setText(1, yes);
392 subparagraphitem->setText(1, yes);
393 partitem->setText(2, yes);
394 chapteritem->setText(2, yes);
395 sectionitem->setText(2, yes);
396 subsectionitem->setText(2, yes);
397 subsubsectionitem->setText(2, yes);
398 paragraphitem->setText(2, yes);
399 subparagraphitem->setText(2, yes);
402 if (depth < -1) partitem->setText(1, no);
403 if (depth < 0) chapteritem->setText(1, no);
404 if (depth < 1) sectionitem->setText(1, no);
405 if (depth < 2) subsectionitem->setText(1, no);
406 if (depth < 3) subsubsectionitem->setText(1, no);
407 if (depth < 4) paragraphitem->setText(1, no);
408 if (depth < 5) subparagraphitem->setText(1, no);
411 if (toc < 0) chapteritem->setText(2, no);
412 if (toc < 1) sectionitem->setText(2, no);
413 if (toc < 2) subsectionitem->setText(2, no);
414 if (toc < 3) subsubsectionitem->setText(2, no);
415 if (toc < 4) paragraphitem->setText(2, no);
416 if (toc < 5) subparagraphitem->setText(2, no);
418 //numberingModule->tocLV->setUpdatesEnabled(true);
419 //numberingModule->tocLV->update();
423 void QDocumentDialog::updateBranchView()
425 // store the selected branch
426 QListViewItem * selItem =
427 branchesModule->branchesLV->selectedItem();
430 sel_branch = selItem->text(0);
432 branchesModule->branchesLV->clear();
434 BranchList::const_iterator it = form_->branchlist_.begin();
435 BranchList::const_iterator const end = form_->branchlist_.end();
436 for (; it != end; ++it) {
437 QString const bname = toqstr(it->getBranch());
438 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
439 QListViewItem * newItem =
440 new QListViewItem(branchesModule->branchesLV, bname, sel);
441 string const x11hexname = it->getColor();
443 if (x11hexname[0] == '#')
444 itemcolor.setNamedColor(toqstr(x11hexname));
445 if (itemcolor.isValid()) {
446 QPixmap coloritem(30, 10);
447 coloritem.fill(itemcolor);
448 newItem->setPixmap(2, coloritem);
450 // restore selected branch
451 if (bname == sel_branch)
452 branchesModule->branchesLV->setSelected(newItem, true);
458 void QDocumentDialog::addBranchPressed()
460 QString const new_branch = branchesModule->newBranchLE->text();
461 if (!new_branch.isEmpty()) {
462 form_->branchlist_.add(fromqstr(new_branch));
463 branchesModule->newBranchLE->clear();
469 void QDocumentDialog::deleteBranchPressed()
471 QListViewItem * selItem =
472 branchesModule->branchesLV->selectedItem();
475 sel_branch = selItem->text(0);
477 form_->branchlist_.remove(fromqstr(sel_branch));
478 branchesModule->newBranchLE->clear();
484 void QDocumentDialog::toggleBranchPressed()
486 QListViewItem * selItem =
487 branchesModule->branchesLV->selectedItem();
488 toggleBranch(selItem);
492 void QDocumentDialog::branchDoubleClicked(QListViewItem * selItem)
494 toggleBranch(selItem);
498 void QDocumentDialog::toggleBranch(QListViewItem * selItem)
503 QString sel_branch = selItem->text(0);
505 bool const selected = selItem->text(1) == qt_("Yes");
506 Branch * branch = form_->branchlist_.find(fromqstr(sel_branch));
507 if (branch && branch->setSelected(!selected)) {
508 branchesModule->newBranchLE->clear();
515 void QDocumentDialog::toggleBranchColor()
517 QListViewItem * selItem =
518 branchesModule->branchesLV->selectedItem();
521 sel_branch = selItem->text(0);
524 string current_branch = fromqstr(sel_branch);
526 form_->branchlist_.find(current_branch);
530 string x11hexname = branch->getColor();
531 if (x11hexname[0] == '#')
532 initial.setNamedColor(toqstr(x11hexname));
533 QColor ncol(QColorDialog::getColor(initial));
535 // add the color to the branchlist
536 branch->setColor(fromqstr(ncol.name()));
537 branchesModule->newBranchLE->clear();