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 "ColorCache.h"
17 #include "GuiApplication.h"
18 #include "Validator.h"
19 #include "qt_helpers.h"
21 #include "BufferParams.h"
23 #include "support/lstrings.h"
25 #include <QTreeWidget>
26 #include <QTreeWidgetItem>
30 #include <QColorDialog>
37 GuiBranches::GuiBranches(QWidget * parent)
41 branchesTW->setColumnCount(3);
42 branchesTW->headerItem()->setText(0, qt_("Branch"));
43 branchesTW->headerItem()->setText(1, qt_("Activated"));
44 branchesTW->headerItem()->setText(2, qt_("Color"));
45 branchesTW->setSortingEnabled(true);
48 void GuiBranches::update(BufferParams const & params)
50 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 = new QTreeWidgetItem(branchesTW);
70 QString const bname = toqstr(it->branch());
71 newItem->setText(0, bname);
72 newItem->setText(1, it->isSelected() ? qt_("Yes") : qt_("No"));
74 QColor const itemcolor = rgb2qcolor(it->color());
75 if (itemcolor.isValid()) {
76 QPixmap coloritem(30, 10);
77 coloritem.fill(itemcolor);
78 newItem->setIcon(2, QIcon(coloritem));
80 // restore selected branch
81 if (bname == sel_branch) {
82 branchesTW->setCurrentItem(newItem);
83 branchesTW->setItemSelected(newItem, true);
91 void GuiBranches::apply(BufferParams & params) const
93 params.branchlist() = branchlist_;
97 void GuiBranches::on_addBranchPB_pressed()
99 QString const new_branch = newBranchLE->text();
100 if (!new_branch.isEmpty()) {
101 branchlist_.add(qstring_to_ucs4(new_branch));
102 newBranchLE->clear();
108 void GuiBranches::on_removePB_pressed()
110 QTreeWidgetItem * selItem = branchesTW->currentItem();
113 sel_branch = selItem->text(0);
114 if (!sel_branch.isEmpty()) {
115 branchlist_.remove(qstring_to_ucs4(sel_branch));
116 newBranchLE->clear();
122 void GuiBranches::on_activatePB_pressed()
124 toggleBranch(branchesTW->currentItem());
128 void GuiBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
137 void GuiBranches::toggleBranch(QTreeWidgetItem * item)
142 QString sel_branch = item->text(0);
143 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();
155 void GuiBranches::on_colorPB_clicked()
157 toggleColor(branchesTW->currentItem());
161 void GuiBranches::toggleColor(QTreeWidgetItem * item)
166 QString sel_branch = item->text(0);
167 if (sel_branch.isEmpty())
170 docstring current_branch = qstring_to_ucs4(sel_branch);
171 Branch * branch = branchlist_.find(current_branch);
175 QColor const initial = rgb2qcolor(branch->color());
176 QColor ncol = QColorDialog::getColor(initial, qApp->focusWidget());
180 // add the color to the branchlist
181 branch->setColor(fromqstr(ncol.name()));
182 newBranchLE->clear();
186 } // namespace frontend
189 #include "GuiBranches_moc.cpp"