From 7ad28349ab345b93330c800132891837498cc4b0 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Fri, 27 Mar 2009 17:41:58 +0000 Subject: [PATCH] Fix bug 4935: Scroll down below document 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 | 15 +++++++++++++-- src/BufferView.h | 4 ++++ src/LyXFunc.cpp | 1 + src/LyXRC.cpp | 19 +++++++++++++++++++ src/LyXRC.h | 3 +++ src/frontends/qt4/GuiPrefs.cpp | 4 ++++ src/frontends/qt4/ui/PrefEditUi.ui | 8 ++++++++ 7 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 6e120dc53d..ad4e15fb28 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -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 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; diff --git a/src/BufferView.h b/src/BufferView.h index fcf58544a7..0105275eae 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -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( diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 5fc04c1eac..17eaf64fe6 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -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: diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 19bbb157a3..e458a0bef1 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -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(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; diff --git a/src/LyXRC.h b/src/LyXRC.h index 3e513e3500..9cb0d66766 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -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, diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 1af5c049e6..525132bacd 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -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); diff --git a/src/frontends/qt4/ui/PrefEditUi.ui b/src/frontends/qt4/ui/PrefEditUi.ui index 48570af1c3..bf858c32b1 100644 --- a/src/frontends/qt4/ui/PrefEditUi.ui +++ b/src/frontends/qt4/ui/PrefEditUi.ui @@ -52,6 +52,13 @@ + + + + Scroll &below end of document + + + @@ -213,6 +220,7 @@ cursorFollowsCB + scrollBelowCB sortEnvironmentsCB groupEnvironmentsCB macroEditStyleCO -- 2.39.2