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
This commit is contained in:
Vincent van Ravesteijn 2011-02-15 16:53:37 +00:00
parent 8486940675
commit b9e7a9b269
3 changed files with 29 additions and 7 deletions

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

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

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