]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDocumentDialog.C
Use PanelStack for the document dialog too
[lyx.git] / src / frontends / qt2 / QDocumentDialog.C
1 /**
2  * \file QDocumentDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12 #include "qt_helpers.h"
13
14 #include "ControlDocument.h"
15 #include "QDocument.h"
16
17
18 #include "QDocumentDialog.h"
19
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"
31
32 #include "Spacing.h"
33 #include "support/lstrings.h"
34 #include "lyxrc.h"
35 #include "buffer.h"
36
37 #include <qwidgetstack.h>
38 #include <qlistbox.h>
39 #include <qlabel.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>
47 #include <qspinbox.h>
48 #include "lengthcombo.h"
49
50
51 QDocumentDialog::QDocumentDialog(QDocument * form)
52         : QDocumentDialogBase(0, 0, false, 0), form_(form)
53 {
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()));
62
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);
72
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"));
83
84         // preamble
85         connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
86         // biblio
87         connect(biblioModule->natbibCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
88         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
89         // language & quote
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()));
96         // numbering
97         connect(numberingModule->sectionnrDepthSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
98         connect(numberingModule->tocDepthSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
99         // packages
100         connect(packagesModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
101         connect(packagesModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
102         // layout
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()));
117
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)));
121
122         // margins
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()));
139
140         // paper
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()));
145
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()));
155
156         // bullets
157         connect(bulletsModule->bulletsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
158         connect(bulletsModule->bulletsLV, SIGNAL(selectionChanged()), this, SLOT(change_adaptor()));
159 }
160
161
162 QDocumentDialog::~QDocumentDialog()
163 {
164 }
165
166
167 void QDocumentDialog::showPreamble()
168 {
169         docPS->setCurrentPanel(_("LaTeX Preamble"));
170 }
171
172
173 void QDocumentDialog::saveDefaultClicked()
174 {
175         form_->saveDocDefault();
176 }
177
178
179 void QDocumentDialog::useDefaultsClicked()
180 {
181     form_->useClassDefaults();
182 }
183
184
185 void QDocumentDialog::change_adaptor()
186 {
187         form_->changed();
188 }
189
190
191 void QDocumentDialog::closeEvent(QCloseEvent * e)
192 {
193         form_->slotWMHide();
194         e->accept();
195 }
196
197
198 void QDocumentDialog::setLSpacing(int item)
199 {
200         layoutModule->lspacingLE->setEnabled(item == 3);
201 }
202
203
204 void QDocumentDialog::setSkip(int item)
205 {
206         bool const enable = (item == 3);
207         layoutModule->skipLE->setEnabled(enable);
208         layoutModule->skipLengthCO->setEnabled(enable);
209 }
210
211
212 void QDocumentDialog::enableSkip(bool skip)
213 {
214         layoutModule->skipCO->setEnabled(skip);
215         layoutModule->skipLE->setEnabled(skip);
216         layoutModule->skipLengthCO->setEnabled(skip);
217         if (skip)
218                 setSkip(layoutModule->skipCO->currentItem());
219 }
220
221 void QDocumentDialog::portraitChanged()
222 {
223         setMargins(paperModule->papersizeCO->currentItem());
224 }
225
226 void QDocumentDialog::setMargins(int papersize)
227 {
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) {
239                 olditem = 0;
240         }
241         marginsModule->marginCO->setCurrentItem(olditem);
242         setCustomMargins(olditem);
243 }
244
245
246 void QDocumentDialog::setCustomPapersize(int papersize)
247 {
248         bool const custom = (papersize == 1);
249
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);
257 }
258
259
260 void QDocumentDialog::setCustomMargins(int margin)
261 {
262         bool const custom = (margin == 1);
263
264         marginsModule->topL->setEnabled(custom);
265         marginsModule->topLE->setEnabled(custom);
266         marginsModule->topUnit->setEnabled(custom);
267
268         marginsModule->bottomL->setEnabled(custom);
269         marginsModule->bottomLE->setEnabled(custom);
270         marginsModule->bottomUnit->setEnabled(custom);
271
272         marginsModule->innerL->setEnabled(custom);
273         marginsModule->innerLE->setEnabled(custom);
274         marginsModule->innerUnit->setEnabled(custom);
275
276         marginsModule->outerL->setEnabled(custom);
277         marginsModule->outerLE->setEnabled(custom);
278         marginsModule->outerUnit->setEnabled(custom);
279
280         marginsModule->headheightL->setEnabled(custom);
281         marginsModule->headheightLE->setEnabled(custom);
282         marginsModule->headheightUnit->setEnabled(custom);
283
284         marginsModule->headsepL->setEnabled(custom);
285         marginsModule->headsepLE->setEnabled(custom);
286         marginsModule->headsepUnit->setEnabled(custom);
287
288         marginsModule->footskipL->setEnabled(custom);
289         marginsModule->footskipLE->setEnabled(custom);
290         marginsModule->footskipUnit->setEnabled(custom);
291
292 }
293
294
295 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
296 {
297         layoutModule->fontsizeCO->clear();
298         layoutModule->fontsizeCO->insertItem("default");
299
300         for (int n=0; !token(items,'|',n).empty(); ++n)
301                 layoutModule->fontsizeCO->
302                         insertItem(toqstr(token(items,'|',n)));
303
304         for (int n = 0; n<layoutModule->fontsizeCO->count(); ++n) {
305                 if (fromqstr(layoutModule->fontsizeCO->text(n)) == sel) {
306                         layoutModule->fontsizeCO->setCurrentItem(n);
307                         break;
308                 }
309         }
310 }
311
312
313 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
314 {
315         layoutModule->pagestyleCO->clear();
316         layoutModule->pagestyleCO->insertItem("default");
317
318         for (int n=0; !token(items,'|',n).empty(); ++n)
319                 layoutModule->pagestyleCO->
320                         insertItem(toqstr(token(items,'|',n)));
321
322         for (int n = 0; n<layoutModule->pagestyleCO->count(); ++n) {
323                 if (fromqstr(layoutModule->pagestyleCO->text(n))==sel) {
324                         layoutModule->pagestyleCO->setCurrentItem(n);
325                         break;
326                 }
327         }
328 }
329
330
331 void QDocumentDialog::classChanged()
332 {
333         ControlDocument & cntrl = form_->controller();
334         BufferParams & params = cntrl.params();
335
336         lyx::textclass_type const tc = layoutModule->classCO->currentItem();
337
338         if (form_->controller().loadTextclass(tc)) {
339                 params.textclass = tc;
340
341                 if (lyxrc.auto_reset_options) {
342                         params.useClassDefaults();
343                         form_->update_contents();
344                 } else {
345                         updateFontsize(cntrl.textClass().opt_fontsize(),
346                                        params.fontsize);
347
348                         updatePagestyle(cntrl.textClass().opt_pagestyle(),
349                                         params.pagestyle);
350                 }
351         } else {
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);
356                                 break;
357                         }
358                 }
359         }
360 }