2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file PanelStack.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* 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>
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "PanelStack.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2006-10-30 14:39:05 +00:00
|
|
|
|
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
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
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);
|
|
|
|
|
2007-08-30 14:22:56 +00:00
|
|
|
list_->setRootIsDecorated(false);
|
2008-03-19 13:11:14 +00:00
|
|
|
list_->setColumnCount(1);
|
2006-11-05 12:30:12 +00:00
|
|
|
// Hide the pointless list header
|
|
|
|
list_->header()->hide();
|
2007-05-28 22:27:45 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 20:48:19 +00:00
|
|
|
void PanelStack::addCategory(QString const & name, QString const & parent)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-04-25 16:39:21 +00:00
|
|
|
QTreeWidgetItem * item = 0;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-05 20:48:19 +00:00
|
|
|
LYXERR(Debug::GUI, "addCategory n= " << fromqstr(name) << " parent= ");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-05 12:30:12 +00:00
|
|
|
int depth = 1;
|
|
|
|
|
2008-03-05 20:48:19 +00:00
|
|
|
if (parent.isEmpty()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
item = new QTreeWidgetItem(list_);
|
|
|
|
item->setText(0, name);
|
|
|
|
}
|
|
|
|
else {
|
2008-03-05 20:48:19 +00:00
|
|
|
if (!panel_map_.contains(parent))
|
2006-05-20 11:49:53 +00:00
|
|
|
addCategory(parent);
|
2008-03-05 20:48:19 +00:00
|
|
|
item = new QTreeWidgetItem(panel_map_.value(parent));
|
2006-03-05 17:24:44 +00:00
|
|
|
item->setText(0, name);
|
2006-11-05 12:30:12 +00:00
|
|
|
depth = 2;
|
2008-03-19 13:11:14 +00:00
|
|
|
list_->setRootIsDecorated(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 20:48:19 +00:00
|
|
|
panel_map_[name] = item;
|
2006-03-20 17:25:02 +00:00
|
|
|
|
2006-11-05 12:30:12 +00:00
|
|
|
QFontMetrics fm(list_->font());
|
2008-03-19 13:11:14 +00:00
|
|
|
|
2006-11-05 12:30:12 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 20:48:19 +00:00
|
|
|
void PanelStack::addPanel(QWidget * panel, QString const & name, QString const & parent)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
addCategory(name, parent);
|
2008-03-05 20:48:19 +00:00
|
|
|
QTreeWidgetItem * item = panel_map_.value(name);
|
2006-03-05 17:24:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 20:48:19 +00:00
|
|
|
void PanelStack::setCurrentPanel(QString const & name)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-03-05 20:48:19 +00:00
|
|
|
QTreeWidgetItem * item = panel_map_.value(name, 0);
|
|
|
|
BOOST_ASSERT(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// force on first set
|
2008-03-05 20:48:19 +00:00
|
|
|
if (list_->currentItem() == item)
|
|
|
|
switchPanel(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-05 20:48:19 +00:00
|
|
|
list_->setCurrentItem(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-06 08:18:51 +00:00
|
|
|
void PanelStack::switchPanel(QTreeWidgetItem * item,
|
|
|
|
QTreeWidgetItem * /*previous*/)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-03-19 13:11:14 +00:00
|
|
|
// if we have a category, expand the tree and go to the
|
|
|
|
// first item
|
|
|
|
if (item->childCount() > 0) {
|
|
|
|
item->setExpanded(true);
|
|
|
|
list_->setCurrentItem(item->child(0));
|
|
|
|
}
|
2008-03-05 20:48:19 +00:00
|
|
|
if (QWidget * w = widget_map_.value(item, 0))
|
|
|
|
stack_->setCurrentWidget(w);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
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
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "PanelStack_moc.cpp"
|