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 "QBranches.h"
16 #include "GuiApplication.h"
17 #include "validators.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>
38 QBranches::QBranches(QWidget * parent, Qt::WFlags f)
42 branchesTW->setColumnCount(2);
43 branchesTW->headerItem()->setText(0, qt_("Branch"));
44 branchesTW->headerItem()->setText(1, qt_("Activated"));
47 void QBranches::update(BufferParams const & params)
49 branchlist_ = params.branchlist();
53 void QBranches::update()
55 // store the selected branch
56 QTreeWidgetItem * item = branchesTW->currentItem();
59 sel_branch = item->text(0);
63 BranchList::const_iterator it = branchlist_.begin();
64 BranchList::const_iterator const end = branchlist_.end();
65 for (; it != end; ++it) {
66 QTreeWidgetItem * newItem =
67 new QTreeWidgetItem(branchesTW);
69 QString const bname = toqstr(it->getBranch());
70 newItem->setText(0, bname);
72 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
73 newItem->setText(1, sel);
75 QColor const itemcolor = rgb2qcolor(it->getColor());
76 if (itemcolor.isValid()) {
77 QPixmap coloritem(32, 32);
78 coloritem.fill(itemcolor);
79 newItem->setIcon(0, QIcon(coloritem));
81 // restore selected branch
82 if (bname == sel_branch)
83 branchesTW->setItemSelected(newItem, true);
89 void QBranches::apply(BufferParams & params) const
91 params.branchlist() = branchlist_;
94 void QBranches::on_addBranchPB_pressed()
96 QString const new_branch = newBranchLE->text();
97 if (!new_branch.isEmpty()) {
98 branchlist_.add(fromqstr(new_branch));
105 void QBranches::on_removePB_pressed()
107 QTreeWidgetItem * selItem =
108 branchesTW->currentItem();
111 sel_branch = selItem->text(0);
112 if (!sel_branch.isEmpty()) {
113 branchlist_.remove(fromqstr(sel_branch));
114 newBranchLE->clear();
120 void QBranches::on_activatePB_pressed()
122 toggleBranch(branchesTW->currentItem());
126 void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int /*col*/)
132 void QBranches::toggleBranch(QTreeWidgetItem * item)
137 QString sel_branch = item->text(0);
138 if (!sel_branch.isEmpty()) {
139 bool const selected = item->text(1) == qt_("Yes");
140 Branch * branch = branchlist_.find(fromqstr(sel_branch));
141 if (branch && branch->setSelected(!selected)) {
142 newBranchLE->clear();
149 void QBranches::on_colorPB_clicked()
151 QTreeWidgetItem * selItem =
152 branchesTW->currentItem();
155 sel_branch = selItem->text(0);
156 if (!sel_branch.isEmpty()) {
157 string current_branch = fromqstr(sel_branch);
159 branchlist_.find(current_branch);
163 QColor const initial = rgb2qcolor(branch->getColor());
164 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget()));
166 // add the color to the branchlist
167 branch->setColor(fromqstr(ncol.name()));
168 newBranchLE->clear();
174 } // namespace frontend
177 #include "QBranches_moc.cpp"