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
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "panelstack.h"
|
|
|
|
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include <qwidgetstack.h>
|
|
|
|
#include <qlayout.h>
|
|
|
|
#include <qlistview.h>
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2003-03-28 01:21:42 +00:00
|
|
|
using std::map;
|
|
|
|
|
|
|
|
|
|
|
|
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-06-30 23:56:22 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
// Qt is just unbelievably moronic
|
|
|
|
list_->setMinimumSize(QSize(150, list_->minimumHeight()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-06-30 23:56:22 +00:00
|
|
|
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);
|
|
|
|
}
|