]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/PanelStack.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / PanelStack.cpp
index a8974fcf73cd6ece22aa885b5916ff7d621725df..b4e24554d59361e55144f815041c0ac9c6f7a428 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "qt_helpers.h"
 
-#include "debug.h"
+#include "support/debug.h"
 
 #include <QFontMetrics>
 #include <QStackedWidget>
 #include <QHBoxLayout>
 #include <QHeaderView>
 
-#include <boost/assert.hpp>
+#include "support/assert.h"
 
 #include <iostream>
 
-
-using std::endl;
-using std::cout;
+using namespace std;
 
 namespace lyx {
 namespace frontend {
@@ -40,8 +38,8 @@ PanelStack::PanelStack(QWidget * parent)
        list_ = new QTreeWidget(this);
        stack_ = new QStackedWidget(this);
 
-       list_->setColumnCount(1);
        list_->setRootIsDecorated(false);
+       list_->setColumnCount(1);
        // Hide the pointless list header
        list_->header()->hide();
 //     QStringList HeaderLabels;
@@ -50,6 +48,8 @@ PanelStack::PanelStack(QWidget * parent)
 
        connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
                this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*)));
+       connect(list_, SIGNAL(itemClicked (QTreeWidgetItem*, int)),
+               this, SLOT(itemSelected(QTreeWidgetItem *, int)));
 
        QHBoxLayout * layout = new QHBoxLayout(this);
        layout->addWidget(list_, 0);
@@ -57,36 +57,31 @@ PanelStack::PanelStack(QWidget * parent)
 }
 
 
-void PanelStack::addCategory(docstring const & n, docstring const & parent)
+void PanelStack::addCategory(QString const & name, QString const & parent)
 {
        QTreeWidgetItem * item = 0;
-       QString const name = toqstr(n);
 
-       LYXERR(Debug::GUI, "addCategory n= " << to_utf8(n) << "   parent= ");
+       LYXERR(Debug::GUI, "addCategory n= " << fromqstr(name) << "   parent= ");
 
        int depth = 1;
 
-       if (parent.empty()) {
+       if (parent.isEmpty()) {
                item = new QTreeWidgetItem(list_);
                item->setText(0, name);
        }
        else {
-               PanelMap::iterator it = panel_map_.find(parent);
-               //BOOST_ASSERT(it != panel_map_.end());
-               if (it == panel_map_.end()) {
+               if (!panel_map_.contains(parent))
                        addCategory(parent);
-                       it = panel_map_.find(parent);
-               }
-               BOOST_ASSERT(it != panel_map_.end());
-
-               item = new QTreeWidgetItem(it->second);
+               item = new QTreeWidgetItem(panel_map_.value(parent));
                item->setText(0, name);
                depth = 2;
+               list_->setRootIsDecorated(true);
        }
 
-       panel_map_[n] = item;
+       panel_map_[name] = item;
 
        QFontMetrics fm(list_->font());
+               
        // calculate the real size the current item needs in the listview
        int itemsize = fm.width(name) + 10
                + list_->indentation() * depth;
@@ -96,38 +91,49 @@ void PanelStack::addCategory(docstring const & n, docstring const & parent)
 }
 
 
-void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring const & parent)
+void PanelStack::addPanel(QWidget * panel, QString const & name, QString const & parent)
 {
        addCategory(name, parent);
-       QTreeWidgetItem * item = panel_map_.find(name)->second;
-
+       QTreeWidgetItem * item = panel_map_.value(name);
        widget_map_[item] = panel;
        stack_->addWidget(panel);
        stack_->setMinimumSize(panel->minimumSize());
 }
 
 
-void PanelStack::setCurrentPanel(docstring const & name)
+void PanelStack::setCurrentPanel(QString const & name)
 {
-       PanelMap::const_iterator cit = panel_map_.find(name);
-       BOOST_ASSERT(cit != panel_map_.end());
+       QTreeWidgetItem * item = panel_map_.value(name, 0);
+       LASSERT(item, /**/);
 
        // force on first set
-       if (list_->currentItem() ==  cit->second)
-               switchPanel(cit->second);
+       if (list_->currentItem() == item)
+               switchPanel(item);
 
-       list_->setCurrentItem(cit->second);
+       list_->setCurrentItem(item);
 }
 
 
 void PanelStack::switchPanel(QTreeWidgetItem * item,
-                            QTreeWidgetItem * /*previous*/)
+                            QTreeWidgetItem * previous)
 {
-       WidgetMap::const_iterator cit = widget_map_.find(item);
-       if (cit == widget_map_.end())
-               return;
+       // if we have a category, expand the tree and go to the
+       // first item
+       if (item->childCount() > 0) {
+               item->setExpanded(true);
+               if (previous != item->child(0))
+                       list_->setCurrentItem(item->child(0));
+       }
+       if (QWidget * w = widget_map_.value(item, 0))
+               stack_->setCurrentWidget(w);
+}
 
-       stack_->setCurrentWidget(cit->second);
+
+void PanelStack::itemSelected(QTreeWidgetItem * item, int)
+{
+       // de-select the category if a child is selected
+       if (item->childCount() > 0 && item->child(0)->isSelected())
+               item->setSelected(false);
 }