X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FQBranches.C;h=49a5682081637545a3bdb475b1789776742b0f6b;hb=6fdb8bf85a4237cf774cbe68f626642ec2c9e8f6;hp=fcbe74678868c3db6aa6beb289f666ffcddf8047;hpb=1032cc5ae85c3dfde2329f2f33418dc3873c0585;p=lyx.git diff --git a/src/frontends/qt4/QBranches.C b/src/frontends/qt4/QBranches.C index fcbe746788..49a5682081 100644 --- a/src/frontends/qt4/QBranches.C +++ b/src/frontends/qt4/QBranches.C @@ -1,5 +1,5 @@ /** - * \file QBranches.C + * \file QBranches.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -13,8 +13,8 @@ #include "QBranches.h" -#include "lcolorcache.h" -#include "validators.h" +#include "GuiApplication.h" +#include "Validator.h" #include "qt_helpers.h" #include "bufferparams.h" @@ -29,7 +29,6 @@ #include #include -using std::string; namespace lyx { namespace frontend { @@ -40,13 +39,10 @@ QBranches::QBranches(QWidget * parent, Qt::WFlags f) { setupUi(this); branchesTW->setColumnCount(3); - branchesTW->headerItem()->setText(0, qt_("Name")); + branchesTW->headerItem()->setText(0, qt_("Branch")); branchesTW->headerItem()->setText(1, qt_("Activated")); branchesTW->headerItem()->setText(2, qt_("Color")); -} - -QBranches::~QBranches() -{ + branchesTW->setSortingEnabled(true); } void QBranches::update(BufferParams const & params) @@ -57,10 +53,8 @@ void QBranches::update(BufferParams const & params) void QBranches::update() { - // store the selected branch - QTreeWidgetItem * item = - branchesTW->currentItem(); + QTreeWidgetItem * item = branchesTW->currentItem(); QString sel_branch; if (item != 0) sel_branch = item->text(0); @@ -86,10 +80,13 @@ void QBranches::update() newItem->setIcon(2, QIcon(coloritem)); } // restore selected branch - if (bname == sel_branch) + if (bname == sel_branch) { + branchesTW->setCurrentItem(newItem); branchesTW->setItemSelected(newItem, true); + } } - emit changed(); + // emit signal + changed(); } void QBranches::apply(BufferParams & params) const @@ -101,7 +98,7 @@ void QBranches::on_addBranchPB_pressed() { QString const new_branch = newBranchLE->text(); if (!new_branch.isEmpty()) { - branchlist_.add(fromqstr(new_branch)); + branchlist_.add(qstring_to_ucs4(new_branch)); newBranchLE->clear(); update(); } @@ -116,7 +113,7 @@ void QBranches::on_removePB_pressed() if (selItem != 0) sel_branch = selItem->text(0); if (!sel_branch.isEmpty()) { - branchlist_.remove(fromqstr(sel_branch)); + branchlist_.remove(qstring_to_ucs4(sel_branch)); newBranchLE->clear(); update(); } @@ -131,7 +128,10 @@ void QBranches::on_activatePB_pressed() void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col) { - toggleBranch(item); + if (col < 2) + toggleBranch(item); + else + toggleColor(item); } @@ -143,7 +143,7 @@ void QBranches::toggleBranch(QTreeWidgetItem * item) QString sel_branch = item->text(0); if (!sel_branch.isEmpty()) { bool const selected = item->text(1) == qt_("Yes"); - Branch * branch = branchlist_.find(fromqstr(sel_branch)); + Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch)); if (branch && branch->setSelected(!selected)) { newBranchLE->clear(); update(); @@ -154,20 +154,25 @@ void QBranches::toggleBranch(QTreeWidgetItem * item) void QBranches::on_colorPB_clicked() { - QTreeWidgetItem * selItem = - branchesTW->currentItem(); - QString sel_branch; - if (selItem != 0) - sel_branch = selItem->text(0); + toggleColor(branchesTW->currentItem()); +} + + +void QBranches::toggleColor(QTreeWidgetItem * item) +{ + if (item == 0) + return; + + QString sel_branch = item->text(0); if (!sel_branch.isEmpty()) { - string current_branch = fromqstr(sel_branch); + docstring current_branch = qstring_to_ucs4(sel_branch); Branch * branch = branchlist_.find(current_branch); if (!branch) return; QColor const initial = rgb2qcolor(branch->getColor()); - QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget())); + QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget())); if (ncol.isValid()){ // add the color to the branchlist branch->setColor(fromqstr(ncol.name())); @@ -179,3 +184,5 @@ void QBranches::on_colorPB_clicked() } // namespace frontend } // namespace lyx + +#include "QBranches_moc.cpp"