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>
37 QBranches::QBranches(QWidget * parent, Qt::WFlags f)
41 branchesTW->setColumnCount(2);
42 branchesTW->headerItem()->setText(0, qt_("Branch"));
43 branchesTW->headerItem()->setText(1, qt_("Activated"));
46 void QBranches::update(BufferParams const & params)
48 branchlist_ = params.branchlist();
52 void QBranches::update()
54 // store the selected branch
55 QTreeWidgetItem * item = branchesTW->currentItem();
58 sel_branch = item->text(0);
62 BranchList::const_iterator it = branchlist_.begin();
63 BranchList::const_iterator const end = branchlist_.end();
64 for (; it != end; ++it) {
65 QTreeWidgetItem * newItem =
66 new QTreeWidgetItem(branchesTW);
68 QString const bname = toqstr(it->getBranch());
69 newItem->setText(0, bname);
71 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
72 newItem->setText(1, sel);
74 QColor const itemcolor = rgb2qcolor(it->getColor());
75 if (itemcolor.isValid()) {
76 QPixmap coloritem(32, 32);
77 coloritem.fill(itemcolor);
78 newItem->setIcon(0, QIcon(coloritem));
80 // restore selected branch
81 if (bname == sel_branch)
82 branchesTW->setItemSelected(newItem, true);
88 void QBranches::apply(BufferParams & params) const
90 params.branchlist() = branchlist_;
93 void QBranches::on_addBranchPB_pressed()
95 QString const new_branch = newBranchLE->text();
96 if (!new_branch.isEmpty()) {
97 branchlist_.add(qstring_to_ucs4(new_branch));
104 void QBranches::on_removePB_pressed()
106 QTreeWidgetItem * selItem =
107 branchesTW->currentItem();
110 sel_branch = selItem->text(0);
111 if (!sel_branch.isEmpty()) {
112 branchlist_.remove(qstring_to_ucs4(sel_branch));
113 newBranchLE->clear();
119 void QBranches::on_activatePB_pressed()
121 toggleBranch(branchesTW->currentItem());
125 void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int /*col*/)
131 void QBranches::toggleBranch(QTreeWidgetItem * item)
136 QString sel_branch = item->text(0);
137 if (!sel_branch.isEmpty()) {
138 bool const selected = item->text(1) == qt_("Yes");
139 Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
140 if (branch && branch->setSelected(!selected)) {
141 newBranchLE->clear();
148 void QBranches::on_colorPB_clicked()
150 QTreeWidgetItem * selItem =
151 branchesTW->currentItem();
154 sel_branch = selItem->text(0);
155 if (!sel_branch.isEmpty()) {
156 docstring current_branch = qstring_to_ucs4(sel_branch);
158 branchlist_.find(current_branch);
162 QColor const initial = rgb2qcolor(branch->getColor());
163 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget()));
165 // add the color to the branchlist
166 branch->setColor(fromqstr(ncol.name()));
167 newBranchLE->clear();
173 } // namespace frontend
176 #include "QBranches_moc.cpp"