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 <QFontMetrics>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLayout>
|
|
|
|
|
|
|
|
#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);
|
|
|
|
list_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
|
2006-03-20 17:25:02 +00:00
|
|
|
stack_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
list_->setSortingEnabled(false);
|
|
|
|
// list_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
// list_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
// list_->addColumn("");
|
|
|
|
// list_->setColumnWidthMode(0, QTreeWidget::Maximum);
|
|
|
|
|
|
|
|
// list_->setResizeMode(QTreeWidget::AllColumns);
|
|
|
|
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
//list_->addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
//it->second->addChild(item);
|
|
|
|
}
|
|
|
|
|
2006-03-20 17:25:02 +00:00
|
|
|
panel_map_[n] = item;
|
|
|
|
|
2006-03-16 11:23:23 +00:00
|
|
|
list_->setFixedWidth(list_->sizeHint().width());
|
2006-03-05 17:24:44 +00:00
|
|
|
/*
|
|
|
|
item->setFlags(false);
|
|
|
|
item->setOpen(true);
|
|
|
|
|
|
|
|
// calculate the real size the current item needs in the listview
|
|
|
|
int itemsize = item->width(list_->fontMetrics(), list_, 0) + 10
|
|
|
|
+ list_->treeStepSize() * (item->depth() + 1) + list_->itemMargin();
|
|
|
|
// adjust the listview width to the max. itemsize
|
|
|
|
if (itemsize > list_->minimumWidth())
|
|
|
|
list_->setMinimumWidth(itemsize);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// reset the selectability set by addCategory
|
|
|
|
// item->setSelectable(true);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
#include "panelstack_moc.cpp"
|