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
This commit is contained in:
Vincent van Ravesteijn 2009-03-27 17:41:58 +00:00
parent 1bbcd403fc
commit 7ad28349ab
7 changed files with 52 additions and 2 deletions

View 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;

View 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(

View 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:

View 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;

View 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,

View 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);

View File

@ -52,6 +52,13 @@
</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" >
@ -213,6 +220,7 @@
<layoutdefault spacing="4" margin="9" />
<tabstops>
<tabstop>cursorFollowsCB</tabstop>
<tabstop>scrollBelowCB</tabstop>
<tabstop>sortEnvironmentsCB</tabstop>
<tabstop>groupEnvironmentsCB</tabstop>
<tabstop>macroEditStyleCO</tabstop>