From b9e7a9b26964be3857d90d847dd02a1b813be221 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Tue, 15 Feb 2011 16:53:37 +0000 Subject: [PATCH] Fix bug #5414: Show context menu accelerators when the context menu is shown after pressing the keyboard context menu key. 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 | 5 ++++- src/frontends/qt4/Menus.cpp | 26 ++++++++++++++++++++++---- src/frontends/qt4/Menus.h | 5 +++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 4ac179a226..1f8a0a191e 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -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; diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 598486adc3..52305e290c 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -71,6 +71,7 @@ #include #include #include +#include #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; } diff --git a/src/frontends/qt4/Menus.h b/src/frontends/qt4/Menus.h index 1ab407a5e1..9513088f6e 100644 --- a/src/frontends/qt4/Menus.h +++ b/src/frontends/qt4/Menus.h @@ -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 &); -- 2.39.2