2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file panelstack.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "panelstack.h"
|
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include <QStackedWidget>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QHBoxLayout>
|
2006-10-24 11:32:20 +00:00
|
|
|
#include <QHeaderView>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
|
|
#include <iostream>
|
2006-10-09 12:07:05 +00:00
|
|
|
|
|
|
|
using lyx::docstring;
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::endl;
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
|
|
|
|
PanelStack::PanelStack(QWidget * parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
list_ = new QTreeWidget(this);
|
|
|
|
stack_ = new QStackedWidget(this);
|
|
|
|
|
|
|
|
list_->setColumnCount(1);
|
|
|
|
QStringList HeaderLabels; HeaderLabels << QString("Category");
|
|
|
|
list_->setHeaderLabels(HeaderLabels);
|
|
|
|
|
|
|
|
connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
|
2006-04-05 23:56:29 +00:00
|
|
|
this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
QHBoxLayout * layout = new QHBoxLayout(this);
|
|
|
|
layout->addWidget(list_, 0);
|
|
|
|
layout->addWidget(stack_, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-09 12:07:05 +00:00
|
|
|
void PanelStack::addCategory(docstring const & n, docstring const & parent)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QTreeWidgetItem * item;
|
|
|
|
|
2006-10-09 12:07:05 +00:00
|
|
|
QString name;
|
2006-10-21 00:16:43 +00:00
|
|
|
lyx::ucs4_to_qstring(n, name);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-10-09 12:07:05 +00:00
|
|
|
cout << "addCategory n= " << lyx::to_utf8(n) << " parent= " << endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
if (parent.empty()) {
|
|
|
|
item = new QTreeWidgetItem(list_);
|
|
|
|
item->setText(0, name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PanelMap::iterator it = panel_map_.find(parent);
|
2006-05-20 11:49:53 +00:00
|
|
|
//BOOST_ASSERT(it != panel_map_.end());
|
|
|
|
if (it == panel_map_.end()) {
|
|
|
|
addCategory(parent);
|
|
|
|
it = panel_map_.find(parent);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
BOOST_ASSERT(it != panel_map_.end());
|
2006-05-20 11:49:53 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
item = new QTreeWidgetItem(it->second);
|
|
|
|
item->setText(0, name);
|
|
|
|
}
|
|
|
|
|
2006-03-20 17:25:02 +00:00
|
|
|
panel_map_[n] = item;
|
|
|
|
|
2006-10-24 11:32:20 +00:00
|
|
|
list_->setMinimumWidth(list_->header()->sectionSize(0) + list_->indentation());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-09 12:07:05 +00:00
|
|
|
void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring const & parent)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
addCategory(name, parent);
|
|
|
|
QTreeWidgetItem * item = panel_map_.find(name)->second;
|
|
|
|
|
|
|
|
widget_map_[item] = panel;
|
|
|
|
stack_->addWidget(panel);
|
|
|
|
stack_->setMinimumSize(panel->minimumSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-09 12:07:05 +00:00
|
|
|
void PanelStack::setCurrentPanel(docstring const & name)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
PanelMap::const_iterator cit = panel_map_.find(name);
|
|
|
|
BOOST_ASSERT(cit != panel_map_.end());
|
|
|
|
|
|
|
|
// force on first set
|
|
|
|
if (list_->currentItem() == cit->second)
|
|
|
|
switchPanel(cit->second);
|
|
|
|
|
|
|
|
list_->setCurrentItem(cit->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
void PanelStack::switchPanel(QTreeWidgetItem * item,
|
|
|
|
QTreeWidgetItem * /*previous*/)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
WidgetMap::const_iterator cit = widget_map_.find(item);
|
|
|
|
if (cit == widget_map_.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
stack_->setCurrentWidget(cit->second);
|
|
|
|
}
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2006-10-24 11:32:20 +00:00
|
|
|
QSize PanelStack::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(list_->width() + stack_->width(),
|
|
|
|
qMax(list_->height(), stack_->height()));
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2006-10-24 11:32:20 +00:00
|
|
|
#include "panelstack_moc.cpp"
|