]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/panelstack.C
Remove unused symbol encoding
[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 "debug.h"
18
19 #include <QFontMetrics>
20 #include <QStackedWidget>
21 #include <QTreeWidget>
22 #include <QHBoxLayout>
23 #include <QHeaderView>
24
25 #include <boost/assert.hpp>
26
27 #include <iostream>
28
29
30 using std::endl;
31 using std::cout;
32
33 namespace lyx {
34 namespace frontend {
35
36
37 PanelStack::PanelStack(QWidget * parent)
38         : QWidget(parent)
39 {
40         list_ = new QTreeWidget(this);
41         stack_ = new QStackedWidget(this);
42
43         list_->setColumnCount(1);
44         // Hide the pointless list header
45         list_->header()->hide();
46 //      QStringList HeaderLabels;
47 //      HeaderLabels << QString("Category");
48 //      list_->setHeaderLabels(HeaderLabels);
49
50         connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
51                 this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*)));
52
53         QHBoxLayout * layout = new QHBoxLayout(this);
54         layout->addWidget(list_, 0);
55         layout->addWidget(stack_, 1);
56 }
57
58
59 void PanelStack::addCategory(docstring const & n, docstring const & parent)
60 {
61         QTreeWidgetItem * item;
62
63         QString name;
64         lyx::ucs4_to_qstring(n, name);
65
66         lyxerr[Debug::GUI] << "addCategory n= " << lyx::to_utf8(n) << "   parent= " << endl;
67
68         int depth = 1;
69
70         if (parent.empty()) {
71                 item = new QTreeWidgetItem(list_);
72                 item->setText(0, name);
73         }
74         else {
75                 PanelMap::iterator it = panel_map_.find(parent);
76                 //BOOST_ASSERT(it != panel_map_.end());
77                 if (it == panel_map_.end()) {
78                         addCategory(parent);
79                         it = panel_map_.find(parent);
80                 }
81                 BOOST_ASSERT(it != panel_map_.end());
82
83                 item = new QTreeWidgetItem(it->second);
84                 item->setText(0, name);
85                 depth = 2;
86         }
87
88         panel_map_[n] = item;
89
90         QFontMetrics fm(list_->font());
91         // calculate the real size the current item needs in the listview
92         int itemsize = fm.width(name) + 10
93                 + list_->indentation() * depth;
94         // adjust the listview width to the max. itemsize
95         if (itemsize > list_->minimumWidth())
96                 list_->setMinimumWidth(itemsize);
97 }
98
99
100 void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring const & parent)
101 {
102         addCategory(name, parent);
103         QTreeWidgetItem * item = panel_map_.find(name)->second;
104
105         widget_map_[item] = panel;
106         stack_->addWidget(panel);
107         stack_->setMinimumSize(panel->minimumSize());
108 }
109
110
111 void PanelStack::setCurrentPanel(docstring const & name)
112 {
113         PanelMap::const_iterator cit = panel_map_.find(name);
114         BOOST_ASSERT(cit != panel_map_.end());
115
116         // force on first set
117         if (list_->currentItem() ==  cit->second)
118                 switchPanel(cit->second);
119
120         list_->setCurrentItem(cit->second);
121 }
122
123
124 void PanelStack::switchPanel(QTreeWidgetItem * item,
125                              QTreeWidgetItem * /*previous*/)
126 {
127         WidgetMap::const_iterator cit = widget_map_.find(item);
128         if (cit == widget_map_.end())
129                 return;
130
131         stack_->setCurrentWidget(cit->second);
132 }
133
134
135 QSize PanelStack::sizeHint() const
136 {
137         return QSize(list_->width() + stack_->width(),
138                 qMax(list_->height(), stack_->height()));
139 }
140
141 } // namespace frontend
142 } // namespace lyx
143
144 #include "panelstack_moc.cpp"