]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDocumentDialog.C
some tabular fixes for the problems reported by Helge
[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
13 #include "QDocument.h"
14 #include "QDocumentDialog.h"
15
16 #include "floatplacement.h"
17 #include "lengthcombo.h"
18 #include "lengthvalidator.h"
19 #include "panelstack.h"
20 #include "qt_helpers.h"
21
22 #include "bufferparams.h"
23 #include "gettext.h"
24 #include "lyxrc.h"
25
26 #include "controllers/ControlDocument.h"
27
28 #include "support/lstrings.h"
29
30 #include <qlabel.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>
37 #include <qslider.h>
38 #include <qpixmap.h>
39 #include <qcolor.h>
40 #include <qcolordialog.h>
41 #include <qvalidator.h>
42
43 using lyx::support::token;
44
45 using std::string;
46
47 namespace lyx {
48 namespace frontend {
49
50
51 namespace {
52
53 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
54 {
55         LengthValidator * v = new LengthValidator(ed);
56         v->setBottom(LyXLength());
57         return v;
58 }
59
60 } // namespace anon
61
62
63 QDocumentDialog::QDocumentDialog(QDocument * form)
64         : QDocumentDialogBase(0, 0, false, 0), form_(form)
65 {
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()));
74
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);
87
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"));
101
102         // preamble
103         connect(preambleModule->preambleMLE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
104         // biblio
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()));
110         // language & quote
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()));
115         // numbering
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);
121         // maths
122         connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
123         connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
124         // float
125         connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
126         // latex class
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()));
131         // text layout
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()));
145
146         // margins
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()));
163
164         // page layout
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()));
178
179         // bullets
180         connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
181
182         // branches
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);
190         
191         textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
192                 textLayoutModule->lspacingLE));
193         
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));
214 }
215
216
217 QDocumentDialog::~QDocumentDialog()
218 {
219 }
220
221
222 void QDocumentDialog::showPreamble()
223 {
224         docPS->setCurrentPanel(_("LaTeX Preamble"));
225 }
226
227
228 void QDocumentDialog::saveDefaultClicked()
229 {
230         form_->saveDocDefault();
231 }
232
233
234 void QDocumentDialog::useDefaultsClicked()
235 {
236         form_->useClassDefaults();
237 }
238
239
240 void QDocumentDialog::change_adaptor()
241 {
242         form_->changed();
243 }
244
245
246 void QDocumentDialog::closeEvent(QCloseEvent * e)
247 {
248         form_->slotWMHide();
249         e->accept();
250 }
251
252
253 void QDocumentDialog::setLSpacing(int item)
254 {
255         textLayoutModule->lspacingLE->setEnabled(item == 3);
256 }
257
258
259 void QDocumentDialog::setSkip(int item)
260 {
261         bool const enable = (item == 3);
262         textLayoutModule->skipLE->setEnabled(enable);
263         textLayoutModule->skipLengthCO->setEnabled(enable);
264 }
265
266
267 void QDocumentDialog::enableSkip(bool skip)
268 {
269         textLayoutModule->skipCO->setEnabled(skip);
270         textLayoutModule->skipLE->setEnabled(skip);
271         textLayoutModule->skipLengthCO->setEnabled(skip);
272         if (skip)
273                 setSkip(textLayoutModule->skipCO->currentItem());
274 }
275
276 void QDocumentDialog::portraitChanged()
277 {
278         setMargins(pageLayoutModule->papersizeCO->currentItem());
279 }
280
281 void QDocumentDialog::setMargins(int papersize)
282 {
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) {
294                 olditem = 0;
295         }
296         marginsModule->marginCO->setCurrentItem(olditem);
297         setCustomMargins(olditem);
298 }
299
300
301 void QDocumentDialog::setCustomPapersize(int papersize)
302 {
303         bool const custom = (papersize == 1);
304
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);
312 }
313
314
315 void QDocumentDialog::setCustomMargins(int margin)
316 {
317         bool const custom = (margin == 1);
318
319         marginsModule->topL->setEnabled(custom);
320         marginsModule->topLE->setEnabled(custom);
321         marginsModule->topUnit->setEnabled(custom);
322
323         marginsModule->bottomL->setEnabled(custom);
324         marginsModule->bottomLE->setEnabled(custom);
325         marginsModule->bottomUnit->setEnabled(custom);
326
327         marginsModule->innerL->setEnabled(custom);
328         marginsModule->innerLE->setEnabled(custom);
329         marginsModule->innerUnit->setEnabled(custom);
330
331         marginsModule->outerL->setEnabled(custom);
332         marginsModule->outerLE->setEnabled(custom);
333         marginsModule->outerUnit->setEnabled(custom);
334
335         marginsModule->headheightL->setEnabled(custom);
336         marginsModule->headheightLE->setEnabled(custom);
337         marginsModule->headheightUnit->setEnabled(custom);
338
339         marginsModule->headsepL->setEnabled(custom);
340         marginsModule->headsepLE->setEnabled(custom);
341         marginsModule->headsepUnit->setEnabled(custom);
342
343         marginsModule->footskipL->setEnabled(custom);
344         marginsModule->footskipLE->setEnabled(custom);
345         marginsModule->footskipUnit->setEnabled(custom);
346 }
347
348
349 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
350 {
351         textLayoutModule->fontsizeCO->clear();
352         textLayoutModule->fontsizeCO->insertItem("default");
353
354         for (int n = 0; !token(items,'|',n).empty(); ++n)
355                 textLayoutModule->fontsizeCO->
356                         insertItem(toqstr(token(items,'|',n)));
357
358         for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
359                 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
360                         textLayoutModule->fontsizeCO->setCurrentItem(n);
361                         break;
362                 }
363         }
364 }
365
366
367 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
368 {
369         pageLayoutModule->pagestyleCO->clear();
370         pageLayoutModule->pagestyleCO->insertItem("default");
371
372         for (int n=0; !token(items,'|',n).empty(); ++n)
373                 pageLayoutModule->pagestyleCO->
374                         insertItem(toqstr(token(items,'|',n)));
375
376         for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
377                 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
378                         pageLayoutModule->pagestyleCO->setCurrentItem(n);
379                         break;
380                 }
381         }
382 }
383
384
385 void QDocumentDialog::classChanged()
386 {
387         ControlDocument & cntrl = form_->controller();
388         BufferParams & params = cntrl.params();
389
390         lyx::textclass_type const tc = latexModule->classCO->currentItem();
391
392         if (form_->controller().loadTextclass(tc)) {
393                 params.textclass = tc;
394
395                 if (lyxrc.auto_reset_options) {
396                         params.useClassDefaults();
397                         form_->update_contents();
398                 } else {
399                         updateFontsize(cntrl.textClass().opt_fontsize(),
400                                        params.fontsize);
401
402                         updatePagestyle(cntrl.textClass().opt_pagestyle(),
403                                         params.pagestyle);
404                 }
405         } else {
406                 latexModule->classCO->setCurrentItem(params.textclass);
407         }
408 }
409
410
411 void QDocumentDialog::updateNumbering()
412 {
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();
422
423         QString const no = qt_("No");
424         QString const yes = qt_("Yes");
425
426         //numberingModule->tocLV->setUpdatesEnabled(false);
427
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);
442
443         // numbering
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);
451
452         // in toc
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);
459
460         //numberingModule->tocLV->setUpdatesEnabled(true);
461         //numberingModule->tocLV->update();
462 }
463
464
465 void QDocumentDialog::updateBranchView()
466 {
467         // store the selected branch
468         QListViewItem * selItem =
469                 branchesModule->branchesLV->selectedItem();
470         QString sel_branch;
471         if (selItem != 0)
472                 sel_branch = selItem->text(0);
473
474         branchesModule->branchesLV->clear();
475
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();
484                 QColor itemcolor;
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);
491                 }
492                 // restore selected branch
493                 if (bname == sel_branch)
494                         branchesModule->branchesLV->setSelected(newItem, true);
495         }
496         form_->changed();
497 }
498
499
500 void QDocumentDialog::addBranchPressed()
501 {
502         QString const new_branch = branchesModule->newBranchLE->text();
503         if (!new_branch.isEmpty()) {
504                 form_->branchlist_.add(fromqstr(new_branch));
505                 branchesModule->newBranchLE->clear();
506                 updateBranchView();
507         }
508 }
509
510
511 void QDocumentDialog::deleteBranchPressed()
512 {
513         QListViewItem * selItem =
514                 branchesModule->branchesLV->selectedItem();
515         QString sel_branch;
516         if (selItem != 0)
517                 sel_branch = selItem->text(0);
518         if (sel_branch) {
519                 form_->branchlist_.remove(fromqstr(sel_branch));
520                 branchesModule->newBranchLE->clear();
521                 updateBranchView();
522         }
523 }
524
525
526 void QDocumentDialog::toggleBranchPressed()
527 {
528         QListViewItem * selItem =
529                 branchesModule->branchesLV->selectedItem();
530         toggleBranch(selItem);
531 }
532
533
534 void QDocumentDialog::branchDoubleClicked(QListViewItem * selItem)
535 {
536         toggleBranch(selItem);
537 }
538
539
540 void QDocumentDialog::toggleBranch(QListViewItem * selItem)
541 {
542         if (selItem == 0)
543                 return;
544
545         QString sel_branch = selItem->text(0);
546         if (sel_branch) {
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();
551                         updateBranchView();
552                 }
553         }
554 }
555
556
557 void QDocumentDialog::toggleBranchColor()
558 {
559         QListViewItem * selItem =
560                 branchesModule->branchesLV->selectedItem();
561         QString sel_branch;
562         if (selItem != 0)
563                 sel_branch = selItem->text(0);
564         if (sel_branch) {
565                 QColor initial;
566                 string current_branch = fromqstr(sel_branch);
567                 Branch * branch =
568                         form_->branchlist_.find(current_branch);
569                 if (!branch)
570                         return;
571
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()));
576                 if (ncol.isValid()){
577                         // add the color to the branchlist
578                         branch->setColor(fromqstr(ncol.name()));
579                         branchesModule->newBranchLE->clear();
580                         updateBranchView();
581                 }
582         }
583 }
584
585 } // namespace frontend
586 } // namespace lyx