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 "validators.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;
51 QDocumentDialog::QDocumentDialog(QDocument * form)
52 : QDocumentDialogBase(0, 0, false, 0), form_(form)
54 connect(okPB, SIGNAL(clicked()),
55 form, SLOT(slotOK()));
56 connect(applyPB, SIGNAL(clicked()),
57 form, SLOT(slotApply()));
58 connect(closePB, SIGNAL(clicked()),
59 form, SLOT(slotClose()));
60 connect(restorePB, SIGNAL(clicked()),
61 form, SLOT(slotRestore()));
63 textLayoutModule = new TextLayoutModuleBase(this);
64 pageLayoutModule = new PageLayoutModuleBase(this);
65 marginsModule = new MarginsModuleBase(this);
66 langModule = new LanguageModuleBase(this);
67 bulletsModule = new BulletsModule(this);
68 numberingModule = new NumberingModuleBase(this);
69 biblioModule = new BiblioModuleBase(this);
70 mathsModule = new MathsModuleBase(this);
71 floatModule = new FloatPlacement(this, "floatplacement");
72 latexModule = new LaTeXModuleBase(this);
73 branchesModule = new BranchesModuleBase(this);
74 preambleModule = new PreambleModuleBase(this);
76 docPS->addPanel(latexModule, _("Document Class"));
77 docPS->addPanel(textLayoutModule, _("Text Layout"));
78 docPS->addPanel(pageLayoutModule, _("Page Layout"));
79 docPS->addPanel(marginsModule, _("Page Margins"));
80 docPS->addPanel(langModule, _("Language"));
81 docPS->addPanel(numberingModule, _("Numbering & TOC"));
82 docPS->addPanel(biblioModule, _("Bibliography"));
83 docPS->addPanel(mathsModule, _("Math Options"));
84 docPS->addPanel(floatModule, _("Float Placement"));
85 docPS->addPanel(bulletsModule, _("Bullets"));
86 docPS->addPanel(branchesModule, _("Branches"));
87 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
88 docPS->setCurrentPanel(_("Document Class"));
91 connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
93 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
94 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
95 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
96 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
97 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
99 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
100 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
101 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
102 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
104 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
105 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
106 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
107 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
108 numberingModule->tocLV->setSorting(-1);
110 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
111 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
113 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
115 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
116 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
117 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
118 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
120 connect(textLayoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
121 connect(textLayoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
122 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
123 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
124 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
125 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
126 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
127 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
128 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
129 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
130 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
131 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
132 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
135 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(setCustomMargins(int)));
136 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
137 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
138 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
139 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
140 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
141 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
142 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
143 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
144 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
145 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
146 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
147 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
148 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
149 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
150 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
153 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setMargins(int)));
154 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
155 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
156 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
157 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
158 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
159 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
160 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
161 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
162 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
163 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
164 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
165 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
168 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
171 connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed()));
172 connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed()));
173 connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed()));
174 connect(branchesModule->branchesLV, SIGNAL(doubleClicked(QListViewItem *)), this,
175 SLOT(branchDoubleClicked(QListViewItem *)));
176 connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
177 branchesModule->branchesLV->setSorting(0);
179 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
180 textLayoutModule->lspacingLE));
182 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
183 textLayoutModule->skipLE));
184 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
185 pageLayoutModule->paperheightLE));
186 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
187 pageLayoutModule->paperwidthLE));
188 marginsModule->topLE->setValidator(unsignedLengthValidator(
189 marginsModule->topLE));
190 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
191 marginsModule->bottomLE));
192 marginsModule->innerLE->setValidator(unsignedLengthValidator(
193 marginsModule->innerLE));
194 marginsModule->outerLE->setValidator(unsignedLengthValidator(
195 marginsModule->outerLE));
196 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
197 marginsModule->headsepLE));
198 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
199 marginsModule->headheightLE));
200 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
201 marginsModule->footskipLE));
205 QDocumentDialog::~QDocumentDialog()
210 void QDocumentDialog::showPreamble()
212 docPS->setCurrentPanel(_("LaTeX Preamble"));
216 void QDocumentDialog::saveDefaultClicked()
218 form_->saveDocDefault();
222 void QDocumentDialog::useDefaultsClicked()
224 form_->useClassDefaults();
228 void QDocumentDialog::change_adaptor()
234 void QDocumentDialog::closeEvent(QCloseEvent * e)
241 void QDocumentDialog::setLSpacing(int item)
243 textLayoutModule->lspacingLE->setEnabled(item == 3);
247 void QDocumentDialog::setSkip(int item)
249 bool const enable = (item == 3);
250 textLayoutModule->skipLE->setEnabled(enable);
251 textLayoutModule->skipLengthCO->setEnabled(enable);
255 void QDocumentDialog::enableSkip(bool skip)
257 textLayoutModule->skipCO->setEnabled(skip);
258 textLayoutModule->skipLE->setEnabled(skip);
259 textLayoutModule->skipLengthCO->setEnabled(skip);
261 setSkip(textLayoutModule->skipCO->currentItem());
264 void QDocumentDialog::portraitChanged()
266 setMargins(pageLayoutModule->papersizeCO->currentItem());
269 void QDocumentDialog::setMargins(int papersize)
271 int olditem = marginsModule->marginCO->currentItem();
272 marginsModule->marginCO->clear();
273 marginsModule->marginCO->insertItem(qt_("Default"));
274 marginsModule->marginCO->insertItem(qt_("Custom"));
275 bool a4size = (papersize == 6 || papersize == 0
276 && lyxrc.default_papersize == PAPER_A4);
277 if (a4size && pageLayoutModule->portraitRB->isChecked()) {
278 marginsModule->marginCO->insertItem(qt_("Small margins"));
279 marginsModule->marginCO->insertItem(qt_("Very small margins"));
280 marginsModule->marginCO->insertItem(qt_("Very wide margins"));
281 } else if (olditem > 1) {
284 marginsModule->marginCO->setCurrentItem(olditem);
285 setCustomMargins(olditem);
289 void QDocumentDialog::setCustomPapersize(int papersize)
291 bool const custom = (papersize == 1);
293 pageLayoutModule->paperwidthL->setEnabled(custom);
294 pageLayoutModule->paperwidthLE->setEnabled(custom);
295 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
296 pageLayoutModule->paperheightL->setEnabled(custom);
297 pageLayoutModule->paperheightLE->setEnabled(custom);
298 pageLayoutModule->paperheightLE->setFocus();
299 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
303 void QDocumentDialog::setCustomMargins(int margin)
305 bool const custom = (margin == 1);
307 marginsModule->topL->setEnabled(custom);
308 marginsModule->topLE->setEnabled(custom);
309 marginsModule->topUnit->setEnabled(custom);
311 marginsModule->bottomL->setEnabled(custom);
312 marginsModule->bottomLE->setEnabled(custom);
313 marginsModule->bottomUnit->setEnabled(custom);
315 marginsModule->innerL->setEnabled(custom);
316 marginsModule->innerLE->setEnabled(custom);
317 marginsModule->innerUnit->setEnabled(custom);
319 marginsModule->outerL->setEnabled(custom);
320 marginsModule->outerLE->setEnabled(custom);
321 marginsModule->outerUnit->setEnabled(custom);
323 marginsModule->headheightL->setEnabled(custom);
324 marginsModule->headheightLE->setEnabled(custom);
325 marginsModule->headheightUnit->setEnabled(custom);
327 marginsModule->headsepL->setEnabled(custom);
328 marginsModule->headsepLE->setEnabled(custom);
329 marginsModule->headsepUnit->setEnabled(custom);
331 marginsModule->footskipL->setEnabled(custom);
332 marginsModule->footskipLE->setEnabled(custom);
333 marginsModule->footskipUnit->setEnabled(custom);
337 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
339 textLayoutModule->fontsizeCO->clear();
340 textLayoutModule->fontsizeCO->insertItem("default");
342 for (int n = 0; !token(items,'|',n).empty(); ++n)
343 textLayoutModule->fontsizeCO->
344 insertItem(toqstr(token(items,'|',n)));
346 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
347 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
348 textLayoutModule->fontsizeCO->setCurrentItem(n);
355 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
357 pageLayoutModule->pagestyleCO->clear();
358 pageLayoutModule->pagestyleCO->insertItem("default");
360 for (int n=0; !token(items,'|',n).empty(); ++n)
361 pageLayoutModule->pagestyleCO->
362 insertItem(toqstr(token(items,'|',n)));
364 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
365 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
366 pageLayoutModule->pagestyleCO->setCurrentItem(n);
373 void QDocumentDialog::classChanged()
375 ControlDocument & cntrl = form_->controller();
376 BufferParams & params = cntrl.params();
378 lyx::textclass_type const tc = latexModule->classCO->currentItem();
380 if (form_->controller().loadTextclass(tc)) {
381 params.textclass = tc;
382 if (lyxrc.auto_reset_options)
383 params.useClassDefaults();
384 form_->update_contents();
386 latexModule->classCO->setCurrentItem(params.textclass);
391 void QDocumentDialog::updateNumbering()
393 LyXTextClass const & tclass =
394 form_->controller().params().getLyXTextClass();
396 //numberingModule->tocLV->setUpdatesEnabled(false);
398 // Update the example QListView
399 int const depth = numberingModule->depthSL->value();
400 int const toc = numberingModule->tocSL->value();
401 QString const no = qt_("No");
402 QString const yes = qt_("Yes");
403 LyXTextClass::const_iterator end = tclass.end();
404 LyXTextClass::const_iterator cit = tclass.begin();
405 numberingModule->tocLV->clear();
406 QListViewItem * item = 0;
407 for ( ; cit != end ; ++cit) {
408 int const toclevel = (*cit)->toclevel;
409 if (toclevel != LyXLayout::NOT_IN_TOC) {
410 item = new QListViewItem(numberingModule->tocLV,
411 item, qt_((*cit)->name()));
412 item->setText(1, (toclevel <= depth) ? yes : no);
413 item->setText(2, (toclevel <= toc) ? yes : no);
417 //numberingModule->tocLV->setUpdatesEnabled(true);
418 //numberingModule->tocLV->update();
422 void QDocumentDialog::updateBranchView()
424 // store the selected branch
425 QListViewItem * selItem =
426 branchesModule->branchesLV->selectedItem();
429 sel_branch = selItem->text(0);
431 branchesModule->branchesLV->clear();
433 BranchList::const_iterator it = form_->branchlist_.begin();
434 BranchList::const_iterator const end = form_->branchlist_.end();
435 for (; it != end; ++it) {
436 QString const bname = toqstr(it->getBranch());
437 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
438 QListViewItem * newItem =
439 new QListViewItem(branchesModule->branchesLV, bname, sel);
440 string const x11hexname = it->getColor();
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);
449 // restore selected branch
450 if (bname == sel_branch)
451 branchesModule->branchesLV->setSelected(newItem, true);
457 void QDocumentDialog::addBranchPressed()
459 QString const new_branch = branchesModule->newBranchLE->text();
460 if (!new_branch.isEmpty()) {
461 form_->branchlist_.add(fromqstr(new_branch));
462 branchesModule->newBranchLE->clear();
468 void QDocumentDialog::deleteBranchPressed()
470 QListViewItem * selItem =
471 branchesModule->branchesLV->selectedItem();
474 sel_branch = selItem->text(0);
476 form_->branchlist_.remove(fromqstr(sel_branch));
477 branchesModule->newBranchLE->clear();
483 void QDocumentDialog::toggleBranchPressed()
485 QListViewItem * selItem =
486 branchesModule->branchesLV->selectedItem();
487 toggleBranch(selItem);
491 void QDocumentDialog::branchDoubleClicked(QListViewItem * selItem)
493 toggleBranch(selItem);
497 void QDocumentDialog::toggleBranch(QListViewItem * selItem)
502 QString sel_branch = selItem->text(0);
504 bool const selected = selItem->text(1) == qt_("Yes");
505 Branch * branch = form_->branchlist_.find(fromqstr(sel_branch));
506 if (branch && branch->setSelected(!selected)) {
507 branchesModule->newBranchLE->clear();
514 void QDocumentDialog::toggleBranchColor()
516 QListViewItem * selItem =
517 branchesModule->branchesLV->selectedItem();
520 sel_branch = selItem->text(0);
523 string current_branch = fromqstr(sel_branch);
525 form_->branchlist_.find(current_branch);
529 string x11hexname = branch->getColor();
530 if (x11hexname[0] == '#')
531 initial.setNamedColor(toqstr(x11hexname));
532 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
534 // add the color to the branchlist
535 branch->setColor(fromqstr(ncol.name()));
536 branchesModule->newBranchLE->clear();
542 } // namespace frontend