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"
17 #include <qwidgetstack.h>
19 #include <qlistview.h>
21 #include <boost/assert.hpp>
26 PanelStack::PanelStack(QWidget * parent, const char * name)
27 : QWidget(parent, name)
29 list_ = new QListView(this);
30 stack_ = new QWidgetStack(this);
31 list_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
32 stack_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
34 list_->setSorting(-1);
35 list_->setHScrollBarMode(QScrollView::AlwaysOff);
36 list_->setVScrollBarMode(QScrollView::AlwaysOff);
38 list_->setColumnWidthMode(0, QListView::Maximum);
40 list_->setResizeMode(QListView::AllColumns);
42 list_->setRootIsDecorated(true);
43 QWidget * w = static_cast<QWidget*>(list_->child("list view header"));
47 connect(list_, SIGNAL(currentChanged(QListViewItem*)),
48 this, SLOT(switchPanel(QListViewItem *)));
50 QHBoxLayout * layout = new QHBoxLayout(this);
51 layout->addWidget(list_, 0);
52 layout->addWidget(stack_, 1);
56 void PanelStack::addCategory(string const & n, string const & parent)
60 QString name = toqstr(n);
62 if (!parent.empty()) {
63 PanelMap::iterator it = panel_map_.find(parent);
64 BOOST_ASSERT(it != panel_map_.end());
66 QListViewItem * before = it->second->firstChild();
68 while (before->nextSibling())
69 before = before->nextSibling();
71 item = new QListViewItem(it->second, before, name);
73 item = new QListViewItem(it->second, name);
76 QListViewItem * before = list_->firstChild();
78 while (before->nextSibling())
79 before = before->nextSibling();
80 item = new QListViewItem(list_, before, name);
82 item = new QListViewItem(list_, name);
86 item->setSelectable(false);
90 // Qt is just unbelievably moronic
91 list_->setMinimumSize(QSize(150, list_->minimumHeight()));
95 void PanelStack::addPanel(QWidget * panel, string const & name, string const & parent)
97 addCategory(name, parent);
98 QListViewItem * item = panel_map_.find(name)->second;
100 // reset the selectability set by addCategory
101 item->setSelectable(true);
103 widget_map_[item] = panel;
104 stack_->addWidget(panel, -1);
105 stack_->setMinimumSize(panel->minimumSize());
110 void PanelStack::setCurrentPanel(string const & name)
112 PanelMap::const_iterator cit = panel_map_.find(name);
113 BOOST_ASSERT(cit != panel_map_.end());
115 // force on first set
116 if (list_->currentItem() == cit->second)
117 switchPanel(cit->second);
119 list_->setCurrentItem(cit->second);
123 void PanelStack::switchPanel(QListViewItem * item)
125 WidgetMap::const_iterator cit = widget_map_.find(item);
126 if (cit == widget_map_.end())
129 stack_->raiseWidget(cit->second);