From 10dd2cbdcb471344fc91bc8ef2c6b4d32c174869 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 25 Nov 2006 22:16:22 +0000 Subject: [PATCH] Toc Slider fixes from Ugras Baran. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16045 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/QToc.C | 6 ++++++ src/frontends/qt4/QToc.h | 2 ++ src/frontends/qt4/QTocDialog.C | 12 ++++++++++-- src/frontends/qt4/QTocDialog.h | 2 ++ src/frontends/qt4/TocModel.C | 15 ++++++++++++++- src/frontends/qt4/TocModel.h | 5 +++++ src/frontends/qt4/ui/QTocUi.ui | 2 +- 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/frontends/qt4/QToc.C b/src/frontends/qt4/QToc.C index 039d3980ce..949e87c8ce 100644 --- a/src/frontends/qt4/QToc.C +++ b/src/frontends/qt4/QToc.C @@ -51,6 +51,12 @@ bool QToc::canOutline() } +int QToc::getTocDepth() +{ + return toc_models_[type_]->modelDepth(); +} + + QStandardItemModel * QToc::tocModel() { lyxerr[Debug::GUI] diff --git a/src/frontends/qt4/QToc.h b/src/frontends/qt4/QToc.h index 15d65d590a..5827be40cb 100644 --- a/src/frontends/qt4/QToc.h +++ b/src/frontends/qt4/QToc.h @@ -51,6 +51,8 @@ public: void goTo(QModelIndex const & index); /// int getType(); + /// + int getTocDepth(); private: diff --git a/src/frontends/qt4/QTocDialog.C b/src/frontends/qt4/QTocDialog.C index aa26e61cfd..9264be428d 100644 --- a/src/frontends/qt4/QTocDialog.C +++ b/src/frontends/qt4/QTocDialog.C @@ -98,15 +98,21 @@ void QTocDialog::on_depthSL_valueChanged(int depth) { if (depth == depth_) return; + setTreeDepth(depth); +} + - depth_ = depth; +void QTocDialog::setTreeDepth(int depth) +{ + if(depth!=-1) + depth_ = depth; // tocTV->expandAll(); //expanding and then collapsing is probably better, but my qt 4.1.2 doesn't have expandAll().. QModelIndexList indices = form_->tocModel()->match(form_->tocModel()->index(0,0), Qt::DisplayRole, "*", -1, Qt::MatchWildcard|Qt::MatchRecursive); Q_FOREACH (QModelIndex index, indices) { // I had to use Q_FOREACH instead of foreach - if(getIndexDepth(index) < depth) // because compile flag -DQT_NO_KEYWORDS doesn't allow me.. + if(getIndexDepth(index) < depth_) // because compile flag -DQT_NO_KEYWORDS doesn't allow me.. tocTV->expand(index); else tocTV->collapse(index); @@ -224,6 +230,8 @@ void QTocDialog::updateGui() enableButtons(); reconnectSelectionModel(); + depthSL->setMaximum(form_->getTocDepth()); + setTreeDepth(); select(form_->getCurrentIndex()); lyxerr[Debug::GUI] diff --git a/src/frontends/qt4/QTocDialog.h b/src/frontends/qt4/QTocDialog.h index a41c152e80..c93e95e360 100644 --- a/src/frontends/qt4/QTocDialog.h +++ b/src/frontends/qt4/QTocDialog.h @@ -75,6 +75,8 @@ protected: void reconnectSelectionModel(); /// int getIndexDepth(QModelIndex const & index, int depth = -1); + /// + void setTreeDepth(int depth = -1); private: diff --git a/src/frontends/qt4/TocModel.C b/src/frontends/qt4/TocModel.C index c660842aeb..d318299268 100644 --- a/src/frontends/qt4/TocModel.C +++ b/src/frontends/qt4/TocModel.C @@ -24,6 +24,8 @@ using std::map; using std::vector; using std::string; using std::make_pair; +using std::max; +using std::min; namespace lyx { namespace frontend { @@ -78,7 +80,6 @@ void TocModel::populate(Toc const & toc) if (toc.empty()) return; - int current_row; QModelIndex top_level_item; @@ -86,11 +87,15 @@ void TocModel::populate(Toc const & toc) TocIterator end = toc.end(); insertColumns(0, 1); + maxdepth_ = 0; + mindepth_ = INT_MAX; while (iter != end) { if (iter->isValid()) { + maxdepth_ = max(maxdepth_, iter->depth()); + mindepth_ = min(mindepth_, iter->depth()); current_row = rowCount(); insertRows(current_row, 1); top_level_item = QStandardItemModel::index(current_row, 0); @@ -127,6 +132,7 @@ void TocModel::populate(TocIterator & iter, QModelIndex const & parent) { int curdepth = iter->depth() + 1; + int current_row; QModelIndex child_item; @@ -143,6 +149,8 @@ void TocModel::populate(TocIterator & iter, return; } + maxdepth_ = max(maxdepth_, iter->depth()); + mindepth_ = min(mindepth_, iter->depth()); current_row = rowCount(parent); insertRows(current_row, 1, parent); child_item = QStandardItemModel::index(current_row, 0, parent); @@ -159,6 +167,11 @@ void TocModel::populate(TocIterator & iter, } +int TocModel::modelDepth() +{ + return maxdepth_ - mindepth_; +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/TocModel.h b/src/frontends/qt4/TocModel.h index 175d40ab33..55915c4bde 100644 --- a/src/frontends/qt4/TocModel.h +++ b/src/frontends/qt4/TocModel.h @@ -43,6 +43,8 @@ public: TocIterator const tocIterator(QModelIndex const & index) const; /// QModelIndex const modelIndex(TocIterator const & it) const; + /// + int modelDepth(); private: /// @@ -59,6 +61,9 @@ private: TocMap toc_map_; /// ModelMap model_map_; + /// + int maxdepth_; + int mindepth_; }; } // namespace frontend diff --git a/src/frontends/qt4/ui/QTocUi.ui b/src/frontends/qt4/ui/QTocUi.ui index c3c9ad4072..91a9e60cbc 100644 --- a/src/frontends/qt4/ui/QTocUi.ui +++ b/src/frontends/qt4/ui/QTocUi.ui @@ -109,7 +109,7 @@ 1 - 1 + 2 Qt::Horizontal -- 2.39.2