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
11 #include "panelstack.h"
13 #include "support/LAssert.h"
15 #include "qt_helpers.h"
17 #include <qwidgetstack.h>
19 #include <qlistview.h>
24 PanelStack::PanelStack(QWidget * parent, const char * name)
25 : QWidget(parent, name)
27 list_ = new QListView(this);
28 stack_ = new QWidgetStack(this);
29 list_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
30 stack_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
32 list_->setSorting(-1);
33 list_->setHScrollBarMode(QScrollView::AlwaysOff);
34 list_->setVScrollBarMode(QScrollView::AlwaysOff);
36 list_->setColumnWidthMode(0, QListView::Maximum);
37 list_->setResizeMode(QListView::AllColumns);
38 list_->setRootIsDecorated(true);
40 connect(list_, SIGNAL(currentChanged(QListViewItem*)),
41 this, SLOT(switchPanel(QListViewItem *)));
43 QHBoxLayout * layout = new QHBoxLayout(this);
44 layout->addWidget(list_, 0);
45 layout->addWidget(stack_, 1);
49 void PanelStack::addCategory(string const & n, string const & parent)
53 QString name = toqstr(n);
55 if (!parent.empty()) {
56 PanelMap::iterator it = panel_map_.find(parent);
57 lyx::Assert(it != panel_map_.end());
59 QListViewItem * before = it->second->firstChild();
61 while (before->nextSibling())
62 before = before->nextSibling();
64 item = new QListViewItem(it->second, before, name);
66 item = new QListViewItem(it->second, name);
69 QListViewItem * before = list_->firstChild();
71 while (before->nextSibling())
72 before = before->nextSibling();
73 item = new QListViewItem(list_, before, name);
75 item = new QListViewItem(list_, name);
79 item->setSelectable(false);
83 // Qt is just unbelievably moronic
84 list_->setMinimumSize(QSize(150, list_->minimumHeight()));
88 void PanelStack::addPanel(QWidget * panel, string const & name, string const & parent)
90 addCategory(name, parent);
91 QListViewItem * item = panel_map_.find(name)->second;
93 // reset the selectability set by addCategory
94 item->setSelectable(true);
96 widget_map_[item] = panel;
97 stack_->addWidget(panel);
98 stack_->setMinimumSize(panel->minimumSize());
103 void PanelStack::setCurrentPanel(string const & name)
105 PanelMap::const_iterator cit = panel_map_.find(name);
106 lyx::Assert(cit != panel_map_.end());
108 switchPanel(cit->second);
112 void PanelStack::switchPanel(QListViewItem * item)
114 WidgetMap::const_iterator cit = widget_map_.find(item);
115 if (cit == widget_map_.end())
118 stack_->raiseWidget(cit->second);