]> git.lyx.org Git - features.git/commitdiff
Fix bug 4935: Scroll down below document
authorVincent van Ravesteijn <vfr@lyx.org>
Fri, 27 Mar 2009 17:41:58 +0000 (17:41 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Fri, 27 Mar 2009 17:41:58 +0000 (17:41 +0000)
http://bugzilla.lyx.org/show_bug.cgi?id=4935

* GuiPrefs: Add an option to the Editing dialog.

* BufferView: Scroll below document if the option is set.

* LyXRC: Write/read the option from preferences file.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28947 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h
src/LyXFunc.cpp
src/LyXRC.cpp
src/LyXRC.h
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/ui/PrefEditUi.ui

index 6e120dc53d2363f91dbd62c4b2e71abf27980ee7..ad4e15fb2862869a3f573debcc732982fc6542b7 100644 (file)
@@ -517,7 +517,10 @@ void BufferView::updateScrollbar()
 
        d->scrollbarParameters_.position = 0;
        // The reference is the top position so we remove one page.
-       d->scrollbarParameters_.max -= d->scrollbarParameters_.page_step;
+       if (lyxrc.scroll_below_document)
+               d->scrollbarParameters_.max -= minVisiblePart();
+       else
+               d->scrollbarParameters_.max -= d->scrollbarParameters_.page_step;
 }
 
 
@@ -1772,6 +1775,12 @@ void BufferView::lfunScroll(FuncRequest const & cmd)
 }
 
 
