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