2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2006-05-04 07:31:46 +00:00
|
|
|
* \file QBranches.C
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "QBranches.h"
|
|
|
|
|
2006-03-23 20:04:05 +00:00
|
|
|
#include "lcolorcache.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "validators.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "bufferparams.h"
|
|
|
|
#include "controllers/ControlDocument.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QTreeWidgetItem>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QPixmap>
|
2006-05-04 07:31:46 +00:00
|
|
|
#include <QIcon>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QColor>
|
|
|
|
#include <QColorDialog>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
|
|
QBranches::QBranches(QWidget * parent, Qt::WFlags f)
|
|
|
|
: QWidget(parent, f)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2006-05-07 10:20:43 +00:00
|
|
|
branchesTW->setColumnCount(2);
|
|
|
|
branchesTW->headerItem()->setText(0, qt_("Branch"));
|
2006-05-04 07:31:46 +00:00
|
|
|
branchesTW->headerItem()->setText(1, qt_("Activated"));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QBranches::~QBranches()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void QBranches::update(BufferParams const & params)
|
|
|
|
{
|
|
|
|
branchlist_ = params.branchlist();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QBranches::update()
|
|
|
|
{
|
|
|
|
// store the selected branch
|
2006-05-07 10:20:43 +00:00
|
|
|
QTreeWidgetItem * item = branchesTW->currentItem();
|
2006-03-05 17:24:44 +00:00
|
|
|
QString sel_branch;
|
2006-05-04 07:31:46 +00:00
|
|
|
if (item != 0)
|
|
|
|
sel_branch = item->text(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
branchesTW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
BranchList::const_iterator it = branchlist_.begin();
|
|
|
|
BranchList::const_iterator const end = branchlist_.end();
|
|
|
|
for (; it != end; ++it) {
|
2006-05-04 07:31:46 +00:00
|
|
|
QTreeWidgetItem * newItem =
|
|
|
|
new QTreeWidgetItem(branchesTW);
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
QString const bname = toqstr(it->getBranch());
|
2006-05-04 07:31:46 +00:00
|
|
|
newItem->setText(0, bname);
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
|
2006-05-04 07:31:46 +00:00
|
|
|
newItem->setText(1, sel);
|
|
|
|
|
2006-03-23 20:04:05 +00:00
|
|
|
QColor const itemcolor = rgb2qcolor(it->getColor());
|
2006-03-05 17:24:44 +00:00
|
|
|
if (itemcolor.isValid()) {
|
2006-05-07 10:20:43 +00:00
|
|
|
QPixmap coloritem(32, 32);
|
2006-03-05 17:24:44 +00:00
|
|
|
coloritem.fill(itemcolor);
|
2006-05-07 10:20:43 +00:00
|
|
|
newItem->setIcon(0, QIcon(coloritem));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
// restore selected branch
|
|
|
|
if (bname == sel_branch)
|
2006-05-04 07:31:46 +00:00
|
|
|
branchesTW->setItemSelected(newItem, true);
|
2006-03-20 17:25:02 +00:00
|
|
|
}
|
2006-03-20 14:40:27 +00:00
|
|
|
emit changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QBranches::apply(BufferParams & params) const
|
|
|
|
{
|
|
|
|
params.branchlist() = branchlist_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QBranches::on_addBranchPB_pressed()
|
|
|
|
{
|
|
|
|
QString const new_branch = newBranchLE->text();
|
|
|
|
if (!new_branch.isEmpty()) {
|
|
|
|
branchlist_.add(fromqstr(new_branch));
|
|
|
|
newBranchLE->clear();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBranches::on_removePB_pressed()
|
|
|
|
{
|
2006-05-04 07:31:46 +00:00
|
|
|
QTreeWidgetItem * selItem =
|
|
|
|
branchesTW->currentItem();
|
2006-03-05 17:24:44 +00:00
|
|
|
QString sel_branch;
|
|
|
|
if (selItem != 0)
|
|
|
|
sel_branch = selItem->text(0);
|
|
|
|
if (!sel_branch.isEmpty()) {
|
|
|
|
branchlist_.remove(fromqstr(sel_branch));
|
|
|
|
newBranchLE->clear();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBranches::on_activatePB_pressed()
|
|
|
|
{
|
2006-05-04 07:31:46 +00:00
|
|
|
toggleBranch(branchesTW->currentItem());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-05-04 07:31:46 +00:00
|
|
|
toggleBranch(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
void QBranches::toggleBranch(QTreeWidgetItem * item)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-05-04 07:31:46 +00:00
|
|
|
if (item == 0)
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
|
2006-05-04 07:31:46 +00:00
|
|
|
QString sel_branch = item->text(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
if (!sel_branch.isEmpty()) {
|
2006-05-04 07:31:46 +00:00
|
|
|
bool const selected = item->text(1) == qt_("Yes");
|
2006-03-05 17:24:44 +00:00
|
|
|
Branch * branch = branchlist_.find(fromqstr(sel_branch));
|
|
|
|
if (branch && branch->setSelected(!selected)) {
|
|
|
|
newBranchLE->clear();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QBranches::on_colorPB_clicked()
|
|
|
|
{
|
2006-05-04 07:31:46 +00:00
|
|
|
QTreeWidgetItem * selItem =
|
|
|
|
branchesTW->currentItem();
|
2006-03-05 17:24:44 +00:00
|
|
|
QString sel_branch;
|
|
|
|
if (selItem != 0)
|
|
|
|
sel_branch = selItem->text(0);
|
|
|
|
if (!sel_branch.isEmpty()) {
|
|
|
|
string current_branch = fromqstr(sel_branch);
|
|
|
|
Branch * branch =
|
|
|
|
branchlist_.find(current_branch);
|
|
|
|
if (!branch)
|
|
|
|
return;
|
|
|
|
|
2006-03-23 20:04:05 +00:00
|
|
|
QColor const initial = rgb2qcolor(branch->getColor());
|
2006-03-05 17:24:44 +00:00
|
|
|
QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
|
|
|
|
if (ncol.isValid()){
|
|
|
|
// add the color to the branchlist
|
|
|
|
branch->setColor(fromqstr(ncol.name()));
|
|
|
|
newBranchLE->clear();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
|
|
#include "QBranches_moc.cpp"
|