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 "lengthvalidator.h"
19 #include "panelstack.h"
20 #include "qt_helpers.h"
22 #include "bufferparams.h"
26 #include "controllers/ControlDocument.h"
28 #include "support/lstrings.h"
31 #include <qmultilineedit.h>
32 #include <qlineedit.h>
33 #include <qlistview.h>
34 #include <qpushbutton.h>
35 #include <qradiobutton.h>
36 #include <qcheckbox.h>
40 #include <qcolordialog.h>
41 #include <qvalidator.h>
43 using lyx::support::token;
53 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
55 LengthValidator * v = new LengthValidator(ed);
56 v->setBottom(LyXLength());
63 QDocumentDialog::QDocumentDialog(QDocument * form)
64 : QDocumentDialogBase(0, 0, false, 0), form_(form)
66 connect(okPB, SIGNAL(clicked()),
67 form, SLOT(slotOK()));
68 connect(applyPB, SIGNAL(clicked()),
69 form, SLOT(slotApply()));
70 connect(closePB, SIGNAL(clicked()),
71 form, SLOT(slotClose()));
72 connect(restorePB, SIGNAL(clicked()),
73 form, SLOT(slotRestore()));
75 textLayoutModule = new TextLayoutModuleBase(this);
76 pageLayoutModule = new PageLayoutModuleBase(this);
77 marginsModule = new MarginsModuleBase(this);
78 langModule = new LanguageModuleBase(this);
79 bulletsModule = new BulletsModule(this);
80 numberingModule = new NumberingModuleBase(this);
81 biblioModule = new BiblioModuleBase(this);
82 mathsModule = new MathsModuleBase(this);
83 floatModule = new FloatPlacement(this, "floatplacement");
84 latexModule = new LaTeXModuleBase(this);
85 branchesModule = new BranchesModuleBase(this);
86 preambleModule = new PreambleModuleBase(this);
88 docPS->addPanel(latexModule, _("Document Class"));
89 docPS->addPanel(textLayoutModule, _("Text Layout"));
90 docPS->addPanel(pageLayoutModule, _("Page Layout"));
91 docPS->addPanel(marginsModule, _("Page Margins"));
92 docPS->addPanel(langModule, _("Language"));
93 docPS->addPanel(numberingModule, _("Numbering & TOC"));
94 docPS->addPanel(biblioModule, _("Bibliography"));
95 docPS->addPanel(mathsModule, _("Math options"));
96 docPS->addPanel(floatModule, _("Float Placement"));
97 docPS->addPanel(bulletsModule, _("Bullets"));
98 docPS->addPanel(branchesModule, _("Branches"));
99 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
100 docPS->setCurrentPanel(_("Document Class"));
103 connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
105 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
106 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
107 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
108 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
109 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
111 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
112 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
113 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
114 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
116 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
117 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
118 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
119 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
120 numberingModule->tocLV->setSorting(-1);
122 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
123 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
125 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
127 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
128 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
129 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
130 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
132 connect(textLayoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
133 connect(textLayoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
134 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
135 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
136 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
137 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
138 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
139 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
140 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
141 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
142 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
143 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
144 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
147 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(setCustomMargins(int)));
148 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
149 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
150 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
151 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
152 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
153 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
154 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
155 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
156 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
157 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
158 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
159 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
160 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
161 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
162 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
165 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setMargins(int)));
166 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
167 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
168 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
169 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
170 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
171 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
172 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
173 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
174 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
175 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
176 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
177 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
180 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
183 connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed()));
184 connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed()));
185 connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed()));
186 connect(branchesModule->branchesLV, SIGNAL(doubleClicked(QListViewItem *)), this,
187 SLOT(branchDoubleClicked(QListViewItem *)));
188 connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
189 branchesModule->branchesLV->setSorting(0);
191 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
192 textLayoutModule->lspacingLE));
194 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
195 textLayoutModule->skipLE));
196 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
197 pageLayoutModule->paperheightLE));
198 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
199 pageLayoutModule->paperwidthLE));
200 marginsModule->topLE->setValidator(unsignedLengthValidator(
201 marginsModule->topLE));
202 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
203 marginsModule->bottomLE));
204 marginsModule->innerLE->setValidator(unsignedLengthValidator(
205 marginsModule->innerLE));
206 marginsModule->outerLE->setValidator(unsignedLengthValidator(
207 marginsModule->outerLE));
208 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
209 marginsModule->headsepLE));
210 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
211 marginsModule->headheightLE));
212 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
213 marginsModule->footskipLE));
217 QDocumentDialog::~QDocumentDialog()
222 void QDocumentDialog::showPreamble()
224 docPS->setCurrentPanel(_("LaTeX Preamble"));
228 void QDocumentDialog::saveDefaultClicked()
230 form_->saveDocDefault();
234 void QDocumentDialog::useDefaultsClicked()
236 form_->useClassDefaults();
240 void QDocumentDialog::change_adaptor()
246 void QDocumentDialog::closeEvent(QCloseEvent * e)
253 void QDocumentDialog::setLSpacing(int item)
255 textLayoutModule->lspacingLE->setEnabled(item == 3);
259 void QDocumentDialog::setSkip(int item)
261 bool const enable = (item == 3);
262 textLayoutModule->skipLE->setEnabled(enable);
263 textLayoutModule->skipLengthCO->setEnabled(enable);
267 void QDocumentDialog::enableSkip(bool skip)
269 textLayoutModule->skipCO->setEnabled(skip);
270 textLayoutModule->skipLE->setEnabled(skip);
271 textLayoutModule->skipLengthCO->setEnabled(skip);
273 setSkip(textLayoutModule->skipCO->currentItem());
276 void QDocumentDialog::portraitChanged()
278 setMargins(pageLayoutModule->papersizeCO->currentItem());
281 void QDocumentDialog::setMargins(int papersize)
283 int olditem = marginsModule->marginCO->currentItem();
284 marginsModule->marginCO->clear();
285 marginsModule->marginCO->insertItem(qt_("Default"));
286 marginsModule->marginCO->insertItem(qt_("Custom"));
287 bool a4size = (papersize == 6 || papersize == 0
288 && lyxrc.default_papersize == PAPER_A4PAPER);
289 if (a4size && pageLayoutModule->portraitRB->isChecked()) {
290 marginsModule->marginCO->insertItem(qt_("Small margins"));
291 marginsModule->marginCO->insertItem(qt_("Very small margins"));
292 marginsModule->marginCO->insertItem(qt_("Very wide margins"));
293 } else if (olditem > 1) {
296 marginsModule->marginCO->setCurrentItem(olditem);
297 setCustomMargins(olditem);
301 void QDocumentDialog::setCustomPapersize(int papersize)
303 bool const custom = (papersize == 1);
305 pageLayoutModule->paperwidthL->setEnabled(custom);
306 pageLayoutModule->paperwidthLE->setEnabled(custom);
307 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
308 pageLayoutModule->paperheightL->setEnabled(custom);
309 pageLayoutModule->paperheightLE->setEnabled(custom);
310 pageLayoutModule->paperheightLE->setFocus();
311 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
315 void QDocumentDialog::setCustomMargins(int margin)
317 bool const custom = (margin == 1);
319 marginsModule->topL->setEnabled(custom);
320 marginsModule->topLE->setEnabled(custom);
321 marginsModule->topUnit->setEnabled(custom);
323 marginsModule->bottomL->setEnabled(custom);
324 marginsModule->bottomLE->setEnabled(custom);
325 marginsModule->bottomUnit->setEnabled(custom);
327 marginsModule->innerL->setEnabled(custom);
328 marginsModule->innerLE->setEnabled(custom);
329 marginsModule->innerUnit->setEnabled(custom);
331 marginsModule->outerL->setEnabled(custom);
332 marginsModule->outerLE->setEnabled(custom);
333 marginsModule->outerUnit->setEnabled(custom);
335 marginsModule->headheightL->setEnabled(custom);
336 marginsModule->headheightLE->setEnabled(custom);
337 marginsModule->headheightUnit->setEnabled(custom);
339 marginsModule->headsepL->setEnabled(custom);
340 marginsModule->headsepLE->setEnabled(custom);
341 marginsModule->headsepUnit->setEnabled(custom);
343 marginsModule->footskipL->setEnabled(custom);
344 marginsModule->footskipLE->setEnabled(custom);
345 marginsModule->footskipUnit->setEnabled(custom);
349 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
351 textLayoutModule->fontsizeCO->clear();
352 textLayoutModule->fontsizeCO->insertItem("default");
354 for (int n = 0; !token(items,'|',n).empty(); ++n)
355 textLayoutModule->fontsizeCO->
356 insertItem(toqstr(token(items,'|',n)));
358 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
359 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
360 textLayoutModule->fontsizeCO->setCurrentItem(n);
367 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
369 pageLayoutModule->pagestyleCO->clear();
370 pageLayoutModule->pagestyleCO->insertItem("default");
372 for (int n=0; !token(items,'|',n).empty(); ++n)
373 pageLayoutModule->pagestyleCO->
374 insertItem(toqstr(token(items,'|',n)));
376 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
377 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
378 pageLayoutModule->pagestyleCO->setCurrentItem(n);
385 void QDocumentDialog::classChanged()
387 ControlDocument & cntrl = form_->controller();
388 BufferParams & params = cntrl.params();
390 lyx::textclass_type const tc = latexModule->classCO->currentItem();
392 if (form_->controller().loadTextclass(tc)) {
393 params.textclass = tc;
395 if (lyxrc.auto_reset_options) {
396 params.useClassDefaults();
397 form_->update_contents();
399 updateFontsize(cntrl.textClass().opt_fontsize(),
402 updatePagestyle(cntrl.textClass().opt_pagestyle(),
406 latexModule->classCO->setCurrentItem(params.textclass);
411 void QDocumentDialog::updateNumbering()
413 int const depth = numberingModule->depthSL->value();
414 int const toc = numberingModule->tocSL->value();
415 QListViewItem * partitem = numberingModule->tocLV->firstChild();
416 QListViewItem * chapteritem = partitem->nextSibling();
417 QListViewItem * sectionitem = chapteritem->nextSibling();
418 QListViewItem * subsectionitem = sectionitem->nextSibling();
419 QListViewItem * subsubsectionitem = subsectionitem->nextSibling();
420 QListViewItem * paragraphitem = subsubsectionitem->nextSibling();
421 QListViewItem * subparagraphitem = paragraphitem->nextSibling();
423 QString const no = qt_("No");
424 QString const yes = qt_("Yes");
426 //numberingModule->tocLV->setUpdatesEnabled(false);
428 partitem->setText(1, yes);
429 chapteritem->setText(1, yes);
430 sectionitem->setText(1, yes);
431 subsectionitem->setText(1, yes);
432 subsubsectionitem->setText(1, yes);
433 paragraphitem->setText(1, yes);
434 subparagraphitem->setText(1, yes);
435 partitem->setText(2, yes);
436 chapteritem->setText(2, yes);
437 sectionitem->setText(2, yes);
438 subsectionitem->setText(2, yes);
439 subsubsectionitem->setText(2, yes);
440 paragraphitem->setText(2, yes);
441 subparagraphitem->setText(2, yes);
444 if (depth < -1) partitem->setText(1, no);
445 if (depth < 0) chapteritem->setText(1, no);
446 if (depth < 1) sectionitem->setText(1, no);
447 if (depth < 2) subsectionitem->setText(1, no);
448 if (depth < 3) subsubsectionitem->setText(1, no);
449 if (depth < 4) paragraphitem->setText(1, no);
450 if (depth < 5) subparagraphitem->setText(1, no);
453 if (toc < 0) chapteritem->setText(2, no);
454 if (toc < 1) sectionitem->setText(2, no);
455 if (toc < 2) subsectionitem->setText(2, no);
456 if (toc < 3) subsubsectionitem->setText(2, no);
457 if (toc < 4) paragraphitem->setText(2, no);
458 if (toc < 5) subparagraphitem->setText(2, no);
460 //numberingModule->tocLV->setUpdatesEnabled(true);
461 //numberingModule->tocLV->update();
465 void QDocumentDialog::updateBranchView()
467 // store the selected branch
468 QListViewItem * selItem =
469 branchesModule->branchesLV->selectedItem();
472 sel_branch = selItem->text(0);
474 branchesModule->branchesLV->clear();
476 BranchList::const_iterator it = form_->branchlist_.begin();
477 BranchList::const_iterator const end = form_->branchlist_.end();
478 for (; it != end; ++it) {
479 QString const bname = toqstr(it->getBranch());
480 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
481 QListViewItem * newItem =
482 new QListViewItem(branchesModule->branchesLV, bname, sel);
483 string const x11hexname = it->getColor();
485 if (x11hexname[0] == '#')
486 itemcolor.setNamedColor(toqstr(x11hexname));
487 if (itemcolor.isValid()) {
488 QPixmap coloritem(30, 10);
489 coloritem.fill(itemcolor);
490 newItem->setPixmap(2, coloritem);
492 // restore selected branch
493 if (bname == sel_branch)
494 branchesModule->branchesLV->setSelected(newItem, true);
500 void QDocumentDialog::addBranchPressed()
502 QString const new_branch = branchesModule->newBranchLE->text();
503 if (!new_branch.isEmpty()) {
504 form_->branchlist_.add(fromqstr(new_branch));
505 branchesModule->newBranchLE->clear();
511 void QDocumentDialog::deleteBranchPressed()
513 QListViewItem * selItem =
514 branchesModule->branchesLV->selectedItem();
517 sel_branch = selItem->text(0);
519 form_->branchlist_.remove(fromqstr(sel_branch));
520 branchesModule->newBranchLE->clear();
526 void QDocumentDialog::toggleBranchPressed()
528 QListViewItem * selItem =
529 branchesModule->branchesLV->selectedItem();
530 toggleBranch(selItem);
534 void QDocumentDialog::branchDoubleClicked(QListViewItem * selItem)
536 toggleBranch(selItem);
540 void QDocumentDialog::toggleBranch(QListViewItem * selItem)
545 QString sel_branch = selItem->text(0);
547 bool const selected = selItem->text(1) == qt_("Yes");
548 Branch * branch = form_->branchlist_.find(fromqstr(sel_branch));
549 if (branch && branch->setSelected(!selected)) {
550 branchesModule->newBranchLE->clear();
557 void QDocumentDialog::toggleBranchColor()
559 QListViewItem * selItem =
560 branchesModule->branchesLV->selectedItem();
563 sel_branch = selItem->text(0);
566 string current_branch = fromqstr(sel_branch);
568 form_->branchlist_.find(current_branch);
572 string x11hexname = branch->getColor();
573 if (x11hexname[0] == '#')
574 initial.setNamedColor(toqstr(x11hexname));
575 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
577 // add the color to the branchlist
578 branch->setColor(fromqstr(ncol.name()));
579 branchesModule->newBranchLE->clear();
585 } // namespace frontend