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
12 #include "qt_helpers.h"
14 #include "ControlDocument.h"
15 #include "QDocument.h"
18 #include "QDocumentDialog.h"
20 #include "ui/ClassModuleBase.h"
21 #include "ui/PackagesModuleBase.h"
22 #include "ui/PaperModuleBase.h"
23 #include "ui/LanguageModuleBase.h"
24 #include "ui/BulletsModuleBase.h"
25 #include "BulletsModule.h"
26 #include "ui/BiblioModuleBase.h"
27 #include "ui/NumberingModuleBase.h"
28 #include "ui/MarginsModuleBase.h"
29 #include "ui/PreambleModuleBase.h"
30 #include "panelstack.h"
33 #include "support/lstrings.h"
37 #include <qwidgetstack.h>
40 #include <qmultilineedit.h>
41 #include <qlineedit.h>
42 #include <qlistview.h>
43 #include <qpushbutton.h>
44 #include <qcombobox.h>
45 #include <qradiobutton.h>
46 #include <qcheckbox.h>
48 #include "lengthcombo.h"
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 layoutModule = new ClassModuleBase(this);
64 paperModule = new PaperModuleBase(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 packagesModule = new PackagesModuleBase(this);
71 preambleModule = new PreambleModuleBase(this);
73 docPS->addPanel(layoutModule, _("Layout"));
74 docPS->addPanel(paperModule, _("Paper"));
75 docPS->addPanel(marginsModule, _("Margins"));
76 docPS->addPanel(langModule, _("Language"));
77 docPS->addPanel(numberingModule, _("Table of Contents"));
78 docPS->addPanel(biblioModule, _("Bibliography"));
79 docPS->addPanel(packagesModule, _("LaTeX packages"));
80 docPS->addPanel(bulletsModule, _("Bullets"));
81 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
82 docPS->setCurrentPanel(_("Layout"));
85 connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
87 connect(biblioModule->natbibCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
88 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
90 connect(langModule->singleQuoteRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
91 connect(langModule->doubleQuoteRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
92 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
93 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
94 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
95 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
97 connect(numberingModule->sectionnrDepthSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
98 connect(numberingModule->tocDepthSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
100 connect(packagesModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
101 connect(packagesModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
103 connect(layoutModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
104 connect(layoutModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
105 connect(layoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
106 connect(layoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
107 connect(layoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
108 connect(layoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
109 connect(layoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
110 connect(layoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
111 connect(layoutModule->floatPlacementLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
112 connect(layoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
113 connect(layoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
114 connect(layoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
115 connect(layoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
116 connect(layoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
118 connect(layoutModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
119 connect(layoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
120 connect(layoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
123 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(setCustomMargins(int)));
124 connect(marginsModule->marginCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
125 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
126 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
127 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
128 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
129 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
130 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
131 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
132 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
133 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
134 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
135 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
136 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
137 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
138 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
141 connect(paperModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setMargins(int)));
142 connect(paperModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
143 connect(paperModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
144 connect(paperModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
146 connect(paperModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
147 connect(paperModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
148 connect(paperModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
149 connect(paperModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
150 connect(paperModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
151 connect(paperModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
152 connect(paperModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
153 connect(paperModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
154 connect(paperModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
157 connect(bulletsModule->bulletsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
158 connect(bulletsModule->bulletsLV, SIGNAL(selectionChanged()), this, SLOT(change_adaptor()));
162 QDocumentDialog::~QDocumentDialog()
167 void QDocumentDialog::showPreamble()
169 docPS->setCurrentPanel(_("LaTeX Preamble"));
173 void QDocumentDialog::saveDefaultClicked()
175 form_->saveDocDefault();
179 void QDocumentDialog::useDefaultsClicked()
181 form_->useClassDefaults();
185 void QDocumentDialog::change_adaptor()
191 void QDocumentDialog::closeEvent(QCloseEvent * e)
198 void QDocumentDialog::setLSpacing(int item)
200 layoutModule->lspacingLE->setEnabled(item == 3);
204 void QDocumentDialog::setSkip(int item)
206 bool const enable = (item == 3);
207 layoutModule->skipLE->setEnabled(enable);
208 layoutModule->skipLengthCO->setEnabled(enable);
212 void QDocumentDialog::enableSkip(bool skip)
214 layoutModule->skipCO->setEnabled(skip);
215 layoutModule->skipLE->setEnabled(skip);
216 layoutModule->skipLengthCO->setEnabled(skip);
218 setSkip(layoutModule->skipCO->currentItem());
221 void QDocumentDialog::portraitChanged()
223 setMargins(paperModule->papersizeCO->currentItem());
226 void QDocumentDialog::setMargins(int papersize)
228 int olditem = marginsModule->marginCO->currentItem();
229 marginsModule->marginCO->clear();
230 marginsModule->marginCO->insertItem(qt_("Default"));
231 marginsModule->marginCO->insertItem(qt_("Custom"));
232 bool a4size = (papersize == 6 || papersize == 0
233 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER);
234 if (a4size && paperModule->portraitRB->isChecked()) {
235 marginsModule->marginCO->insertItem(qt_("Small margins"));
236 marginsModule->marginCO->insertItem(qt_("Very small margins"));
237 marginsModule->marginCO->insertItem(qt_("Very wide margins"));
238 } else if (olditem > 1) {
241 marginsModule->marginCO->setCurrentItem(olditem);
242 setCustomMargins(olditem);
246 void QDocumentDialog::setCustomPapersize(int papersize)
248 bool const custom = (papersize == 1);
250 paperModule->paperwidthL->setEnabled(custom);
251 paperModule->paperwidthLE->setEnabled(custom);
252 paperModule->paperwidthUnitCO->setEnabled(custom);
253 paperModule->paperheightL->setEnabled(custom);
254 paperModule->paperheightLE->setEnabled(custom);
255 paperModule->paperheightLE->setFocus();
256 paperModule->paperheightUnitCO->setEnabled(custom);
260 void QDocumentDialog::setCustomMargins(int margin)
262 bool const custom = (margin == 1);
264 marginsModule->topL->setEnabled(custom);
265 marginsModule->topLE->setEnabled(custom);
266 marginsModule->topUnit->setEnabled(custom);
268 marginsModule->bottomL->setEnabled(custom);
269 marginsModule->bottomLE->setEnabled(custom);
270 marginsModule->bottomUnit->setEnabled(custom);
272 marginsModule->innerL->setEnabled(custom);
273 marginsModule->innerLE->setEnabled(custom);
274 marginsModule->innerUnit->setEnabled(custom);
276 marginsModule->outerL->setEnabled(custom);
277 marginsModule->outerLE->setEnabled(custom);
278 marginsModule->outerUnit->setEnabled(custom);
280 marginsModule->headheightL->setEnabled(custom);
281 marginsModule->headheightLE->setEnabled(custom);
282 marginsModule->headheightUnit->setEnabled(custom);
284 marginsModule->headsepL->setEnabled(custom);
285 marginsModule->headsepLE->setEnabled(custom);
286 marginsModule->headsepUnit->setEnabled(custom);
288 marginsModule->footskipL->setEnabled(custom);
289 marginsModule->footskipLE->setEnabled(custom);
290 marginsModule->footskipUnit->setEnabled(custom);
295 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
297 layoutModule->fontsizeCO->clear();
298 layoutModule->fontsizeCO->insertItem("default");
300 for (int n=0; !token(items,'|',n).empty(); ++n)
301 layoutModule->fontsizeCO->
302 insertItem(toqstr(token(items,'|',n)));
304 for (int n = 0; n<layoutModule->fontsizeCO->count(); ++n) {
305 if (fromqstr(layoutModule->fontsizeCO->text(n)) == sel) {
306 layoutModule->fontsizeCO->setCurrentItem(n);
313 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
315 layoutModule->pagestyleCO->clear();
316 layoutModule->pagestyleCO->insertItem("default");
318 for (int n=0; !token(items,'|',n).empty(); ++n)
319 layoutModule->pagestyleCO->
320 insertItem(toqstr(token(items,'|',n)));
322 for (int n = 0; n<layoutModule->pagestyleCO->count(); ++n) {
323 if (fromqstr(layoutModule->pagestyleCO->text(n))==sel) {
324 layoutModule->pagestyleCO->setCurrentItem(n);
331 void QDocumentDialog::classChanged()
333 ControlDocument & cntrl = form_->controller();
334 BufferParams & params = cntrl.params();
336 lyx::textclass_type const tc = layoutModule->classCO->currentItem();
338 if (form_->controller().loadTextclass(tc)) {
339 params.textclass = tc;
341 if (lyxrc.auto_reset_options) {
342 params.useClassDefaults();
343 form_->update_contents();
345 updateFontsize(cntrl.textClass().opt_fontsize(),
348 updatePagestyle(cntrl.textClass().opt_pagestyle(),
352 for (int n = 0; n<layoutModule->classCO->count(); ++n) {
353 if (layoutModule->classCO->text(n) ==
354 toqstr(cntrl.textClass().description())) {
355 layoutModule->classCO->setCurrentItem(n);