X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FPanelStack.cpp;h=343b36ecb087f180340312dbfed15cfb8c348b19;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=eae495878aed1c8d23214a74874c0b612fc5373b;hpb=2b7ad272272869162dbf2489dc3285aa88488930;p=lyx.git diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp index eae495878a..343b36ecb0 100644 --- a/src/frontends/qt4/PanelStack.cpp +++ b/src/frontends/qt4/PanelStack.cpp @@ -17,14 +17,12 @@ #include "support/debug.h" #include -#include -#include #include #include +#include +#include -#include - -#include +#include "support/lassert.h" using namespace std; @@ -38,16 +36,14 @@ PanelStack::PanelStack(QWidget * parent) list_ = new QTreeWidget(this); stack_ = new QStackedWidget(this); - list_->setColumnCount(1); list_->setRootIsDecorated(false); - // Hide the pointless list header + list_->setColumnCount(1); list_->header()->hide(); -// QStringList HeaderLabels; -// HeaderLabels << QString("Category"); -// list_->setHeaderLabels(HeaderLabels); - connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)), + connect(list_, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*))); + connect(list_, SIGNAL(itemClicked (QTreeWidgetItem*, int)), + this, SLOT(itemSelected(QTreeWidgetItem *, int))); QHBoxLayout * layout = new QHBoxLayout(this); layout->addWidget(list_, 0); @@ -59,7 +55,7 @@ void PanelStack::addCategory(QString const & name, QString const & parent) { QTreeWidgetItem * item = 0; - LYXERR(Debug::GUI, "addCategory n= " << fromqstr(name) << " parent= "); + LYXERR(Debug::GUI, "addCategory n= " << name << " parent= "); int depth = 1; @@ -73,14 +69,15 @@ void PanelStack::addCategory(QString const & name, QString const & parent) item = new QTreeWidgetItem(panel_map_.value(parent)); item->setText(0, name); depth = 2; + list_->setRootIsDecorated(true); } panel_map_[name] = item; QFontMetrics fm(list_->font()); + // calculate the real size the current item needs in the listview - int itemsize = fm.width(name) + 10 - + list_->indentation() * depth; + int itemsize = fm.width(name) + 10 + list_->indentation() * depth; // adjust the listview width to the max. itemsize if (itemsize > list_->minimumWidth()) list_->setMinimumWidth(itemsize); @@ -97,10 +94,19 @@ void PanelStack::addPanel(QWidget * panel, QString const & name, QString const & } +void PanelStack::showPanel(QString const & name, bool show) +{ + QTreeWidgetItem * item = panel_map_.value(name, 0); + LASSERT(item, return); + + item->setHidden(!show); +} + + void PanelStack::setCurrentPanel(QString const & name) { QTreeWidgetItem * item = panel_map_.value(name, 0); - BOOST_ASSERT(item); + LASSERT(item, return); // force on first set if (list_->currentItem() == item) @@ -110,11 +116,40 @@ void PanelStack::setCurrentPanel(QString const & name) } +bool PanelStack::isCurrentPanel(QString const & name) const +{ + QTreeWidgetItem * item = panel_map_.value(name, 0); + LASSERT(item, return false); + + return (list_->currentItem() == item); +} + + void PanelStack::switchPanel(QTreeWidgetItem * item, - QTreeWidgetItem * /*previous*/) + QTreeWidgetItem * previous) { - if (QWidget * w = widget_map_.value(item, 0)) + // do nothing when clicked on whitespace (item=NULL) + if( !item ) + return; + + // if we have a category, expand the tree and go to the + // first item + if (item->childCount() > 0) { + item->setExpanded(true); + if (previous && previous->parent() != item) + switchPanel( item->child(0), previous ); + } + else if (QWidget * w = widget_map_.value(item, 0)) { stack_->setCurrentWidget(w); + } +} + + +void PanelStack::itemSelected(QTreeWidgetItem * item, int) +{ + // de-select the category if a child is selected + if (item->childCount() > 0 && item->child(0)->isSelected()) + item->setSelected(false); } @@ -127,4 +162,4 @@ QSize PanelStack::sizeHint() const } // namespace frontend } // namespace lyx -#include "PanelStack_moc.cpp" +#include "moc_PanelStack.cpp"