]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/QDocumentDialog.C
Extracted from r14281
[lyx.git] / src / frontends / qt3 / 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
13 #include "QDocument.h"
14 #include "QDocumentDialog.h"
15
16 #include "floatplacement.h"
17 #include "lcolorcache.h"
18 #include "lengthcombo.h"
19 #include "validators.h"
20 #include "panelstack.h"
21 #include "qt_helpers.h"
22
23 #include "bufferparams.h"
24 #include "gettext.h"
25 #include "lyxrc.h"
26 #include "tex-strings.h"
27
28 #include "controllers/ControlDocument.h"
29
30 #include "support/lstrings.h"
31
32 #include <qlabel.h>
33 #include <qmultilineedit.h>
34 #include <qlineedit.h>
35 #include <qlistview.h>
36 #include <qpushbutton.h>
37 #include <qradiobutton.h>
38 #include <qcheckbox.h>
39 #include <qslider.h>
40 #include <qspinbox.h>
41 #include <qpixmap.h>
42 #include <qcolor.h>
43 #include <qcolordialog.h>
44 #include <qvalidator.h>
45
46 using lyx::support::token;
47
48 using std::string;
49
50 namespace lyx {
51 namespace frontend {
52
53
54 QDocumentDialog::QDocumentDialog(QDocument * form)
55         : QDocumentDialogBase(0, 0, false, 0), form_(form)
56 {
57         connect(okPB, SIGNAL(clicked()),
58                 form, SLOT(slotOK()));
59         connect(applyPB, SIGNAL(clicked()),
60                 form, SLOT(slotApply()));
61         connect(closePB, SIGNAL(clicked()),
62                 form, SLOT(slotClose()));
63         connect(restorePB, SIGNAL(clicked()),
64                 form, SLOT(slotRestore()));
65
66         fontModule = new FontModuleBase(this);
67         textLayoutModule = new TextLayoutModuleBase(this);
68         pageLayoutModule = new PageLayoutModuleBase(this);
69         marginsModule = new MarginsModuleBase(this);
70         langModule = new LanguageModuleBase(this);
71         bulletsModule = new BulletsModule(this);
72         numberingModule = new NumberingModuleBase(this);
73         biblioModule = new BiblioModuleBase(this);
74         mathsModule = new MathsModuleBase(this);
75         floatModule = new FloatPlacement(this, "floatplacement");
76         latexModule = new LaTeXModuleBase(this);
77         branchesModule = new BranchesModuleBase(this);
78         preambleModule = new PreambleModuleBase(this);
79
80         docPS->addPanel(latexModule, _("Document Class"));
81         docPS->addPanel(fontModule, _("Fonts"));
82         docPS->addPanel(textLayoutModule, _("Text Layout"));
83         docPS->addPanel(pageLayoutModule, _("Page Layout"));
84         docPS->addPanel(marginsModule, _("Page Margins"));
85         docPS->addPanel(langModule, _("Language"));
86         docPS->addPanel(numberingModule, _("Numbering & TOC"));
87         docPS->addPanel(biblioModule, _("Bibliography"));
88         docPS->addPanel(mathsModule, _("Math Options"));
89         docPS->addPanel(floatModule, _("Float Placement"));
90         docPS->addPanel(bulletsModule, _("Bullets"));
91         docPS->addPanel(branchesModule, _("Branches"));
92         docPS->addPanel(preambleModule, _("LaTeX Preamble"));
93         docPS->setCurrentPanel(_("Document Class"));
94
95         // preamble
96         connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
97         // biblio
98         connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
99         connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
100         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
101         connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
102         connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
103         // language & quote
104         connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
105         connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
106         connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
107         connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
108         // numbering
109         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
110         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
111         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
112         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
113         numberingModule->tocLV->setSorting(-1);
114         // maths
115         connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
116         connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
117         // float
118         connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
119         // latex class
120         connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
121         connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
122         connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
123         connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
124         // text layout
125         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
126         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
127         connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
128         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
129         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
130         connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
131         connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
132         connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
133         connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
134         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
135         connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
136
137         // fonts
138         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
139         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(romanChanged(int)));
140         connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
141         connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(sansChanged(int)));
142         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
143         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(ttChanged(int)));
144         connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
145         connect(fontModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
146         connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
147         connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
148         connect(fontModule->fontScCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
149         connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
150
151         // margins
152         connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool)));
153         connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
154         connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
155         connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
156         connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
157         connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
158         connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
159         connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
160         connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
161         connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
162         connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
163         connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
164         connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
165         connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
166         connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
167         connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
168
169         // page layout
170         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
171         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
172         connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
173         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
174         connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
175         connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
176         connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
177         connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
178         connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
179         connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
180         connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
181         connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
182
183         // bullets
184         connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
185
186         // branches
187         connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed()));
188         connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed()));
189         connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed()));
190         connect(branchesModule->branchesLV, SIGNAL(doubleClicked(QListViewItem *)), this,
191                 SLOT(branchDoubleClicked(QListViewItem *)));
192         connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
193         branchesModule->branchesLV->setSorting(0);
194
195         textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
196                 textLayoutModule->lspacingLE));
197
198         textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
199                 textLayoutModule->skipLE));
200         pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
201                 pageLayoutModule->paperheightLE));
202         pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
203                 pageLayoutModule->paperwidthLE));
204         marginsModule->topLE->setValidator(unsignedLengthValidator(
205                 marginsModule->topLE));
206         marginsModule->bottomLE->setValidator(unsignedLengthValidator(
207                 marginsModule->bottomLE));
208         marginsModule->innerLE->setValidator(unsignedLengthValidator(
209                 marginsModule->innerLE));
210         marginsModule->outerLE->setValidator(unsignedLengthValidator(
211                 marginsModule->outerLE));
212         marginsModule->headsepLE->setValidator(unsignedLengthValidator(
213                 marginsModule->headsepLE));
214         marginsModule->headheightLE->setValidator(unsignedLengthValidator(
215                 marginsModule->headheightLE));
216         marginsModule->footskipLE->setValidator(unsignedLengthValidator(
217                 marginsModule->footskipLE));
218 }
219
220
221 QDocumentDialog::~QDocumentDialog()
222 {
223 }
224
225
226 void QDocumentDialog::showPreamble()
227 {
228         docPS->setCurrentPanel(_("LaTeX Preamble"));
229 }
230
231
232 void QDocumentDialog::saveDefaultClicked()
233 {
234         form_->saveDocDefault();
235 }
236
237
238 void QDocumentDialog::useDefaultsClicked()
239 {
240         form_->useClassDefaults();
241 }
242
243
244 void QDocumentDialog::change_adaptor()
245 {
246         form_->changed();
247 }
248
249
250 void QDocumentDialog::closeEvent(QCloseEvent * e)
251 {
252         form_->slotWMHide();
253         e->accept();
254 }
255
256
257 void QDocumentDialog::setLSpacing(int item)
258 {
259         textLayoutModule->lspacingLE->setEnabled(item == 3);
260 }
261
262
263 void QDocumentDialog::setSkip(int item)
264 {
265         bool const enable = (item == 3);
266         textLayoutModule->skipLE->setEnabled(enable);
267         textLayoutModule->skipLengthCO->setEnabled(enable);
268 }
269
270
271 void QDocumentDialog::enableSkip(bool skip)
272 {
273         textLayoutModule->skipCO->setEnabled(skip);
274         textLayoutModule->skipLE->setEnabled(skip);
275         textLayoutModule->skipLengthCO->setEnabled(skip);
276         if (skip)
277                 setSkip(textLayoutModule->skipCO->currentItem());
278 }
279
280 void QDocumentDialog::portraitChanged()
281 {
282         setMargins(pageLayoutModule->papersizeCO->currentItem());
283 }
284
285 void QDocumentDialog::setMargins(bool custom)
286 {
287         marginsModule->marginCB->setChecked(custom);
288         setCustomMargins(custom);
289 }
290
291
292 void QDocumentDialog::setCustomPapersize(int papersize)
293 {
294         bool const custom = (papersize == 1);
295
296         pageLayoutModule->paperwidthL->setEnabled(custom);
297         pageLayoutModule->paperwidthLE->setEnabled(custom);
298         pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
299         pageLayoutModule->paperheightL->setEnabled(custom);
300         pageLayoutModule->paperheightLE->setEnabled(custom);
301         pageLayoutModule->paperheightLE->setFocus();
302         pageLayoutModule->paperheightUnitCO->setEnabled(custom);
303 }
304
305
306 void QDocumentDialog::setCustomMargins(bool custom)
307 {
308         marginsModule->topL->setEnabled(!custom);
309         marginsModule->topLE->setEnabled(!custom);
310         marginsModule->topUnit->setEnabled(!custom);
311
312         marginsModule->bottomL->setEnabled(!custom);
313         marginsModule->bottomLE->setEnabled(!custom);
314         marginsModule->bottomUnit->setEnabled(!custom);
315
316         marginsModule->innerL->setEnabled(!custom);
317         marginsModule->innerLE->setEnabled(!custom);
318         marginsModule->innerUnit->setEnabled(!custom);
319
320         marginsModule->outerL->setEnabled(!custom);
321         marginsModule->outerLE->setEnabled(!custom);
322         marginsModule->outerUnit->setEnabled(!custom);
323
324         marginsModule->headheightL->setEnabled(!custom);
325         marginsModule->headheightLE->setEnabled(!custom);
326         marginsModule->headheightUnit->setEnabled(!custom);
327
328         marginsModule->headsepL->setEnabled(!custom);
329         marginsModule->headsepLE->setEnabled(!custom);
330         marginsModule->headsepUnit->setEnabled(!custom);
331
332         marginsModule->footskipL->setEnabled(!custom);
333         marginsModule->footskipLE->setEnabled(!custom);
334         marginsModule->footskipUnit->setEnabled(!custom);
335 }
336
337
338 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
339 {
340         fontModule->fontsizeCO->clear();
341         fontModule->fontsizeCO->insertItem(qt_("default"));
342
343         for (int n = 0; !token(items,'|',n).empty(); ++n)
344                 fontModule->fontsizeCO->
345                         insertItem(toqstr(token(items,'|',n)));
346
347         for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
348                 if (fromqstr(fontModule->fontsizeCO->text(n)) == sel) {
349                         fontModule->fontsizeCO->setCurrentItem(n);
350                         break;
351                 }
352         }
353 }
354
355
356 void QDocumentDialog::romanChanged(int item)
357 {
358         string const font = tex_fonts_roman[item];
359         
360         fontModule->fontScCB->setEnabled(
361                 form_->controller().providesSC(font));
362         fontModule->fontOsfCB->setEnabled(
363                 form_->controller().providesOSF(font));
364 }
365
366
367 void QDocumentDialog::sansChanged(int item)
368 {
369         string const font = tex_fonts_sans[item];
370         
371         fontModule->scaleSansSB->setEnabled(
372                 form_->controller().providesScale(font));
373 }
374
375
376 void QDocumentDialog::ttChanged(int item)
377 {
378         string const font = tex_fonts_monospaced[item];
379         
380         fontModule->scaleTypewriterSB->setEnabled(
381                 form_->controller().providesScale(font));
382 }
383
384
385 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
386 {
387         pageLayoutModule->pagestyleCO->clear();
388         pageLayoutModule->pagestyleCO->insertItem("default");
389
390         for (int n=0; !token(items,'|',n).empty(); ++n)
391                 pageLayoutModule->pagestyleCO->
392                         insertItem(toqstr(token(items,'|',n)));
393
394         for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
395                 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
396                         pageLayoutModule->pagestyleCO->setCurrentItem(n);
397                         break;
398                 }
399         }
400 }
401
402
403 void QDocumentDialog::classChanged()
404 {
405         ControlDocument & cntrl = form_->controller();
406         BufferParams & params = cntrl.params();
407
408         lyx::textclass_type const tc = latexModule->classCO->currentItem();
409
410         if (form_->controller().loadTextclass(tc)) {
411                 params.textclass = tc;
412                 if (lyxrc.auto_reset_options)
413                         params.useClassDefaults();
414                 form_->update_contents();
415         } else {
416                 latexModule->classCO->setCurrentItem(params.textclass);
417         }
418 }
419
420
421 void QDocumentDialog::updateNumbering()
422 {
423         LyXTextClass const & tclass =
424                 form_->controller().params().getLyXTextClass();
425
426         //numberingModule->tocLV->setUpdatesEnabled(false);
427
428         // Update the example QListView
429         int const depth = numberingModule->depthSL->value();
430         int const toc = numberingModule->tocSL->value();
431         QString const no = qt_("No");
432         QString const yes = qt_("Yes");
433         LyXTextClass::const_iterator end = tclass.end();
434         LyXTextClass::const_iterator cit = tclass.begin();
435         numberingModule->tocLV->clear();
436         QListViewItem * item = 0;
437         for ( ; cit != end ; ++cit) {
438                 int const toclevel = (*cit)->toclevel;
439                 if (toclevel != LyXLayout::NOT_IN_TOC) {
440                         item = new QListViewItem(numberingModule->tocLV,
441                                                  item, qt_((*cit)->name()));
442                         item->setText(1, (toclevel <= depth) ? yes : no);
443                         item->setText(2, (toclevel <= toc) ? yes : no);
444                 }
445         }
446
447         //numberingModule->tocLV->setUpdatesEnabled(true);
448         //numberingModule->tocLV->update();
449 }
450
451
452 void QDocumentDialog::updateBranchView()
453 {
454         // store the selected branch
455         QListViewItem * selItem =
456                 branchesModule->branchesLV->selectedItem();
457         QString sel_branch;
458         if (selItem != 0)
459                 sel_branch = selItem->text(0);
460
461         branchesModule->branchesLV->clear();
462
463         BranchList::const_iterator it = form_->branchlist_.begin();
464         BranchList::const_iterator const end = form_->branchlist_.end();
465         for (; it != end; ++it) {
466                 QString const bname = toqstr(it->getBranch());
467                 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
468                 QListViewItem * newItem =
469                         new QListViewItem(branchesModule->branchesLV, bname, sel);
470                 QColor const itemcolor = rgb2qcolor(it->getColor());
471                 if (itemcolor.isValid()) {
472                         QPixmap coloritem(30, 10);
473                         coloritem.fill(itemcolor);
474                         newItem->setPixmap(2, coloritem);
475                 }
476                 // restore selected branch
477                 if (bname == sel_branch)
478                         branchesModule->branchesLV->setSelected(newItem, true);
479         }
480         form_->changed();
481 }
482
483
484 void QDocumentDialog::addBranchPressed()
485 {
486         QString const new_branch = branchesModule->newBranchLE->text();
487         if (!new_branch.isEmpty()) {
488                 form_->branchlist_.add(fromqstr(new_branch));
489                 branchesModule->newBranchLE->clear();
490                 updateBranchView();
491         }
492 }
493
494
495 void QDocumentDialog::deleteBranchPressed()
496 {
497         QListViewItem * selItem =
498                 branchesModule->branchesLV->selectedItem();
499         QString sel_branch;
500         if (selItem != 0)
501                 sel_branch = selItem->text(0);
502         if (sel_branch) {
503                 form_->branchlist_.remove(fromqstr(sel_branch));
504                 branchesModule->newBranchLE->clear();
505                 updateBranchView();
506         }
507 }
508
509
510 void QDocumentDialog::toggleBranchPressed()
511 {
512         QListViewItem * selItem =
513                 branchesModule->branchesLV->selectedItem();
514         toggleBranch(selItem);
515 }
516
517
518 void QDocumentDialog::branchDoubleClicked(QListViewItem * selItem)
519 {
520         toggleBranch(selItem);
521 }
522
523
524 void QDocumentDialog::toggleBranch(QListViewItem * selItem)
525 {
526         if (selItem == 0)
527                 return;
528
529         QString sel_branch = selItem->text(0);
530         if (sel_branch) {
531                 bool const selected = selItem->text(1) == qt_("Yes");
532                 Branch * branch = form_->branchlist_.find(fromqstr(sel_branch));
533                 if (branch && branch->setSelected(!selected)) {
534                         branchesModule->newBranchLE->clear();
535                         updateBranchView();
536                 }
537         }
538 }
539
540
541 void QDocumentDialog::toggleBranchColor()
542 {
543         QListViewItem * selItem =
544                 branchesModule->branchesLV->selectedItem();
545         QString sel_branch;
546         if (selItem != 0)
547                 sel_branch = selItem->text(0);
548         if (sel_branch) {
549                 string current_branch = fromqstr(sel_branch);
550                 Branch * branch =
551                         form_->branchlist_.find(current_branch);
552                 if (!branch)
553                         return;
554
555                 QColor const initial = rgb2qcolor(branch->getColor());
556                 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
557                 if (ncol.isValid()){
558                         // add the color to the branchlist
559                         branch->setColor(fromqstr(ncol.name()));
560                         branchesModule->newBranchLE->clear();
561                         updateBranchView();
562                 }
563         }
564 }
565
566 } // namespace frontend
567 } // namespace lyx