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 "ColorCache.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 QBranches::~QBranches()
51 void QBranches::update(BufferParams const & params)
53 branchlist_ = params.branchlist();
57 void QBranches::update()
59 // store the selected branch
60 QTreeWidgetItem * item = branchesTW->currentItem();
63 sel_branch = item->text(0);
67 BranchList::const_iterator it = branchlist_.begin();
68 BranchList::const_iterator const end = branchlist_.end();
69 for (; it != end; ++it) {
70 QTreeWidgetItem * newItem =
71 new QTreeWidgetItem(branchesTW);
73 QString const bname = toqstr(it->getBranch());
74 newItem->setText(0, bname);
76 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
77 newItem->setText(1, sel);
79 QColor const itemcolor = rgb2qcolor(it->getColor());
80 if (itemcolor.isValid()) {
81 QPixmap coloritem(32, 32);
82 coloritem.fill(itemcolor);
83 newItem->setIcon(0, QIcon(coloritem));
85 // restore selected branch
86 if (bname == sel_branch)
87 branchesTW->setItemSelected(newItem, true);
93 void QBranches::apply(BufferParams & params) const
95 params.branchlist() = branchlist_;
98 void QBranches::on_addBranchPB_pressed()
100 QString const new_branch = newBranchLE->text();
101 if (!new_branch.isEmpty()) {
102 branchlist_.add(fromqstr(new_branch));
103 newBranchLE->clear();
109 void QBranches::on_removePB_pressed()
111 QTreeWidgetItem * selItem =
112 branchesTW->currentItem();
115 sel_branch = selItem->text(0);
116 if (!sel_branch.isEmpty()) {
117 branchlist_.remove(fromqstr(sel_branch));
118 newBranchLE->clear();
124 void QBranches::on_activatePB_pressed()
126 toggleBranch(branchesTW->currentItem());
130 void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int /*col*/)
136 void QBranches::toggleBranch(QTreeWidgetItem * item)
141 QString sel_branch = item->text(0);
142 if (!sel_branch.isEmpty()) {
143 bool const selected = item->text(1) == qt_("Yes");
144 Branch * branch = branchlist_.find(fromqstr(sel_branch));
145 if (branch && branch->setSelected(!selected)) {
146 newBranchLE->clear();
153 void QBranches::on_colorPB_clicked()
155 QTreeWidgetItem * selItem =
156 branchesTW->currentItem();
159 sel_branch = selItem->text(0);
160 if (!sel_branch.isEmpty()) {
161 string current_branch = fromqstr(sel_branch);
163 branchlist_.find(current_branch);
167 QColor const initial = rgb2qcolor(branch->getColor());
168 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
170 // add the color to the branchlist
171 branch->setColor(fromqstr(ncol.name()));
172 newBranchLE->clear();
178 } // namespace frontend
181 #include "QBranches_moc.cpp"