#include "support/debug.h"
#include <QFontMetrics>
-#include <QStackedWidget>
-#include <QTreeWidget>
#include <QHBoxLayout>
#include <QHeaderView>
+#include <QStackedWidget>
+#include <QTreeWidget>
-#include <boost/assert.hpp>
-
-#include <iostream>
+#include "support/lassert.h"
using namespace std;
list_ = new QTreeWidget(this);
stack_ = new QStackedWidget(this);
- list_->setColumnCount(1);
list_->setRootIsDecorated(false);
- // Hide the pointless list header
+ list_->setColumnCount(1);
list_->header()->hide();
-// QStringList HeaderLabels;
-// HeaderLabels << QString("Category");
-// list_->setHeaderLabels(HeaderLabels);
- connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
+ 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);
{
QTreeWidgetItem * item = 0;
- LYXERR(Debug::GUI, "addCategory n= " << fromqstr(name) << " parent= ");
+ LYXERR(Debug::GUI, "addCategory n= " << name << " parent= ");
int depth = 1;
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;
+ int itemsize = fm.width(name) + 10 + list_->indentation() * depth;
// adjust the listview width to the max. itemsize
if (itemsize > list_->minimumWidth())
list_->setMinimumWidth(itemsize);
void PanelStack::setCurrentPanel(QString const & name)
{
QTreeWidgetItem * item = panel_map_.value(name, 0);
- BOOST_ASSERT(item);
+ LASSERT(item, return);
// force on first set
if (list_->currentItem() == item)
void PanelStack::switchPanel(QTreeWidgetItem * item,
- QTreeWidgetItem * /*previous*/)
+ QTreeWidgetItem * previous)
{
- if (QWidget * w = widget_map_.value(item, 0))
+ // do nothing when clicked on whitespace (item=NULL)
+ if( !item )
+ return;
+
+ // if we have a category, expand the tree and go to the
+ // first item
+ if (item->childCount() > 0) {
+ item->setExpanded(true);
+ if (previous && previous->parent() != item)
+ switchPanel( item->child(0), previous );
+ }
+ else 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);
}
} // namespace frontend
} // namespace lyx
-#include "PanelStack_moc.cpp"
+#include "moc_PanelStack.cpp"