]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/panelstack.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / qt4 / 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 <config.h>
12
13 #include "panelstack.h"
14
15 #include "qt_helpers.h"
16
17 #include <QStackedWidget>
18 #include <QFontMetrics>
19 #include <QTreeWidget>
20 #include <QHBoxLayout>
21 #include <QLayout>
22
23 #include <boost/assert.hpp>
24
25 using std::string;
26
27 #include <iostream>
28 using std::endl;
29 using std::cout;
30
31
32 PanelStack::PanelStack(QWidget * parent)
33         : QWidget(parent)
34 {
35         list_ = new QTreeWidget(this);
36         stack_ = new QStackedWidget(this);
37
38         list_->setColumnCount(1);
39         list_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
40         stack_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
41
42         list_->setSortingEnabled(false);
43 //      list_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
44 //      list_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
45 //      list_->addColumn("");
46 //      list_->setColumnWidthMode(0, QTreeWidget::Maximum);
47
48 //      list_->setResizeMode(QTreeWidget::AllColumns);
49
50         QStringList HeaderLabels; HeaderLabels << QString("Category");
51         list_->setHeaderLabels(HeaderLabels);
52
53         connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
54                 this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*)));
55
56         QHBoxLayout * layout = new QHBoxLayout(this);
57         layout->addWidget(list_, 0);
58         layout->addWidget(stack_, 1);
59 }
60
61
62 void PanelStack::addCategory(string const & n, string const & parent)
63 {
64         QTreeWidgetItem * item;
65
66         QString name = toqstr(n);
67
68         cout << "addCategory n= " << n << "   parent= " << endl;
69
70         if (parent.empty()) {
71                 item = new QTreeWidgetItem(list_);
72                 item->setText(0, name);
73                 //list_->addTopLevelItem(item);
74         }
75         else {
76                 PanelMap::iterator it = panel_map_.find(parent);
77                 BOOST_ASSERT(it != panel_map_.end());
78                 item = new QTreeWidgetItem(it->second);
79                 item->setText(0, name);
80                 //it->second->addChild(item);
81         }
82
83         panel_map_[n] = item;
84
85         list_->setFixedWidth(list_->sizeHint().width());
86 /*
87         item->setFlags(false);
88         item->setOpen(true);
89
90         // calculate the real size the current item needs in the listview
91         int itemsize = item->width(list_->fontMetrics(), list_, 0) + 10
92                    + list_->treeStepSize() * (item->depth() + 1) + list_->itemMargin();
93         // adjust the listview width to the max. itemsize
94         if (itemsize > list_->minimumWidth())
95                 list_->setMinimumWidth(itemsize);
96                 */
97 }
98
99
100 void PanelStack::addPanel(QWidget * panel, string const & name, string const & parent)
101 {
102         addCategory(name, parent);
103         QTreeWidgetItem * item = panel_map_.find(name)->second;
104
105         // reset the selectability set by addCategory
106 //      item->setSelectable(true);
107
108         widget_map_[item] = panel;
109         stack_->addWidget(panel);
110         stack_->setMinimumSize(panel->minimumSize());
111 }
112
113
114 void PanelStack::setCurrentPanel(string const & name)
115 {
116         PanelMap::const_iterator cit = panel_map_.find(name);
117         BOOST_ASSERT(cit != panel_map_.end());
118
119         // force on first set
120         if (list_->currentItem() ==  cit->second)
121                 switchPanel(cit->second);
122
123         list_->setCurrentItem(cit->second);
124 }
125
126
127 void PanelStack::switchPanel(QTreeWidgetItem * item, QTreeWidgetItem* previous)
128 {
129         WidgetMap::const_iterator cit = widget_map_.find(item);
130         if (cit == widget_map_.end())
131                 return;
132
133         stack_->setCurrentWidget(cit->second);
134 }