2003-03-28 01:21:42 +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
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-03-28 01:21:42 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2003-03-28 01:21:42 +00:00
|
|
|
#include "panelstack.h"
|
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include <qwidgetstack.h>
|
2005-04-11 07:00:03 +00:00
|
|
|
#include <qfontmetrics.h>
|
2003-03-28 01:21:42 +00:00
|
|
|
#include <qlayout.h>
|
|
|
|
#include <qlistview.h>
|
|
|
|
|
2003-09-09 18:19:34 +00:00
|
|
|
#include <boost/assert.hpp>
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2003-03-28 01:21:42 +00:00
|
|
|
|
|
|
|
PanelStack::PanelStack(QWidget * parent, const char * name)
|
|
|
|
: QWidget(parent, name)
|
|
|
|
{
|
|
|
|
list_ = new QListView(this);
|
|
|
|
stack_ = new QWidgetStack(this);
|
|
|
|
list_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
|
|
|
|
stack_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
|
|
|
|
|
|
|
|
list_->setSorting(-1);
|
|
|
|
list_->setHScrollBarMode(QScrollView::AlwaysOff);
|
|
|
|
list_->setVScrollBarMode(QScrollView::AlwaysOff);
|
|
|
|
list_->addColumn("");
|
|
|
|
list_->setColumnWidthMode(0, QListView::Maximum);
|
2003-03-28 17:29:07 +00:00
|
|
|
#if QT_VERSION >= 300
|
2003-03-28 01:21:42 +00:00
|
|
|
list_->setResizeMode(QListView::AllColumns);
|
2003-03-28 17:29:07 +00:00
|
|
|
#endif
|
2003-03-28 01:21:42 +00:00
|
|
|
list_->setRootIsDecorated(true);
|
2003-04-04 03:37:42 +00:00
|
|
|
QWidget * w = static_cast<QWidget*>(list_->child("list view header"));
|
|
|
|
if (w)
|
|
|
|
w->hide();
|
2003-03-28 01:21:42 +00:00
|
|
|
|
|
|
|
connect(list_, SIGNAL(currentChanged(QListViewItem*)),
|
|
|
|
this, SLOT(switchPanel(QListViewItem *)));
|
|
|
|
|
|
|
|
QHBoxLayout * layout = new QHBoxLayout(this);
|
|
|
|
layout->addWidget(list_, 0);
|
|
|
|
layout->addWidget(stack_, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PanelStack::addCategory(string const & n, string const & parent)
|
|
|
|
{
|
|
|
|
QListViewItem * item;
|
|
|
|
|
|
|
|
QString name = toqstr(n);
|
|
|
|
|
|
|
|
if (!parent.empty()) {
|
|
|
|
PanelMap::iterator it = panel_map_.find(parent);
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(it != panel_map_.end());
|
2003-03-28 01:21:42 +00:00
|
|
|
|
|
|
|
QListViewItem * before = it->second->firstChild();
|
|
|
|
if (before) {
|
|
|
|
while (before->nextSibling())
|
|
|
|
before = before->nextSibling();
|
|
|
|
|
|
|
|
item = new QListViewItem(it->second, before, name);
|
|
|
|
} else {
|
|
|
|
item = new QListViewItem(it->second, name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QListViewItem * before = list_->firstChild();
|
|
|
|
if (before) {
|
|
|
|
while (before->nextSibling())
|
|
|
|
before = before->nextSibling();
|
|
|
|
item = new QListViewItem(list_, before, name);
|
|
|
|
} else {
|
|
|
|
item = new QListViewItem(list_, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
item->setSelectable(false);
|
|
|
|
item->setOpen(true);
|
|
|
|
panel_map_[n] = item;
|
|
|
|
|
2005-04-11 07:00:03 +00:00
|
|
|
// calculate the real size the current item needs in the listview
|
|
|
|
QFontMetrics fm(list_->font());
|
|
|
|
int itemsize = item->width(fm, 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);
|
2003-03-28 01:21:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PanelStack::addPanel(QWidget * panel, string const & name, string const & parent)
|
|
|
|
{
|
|
|
|
addCategory(name, parent);
|
|
|
|
QListViewItem * item = panel_map_.find(name)->second;
|
|
|
|
|
|
|
|
// reset the selectability set by addCategory
|
|
|
|
item->setSelectable(true);
|
|
|
|
|
|
|
|
widget_map_[item] = panel;
|
2003-03-28 17:29:07 +00:00
|
|
|
stack_->addWidget(panel, -1);
|
2003-03-28 01:21:42 +00:00
|
|
|
stack_->setMinimumSize(panel->minimumSize());
|
|
|
|
resize(sizeHint());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PanelStack::setCurrentPanel(string const & name)
|
|
|
|
{
|
|
|
|
PanelMap::const_iterator cit = panel_map_.find(name);
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(cit != panel_map_.end());
|
2003-03-28 01:21:42 +00:00
|
|
|
|
2003-03-28 02:10:23 +00:00
|
|
|
// force on first set
|
|
|
|
if (list_->currentItem() == cit->second)
|
|
|
|
switchPanel(cit->second);
|
|
|
|
|
|
|
|
list_->setCurrentItem(cit->second);
|
2003-03-28 01:21:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PanelStack::switchPanel(QListViewItem * item)
|
|
|
|
{
|
|
|
|
WidgetMap::const_iterator cit = widget_map_.find(item);
|
|
|
|
if (cit == widget_map_.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
stack_->raiseWidget(cit->second);
|
|
|
|
}
|