#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/lassert.h"
#include <iostream>
-
-using std::endl;
-using std::cout;
+using namespace std;
namespace lyx {
namespace frontend {
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;
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);
}
-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= " << endl;
+ LYXERR(Debug::GUI, "addCategory n= " << 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;
}
-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);
}