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"
21 #include "controllers/ControlDocument.h"
23 #include "support/lstrings.h"
25 #include <QTreeWidget>
26 #include <QTreeWidgetItem>
30 #include <QColorDialog>
37 GuiBranches::GuiBranches(QWidget * parent, Qt::WFlags f)
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();
54 void GuiBranches::update()
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 =
68 new QTreeWidgetItem(branchesTW);
70 QString const bname = toqstr(it->getBranch());
71 newItem->setText(0, bname);
73 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
74 newItem->setText(1, sel);
76 QColor const itemcolor = rgb2qcolor(it->getColor());
77 if (itemcolor.isValid()) {
78 QPixmap coloritem(30, 10);
79 coloritem.fill(itemcolor);
80 newItem->setIcon(2, QIcon(coloritem));
82 // restore selected branch
83 if (bname == sel_branch) {
84 branchesTW->setCurrentItem(newItem);
85 branchesTW->setItemSelected(newItem, true);
92 void GuiBranches::apply(BufferParams & params) const
94 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 =
111 branchesTW->currentItem();
114 sel_branch = selItem->text(0);
115 if (!sel_branch.isEmpty()) {
116 branchlist_.remove(qstring_to_ucs4(sel_branch));
117 newBranchLE->clear();
123 void GuiBranches::on_activatePB_pressed()
125 toggleBranch(branchesTW->currentItem());
129 void GuiBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
138 void GuiBranches::toggleBranch(QTreeWidgetItem * item)
143 QString sel_branch = item->text(0);
144 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();
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()) {
168 docstring current_branch = qstring_to_ucs4(sel_branch);
170 branchlist_.find(current_branch);
174 QColor const initial = rgb2qcolor(branch->getColor());
175 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget()));
177 // add the color to the branchlist
178 branch->setColor(fromqstr(ncol.name()));
179 newBranchLE->clear();
185 } // namespace frontend
188 #include "GuiBranches_moc.cpp"