2 * \file GuiBranches.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "GuiBranches.h"
16 #include "ControlBranch.h"
17 #include "ControlDocument.h"
18 #include "GuiApplication.h"
19 #include "Validator.h"
20 #include "qt_helpers.h"
22 #include "BufferParams.h"
24 #include "support/lstrings.h"
26 #include <QTreeWidget>
27 #include <QTreeWidgetItem>
31 #include <QColorDialog>
38 GuiBranches::GuiBranches(QWidget * parent, Qt::WFlags f)
42 branchesTW->setColumnCount(3);
43 branchesTW->headerItem()->setText(0, qt_("Branch"));
44 branchesTW->headerItem()->setText(1, qt_("Activated"));
45 branchesTW->headerItem()->setText(2, qt_("Color"));
46 branchesTW->setSortingEnabled(true);
49 void GuiBranches::update(BufferParams const & params)
51 branchlist_ = params.branchlist();
55 void GuiBranches::updateView()
57 // store the selected branch
58 QTreeWidgetItem * item = branchesTW->currentItem();
61 sel_branch = item->text(0);
65 BranchList::const_iterator it = branchlist_.begin();
66 BranchList::const_iterator const end = branchlist_.end();
67 for (; it != end; ++it) {
68 QTreeWidgetItem * newItem =
69 new QTreeWidgetItem(branchesTW);
71 QString const bname = toqstr(it->getBranch());
72 newItem->setText(0, bname);
74 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
75 newItem->setText(1, sel);
77 QColor const itemcolor = rgb2qcolor(it->getColor());
78 if (itemcolor.isValid()) {
79 QPixmap coloritem(30, 10);
80 coloritem.fill(itemcolor);
81 newItem->setIcon(2, QIcon(coloritem));
83 // restore selected branch
84 if (bname == sel_branch) {
85 branchesTW->setCurrentItem(newItem);
86 branchesTW->setItemSelected(newItem, true);
93 void GuiBranches::apply(BufferParams & params) const
95 params.branchlist() = branchlist_;
98 void GuiBranches::on_addBranchPB_pressed()
100 QString const new_branch = newBranchLE->text();
101 if (!new_branch.isEmpty()) {
102 branchlist_.add(qstring_to_ucs4(new_branch));
103 newBranchLE->clear();
109 void GuiBranches::on_removePB_pressed()
111 QTreeWidgetItem * selItem =
112 branchesTW->currentItem();
115 sel_branch = selItem->text(0);
116 if (!sel_branch.isEmpty()) {
117 branchlist_.remove(qstring_to_ucs4(sel_branch));
118 newBranchLE->clear();
124 void GuiBranches::on_activatePB_pressed()
126 toggleBranch(branchesTW->currentItem());
130 void GuiBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
139 void GuiBranches::toggleBranch(QTreeWidgetItem * item)
144 QString sel_branch = item->text(0);
145 if (!sel_branch.isEmpty()) {
146 bool const selected = item->text(1) == qt_("Yes");
147 Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
148 if (branch && branch->setSelected(!selected)) {
149 newBranchLE->clear();
156 void GuiBranches::on_colorPB_clicked()
158 toggleColor(branchesTW->currentItem());
162 void GuiBranches::toggleColor(QTreeWidgetItem * item)
167 QString sel_branch = item->text(0);
168 if (!sel_branch.isEmpty()) {
169 docstring current_branch = qstring_to_ucs4(sel_branch);
171 branchlist_.find(current_branch);
175 QColor const initial = rgb2qcolor(branch->getColor());
176 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget()));
178 // add the color to the branchlist
179 branch->setColor(fromqstr(ncol.name()));
180 newBranchLE->clear();
186 } // namespace frontend
189 #include "GuiBranches_moc.cpp"