]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/TocWidget.cpp
Make code a bit easier to read
[lyx.git] / src / frontends / qt / TocWidget.cpp
index fcbd605848125e64840138b116e1a1ecb860fc7f..03d870a5f4c37d7123348cf91cc93e1b9646c61e 100644 (file)
@@ -47,8 +47,8 @@ namespace lyx {
 namespace frontend {
 
 TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
-       : QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view),
-         timer_(new QTimer(this))
+       : QWidget(parent), depth_(0), persistent_(false), keep_expanded_(false),
+         gui_view_(gui_view), timer_(new QTimer(this))
 {
        setupUi(this);
 
@@ -193,7 +193,6 @@ bool TocWidget::getStatus(Cursor & cur, FuncRequest const & cmd,
 void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd,
                DispatchResult & dr)
 {
-
        Inset * inset = itemInset();
 
        QModelIndex const & index = tocTV->currentIndex();
@@ -263,7 +262,8 @@ void TocWidget::on_tocTV_activated(QModelIndex const & index)
 
 void TocWidget::on_tocTV_pressed(QModelIndex const & index)
 {
-
+       DocIterator const & dit = gui_view_.documentBufferView()->cursor();
+       keep_expanded_ = gui_view_.tocModels().currentIndex(current_type_, dit) == index;
        Qt::MouseButtons const button = QApplication::mouseButtons();
        if (button & Qt::LeftButton) {
                goTo(index);
@@ -273,6 +273,12 @@ void TocWidget::on_tocTV_pressed(QModelIndex const & index)
 }
 
 
+void TocWidget::on_tocTV_doubleClicked(QModelIndex const &)
+{
+       keep_expanded_ = true;
+}
+
+
 void TocWidget::goTo(QModelIndex const & index)
 {
        LYXERR(Debug::GUI, "goto " << index.row()
@@ -372,7 +378,6 @@ void TocWidget::outline(FuncCode func_code)
 
 void TocWidget::sendDispatch(FuncRequest fr)
 {
-
        fr.setViewOrigin(&gui_view_);
        GuiWorkArea * old_wa = gui_view_.currentWorkArea();
        GuiWorkArea * doc_wa = gui_view_.currentMainWorkArea();
@@ -492,10 +497,11 @@ void TocWidget::updateView()
        // Expensive operations are on a timer.  We finish the update immediately
        // for sparse edition actions, i.e. there was no edition/cursor movement
        // recently, then every 300ms.
-       if (!timer_->isActive()) {
+       if (!timer_->isActive() && !keep_expanded_) {
                finishUpdateView();
                timer_->start(300);
        }
+       keep_expanded_ = false;
 }
 
 
@@ -512,8 +518,9 @@ void TocWidget::finishUpdateView()
        // text and moving with arrows. For bigger operations, this is negligible,
        // and outweighted by TocModels::reset() anyway.
        if (canNavigate()) {
-               if (!persistent_)
+               if (!persistent_ && !keep_expanded_)
                        setTreeDepth(depth_);
+               keep_expanded_ = false;
                persistentCB->setChecked(persistent_);
                // select the item at current cursor location
                if (gui_view_.documentBufferView()) {
@@ -607,6 +614,8 @@ void TocWidget::init(QString const & str)
        typeCO->setCurrentIndex(new_index);
        typeCO->blockSignals(false);
        updateViewNow();
+       if (persistent_)
+               setTreeDepth(depth_);
 }
 
 } // namespace frontend