From 0d386d7c253ed77af7634f61e9622e021d18e4fe Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Sat, 17 Jul 2010 22:29:42 +0000 Subject: [PATCH] make mouse scroll wheel zoom configurable git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34955 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXRC.cpp | 43 ++++++++++++++++ src/LyXRC.h | 10 ++++ src/frontends/qt4/GuiPrefs.cpp | 42 +++++++++++++++ src/frontends/qt4/GuiPrefs.h | 1 + src/frontends/qt4/GuiWorkArea.cpp | 19 ++++++- src/frontends/qt4/ui/PrefInputUi.ui | 79 ++++++++++++++++++++++++++++- 6 files changed, 191 insertions(+), 3 deletions(-) diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 4de11cc08f..029f78b1d1 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -173,6 +173,7 @@ LexerKeyword lyxrcTags[] = { { "\\screen_font_typewriter_foundry", LyXRC::RC_SCREEN_FONT_TYPEWRITER_FOUNDRY }, { "\\screen_zoom", LyXRC::RC_SCREEN_ZOOM }, { "\\scroll_below_document", LyXRC::RC_SCROLL_BELOW_DOCUMENT }, + { "\\scroll_whell_zoom", LyXRC::RC_SCROLL_WHEEL_ZOOM }, { "\\serverpipe", LyXRC::RC_SERVERPIPE }, { "\\set_color", LyXRC::RC_SET_COLOR }, { "\\show_banner", LyXRC::RC_SHOW_BANNER }, @@ -320,6 +321,7 @@ void LyXRC::setDefaults() date_insert_format = "%x"; cursor_follows_scrollbar = false; scroll_below_document = false; + scroll_whell_zoom = SCROLL_WHEEL_ZOOM_CTRL; paragraph_markers = false; mac_like_word_movement = false; macro_edit_style = MACRO_EDIT_INLINE_BOX; @@ -1195,6 +1197,23 @@ int LyXRC::read(Lexer & lexrc) } } break; + case RC_SCROLL_WHEEL_ZOOM: + if (lexrc.next()) { + string const tmp = lexrc.getString(); + if (tmp == "ctrl") + scroll_whell_zoom = SCROLL_WHEEL_ZOOM_CTRL; + else if (tmp == "shift") + scroll_whell_zoom = SCROLL_WHEEL_ZOOM_SHIFT; + else if (tmp == "option") + scroll_whell_zoom = SCROLL_WHEEL_ZOOM_OPTION; + else { + scroll_whell_zoom = SCROLL_WHEEL_ZOOM_OFF; + if (tmp != "off" && tmp != "false") + LYXERR0("Unrecognized scroll_whell_zoom status \"" + << tmp << '"'); + } + } + break; // Obsoteted in 1.4.0 case RC_USETEMPDIR: @@ -2571,6 +2590,29 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c if (tag != RC_LAST) break; + case RC_SCROLL_WHEEL_ZOOM: + if (ignore_system_lyxrc || + scroll_whell_zoom != system_lyxrc.scroll_whell_zoom) { + string status; + switch (scroll_whell_zoom) { + case SCROLL_WHEEL_ZOOM_OFF: + status = "off"; + break; + case SCROLL_WHEEL_ZOOM_CTRL: + status = "ctrl"; + break; + case SCROLL_WHEEL_ZOOM_SHIFT: + status = "shift"; + break; + case SCROLL_WHEEL_ZOOM_OPTION: + status = "option"; + break; + } + os << "\\scroll_whell_zoom " << status << '\n'; + } + if (tag != RC_LAST) + break; + os << "\n#\n" << "# FORMATS SECTION ##########################\n" << "#\n\n"; @@ -2909,6 +2951,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_FORWARD_SEARCH_PDF: case LyXRC::RC_EXPORT_OVERWRITE: case LyXRC::RC_DEFAULT_DECIMAL_POINT: + case LyXRC::RC_SCROLL_WHEEL_ZOOM: case LyXRC::RC_LAST: break; } diff --git a/src/LyXRC.h b/src/LyXRC.h index 823dc15f74..7429105a4e 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -156,6 +156,7 @@ public: RC_SCREEN_FONT_TYPEWRITER_FOUNDRY, RC_SCREEN_ZOOM, RC_SCROLL_BELOW_DOCUMENT, + RC_SCROLL_WHEEL_ZOOM, RC_SERVERPIPE, RC_SET_COLOR, RC_SHOW_BANNER, @@ -502,6 +503,15 @@ public: int export_overwrite; /// Default decimal point when aligning table columns on decimal std::string default_decimal_point; + /// + enum ScrollWheelZoom { + SCROLL_WHEEL_ZOOM_OFF, + SCROLL_WHEEL_ZOOM_CTRL, + SCROLL_WHEEL_ZOOM_SHIFT, + SCROLL_WHEEL_ZOOM_OPTION + }; + /// + ScrollWheelZoom scroll_whell_zoom; }; diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 0b37b037b4..75eceee499 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -460,6 +460,10 @@ PrefInput::PrefInput(GuiPreferences * form) this, SIGNAL(changed())); connect(mouseWheelSpeedSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed())); + connect(scrollzoomEnableCB, SIGNAL(clicked()), + this, SIGNAL(changed())); + connect(scrollzoomValueCO, SIGNAL(activated(int)), + this, SIGNAL(changed())); } @@ -470,6 +474,21 @@ void PrefInput::apply(LyXRC & rc) const rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text())); rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text())); rc.mouse_wheel_speed = mouseWheelSpeedSB->value(); + if (scrollzoomEnableCB->isChecked()) { + switch (scrollzoomValueCO->currentIndex()) { + case 0: + rc.scroll_whell_zoom = LyXRC::SCROLL_WHEEL_ZOOM_CTRL; + break; + case 1: + rc.scroll_whell_zoom = LyXRC::SCROLL_WHEEL_ZOOM_SHIFT; + break; + case 2: + rc.scroll_whell_zoom = LyXRC::SCROLL_WHEEL_ZOOM_OPTION; + break; + } + } else { + rc.scroll_whell_zoom = LyXRC::SCROLL_WHEEL_ZOOM_OFF; + } } @@ -480,6 +499,23 @@ void PrefInput::update(LyXRC const & rc) firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap))); secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap))); mouseWheelSpeedSB->setValue(rc.mouse_wheel_speed); + switch (rc.scroll_whell_zoom) { + case LyXRC::SCROLL_WHEEL_ZOOM_OFF: + scrollzoomEnableCB->setChecked(false); + break; + case LyXRC::SCROLL_WHEEL_ZOOM_CTRL: + scrollzoomEnableCB->setChecked(true); + scrollzoomValueCO->setCurrentIndex(0); + break; + case LyXRC::SCROLL_WHEEL_ZOOM_SHIFT: + scrollzoomEnableCB->setChecked(true); + scrollzoomValueCO->setCurrentIndex(1); + break; + case LyXRC::SCROLL_WHEEL_ZOOM_OPTION: + scrollzoomEnableCB->setChecked(true); + scrollzoomValueCO->setCurrentIndex(2); + break; + } } @@ -516,6 +552,12 @@ void PrefInput::on_keymapCB_toggled(bool keymap) } +void PrefInput::on_scrollzoomEnableCB_toggled(bool enabled) +{ + scrollzoomValueCO->setEnabled(enabled); +} + + ///////////////////////////////////////////////////////////////////// // // PrefCompletion diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index 028ac48a36..1256d603b3 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -183,6 +183,7 @@ private Q_SLOTS: void on_firstKeymapPB_clicked(bool); void on_secondKeymapPB_clicked(bool); void on_keymapCB_toggled(bool); + void on_scrollzoomEnableCB_toggled(bool); private: QString testKeymap(QString const & keymap); diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index b7e68ff77c..1f582cffaf 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -817,7 +817,24 @@ void GuiWorkArea::wheelEvent(QWheelEvent * ev) // Wheel rotation by one notch results in a delta() of 120 (see // documentation of QWheelEvent) double const delta = ev->delta() / 120.0; - if (ev->modifiers() & Qt::ControlModifier) { + bool zoom = false; + switch (lyxrc.scroll_whell_zoom) { + case LyXRC::SCROLL_WHEEL_ZOOM_CTRL: + zoom = ev->modifiers() & Qt::ControlModifier; + zoom &= !(ev->modifiers() & (Qt::ShiftModifier || Qt::AltModifier)); + break; + case LyXRC::SCROLL_WHEEL_ZOOM_SHIFT: + zoom = ev->modifiers() & Qt::ShiftModifier; + zoom &= !(ev->modifiers() & (Qt::ControlModifier || Qt::AltModifier)); + break; + case LyXRC::SCROLL_WHEEL_ZOOM_OPTION: + zoom = ev->modifiers() & Qt::AltModifier; + zoom &= !(ev->modifiers() & (Qt::ShiftModifier || Qt::ControlModifier)); + break; + case LyXRC::SCROLL_WHEEL_ZOOM_OFF: + break; + } + if (zoom) { docstring arg = convert(int(5 * delta)); lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM_IN, arg)); return; diff --git a/src/frontends/qt4/ui/PrefInputUi.ui b/src/frontends/qt4/ui/PrefInputUi.ui index 4edeb96610..a0b8c8a856 100644 --- a/src/frontends/qt4/ui/PrefInputUi.ui +++ b/src/frontends/qt4/ui/PrefInputUi.ui @@ -5,8 +5,8 @@ 0 0 - 426 - 227 + 432 + 303 @@ -177,6 +177,81 @@ + + + + + 0 + 65 + + + + Scroll wheel zoom + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + 10 + 30 + 304 + 27 + + + + + 5 + + + QLayout::SetNoConstraint + + + + + + 150 + 0 + + + + Enable + + + + + + + false + + + false + + + + Ctrl + + + + + Shift + + + + + Option + + + + + + + +