- implement sizeHint()

- set minimum width of QTreeWidget
- bit of cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15526 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Edwin Leuven 2006-10-24 11:32:20 +00:00
parent 6222e8558a
commit 163dcb1210
2 changed files with 10 additions and 36 deletions

View File

@ -15,10 +15,9 @@
#include "qt_helpers.h" #include "qt_helpers.h"
#include <QStackedWidget> #include <QStackedWidget>
#include <QFontMetrics>
#include <QTreeWidget> #include <QTreeWidget>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLayout> #include <QHeaderView>
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -37,17 +36,6 @@ PanelStack::PanelStack(QWidget * parent)
stack_ = new QStackedWidget(this); stack_ = new QStackedWidget(this);
list_->setColumnCount(1); list_->setColumnCount(1);
list_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
stack_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
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"); QStringList HeaderLabels; HeaderLabels << QString("Category");
list_->setHeaderLabels(HeaderLabels); list_->setHeaderLabels(HeaderLabels);
@ -72,7 +60,6 @@ void PanelStack::addCategory(docstring const & n, docstring const & parent)
if (parent.empty()) { if (parent.empty()) {
item = new QTreeWidgetItem(list_); item = new QTreeWidgetItem(list_);
item->setText(0, name); item->setText(0, name);
//list_->addTopLevelItem(item);
} }
else { else {
PanelMap::iterator it = panel_map_.find(parent); PanelMap::iterator it = panel_map_.find(parent);
@ -85,23 +72,11 @@ void PanelStack::addCategory(docstring const & n, docstring const & parent)
item = new QTreeWidgetItem(it->second); item = new QTreeWidgetItem(it->second);
item->setText(0, name); item->setText(0, name);
//it->second->addChild(item);
} }
panel_map_[n] = item; panel_map_[n] = item;
list_->setFixedWidth(list_->sizeHint().width()); list_->setMinimumWidth(list_->header()->sectionSize(0) + list_->indentation());
/*
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);
*/
} }
@ -110,9 +85,6 @@ void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring con
addCategory(name, parent); addCategory(name, parent);
QTreeWidgetItem * item = panel_map_.find(name)->second; QTreeWidgetItem * item = panel_map_.find(name)->second;
// reset the selectability set by addCategory
// item->setSelectable(true);
widget_map_[item] = panel; widget_map_[item] = panel;
stack_->addWidget(panel); stack_->addWidget(panel);
stack_->setMinimumSize(panel->minimumSize()); stack_->setMinimumSize(panel->minimumSize());
@ -142,10 +114,11 @@ void PanelStack::switchPanel(QTreeWidgetItem * item,
stack_->setCurrentWidget(cit->second); stack_->setCurrentWidget(cit->second);
} }
QSize PanelStack::sizeHint() const
{
return QSize(list_->width() + stack_->width(),
qMax(list_->height(), stack_->height()));
}
#include "panelstack_moc.cpp" #include "panelstack_moc.cpp"
namespace lyx {
} // namespace lyx

View File

@ -43,6 +43,7 @@ public:
/// set current panel by logical name /// set current panel by logical name
void setCurrentPanel(lyx::docstring const &); void setCurrentPanel(lyx::docstring const &);
virtual QSize sizeHint() const;
public Q_SLOTS: public Q_SLOTS:
/// set current panel from an item /// set current panel from an item
void switchPanel(QTreeWidgetItem * i, QTreeWidgetItem* previous=0); void switchPanel(QTreeWidgetItem * i, QTreeWidgetItem* previous=0);