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.
14 #include "qt_helpers.h"
16 #include "ControlDocument.h"
17 #include "QDocument.h"
18 #include "QDocumentDialog.h"
20 #include "panelstack.h"
21 #include "floatplacement.h"
24 #include "support/lstrings.h"
25 #include "bufferparams.h"
29 #include <qmultilineedit.h>
30 #include <qlineedit.h>
31 #include <qlistview.h>
32 #include <qpushbutton.h>
33 #include <qradiobutton.h>
34 #include <qcheckbox.h>
38 #include <qcolordialog.h>
39 #include "lengthcombo.h"
41 using lyx::support::token;
42 using lyx::support::getVectorFromString;
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->natbibCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
91 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
93 connect(langModule->singleQuoteRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
94 connect(langModule->doubleQuoteRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
95 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
96 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
97 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
98 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
100 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
101 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
102 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
103 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
104 numberingModule->tocLV->setSorting(-1);
106 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
107 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
109 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
111 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
112 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
113 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
114 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
116 connect(textLayoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
117 connect(textLayoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
118 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
119 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
120 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
121 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
122 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
123 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
124 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
125 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
126 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
127 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
128 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
131 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(setCustomMargins(int)));
132 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
133 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
134 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
135 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
136 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
137 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
138 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
139 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
140 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
141 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
142 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
143 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
144 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
145 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
146 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
149 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setMargins(int)));
150 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
151 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
152 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
153 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
154 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
155 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
156 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
157 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
158 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
159 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
160 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
161 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
164 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
167 connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed()));
168 connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed()));
169 connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed()));
170 connect(branchesModule->branchesLV, SIGNAL(doubleClicked(QListViewItem *)), this,
171 SLOT(branchDoubleClicked(QListViewItem *)));
172 connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
173 branchesModule->branchesLV->setSorting(0);
177 QDocumentDialog::~QDocumentDialog()
182 void QDocumentDialog::showPreamble()
184 docPS->setCurrentPanel(_("LaTeX Preamble"));
188 void QDocumentDialog::saveDefaultClicked()
190 form_->saveDocDefault();
194 void QDocumentDialog::useDefaultsClicked()
196 form_->useClassDefaults();
200 void QDocumentDialog::change_adaptor()
206 void QDocumentDialog::closeEvent(QCloseEvent * e)
213 void QDocumentDialog::setLSpacing(int item)
215 textLayoutModule->lspacingLE->setEnabled(item == 3);
219 void QDocumentDialog::setSkip(int item)
221 bool const enable = (item == 3);
222 textLayoutModule->skipLE->setEnabled(enable);
223 textLayoutModule->skipLengthCO->setEnabled(enable);
227 void QDocumentDialog::enableSkip(bool skip)
229 textLayoutModule->skipCO->setEnabled(skip);
230 textLayoutModule->skipLE->setEnabled(skip);
231 textLayoutModule->skipLengthCO->setEnabled(skip);
233 setSkip(textLayoutModule->skipCO->currentItem());
236 void QDocumentDialog::portraitChanged()
238 setMargins(pageLayoutModule->papersizeCO->currentItem());
241 void QDocumentDialog::setMargins(int papersize)
243 int olditem = marginsModule->marginCO->currentItem();
244 marginsModule->marginCO->clear();
245 marginsModule->marginCO->insertItem(qt_("Default"));
246 marginsModule->marginCO->insertItem(qt_("Custom"));
247 bool a4size = (papersize == 6 || papersize == 0
248 && lyxrc.default_papersize == PAPER_A4PAPER);
249 if (a4size && pageLayoutModule->portraitRB->isChecked()) {
250 marginsModule->marginCO->insertItem(qt_("Small margins"));
251 marginsModule->marginCO->insertItem(qt_("Very small margins"));
252 marginsModule->marginCO->insertItem(qt_("Very wide margins"));
253 } else if (olditem > 1) {
256 marginsModule->marginCO->setCurrentItem(olditem);
257 setCustomMargins(olditem);
261 void QDocumentDialog::setCustomPapersize(int papersize)
263 bool const custom = (papersize == 1);
265 pageLayoutModule->paperwidthL->setEnabled(custom);
266 pageLayoutModule->paperwidthLE->setEnabled(custom);
267 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
268 pageLayoutModule->paperheightL->setEnabled(custom);
269 pageLayoutModule->paperheightLE->setEnabled(custom);
270 pageLayoutModule->paperheightLE->setFocus();
271 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
275 void QDocumentDialog::setCustomMargins(int margin)
277 bool const custom = (margin == 1);
279 marginsModule->topL->setEnabled(custom);
280 marginsModule->topLE->setEnabled(custom);
281 marginsModule->topUnit->setEnabled(custom);
283 marginsModule->bottomL->setEnabled(custom);
284 marginsModule->bottomLE->setEnabled(custom);
285 marginsModule->bottomUnit->setEnabled(custom);
287 marginsModule->innerL->setEnabled(custom);
288 marginsModule->innerLE->setEnabled(custom);
289 marginsModule->innerUnit->setEnabled(custom);
291 marginsModule->outerL->setEnabled(custom);
292 marginsModule->outerLE->setEnabled(custom);
293 marginsModule->outerUnit->setEnabled(custom);
295 marginsModule->headheightL->setEnabled(custom);
296 marginsModule->headheightLE->setEnabled(custom);
297 marginsModule->headheightUnit->setEnabled(custom);
299 marginsModule->headsepL->setEnabled(custom);
300 marginsModule->headsepLE->setEnabled(custom);
301 marginsModule->headsepUnit->setEnabled(custom);
303 marginsModule->footskipL->setEnabled(custom);
304 marginsModule->footskipLE->setEnabled(custom);
305 marginsModule->footskipUnit->setEnabled(custom);
309 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
311 textLayoutModule->fontsizeCO->clear();
312 textLayoutModule->fontsizeCO->insertItem("default");
314 for (int n = 0; !token(items,'|',n).empty(); ++n)
315 textLayoutModule->fontsizeCO->
316 insertItem(toqstr(token(items,'|',n)));
318 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
319 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
320 textLayoutModule->fontsizeCO->setCurrentItem(n);
327 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
329 pageLayoutModule->pagestyleCO->clear();
330 pageLayoutModule->pagestyleCO->insertItem("default");
332 for (int n=0; !token(items,'|',n).empty(); ++n)
333 pageLayoutModule->pagestyleCO->
334 insertItem(toqstr(token(items,'|',n)));
336 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
337 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
338 pageLayoutModule->pagestyleCO->setCurrentItem(n);
345 void QDocumentDialog::classChanged()
347 ControlDocument & cntrl = form_->controller();
348 BufferParams & params = cntrl.params();
350 lyx::textclass_type const tc = latexModule->classCO->currentItem();
352 if (form_->controller().loadTextclass(tc)) {
353 params.textclass = tc;
355 if (lyxrc.auto_reset_options) {
356 params.useClassDefaults();
357 form_->update_contents();
359 updateFontsize(cntrl.textClass().opt_fontsize(),
362 updatePagestyle(cntrl.textClass().opt_pagestyle(),
366 latexModule->classCO->setCurrentItem(params.textclass);
371 void QDocumentDialog::updateNumbering()
373 int const depth = numberingModule->depthSL->value();
374 int const toc = numberingModule->tocSL->value();
375 QListViewItem * partitem = numberingModule->tocLV->firstChild();
376 QListViewItem * chapteritem = partitem->nextSibling();
377 QListViewItem * sectionitem = chapteritem->nextSibling();
378 QListViewItem * subsectionitem = sectionitem->nextSibling();
379 QListViewItem * subsubsectionitem = subsectionitem->nextSibling();
380 QListViewItem * paragraphitem = subsubsectionitem->nextSibling();
381 QListViewItem * subparagraphitem = paragraphitem->nextSibling();
383 QString const no = qt_("No");
384 QString const yes = qt_("Yes");
386 //numberingModule->tocLV->setUpdatesEnabled(false);
388 partitem->setText(1, yes);
389 chapteritem->setText(1, yes);
390 sectionitem->setText(1, yes);
391 subsectionitem->setText(1, yes);
392 subsubsectionitem->setText(1, yes);
393 paragraphitem->setText(1, yes);
394 subparagraphitem->setText(1, yes);
395 partitem->setText(2, yes);
396 chapteritem->setText(2, yes);
397 sectionitem->setText(2, yes);
398 subsectionitem->setText(2, yes);
399 subsubsectionitem->setText(2, yes);
400 paragraphitem->setText(2, yes);
401 subparagraphitem->setText(2, yes);
404 if (depth < -1) partitem->setText(1, no);
405 if (depth < 0) chapteritem->setText(1, no);
406 if (depth < 1) sectionitem->setText(1, no);
407 if (depth < 2) subsectionitem->setText(1, no);
408 if (depth < 3) subsubsectionitem->setText(1, no);
409 if (depth < 4) paragraphitem->setText(1, no);
410 if (depth < 5) subparagraphitem->setText(1, no);
413 if (toc < 0) chapteritem->setText(2, no);
414 if (toc < 1) sectionitem->setText(2, no);
415 if (toc < 2) subsectionitem->setText(2, no);
416 if (toc < 3) subsubsectionitem->setText(2, no);
417 if (toc < 4) paragraphitem->setText(2, no);
418 if (toc < 5) subparagraphitem->setText(2, no);
420 //numberingModule->tocLV->setUpdatesEnabled(true);
421 //numberingModule->tocLV->update();
425 void QDocumentDialog::updateBranchView()
427 ControlDocument & cntrl = form_->controller();
428 BufferParams & params = cntrl.params();
430 string const all_branches = params.branchlist().allBranches();
431 branchesModule->branchesLV->clear();
432 if (!all_branches.empty()) {
433 std::vector<string> all = getVectorFromString(all_branches, "|");
434 for (unsigned i = 0; i < all.size(); ++i) {
435 QString const bname = toqstr(all[i].c_str());
437 (params.branchlist().selected(fromqstr(bname))) ? qt_("Yes") : qt_("No");
438 QListViewItem * newItem =
439 new QListViewItem(branchesModule->branchesLV, bname, sel);
441 string x11hexname = params.branchlist().getColor(fromqstr(bname));
442 if (x11hexname[0] == '#')
443 itemcolor.setNamedColor(toqstr(x11hexname));
444 if (itemcolor.isValid()) {
445 QPixmap coloritem(30, 10);
446 coloritem.fill(itemcolor);
447 newItem->setPixmap(2, coloritem);
451 form_->branchlist_ = params.branchlist();
456 void QDocumentDialog::addBranchPressed()
458 ControlDocument & cntrl = form_->controller();
459 BufferParams & params = cntrl.params();
461 QString const new_branch = branchesModule->newBranchLE->text();
462 if (!new_branch.isEmpty()) {
463 params.branchlist().add(fromqstr(new_branch));
464 branchesModule->newBranchLE->clear();
470 void QDocumentDialog::deleteBranchPressed()
472 ControlDocument & cntrl = form_->controller();
473 BufferParams & params = cntrl.params();
475 QListViewItem * selItem =
476 branchesModule->branchesLV->selectedItem();
479 sel_branch = selItem->text(0);
481 params.branchlist().remove(fromqstr(sel_branch));
482 branchesModule->newBranchLE->clear();
488 void QDocumentDialog::toggleBranchPressed()
490 QListViewItem * selItem =
491 branchesModule->branchesLV->selectedItem();
492 toggleBranch(selItem);
496 void QDocumentDialog::branchDoubleClicked(QListViewItem * selItem)
498 toggleBranch(selItem);
502 void QDocumentDialog::toggleBranch(QListViewItem * selItem)
504 ControlDocument & cntrl = form_->controller();
505 BufferParams & params = cntrl.params();
509 sel_branch = selItem->text(0);
511 bool selected = false;
512 if (selItem->text(1) == qt_("Yes"))
514 params.branchlist().setSelected(fromqstr(sel_branch), !selected);
515 branchesModule->newBranchLE->clear();
521 void QDocumentDialog::toggleBranchColor()
523 ControlDocument & cntrl = form_->controller();
524 BufferParams & params = cntrl.params();
526 QListViewItem * selItem =
527 branchesModule->branchesLV->selectedItem();
530 sel_branch = selItem->text(0);
533 string current_branch = fromqstr(sel_branch);
534 string x11hexname = params.branchlist().getColor(current_branch);
535 if (x11hexname[0] == '#')
536 initial.setNamedColor(toqstr(x11hexname));
537 QColor ncol(QColorDialog::getColor(initial));
539 // add the color to the branchlist
540 params.branchlist().setColor(current_branch, fromqstr(ncol.name()));
541 branchesModule->newBranchLE->clear();