]> git.lyx.org Git - features.git/commitdiff
Toc Slider fixes from Ugras Baran.
authorAbdelrazak Younes <younes@lyx.org>
Sat, 25 Nov 2006 22:16:22 +0000 (22:16 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 25 Nov 2006 22:16:22 +0000 (22:16 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16045 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/QToc.C
src/frontends/qt4/QToc.h
src/frontends/qt4/QTocDialog.C
src/frontends/qt4/QTocDialog.h
src/frontends/qt4/TocModel.C
src/frontends/qt4/TocModel.h
src/frontends/qt4/ui/QTocUi.ui

index 039d3980ce1c0b4bd41f926afc0d1b5868fe2a7c..949e87c8ce0cb591023e0bb37a69da957ffe03f1 100644 (file)
@@ -51,6 +51,12 @@ bool QToc::canOutline()
 }
 
 
+int QToc::getTocDepth()
+{
+       return toc_models_[type_]->modelDepth();
+}
+
+
 QStandardItemModel * QToc::tocModel()
 {
        lyxerr[Debug::GUI]
index 15d65d590aa13c419b884b60b9645b11437d8290..5827be40cb56d42e8b2a4fb85c94cc98d7ec8c4d 100644 (file)
@@ -51,6 +51,8 @@ public:
        void goTo(QModelIndex const & index);
        ///
        int getType();
+       ///
+       int getTocDepth();
 
 private:
 
index aa26e61cfd050eb358f4714451d0623491b5d53a..9264be428ddb01cc0c03074da8d317f2ed1703b3 100644 (file)
@@ -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]
index a41c152e807781e7cab0567679039ef097daf311..c93e95e3604b34bb36ca5ecb76acdb7f7ca3cf60 100644 (file)
@@ -75,6 +75,8 @@ protected:
        void reconnectSelectionModel();
        ///
        int getIndexDepth(QModelIndex const & index, int depth = -1);
+       ///
+       void setTreeDepth(int depth = -1);
 
 private:
 
index c660842aeb82b958f9532b0760639aaae4aad252..d31829926818b08b42335cc905eb97d575771764 100644 (file)
@@ -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
 
index 175d40ab33aff8576ee9a92feda0dee158590ac4..55915c4bdebde516464a5af9dfb3c0a17d4fa08c 100644 (file)
@@ -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
index c3c9ad40723126a57eaa85046ccd297396b11511..91a9e60cbcd439c1b983a831669f305074563616 100644 (file)
       <number>1</number>
      </property>
      <property name="value" >
-      <number>1</number>
+      <number>2</number>
      </property>
      <property name="orientation" >
       <enum>Qt::Horizontal</enum>