]> 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 eae495878aed1c8d23214a74874c0b612fc5373b..b4e24554d59361e55144f815041c0ac9c6f7a428 100644 (file)
@@ -22,7 +22,7 @@
 #include <QHBoxLayout>
 #include <QHeaderView>
 
-#include <boost/assert.hpp>
+#include "support/assert.h"
 
 #include <iostream>
 
@@ -38,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;
@@ -48,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);
@@ -73,11 +75,13 @@ void PanelStack::addCategory(QString const & name, QString const & parent)
                item = new QTreeWidgetItem(panel_map_.value(parent));
                item->setText(0, name);
                depth = 2;
+               list_->setRootIsDecorated(true);
        }
 
        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;
@@ -100,7 +104,7 @@ void PanelStack::addPanel(QWidget * panel, QString const & name, QString const &
 void PanelStack::setCurrentPanel(QString const & name)
 {
        QTreeWidgetItem * item = panel_map_.value(name, 0);
-       BOOST_ASSERT(item);
+       LASSERT(item, /**/);
 
        // force on first set
        if (list_->currentItem() == item)
@@ -111,13 +115,28 @@ void PanelStack::setCurrentPanel(QString const & name)
 
 
 void PanelStack::switchPanel(QTreeWidgetItem * item,
-                            QTreeWidgetItem * /*previous*/)
+                            QTreeWidgetItem * previous)
 {
+       // 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);
 }
 
 
+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);
+}
+
+
 QSize PanelStack::sizeHint() const
 {
        return QSize(list_->width() + stack_->width(),