]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/QBranches.C
getting rid of even more qt3 convenience classes and unused headers...
[lyx.git] / src / frontends / qt4 / QBranches.C
index 43a132b6da5259dfbd72e0cab9f23f1b4955220c..fcbe74678868c3db6aa6beb289f666ffcddf8047 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file QDocumentDialog.C
+ * \file QBranches.C
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
@@ -13,6 +13,7 @@
 
 #include "QBranches.h"
 
+#include "lcolorcache.h"
 #include "validators.h"
 #include "qt_helpers.h"
 
 
 #include "support/lstrings.h"
 
-#include <Q3ListView>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
 #include <QPixmap>
+#include <QIcon>
 #include <QColor>
 #include <QColorDialog>
 
@@ -36,7 +39,10 @@ QBranches::QBranches(QWidget * parent, Qt::WFlags f)
        : QWidget(parent, f)
 {
        setupUi(this);
-       branchesLV->setSorting(0);
+       branchesTW->setColumnCount(3);
+       branchesTW->headerItem()->setText(0, qt_("Name"));
+       branchesTW->headerItem()->setText(1, qt_("Activated"));
+       branchesTW->headerItem()->setText(2, qt_("Color"));
 }
 
 QBranches::~QBranches()
@@ -51,36 +57,39 @@ void QBranches::update(BufferParams const & params)
 
 void QBranches::update()
 {
-       
+
        // store the selected branch
-       Q3ListViewItem * selItem =
-               branchesLV->selectedItem();
+       QTreeWidgetItem * item =
+               branchesTW->currentItem();
        QString sel_branch;
-       if (selItem != 0)
-               sel_branch = selItem->text(0);
+       if (item != 0)
+               sel_branch = item->text(0);
 
-       branchesLV->clear();
+       branchesTW->clear();
 
        BranchList::const_iterator it = branchlist_.begin();
        BranchList::const_iterator const end = branchlist_.end();
        for (; it != end; ++it) {
+               QTreeWidgetItem * newItem =
+                       new QTreeWidgetItem(branchesTW);
+
                QString const bname = toqstr(it->getBranch());
+               newItem->setText(0, bname);
+
                QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
-               Q3ListViewItem * newItem =
-                       new Q3ListViewItem(branchesLV, bname, sel);
-               string const x11hexname = it->getColor();
-               QColor itemcolor;
-               if (x11hexname[0] == '#')
-                       itemcolor.setNamedColor(toqstr(x11hexname));
+               newItem->setText(1, sel);
+
+               QColor const itemcolor = rgb2qcolor(it->getColor());
                if (itemcolor.isValid()) {
                        QPixmap coloritem(30, 10);
                        coloritem.fill(itemcolor);
-                       newItem->setPixmap(2, coloritem);
+                       newItem->setIcon(2, QIcon(coloritem));
                }
                // restore selected branch
                if (bname == sel_branch)
-                       branchesLV->setSelected(newItem, true);
+                       branchesTW->setItemSelected(newItem, true);
        }
+       emit changed();
 }
 
 void QBranches::apply(BufferParams & params) const
@@ -101,8 +110,8 @@ void QBranches::on_addBranchPB_pressed()
 
 void QBranches::on_removePB_pressed()
 {
-       Q3ListViewItem * selItem =
-               branchesLV->selectedItem();
+       QTreeWidgetItem * selItem =
+               branchesTW->currentItem();
        QString sel_branch;
        if (selItem != 0)
                sel_branch = selItem->text(0);
@@ -116,26 +125,24 @@ void QBranches::on_removePB_pressed()
 
 void QBranches::on_activatePB_pressed()
 {
-       Q3ListViewItem * selItem =
-               branchesLV->selectedItem();
-       toggleBranch(selItem);
+       toggleBranch(branchesTW->currentItem());
 }
 
 
-void QBranches::on_branchesLV_doubleClicked(Q3ListViewItem * selItem)
+void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
 {
-       toggleBranch(selItem);
+       toggleBranch(item);
 }
 
 
-void QBranches::toggleBranch(Q3ListViewItem * selItem)
+void QBranches::toggleBranch(QTreeWidgetItem * item)
 {
-       if (selItem == 0)
+       if (item == 0)
                return;
 
-       QString sel_branch = selItem->text(0);
+       QString sel_branch = item->text(0);
        if (!sel_branch.isEmpty()) {
-               bool const selected = selItem->text(1) == qt_("Yes");
+               bool const selected = item->text(1) == qt_("Yes");
                Branch * branch = branchlist_.find(fromqstr(sel_branch));
                if (branch && branch->setSelected(!selected)) {
                        newBranchLE->clear();
@@ -147,22 +154,19 @@ void QBranches::toggleBranch(Q3ListViewItem * selItem)
 
 void QBranches::on_colorPB_clicked()
 {
-       Q3ListViewItem * selItem =
-               branchesLV->selectedItem();
+       QTreeWidgetItem * selItem =
+               branchesTW->currentItem();
        QString sel_branch;
        if (selItem != 0)
                sel_branch = selItem->text(0);
        if (!sel_branch.isEmpty()) {
-               QColor initial("lightskyblue");\r
                string current_branch = fromqstr(sel_branch);
                Branch * branch =
                        branchlist_.find(current_branch);
                if (!branch)
                        return;
 
-               string x11hexname = branch->getColor();
-               if (x11hexname[0] == '#')
-                       initial.setNamedColor(toqstr(x11hexname));
+               QColor const initial = rgb2qcolor(branch->getColor());
                QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
                if (ncol.isValid()){
                        // add the color to the branchlist