]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBranch.cpp
Merge QController into individual dialogs. Also various cleanup
[lyx.git] / src / frontends / qt4 / GuiBranch.cpp
1 /**
2  * \file GuiBranch.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Spitzmüller
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiBranch.h"
14 #include "Qt2BC.h"
15 #include "qt_helpers.h"
16
17 #include "BranchList.h"
18
19 #include "insets/InsetBranch.h"
20
21 #include <QPushButton>
22 #include <QCloseEvent>
23
24 namespace lyx {
25 namespace frontend {
26
27 /////////////////////////////////////////////////////////////////////
28 //
29 // GuiBranchDialog
30 //
31 /////////////////////////////////////////////////////////////////////
32
33 GuiBranchDialog::GuiBranchDialog(GuiBranch * form)
34         : form_(form)
35 {
36         setupUi(this);
37         connect(okPB, SIGNAL(clicked()),
38                 form, SLOT(slotOK()));
39         connect(closePB, SIGNAL(clicked()),
40                 form, SLOT(slotClose()));
41         connect(branchCO, SIGNAL( activated(int) ),
42                 this, SLOT( change_adaptor() ) );
43 }
44
45
46 void GuiBranchDialog::closeEvent(QCloseEvent * e)
47 {
48         form_->slotWMHide();
49         e->accept();
50 }
51
52
53 void GuiBranchDialog::change_adaptor()
54 {
55         form_->changed();
56 }
57
58
59 /////////////////////////////////////////////////////////////////////
60 //
61 // GuiBranch
62 //
63 /////////////////////////////////////////////////////////////////////
64
65
66 GuiBranch::GuiBranch(Dialog & parent)
67         : GuiView<GuiBranchDialog>(parent, _("Branch Settings"))
68 {}
69
70
71 void GuiBranch::build_dialog()
72 {
73         dialog_.reset(new GuiBranchDialog(this));
74
75         bcview().setOK(dialog_->okPB);
76         bcview().setCancel(dialog_->closePB);
77 }
78
79
80 void GuiBranch::update_contents()
81 {
82         typedef BranchList::const_iterator const_iterator;
83
84         BranchList const & branchlist = controller().branchlist();
85         docstring const cur_branch = controller().params().branch;
86
87         dialog_->branchCO->clear();
88
89         const_iterator const begin = branchlist.begin();
90         const_iterator const end = branchlist.end();
91         int id = 0;
92         int count = 0;
93         for (const_iterator it = begin; it != end; ++it, ++count) {
94                 docstring const & branch = it->getBranch();
95                 dialog_->branchCO->addItem(toqstr(branch));
96
97                 if (cur_branch == branch)
98                         id = count;
99         }
100         dialog_->branchCO->setCurrentIndex(id);
101 }
102
103
104 void GuiBranch::apply()
105 {
106         docstring const type = qstring_to_ucs4(dialog_->branchCO->currentText());
107         controller().params().branch = type;
108 }
109
110 } // namespace frontend
111 } // namespace lyx
112
113 #include "GuiBranch_moc.cpp"