X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FPanelStack.cpp;h=343b36ecb087f180340312dbfed15cfb8c348b19;hb=ee7dd4a11ea21851e7e32164c66b37d3bc8ac31d;hp=37cdcc47f37dbe798cba20da4871bb0a2ff5fba9;hpb=9d0ea8aeff32833a90b3fe64df0c5518a9e241be;p=lyx.git diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp index 37cdcc47f3..343b36ecb0 100644 --- a/src/frontends/qt4/PanelStack.cpp +++ b/src/frontends/qt4/PanelStack.cpp @@ -17,18 +17,14 @@ #include "support/debug.h" #include -#include -#include #include #include +#include +#include -#include - -#include - +#include "support/lassert.h" -using std::endl; -using std::cout; +using namespace std; namespace lyx { namespace frontend { @@ -40,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); @@ -57,77 +51,105 @@ PanelStack::PanelStack(QWidget * parent) } -void PanelStack::addCategory(docstring const & n, docstring const & parent) +void PanelStack::addCategory(QString const & name, QString const & parent) { QTreeWidgetItem * item = 0; - QString const name = toqstr(n); - LYXERR(Debug::GUI, "addCategory n= " << to_utf8(n) << " parent= "); + LYXERR(Debug::GUI, "addCategory n= " << name << " parent= "); int depth = 1; - if (parent.empty()) { + if (parent.isEmpty()) { item = new QTreeWidgetItem(list_); item->setText(0, name); } else { - PanelMap::iterator it = panel_map_.find(parent); - //BOOST_ASSERT(it != panel_map_.end()); - if (it == panel_map_.end()) { + if (!panel_map_.contains(parent)) addCategory(parent); - it = panel_map_.find(parent); - } - BOOST_ASSERT(it != panel_map_.end()); - - item = new QTreeWidgetItem(it->second); + item = new QTreeWidgetItem(panel_map_.value(parent)); item->setText(0, name); depth = 2; + list_->setRootIsDecorated(true); } - panel_map_[n] = item; + 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); } -void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring const & parent) +void PanelStack::addPanel(QWidget * panel, QString const & name, QString const & parent) { addCategory(name, parent); - QTreeWidgetItem * item = panel_map_.find(name)->second; - + QTreeWidgetItem * item = panel_map_.value(name); widget_map_[item] = panel; stack_->addWidget(panel); stack_->setMinimumSize(panel->minimumSize()); } -void PanelStack::setCurrentPanel(docstring const & name) +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) { - PanelMap::const_iterator cit = panel_map_.find(name); - BOOST_ASSERT(cit != panel_map_.end()); + QTreeWidgetItem * item = panel_map_.value(name, 0); + LASSERT(item, return); // force on first set - if (list_->currentItem() == cit->second) - switchPanel(cit->second); + if (list_->currentItem() == item) + switchPanel(item); + + list_->setCurrentItem(item); +} + + +bool PanelStack::isCurrentPanel(QString const & name) const +{ + QTreeWidgetItem * item = panel_map_.value(name, 0); + LASSERT(item, return false); - list_->setCurrentItem(cit->second); + return (list_->currentItem() == item); } void PanelStack::switchPanel(QTreeWidgetItem * item, - QTreeWidgetItem * /*previous*/) + QTreeWidgetItem * previous) { - WidgetMap::const_iterator cit = widget_map_.find(item); - if (cit == widget_map_.end()) + // do nothing when clicked on whitespace (item=NULL) + if( !item ) return; - stack_->setCurrentWidget(cit->second); + // 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); } @@ -140,4 +162,4 @@ QSize PanelStack::sizeHint() const } // namespace frontend } // namespace lyx -#include "PanelStack_moc.cpp" +#include "moc_PanelStack.cpp"