]> git.lyx.org Git - features.git/commitdiff
Simplify scrolling code. Instead of using the actionTriggered() signal we now use...
authorAbdelrazak Younes <younes@lyx.org>
Tue, 29 Jan 2008 12:54:23 +0000 (12:54 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 29 Jan 2008 12:54:23 +0000 (12:54 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22709 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/GuiWorkArea.h

index be62b106b81b85b07f526bdcf3495f8d855e4750..76308482d81d8b78c6f125b0d5a1ab0af8aa7088 100644 (file)
@@ -227,8 +227,8 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
                                        this));
 
        // Initialize the vertical Scroll Bar
-       QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
-               this, SLOT(adjustViewWithScrollBar(int)));
+       QObject::connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
+               this, SLOT(scrollTo(int)));
 
        LYXERR(Debug::GUI, "viewport width: " << viewport()->width()
                << "  viewport height: " << viewport()->height());
@@ -458,27 +458,21 @@ void GuiWorkArea::updateScrollbar()
 {
        ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
 
-       verticalScrollBar()->setTracking(false);
-
        verticalScrollBar()->setRange(scroll_.min, scroll_.max);
        verticalScrollBar()->setPageStep(scroll_.page_step);
        verticalScrollBar()->setSingleStep(scroll_.single_step);
+       // Block the scrollbar signal to prevent recursive signal/slot calling.
+       verticalScrollBar()->blockSignals(true);
        verticalScrollBar()->setValue(scroll_.position);
        verticalScrollBar()->setSliderPosition(scroll_.position);
-
-       verticalScrollBar()->setTracking(true);
+       verticalScrollBar()->blockSignals(false);
 }
 
 
-void GuiWorkArea::adjustViewWithScrollBar(int action)
+void GuiWorkArea::scrollTo(int value)
 {
        stopBlinkingCursor();
-       if (action == QAbstractSlider::SliderPageStepAdd)
-               buffer_view_->scrollDown(viewport()->height());
-       else if (action == QAbstractSlider::SliderPageStepSub)
-               buffer_view_->scrollUp(viewport()->height());
-       else
-               buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition());
+       buffer_view_->scrollDocView(value);
 
        if (lyxrc.cursor_follows_scrollbar) {
                buffer_view_->setCursorFromScrollbar();
@@ -667,7 +661,6 @@ void GuiWorkArea::wheelEvent(QWheelEvent * e)
        int const lines = qApp->wheelScrollLines() * e->delta() / 120;
        verticalScrollBar()->setValue(verticalScrollBar()->value() -
                        lines *  verticalScrollBar()->singleStep());
-       adjustViewWithScrollBar();
 }
 
 
index 5019786b4b0070b84a10b50020d4810caf7341fb..313e5fbc87fa0bbb78d56990da3f3adf8c9a2d20 100644 (file)
@@ -132,13 +132,12 @@ Q_SIGNALS:
        void titleChanged(GuiWorkArea *);
 
 private Q_SLOTS:
-       /// Adjust the LyX buffer view with the position of the scrollbar.
+       /// Scroll the BufferView.
        /**
-       * The action argument is not used in the the code, it is there
-       * only for the connection to the vertical srollbar signal which
-       * emits an 'int' action.
+         * This is a slot for the valueChanged() signal of the vertical scrollbar.
+         * \p value value of the scrollbar.
        */
-       void adjustViewWithScrollBar(int action = 0);
+       void scrollTo(int value);
        /// timer to limit triple clicks
        void doubleClickTimeout();
        /// toggle the cursor's visibility