+int BufferView::minVisiblePart()
+{
+       return 2 * defaultRowHeight();
+}
+
+
 int BufferView::scroll(int y)
 {
        if (y > 0)
@@ -1786,10 +1795,12 @@ int BufferView::scrollDown(int offset)
 {
        Text * text = &buffer_.text();
        TextMetrics & tm = d->text_metrics_[text];
-       int ymax = height_ + offset;
+       int const ymax = height_ + offset;
        while (true) {
                pair<pit_type, ParagraphMetrics const *> last = tm.last();
                int bottom_pos = last.second->position() + last.second->descent();
+               if (lyxrc.scroll_below_document)
+                       bottom_pos += height_ - minVisiblePart();
                if (last.first + 1 == int(text->paragraphs().size())) {
                        if (bottom_pos <= height_)
                                return 0;
index fcf58544a72dd533997a7dcaec9c190e8c1167fa..0105275eae1713218550af1e1aace7e7c08ef470 100644 (file)
@@ -311,6 +311,10 @@ private:
        /// \return true if no further update is needed.
        bool singleParUpdate();
 
+       /// The minimal size of the document that is visible. Used
+       /// when it is allowed to scroll below the document.
+       int minVisiblePart();
+
        /// Search recursively for the the innermost inset that covers (x, y) position.
        /// \retval 0 if no inset is found.
        Inset const * getCoveringInset(
index 5fc04c1eac542e861f685f56a625e552266337ca..17eaf64fe6dd93d857cdb7a23adaf3effb0283c2 100644 (file)
@@ -1941,6 +1941,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
        case LyXRC::RC_COPIER:
        case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
+       case LyXRC::RC_SCROLL_BELOW_DOCUMENT:
        case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
        case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
        case LyXRC::RC_DATE_INSERT_FORMAT:
index 19bbb157a3813b33f86c2c117d6a19e081b9bb56..e458a0bef1edd70d3d25932a6021b1bbf02c6e78 100644 (file)
@@ -157,6 +157,7 @@ LexerKeyword lyxrcTags[] = {
        { "\\screen_font_typewriter", LyXRC::RC_SCREEN_FONT_TYPEWRITER },
        { "\\screen_font_typewriter_foundry", LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY },
        { "\\screen_zoom", LyXRC::RC_SCREEN_ZOOM },
+       { "\\scroll_below_document", LyXRC::RC_SCROLL_BELOW_DOCUMENT },
        { "\\serverpipe", LyXRC::RC_SERVERPIPE },
        { "\\set_color", LyXRC::RC_SET_COLOR },
        { "\\show_banner", LyXRC::RC_SHOW_BANNER },
@@ -288,6 +289,7 @@ void LyXRC::setDefaults()
        tex_allows_spaces = false;
        date_insert_format = "%x";
        cursor_follows_scrollbar = false;
+       scroll_below_document = false;
        mac_like_word_movement = false;
        macro_edit_style = MACRO_EDIT_INLINE_BOX;
        dialogs_iconify_with_main = false;
@@ -821,6 +823,10 @@ int LyXRC::read(Lexer & lexrc)
                        lexrc >> cursor_follows_scrollbar;
                        break;
 
+               case RC_SCROLL_BELOW_DOCUMENT:
+                       lexrc >> scroll_below_document;
+                       break;
+
                case RC_MAC_LIKE_WORD_MOVEMENT:
                        lexrc >> mac_like_word_movement;
                        break;
@@ -1518,6 +1524,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
                if (tag != RC_LAST)
                        break;
+       case RC_SCROLL_BELOW_DOCUMENT:
+               if (ignore_system_lyxrc ||
+                   scroll_below_document
+                   != system_lyxrc.scroll_below_document) {
+                       os << "\\scroll_below_document "
+                          << convert<string>(scroll_below_document) << '\n';
+               }
+               if (tag != RC_LAST)
+                       break;
        case RC_MAC_LIKE_WORD_MOVEMENT:
                if (ignore_system_lyxrc ||
                    mac_like_word_movement
@@ -2497,6 +2512,10 @@ string const LyXRC::getDescription(LyXRCTags tag)
                str = _("LyX normally doesn't update the cursor position if you move the scrollbar. Set to true if you'd prefer to always have the cursor on screen.");
                break;
 
+       case RC_SCROLL_BELOW_DOCUMENT:
+               str = _("LyX normally doesn't allow the user to scroll further than the bottom of the document. Set to true if you prefer to scroll the bottom of the document to the top of the screen");
+               break;
+
        case RC_MAC_LIKE_WORD_MOVEMENT:
                str = _("Use the Mac OS X conventions for the word-level cursor movement");
                break;
index 3e513e350066d4e96770672209e5973d0a51a1db..9cb0d667661e45c470f12cc568c42816ab7c6892 100644 (file)
@@ -140,6 +140,7 @@ public:
                RC_SCREEN_FONT_TYPEWRITER,
                RC_SCREEN_FONT_TYPEWRITER_FOUNDRY,
                RC_SCREEN_ZOOM,
+               RC_SCROLL_BELOW_DOCUMENT,
                RC_SERVERPIPE,
                RC_SET_COLOR,
                RC_SHOW_BANNER,
@@ -371,6 +372,8 @@ public:
        ///
        bool cursor_follows_scrollbar;
        ///
+       bool scroll_below_document;
+       ///
        enum MacroEditStyle {
                MACRO_EDIT_INLINE_BOX = 0,
                MACRO_EDIT_INLINE,
index 1af5c049e6031c7174c947ba9edfbff3333afa41..525132bacdbb48fcd034f8c796d1f01ee718566b 100644 (file)
@@ -1970,6 +1970,8 @@ PrefEdit::PrefEdit(GuiPreferences * form)
 
        connect(cursorFollowsCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
+       connect(scrollBelowCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
        connect(sortEnvironmentsCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
        connect(groupEnvironmentsCB, SIGNAL(clicked()),
@@ -1992,6 +1994,7 @@ PrefEdit::PrefEdit(GuiPreferences * form)
 void PrefEdit::apply(LyXRC & rc) const
 {
        rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
+       rc.scroll_below_document = scrollBelowCB->isChecked();
        rc.sort_layouts = sortEnvironmentsCB->isChecked();
        rc.group_layouts = groupEnvironmentsCB->isChecked();
        switch (macroEditStyleCO->currentIndex()) {
@@ -2010,6 +2013,7 @@ void PrefEdit::apply(LyXRC & rc) const
 void PrefEdit::update(LyXRC const & rc)
 {
        cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
+       scrollBelowCB->setChecked(rc.scroll_below_document);
        sortEnvironmentsCB->setChecked(rc.sort_layouts);
        groupEnvironmentsCB->setChecked(rc.group_layouts);
        macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
index 48570af1c33a93da58581a536f366d7a635bdee0..bf858c32b1fa91a6ee5ba04a4f61d268b6c07f83 100644 (file)
         </property>
        </widget>
       </item>
+      <item>
+       <widget class="QCheckBox" name="scrollBelowCB" >
+        <property name="text" >
+         <string>Scroll &amp;below end of document</string>
+        </property>
+       </widget>
+      </item>
       <item>
        <widget class="QCheckBox" name="sortEnvironmentsCB" >
         <property name="text" >
  <layoutdefault spacing="4" margin="9" />
  <tabstops>
   <tabstop>cursorFollowsCB</tabstop>
+  <tabstop>scrollBelowCB</tabstop>
   <tabstop>sortEnvironmentsCB</tabstop>
   <tabstop>groupEnvironmentsCB</tabstop>
   <tabstop>macroEditStyleCO</tabstop>