3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "panelstack.h"
15 #include "qt_helpers.h"
19 #include <QStackedWidget>
20 #include <QTreeWidget>
21 #include <QHBoxLayout>
22 #include <QHeaderView>
24 #include <boost/assert.hpp>
36 PanelStack::PanelStack(QWidget * parent)
39 list_ = new QTreeWidget(this);
40 stack_ = new QStackedWidget(this);
42 list_->setColumnCount(1);
43 QStringList HeaderLabels; HeaderLabels << QString("Category");
44 list_->setHeaderLabels(HeaderLabels);
46 connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
47 this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*)));
49 QHBoxLayout * layout = new QHBoxLayout(this);
50 layout->addWidget(list_, 0);
51 layout->addWidget(stack_, 1);
55 void PanelStack::addCategory(docstring const & n, docstring const & parent)
57 QTreeWidgetItem * item;
60 lyx::ucs4_to_qstring(n, name);
62 lyxerr[Debug::GUI] << "addCategory n= " << lyx::to_utf8(n) << " parent= " << endl;
65 item = new QTreeWidgetItem(list_);
66 item->setText(0, name);
69 PanelMap::iterator it = panel_map_.find(parent);
70 //BOOST_ASSERT(it != panel_map_.end());
71 if (it == panel_map_.end()) {
73 it = panel_map_.find(parent);
75 BOOST_ASSERT(it != panel_map_.end());
77 item = new QTreeWidgetItem(it->second);
78 item->setText(0, name);
83 list_->setMinimumWidth(list_->header()->sectionSize(0) + list_->indentation());
87 void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring const & parent)
89 addCategory(name, parent);
90 QTreeWidgetItem * item = panel_map_.find(name)->second;
92 widget_map_[item] = panel;
93 stack_->addWidget(panel);
94 stack_->setMinimumSize(panel->minimumSize());
98 void PanelStack::setCurrentPanel(docstring const & name)
100 PanelMap::const_iterator cit = panel_map_.find(name);
101 BOOST_ASSERT(cit != panel_map_.end());
103 // force on first set
104 if (list_->currentItem() == cit->second)
105 switchPanel(cit->second);
107 list_->setCurrentItem(cit->second);
111 void PanelStack::switchPanel(QTreeWidgetItem * item,
112 QTreeWidgetItem * /*previous*/)
114 WidgetMap::const_iterator cit = widget_map_.find(item);
115 if (cit == widget_map_.end())
118 stack_->setCurrentWidget(cit->second);
122 QSize PanelStack::sizeHint() const
124 return QSize(list_->width() + stack_->width(),
125 qMax(list_->height(), stack_->height()));
128 } // namespace frontend
131 #include "panelstack_moc.cpp"