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 "lengthcombo.h"
18 #include "panelstack.h"
19 #include "qt_helpers.h"
21 #include "bufferparams.h"
25 #include "controllers/ControlDocument.h"
27 #include "support/lstrings.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;
48 QDocumentDialog::QDocumentDialog(QDocument * form)
49 : QDocumentDialogBase(0, 0, false, 0), form_(form)
51 connect(okPB, SIGNAL(clicked()),
52 form, SLOT(slotOK()));
53 connect(applyPB, SIGNAL(clicked()),
54 form, SLOT(slotApply()));
55 connect(closePB, SIGNAL(clicked()),
56 form, SLOT(slotClose()));
57 connect(restorePB, SIGNAL(clicked()),
58 form, SLOT(slotRestore()));
60 textLayoutModule = new TextLayoutModuleBase(this);
61 pageLayoutModule = new PageLayoutModuleBase(this);
62 marginsModule = new MarginsModuleBase(this);
63 langModule = new LanguageModuleBase(this);
64 bulletsModule = new BulletsModule(this);
65 numberingModule = new NumberingModuleBase(this);
66 biblioModule = new BiblioModuleBase(this);
67 mathsModule = new MathsModuleBase(this);
68 floatModule = new FloatPlacement(this, "floatplacement");
69 latexModule = new LaTeXModuleBase(this);
70 branchesModule = new BranchesModuleBase(this);
71 preambleModule = new PreambleModuleBase(this);
73 docPS->addPanel(latexModule, _("Document Class"));
74 docPS->addPanel(textLayoutModule, _("Text Layout"));
75 docPS->addPanel(pageLayoutModule, _("Page Layout"));
76 docPS->addPanel(marginsModule, _("Page Margins"));
77 docPS->addPanel(langModule, _("Language"));
78 docPS->addPanel(numberingModule, _("Numbering & TOC"));
79 docPS->addPanel(biblioModule, _("Bibliography"));
80 docPS->addPanel(mathsModule, _("Math options"));
81 docPS->addPanel(floatModule, _("Float Placement"));
82 docPS->addPanel(bulletsModule, _("Bullets"));
83 docPS->addPanel(branchesModule, _("Branches"));
84 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
85 docPS->setCurrentPanel(_("Document Class"));
88 connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
90 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
91 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
92 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
93 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
94 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
96 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
97 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
98 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
99 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
101 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
102 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
103 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
104 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
105 numberingModule->tocLV->setSorting(-1);
107 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
108 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
110 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
112 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
113 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
114 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
115 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
117 connect(textLayoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
118 connect(textLayoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
119 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
120 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
121 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
122 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
123 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
124 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
125 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
126 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
127 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
128 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
129 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
132 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(setCustomMargins(int)));
133 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
134 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
135 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
136 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
137 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
138 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
139 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
140 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
141 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
142 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
143 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
144 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
145 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
146 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
147 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
150 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setMargins(int)));
151 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
152 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
153 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
154 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
155 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
156 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
157 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
158 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
159 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
160 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
161 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
162 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
165 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
168 connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed()));
169 connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed()));
170 connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed()));
171 connect(branchesModule->branchesLV, SIGNAL(doubleClicked(QListViewItem *)), this,
172 SLOT(branchDoubleClicked(QListViewItem *)));
173 connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
174 branchesModule->branchesLV->setSorting(0);
178 QDocumentDialog::~QDocumentDialog()
183 void QDocumentDialog::showPreamble()
185 docPS->setCurrentPanel(_("LaTeX Preamble"));
189 void QDocumentDialog::saveDefaultClicked()
191 form_->saveDocDefault();
195 void QDocumentDialog::useDefaultsClicked()
197 form_->useClassDefaults();
201 void QDocumentDialog::change_adaptor()
207 void QDocumentDialog::closeEvent(QCloseEvent * e)
214 void QDocumentDialog::setLSpacing(int item)
216 textLayoutModule->lspacingLE->setEnabled(item == 3);
220 void QDocumentDialog::setSkip(int item)
222 bool const enable = (item == 3);
223 textLayoutModule->skipLE->setEnabled(enable);
224 textLayoutModule->skipLengthCO->setEnabled(enable);
228 void QDocumentDialog::enableSkip(bool skip)
230 textLayoutModule->skipCO->setEnabled(skip);
231 textLayoutModule->skipLE->setEnabled(skip);
232 textLayoutModule->skipLengthCO->setEnabled(skip);
234 setSkip(textLayoutModule->skipCO->currentItem());
237 void QDocumentDialog::portraitChanged()
239 setMargins(pageLayoutModule->papersizeCO->currentItem());
242 void QDocumentDialog::setMargins(int papersize)
244 int olditem = marginsModule->marginCO->currentItem();
245 marginsModule->marginCO->clear();
246 marginsModule->marginCO->insertItem(qt_("Default"));
247 marginsModule->marginCO->insertItem(qt_("Custom"));
248 bool a4size = (papersize == 6 || papersize == 0
249 && lyxrc.default_papersize == PAPER_A4PAPER);
250 if (a4size && pageLayoutModule->portraitRB->isChecked()) {
251 marginsModule->marginCO->insertItem(qt_("Small margins"));
252 marginsModule->marginCO->insertItem(qt_("Very small margins"));
253 marginsModule->marginCO->insertItem(qt_("Very wide margins"));
254 } else if (olditem > 1) {
257 marginsModule->marginCO->setCurrentItem(olditem);
258 setCustomMargins(olditem);
262 void QDocumentDialog::setCustomPapersize(int papersize)
264 bool const custom = (papersize == 1);
266 pageLayoutModule->paperwidthL->setEnabled(custom);
267 pageLayoutModule->paperwidthLE->setEnabled(custom);
268 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
269 pageLayoutModule->paperheightL->setEnabled(custom);
270 pageLayoutModule->paperheightLE->setEnabled(custom);
271 pageLayoutModule->paperheightLE->setFocus();
272 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
276 void QDocumentDialog::setCustomMargins(int margin)
278 bool const custom = (margin == 1);
280 marginsModule->topL->setEnabled(custom);
281 marginsModule->topLE->setEnabled(custom);
282 marginsModule->topUnit->setEnabled(custom);
284 marginsModule->bottomL->setEnabled(custom);
285 marginsModule->bottomLE->setEnabled(custom);
286 marginsModule->bottomUnit->setEnabled(custom);
288 marginsModule->innerL->setEnabled(custom);
289 marginsModule->innerLE->setEnabled(custom);
290 marginsModule->innerUnit->setEnabled(custom);
292 marginsModule->outerL->setEnabled(custom);
293 marginsModule->outerLE->setEnabled(custom);
294 marginsModule->outerUnit->setEnabled(custom);
296 marginsModule->headheightL->setEnabled(custom);
297 marginsModule->headheightLE->setEnabled(custom);
298 marginsModule->headheightUnit->setEnabled(custom);
300 marginsModule->headsepL->setEnabled(custom);
301 marginsModule->headsepLE->setEnabled(custom);
302 marginsModule->headsepUnit->setEnabled(custom);
304 marginsModule->footskipL->setEnabled(custom);
305 marginsModule->footskipLE->setEnabled(custom);
306 marginsModule->footskipUnit->setEnabled(custom);
310 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
312 textLayoutModule->fontsizeCO->clear();
313 textLayoutModule->fontsizeCO->insertItem("default");
315 for (int n = 0; !token(items,'|',n).empty(); ++n)
316 textLayoutModule->fontsizeCO->
317 insertItem(toqstr(token(items,'|',n)));
319 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
320 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
321 textLayoutModule->fontsizeCO->setCurrentItem(n);
328 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
330 pageLayoutModule->pagestyleCO->clear();
331 pageLayoutModule->pagestyleCO->insertItem("default");
333 for (int n=0; !token(items,'|',n).empty(); ++n)
334 pageLayoutModule->pagestyleCO->
335 insertItem(toqstr(token(items,'|',n)));
337 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
338 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
339 pageLayoutModule->pagestyleCO->setCurrentItem(n);
346 void QDocumentDialog::classChanged()
348 ControlDocument & cntrl = form_->controller();
349 BufferParams & params = cntrl.params();
351 lyx::textclass_type const tc = latexModule->classCO->currentItem();
353 if (form_->controller().loadTextclass(tc)) {
354 params.textclass = tc;
356 if (lyxrc.auto_reset_options) {
357 params.useClassDefaults();
358 form_->update_contents();
360 updateFontsize(cntrl.textClass().opt_fontsize(),
363 updatePagestyle(cntrl.textClass().opt_pagestyle(),
367 latexModule->classCO->setCurrentItem(params.textclass);
372 void QDocumentDialog::updateNumbering()
374 int const depth = numberingModule->depthSL->value();
375 int const toc = numberingModule->tocSL->value();
376 QListViewItem * partitem = numberingModule->tocLV->firstChild();
377 QListViewItem * chapteritem = partitem->nextSibling();
378 QListViewItem * sectionitem = chapteritem->nextSibling();
379 QListViewItem * subsectionitem = sectionitem->nextSibling();
380 QListViewItem * subsubsectionitem = subsectionitem->nextSibling();
381 QListViewItem * paragraphitem = subsubsectionitem->nextSibling();
382 QListViewItem * subparagraphitem = paragraphitem->nextSibling();
384 QString const no = qt_("No");
385 QString const yes = qt_("Yes");
387 //numberingModule->tocLV->setUpdatesEnabled(false);
389 partitem->setText(1, yes);
390 chapteritem->setText(1, yes);
391 sectionitem->setText(1, yes);
392 subsectionitem->setText(1, yes);
393 subsubsectionitem->setText(1, yes);
394 paragraphitem->setText(1, yes);
395 subparagraphitem->setText(1, yes);
396 partitem->setText(2, yes);
397 chapteritem->setText(2, yes);
398 sectionitem->setText(2, yes);
399 subsectionitem->setText(2, yes);
400 subsubsectionitem->setText(2, yes);
401 paragraphitem->setText(2, yes);
402 subparagraphitem->setText(2, yes);
405 if (depth < -1) partitem->setText(1, no);
406 if (depth < 0) chapteritem->setText(1, no);
407 if (depth < 1) sectionitem->setText(1, no);
408 if (depth < 2) subsectionitem->setText(1, no);
409 if (depth < 3) subsubsectionitem->setText(1, no);
410 if (depth < 4) paragraphitem->setText(1, no);
411 if (depth < 5) subparagraphitem->setText(1, no);
414 if (toc < 0) chapteritem->setText(2, no);
415 if (toc < 1) sectionitem->setText(2, no);
416 if (toc < 2) subsectionitem->setText(2, no);
417 if (toc < 3) subsubsectionitem->setText(2, no);
418 if (toc < 4) paragraphitem->setText(2, no);
419 if (toc < 5) subparagraphitem->setText(2, no);
421 //numberingModule->tocLV->setUpdatesEnabled(true);
422 //numberingModule->tocLV->update();
426 void QDocumentDialog::updateBranchView()
428 // store the selected branch
429 QListViewItem * selItem =
430 branchesModule->branchesLV->selectedItem();
433 sel_branch = selItem->text(0);
435 branchesModule->branchesLV->clear();
437 BranchList::const_iterator it = form_->branchlist_.begin();
438 BranchList::const_iterator const end = form_->branchlist_.end();
439 for (; it != end; ++it) {
440 QString const bname = toqstr(it->getBranch());
441 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
442 QListViewItem * newItem =
443 new QListViewItem(branchesModule->branchesLV, bname, sel);
444 string const x11hexname = it->getColor();
446 if (x11hexname[0] == '#')
447 itemcolor.setNamedColor(toqstr(x11hexname));
448 if (itemcolor.isValid()) {
449 QPixmap coloritem(30, 10);
450 coloritem.fill(itemcolor);
451 newItem->setPixmap(2, coloritem);
453 // restore selected branch
454 if (bname == sel_branch)
455 branchesModule->branchesLV->setSelected(newItem, true);
461 void QDocumentDialog::addBranchPressed()
463 QString const new_branch = branchesModule->newBranchLE->text();
464 if (!new_branch.isEmpty()) {
465 form_->branchlist_.add(fromqstr(new_branch));
466 branchesModule->newBranchLE->clear();
472 void QDocumentDialog::deleteBranchPressed()
474 QListViewItem * selItem =
475 branchesModule->branchesLV->selectedItem();
478 sel_branch = selItem->text(0);
480 form_->branchlist_.remove(fromqstr(sel_branch));
481 branchesModule->newBranchLE->clear();
487 void QDocumentDialog::toggleBranchPressed()
489 QListViewItem * selItem =
490 branchesModule->branchesLV->selectedItem();
491 toggleBranch(selItem);
495 void QDocumentDialog::branchDoubleClicked(QListViewItem * selItem)
497 toggleBranch(selItem);
501 void QDocumentDialog::toggleBranch(QListViewItem * selItem)
506 QString sel_branch = selItem->text(0);
508 bool const selected = selItem->text(1) == qt_("Yes");
509 Branch * branch = form_->branchlist_.find(fromqstr(sel_branch));
510 if (branch && branch->setSelected(!selected)) {
511 branchesModule->newBranchLE->clear();
518 void QDocumentDialog::toggleBranchColor()
520 QListViewItem * selItem =
521 branchesModule->branchesLV->selectedItem();
524 sel_branch = selItem->text(0);
527 string current_branch = fromqstr(sel_branch);
529 form_->branchlist_.find(current_branch);
533 string x11hexname = branch->getColor();
534 if (x11hexname[0] == '#')
535 initial.setNamedColor(toqstr(x11hexname));
536 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
538 // add the color to the branchlist
539 branch->setColor(fromqstr(ncol.name()));
540 branchesModule->newBranchLE->clear();
546 } // namespace frontend