2 * \file QDocumentDialog.C
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 "validators.h"
17 #include "qt_helpers.h"
19 #include "bufferparams.h"
20 #include "controllers/ControlDocument.h"
22 #include "support/lstrings.h"
27 #include <QColorDialog>
35 QBranches::QBranches(QWidget * parent, Qt::WFlags f)
39 branchesLV->setSorting(0);
42 QBranches::~QBranches()
46 void QBranches::update(BufferParams const & params)
48 branchlist_ = params.branchlist();
52 void QBranches::update()
55 // store the selected branch
56 Q3ListViewItem * selItem =
57 branchesLV->selectedItem();
60 sel_branch = selItem->text(0);
64 BranchList::const_iterator it = branchlist_.begin();
65 BranchList::const_iterator const end = branchlist_.end();
66 for (; it != end; ++it) {
67 QString const bname = toqstr(it->getBranch());
68 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
69 Q3ListViewItem * newItem =
70 new Q3ListViewItem(branchesLV, bname, sel);
71 string const x11hexname = it->getColor();
73 if (x11hexname[0] == '#')
74 itemcolor.setNamedColor(toqstr(x11hexname));
75 if (itemcolor.isValid()) {
76 QPixmap coloritem(30, 10);
77 coloritem.fill(itemcolor);
78 newItem->setPixmap(2, coloritem);
80 // restore selected branch
81 if (bname == sel_branch)
82 branchesLV->setSelected(newItem, true);
86 void QBranches::apply(BufferParams & params) const
88 params.branchlist() = branchlist_;
91 void QBranches::on_addBranchPB_pressed()
93 QString const new_branch = newBranchLE->text();
94 if (!new_branch.isEmpty()) {
95 branchlist_.add(fromqstr(new_branch));
102 void QBranches::on_removePB_pressed()
104 Q3ListViewItem * selItem =
105 branchesLV->selectedItem();
108 sel_branch = selItem->text(0);
109 if (!sel_branch.isEmpty()) {
110 branchlist_.remove(fromqstr(sel_branch));
111 newBranchLE->clear();
117 void QBranches::on_activatePB_pressed()
119 Q3ListViewItem * selItem =
120 branchesLV->selectedItem();
121 toggleBranch(selItem);
125 void QBranches::on_branchesLV_doubleClicked(Q3ListViewItem * selItem)
127 toggleBranch(selItem);
131 void QBranches::toggleBranch(Q3ListViewItem * selItem)
136 QString sel_branch = selItem->text(0);
137 if (!sel_branch.isEmpty()) {
138 bool const selected = selItem->text(1) == qt_("Yes");
139 Branch * branch = branchlist_.find(fromqstr(sel_branch));
140 if (branch && branch->setSelected(!selected)) {
141 newBranchLE->clear();
148 void QBranches::on_colorPB_clicked()
150 Q3ListViewItem * selItem =
151 branchesLV->selectedItem();
154 sel_branch = selItem->text(0);
155 if (!sel_branch.isEmpty()) {
157 string current_branch = fromqstr(sel_branch);
159 branchlist_.find(current_branch);
163 string x11hexname = branch->getColor();
164 if (x11hexname[0] == '#')
165 initial.setNamedColor(toqstr(x11hexname));
166 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
168 // add the color to the branchlist
169 branch->setColor(fromqstr(ncol.name()));
170 newBranchLE->clear();
176 } // namespace frontend