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"
|
|
|
|
|
2006-10-30 14:39:05 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
2006-11-05 12:30:12 +00:00
|
|
|
#include <QFontMetrics>
|
2006-03-05 17:24:44 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::endl;
|
|
|
|
using std::cout;
|
|
|
|
|
2006-10-30 14:39:05 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
PanelStack::PanelStack(QWidget * parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
list_ = new QTreeWidget(this);
|
|
|
|
stack_ = new QStackedWidget(this);
|
|
|
|
|
|
|
|
list_->setColumnCount(1);
|
2006-11-05 12:30:12 +00:00
|
|
|
// Hide the pointless list header
|
|
|
|
list_->header()->hide();
|
|
|
|
// QStringList HeaderLabels;
|
|
|
|
// HeaderLabels << QString("Category");
|
|
|
|
// list_->setHeaderLabels(HeaderLabels);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
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-12-04 13:50:46 +00:00
|
|
|
QString const name(toqstr(n));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "addCategory n= " << lyx::to_utf8(n) << " parent= " << endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-05 12:30:12 +00:00
|
|
|
int depth = 1;
|
|
|
|
|
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-11-05 12:30:12 +00:00
|
|
|
depth = 2;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 17:25:02 +00:00
|
|
|
panel_map_[n] = item;
|
|
|
|
|
2006-11-05 12:30:12 +00:00
|
|
|
QFontMetrics fm(list_->font());
|
|
|
|
// calculate the real size the current item needs in the listview
|
|
|
|
int itemsize = fm.width(name) + 10
|
|
|
|
+ list_->indentation() * depth;
|
|
|
|
// adjust the listview width to the max. itemsize
|
|
|
|
if (itemsize > list_->minimumWidth())
|
|
|
|
list_->setMinimumWidth(itemsize);
|
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);
|
2006-11-06 18:04:51 +00:00
|
|
|
stack_->setMinimumSize(panel->minimumSize());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-30 14:39:05 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2006-10-24 11:32:20 +00:00
|
|
|
#include "panelstack_moc.cpp"
|