]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/panelstack.C
hide the pointless header for the panel stack
[lyx.git] / src / frontends / qt2 / panelstack.C
1 /**
2  * \file panelstack.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include "panelstack.h"
12
13 #include "support/LAssert.h"
14
15 #include "qt_helpers.h"
16
17 #include <qwidgetstack.h>
18 #include <qlayout.h>
19 #include <qlistview.h>
20
21 using std::map;
22
23
24 PanelStack::PanelStack(QWidget * parent, const char * name)
25         : QWidget(parent, name)
26 {
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));
31
32         list_->setSorting(-1);
33         list_->setHScrollBarMode(QScrollView::AlwaysOff);
34         list_->setVScrollBarMode(QScrollView::AlwaysOff);
35         list_->addColumn("");
36         list_->setColumnWidthMode(0, QListView::Maximum);
37 #if QT_VERSION >= 300
38         list_->setResizeMode(QListView::AllColumns);
39 #endif
40         list_->setRootIsDecorated(true);
41         QWidget * w = static_cast<QWidget*>(list_->child("list view header"));
42         if (w)
43                 w->hide();
44
45         connect(list_, SIGNAL(currentChanged(QListViewItem*)),
46                 this, SLOT(switchPanel(QListViewItem *)));
47
48         QHBoxLayout * layout = new QHBoxLayout(this);
49         layout->addWidget(list_, 0);
50         layout->addWidget(stack_, 1);
51 }
52
53
54 void PanelStack::addCategory(string const & n, string const & parent)
55 {
56         QListViewItem * item;
57
58         QString name = toqstr(n);
59
60         if (!parent.empty()) {
61                 PanelMap::iterator it = panel_map_.find(parent);
62                 lyx::Assert(it != panel_map_.end());
63
64                 QListViewItem * before = it->second->firstChild();
65                 if (before) {
66                         while (before->nextSibling())
67                                 before = before->nextSibling();
68
69                         item = new QListViewItem(it->second, before, name);
70                 } else {
71                         item = new QListViewItem(it->second, name);
72                 }
73         } else {
74                 QListViewItem * before = list_->firstChild();
75                 if (before) {
76                         while (before->nextSibling())
77                                 before = before->nextSibling();
78                         item = new QListViewItem(list_, before, name);
79                 } else {
80                         item = new QListViewItem(list_, name);
81                 }
82         }
83
84         item->setSelectable(false);
85         item->setOpen(true);
86         panel_map_[n] = item;
87
88         // Qt is just unbelievably moronic
89         list_->setMinimumSize(QSize(150, list_->minimumHeight()));
90 }
91
92
93 void PanelStack::addPanel(QWidget * panel, string const & name, string const & parent)
94 {
95         addCategory(name, parent);
96         QListViewItem * item = panel_map_.find(name)->second;
97
98         // reset the selectability set by addCategory
99         item->setSelectable(true);
100
101         widget_map_[item] = panel;
102         stack_->addWidget(panel, -1);
103         stack_->setMinimumSize(panel->minimumSize());
104         resize(sizeHint());
105 }
106
107
108 void PanelStack::setCurrentPanel(string const & name)
109 {
110         PanelMap::const_iterator cit = panel_map_.find(name);
111         lyx::Assert(cit != panel_map_.end());
112
113         // force on first set
114         if (list_->currentItem() ==  cit->second)
115                 switchPanel(cit->second);
116
117         list_->setCurrentItem(cit->second);
118 }
119
120
121 void PanelStack::switchPanel(QListViewItem * item)
122 {
123         WidgetMap::const_iterator cit = widget_map_.find(item);
124         if (cit == widget_map_.end())
125                 return;
126
127         stack_->raiseWidget(cit->second);
128 }