]> git.lyx.org Git - features.git/commitdiff
Fix bug #5414: Show context menu accelerators when the context menu is shown after...
authorVincent van Ravesteijn <vfr@lyx.org>
Tue, 15 Feb 2011 16:53:37 +0000 (16:53 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Tue, 15 Feb 2011 16:53:37 +0000 (16:53 +0000)
This should have been done by qt, but we can override qt by adapting the style on the windows platform.

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

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

index 4ac179a226f641e5f7b69b36590da6d28ae124b7..1f8a0a191e74420f2a1b527412478e7b1f40902a 100644 (file)
@@ -721,7 +721,10 @@ void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
                QAbstractScrollArea::contextMenuEvent(e);
                return;
        }
-       QMenu * menu = guiApp->menus().menu(toqstr(name), *lyx_view_);
+       // always show mnemonics when the keyboard is used to show the context menu
+       // FIXME: This should be fixed in Qt itself
+       bool const keyboard = (e->reason() == QContextMenuEvent::Keyboard);
+       QMenu * menu = guiApp->menus().menu(toqstr(name), *lyx_view_, keyboard);
        if (!menu) {
                QAbstractScrollArea::contextMenuEvent(e);
                return;
index 598486adc373ef73e15688ca3dbd8b400a598654..52305e290c4cf9e61418fe27d2e6dffb70ec9b41 100644 (file)
@@ -71,6 +71,7 @@
 #include <QList>
 #include <QMenuBar>
 #include <QString>
+#include <QProxyStyle>
 
 #include "support/shared_ptr.h"
 
@@ -1569,19 +1570,36 @@ void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
        }
 }
 
+#ifdef Q_WS_WIN
+class AlwaysMnemonicStyle : public QProxyStyle {
+public:
+       int styleHint(StyleHint hint, const QStyleOption *opt = 0, const QWidget *widget = 0,
+               QStyleHintReturn *returnData = 0) const 
+       {
+               if (hint == QStyle::SH_UnderlineShortcut)
+                       return 1;
+               return QProxyStyle::styleHint(hint, opt, widget, returnData);
+       }
+};
+#endif
+
 /////////////////////////////////////////////////////////////////////
 // Menu implementation
 /////////////////////////////////////////////////////////////////////
 
-Menu::Menu(GuiView * gv, QString const & name, bool top_level)
+Menu::Menu(GuiView * gv, QString const & name, bool top_level, bool keyboard)
 : QMenu(gv), d(new Menu::Impl)
 {
+#ifdef Q_WS_WIN
+       if (keyboard)
+               setStyle(new AlwaysMnemonicStyle);
+#endif
        d->top_level_menu = top_level? new MenuDefinition : 0;
        d->view = gv;
        d->name = name;
        setTitle(name);
        if (d->top_level_menu)
-               connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView()));
+               connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView())); 
 }
 
 
@@ -2062,7 +2080,7 @@ void Menus::updateMenu(Menu * qmenu)
 }
 
 
-Menu * Menus::menu(QString const & name, GuiView & view)
+Menu * Menus::menu(QString const & name, GuiView & view, bool keyboard)
 {
        LYXERR(Debug::GUI, "Context menu requested: " << name);
        Menu * menu = d->name_map_[&view].value(name, 0);
@@ -2071,7 +2089,7 @@ Menu * Menus::menu(QString const & name, GuiView & view)
                return 0;
        }
 
-       menu = new Menu(&view, name, true);
+       menu = new Menu(&view, name, true, keyboard);
        d->name_map_[&view][name] = menu;
        return menu;
 }
index 1ab407a5e100c077f7193f1c28b98f777cabc3bb..9513088f6ea9ee6c2a14d6c82758acff4db30046 100644 (file)
@@ -35,7 +35,8 @@ class Menu : public QMenu
        Q_OBJECT
 public:
        ///
-       Menu(GuiView * gv, QString const & name, bool top_level);
+       Menu(GuiView * gv, QString const & name, bool top_level,
+               bool keyboard = false);
 
        ///
        ~Menu();
@@ -70,7 +71,7 @@ public:
        void fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial = false);
 
        /// \return a top-level submenu given its name.
-       Menu * menu(QString const & name, GuiView & view);
+       Menu * menu(QString const & name, GuiView & view, bool keyboard = false);
 
        ///
        void read(Lexer &);