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 "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"
28 #include <QColorDialog>
36 QBranches::QBranches(QWidget * parent, Qt::WFlags f)
40 branchesLV->setSorting(0);
43 QBranches::~QBranches()
47 void QBranches::update(BufferParams const & params)
49 branchlist_ = params.branchlist();
53 void QBranches::update()
56 // store the selected branch
57 Q3ListViewItem * selItem =
58 branchesLV->selectedItem();
61 sel_branch = selItem->text(0);
65 BranchList::const_iterator it = branchlist_.begin();
66 BranchList::const_iterator const end = branchlist_.end();
67 for (; it != end; ++it) {
68 QString const bname = toqstr(it->getBranch());
69 QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
70 Q3ListViewItem * newItem =
71 new Q3ListViewItem(branchesLV, bname, sel);
72 QColor const itemcolor = rgb2qcolor(it->getColor());
73 if (itemcolor.isValid()) {
74 QPixmap coloritem(30, 10);
75 coloritem.fill(itemcolor);
76 newItem->setPixmap(2, coloritem);
78 // restore selected branch
79 if (bname == sel_branch)
80 branchesLV->setSelected(newItem, true);
85 void QBranches::apply(BufferParams & params) const
87 params.branchlist() = branchlist_;
90 void QBranches::on_addBranchPB_pressed()
92 QString const new_branch = newBranchLE->text();
93 if (!new_branch.isEmpty()) {
94 branchlist_.add(fromqstr(new_branch));
101 void QBranches::on_removePB_pressed()
103 Q3ListViewItem * selItem =
104 branchesLV->selectedItem();
107 sel_branch = selItem->text(0);
108 if (!sel_branch.isEmpty()) {
109 branchlist_.remove(fromqstr(sel_branch));
110 newBranchLE->clear();
116 void QBranches::on_activatePB_pressed()
118 Q3ListViewItem * selItem =
119 branchesLV->selectedItem();
120 toggleBranch(selItem);
124 void QBranches::on_branchesLV_doubleClicked(Q3ListViewItem * selItem)
126 toggleBranch(selItem);
130 void QBranches::toggleBranch(Q3ListViewItem * selItem)
135 QString sel_branch = selItem->text(0);
136 if (!sel_branch.isEmpty()) {
137 bool const selected = selItem->text(1) == qt_("Yes");
138 Branch * branch = branchlist_.find(fromqstr(sel_branch));
139 if (branch && branch->setSelected(!selected)) {
140 newBranchLE->clear();
147 void QBranches::on_colorPB_clicked()
149 Q3ListViewItem * selItem =
150 branchesLV->selectedItem();
153 sel_branch = selItem->text(0);
154 if (!sel_branch.isEmpty()) {
155 string current_branch = fromqstr(sel_branch);
157 branchlist_.find(current_branch);
161 QColor const initial = rgb2qcolor(branch->getColor());
162 QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
164 // add the color to the branchlist
165 branch->setColor(fromqstr(ncol.name()));
166 newBranchLE->clear();
172 } // namespace frontend