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 "lcolorcache.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);
92 void QBranches::apply(BufferParams & params) const
94 params.branchlist() = branchlist_;
97 void QBranches::on_addBranchPB_pressed()
99 QString const new_branch = newBranchLE->text();
100 if (!new_branch.isEmpty()) {
101 branchlist_.add(fromqstr(new_branch));
102 newBranchLE->clear();
108 void QBranches::on_removePB_pressed()
110 QTreeWidgetItem * selItem =
111 branchesTW->currentItem();
114 sel_branch = selItem->text(0);
115 if (!sel_branch.isEmpty()) {
116 branchlist_.remove(fromqstr(sel_branch));
117 newBranchLE->clear();
123 void QBranches::on_activatePB_pressed()
125 toggleBranch(branchesTW->currentItem());
129 void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
135 void QBranches::toggleBranch(QTreeWidgetItem * item)
140 QString sel_branch = item->text(0);
141 if (!sel_branch.isEmpty()) {
142 bool const selected = item->text(1) == qt_("Yes");
143 Branch * branch = branchlist_.find(fromqstr(sel_branch));
144 if (branch && branch->setSelected(!selected)) {
145 newBranchLE->clear();
152 void QBranches::on_colorPB_clicked()
154 QTreeWidgetItem * selItem =
155 branchesTW->currentItem();
158 sel_branch = selItem->text(0);
159 if (!sel_branch.isEmpty()) {
160 string current_branch = fromqstr(sel_branch);
162 branchlist_.find(current_branch);
166 QColor const initial = rgb2qcolor(branch->getColor());
167 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
169 // add the color to the branchlist
170 branch->setColor(fromqstr(ncol.name()));
171 newBranchLE->clear();
177 } // namespace frontend
180 #include "QBranches_moc.cpp"