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 "GuiApplication.h"
17 #include "Validator.h"
18 #include "qt_helpers.h"
20 #include "BufferParams.h"
22 #include "support/lstrings.h"
24 #include <QTreeWidget>
25 #include <QTreeWidgetItem>
29 #include <QColorDialog>
36 GuiBranches::GuiBranches(QWidget * parent, Qt::WFlags f)
40 branchesTW->setColumnCount(3);
41 branchesTW->headerItem()->setText(0, qt_("Branch"));
42 branchesTW->headerItem()->setText(1, qt_("Activated"));
43 branchesTW->headerItem()->setText(2, qt_("Color"));
44 branchesTW->setSortingEnabled(true);
47 void GuiBranches::update(BufferParams const & params)
49 branchlist_ = params.branchlist();
54 void GuiBranches::updateView()
56 // store the selected branch
57 QTreeWidgetItem * item = branchesTW->currentItem();
60 sel_branch = item->text(0);
64 BranchList::const_iterator it = branchlist_.begin();
65 BranchList::const_iterator const end = branchlist_.end();
66 for (; it != end; ++it) {
67 QTreeWidgetItem * newItem = new QTreeWidgetItem(branchesTW);
69 QString const bname = toqstr(it->getBranch());
70 newItem->setText(0, bname);
71 newItem->setText(1, it->getSelected() ? qt_("Yes") : qt_("No"));
73 QColor const itemcolor = rgb2qcolor(it->getColor());
74 if (itemcolor.isValid()) {
75 QPixmap coloritem(30, 10);
76 coloritem.fill(itemcolor);
77 newItem->setIcon(2, QIcon(coloritem));
79 // restore selected branch
80 if (bname == sel_branch) {
81 branchesTW->setCurrentItem(newItem);
82 branchesTW->setItemSelected(newItem, true);
90 void GuiBranches::apply(BufferParams & params) const
92 params.branchlist() = branchlist_;
96 void GuiBranches::on_addBranchPB_pressed()
98 QString const new_branch = newBranchLE->text();
99 if (!new_branch.isEmpty()) {
100 branchlist_.add(qstring_to_ucs4(new_branch));
101 newBranchLE->clear();
107 void GuiBranches::on_removePB_pressed()
109 QTreeWidgetItem * selItem = branchesTW->currentItem();
112 sel_branch = selItem->text(0);
113 if (!sel_branch.isEmpty()) {
114 branchlist_.remove(qstring_to_ucs4(sel_branch));
115 newBranchLE->clear();
121 void GuiBranches::on_activatePB_pressed()
123 toggleBranch(branchesTW->currentItem());
127 void GuiBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
136 void GuiBranches::toggleBranch(QTreeWidgetItem * item)
141 QString sel_branch = item->text(0);
142 if (sel_branch.isEmpty())
145 bool const selected = (item->text(1) == qt_("Yes"));
146 Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
147 if (branch && branch->setSelected(!selected)) {
148 newBranchLE->clear();
154 void GuiBranches::on_colorPB_clicked()
156 toggleColor(branchesTW->currentItem());
160 void GuiBranches::toggleColor(QTreeWidgetItem * item)
165 QString sel_branch = item->text(0);
166 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());
180 // add the color to the branchlist
181 branch->setColor(fromqstr(ncol.name()));
182 newBranchLE->clear();
186 } // namespace frontend
189 #include "GuiBranches_moc.cpp"