Forward menu button events to Qt if there is no visible menubar.

Task-number: QTBUG-32334
Change-Id: If1b4517f233b04d4c6c165cbfe62c8cf7b624c60
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
bb10
BogDan Vatra 2014-08-14 16:56:14 +03:00
parent eb5ef33122
commit ef4a999a9f
8 changed files with 37 additions and 21 deletions

View File

@ -815,15 +815,6 @@ public class QtActivityDelegate
if (!m_started)
return false;
if (keyCode == KeyEvent.KEYCODE_MENU) {
try {
return (Boolean)m_super_onKeyDown.invoke(m_activity, keyCode, event);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
m_metaState = MetaKeyKeyListener.handleKeyDown(m_metaState, keyCode, event);
int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(m_metaState));
int lc = c;
@ -858,15 +849,6 @@ public class QtActivityDelegate
if (!m_started)
return false;
if (keyCode == KeyEvent.KEYCODE_MENU) {
try {
return (Boolean)m_super_onKeyUp.invoke(m_activity, keyCode, event);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
|| keyCode == KeyEvent.KEYCODE_MUTE)

View File

@ -484,6 +484,16 @@ public class QtNative
});
}
private static void openOptionsMenu()
{
runAction(new Runnable() {
@Override
public void run() {
m_activity.openOptionsMenu();
}
});
}
private static byte[][] getSSLCertificates()
{
ArrayList<byte[]> certificateList = new ArrayList<byte[]>();

View File

@ -1886,11 +1886,17 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
ev.setAccepted(false);
static bool backKeyPressAccepted = false;
static bool menuKeyPressAccepted = false;
if (e->keyType == QEvent::KeyPress) {
backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
} else if (e->keyType == QEvent::KeyRelease && e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
if (window)
QWindowSystemInterface::handleCloseEvent(window);
menuKeyPressAccepted = e->key == Qt::Key_Menu && ev.isAccepted();
} else if (e->keyType == QEvent::KeyRelease) {
if (e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
if (window)
QWindowSystemInterface::handleCloseEvent(window);
} else if (e->key == Qt::Key_Menu && !menuKeyPressAccepted && !ev.isAccepted()) {
platform_theme->showPlatformMenuBar();
}
}
#endif
}

View File

@ -276,6 +276,7 @@ public:
virtual QPlatformMenuItem* createPlatformMenuItem() const;
virtual QPlatformMenu* createPlatformMenu() const;
virtual QPlatformMenuBar* createPlatformMenuBar() const;
virtual void showPlatformMenuBar() {}
virtual bool usePlatformNativeDialog(DialogType type) const;
virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;

View File

@ -68,6 +68,7 @@ namespace QtAndroidMenu
static jmethodID openContextMenuMethodID = 0;
static jmethodID closeContextMenuMethodID = 0;
static jmethodID resetOptionsMenuMethodID = 0;
static jmethodID openOptionsMenuMethodID = 0;
static jmethodID clearMenuMethodID = 0;
static jmethodID addMenuItemMethodID = 0;
@ -87,6 +88,13 @@ namespace QtAndroidMenu
env.jniEnv->CallStaticVoidMethod(applicationClass(), resetOptionsMenuMethodID);
}
void openOptionsMenu()
{
AttachedJNIEnv env;
if (env.jniEnv)
env.jniEnv->CallStaticVoidMethod(applicationClass(), openOptionsMenuMethodID);
}
void showContextMenu(QAndroidPlatformMenu *menu, JNIEnv *env)
{
QMutexLocker lock(&visibleMenuMutex);
@ -409,6 +417,7 @@ namespace QtAndroidMenu
GET_AND_CHECK_STATIC_METHOD(openContextMenuMethodID, appClass, "openContextMenu", "()V");
GET_AND_CHECK_STATIC_METHOD(closeContextMenuMethodID, appClass, "closeContextMenu", "()V");
GET_AND_CHECK_STATIC_METHOD(resetOptionsMenuMethodID, appClass, "resetOptionsMenu", "()V");
GET_AND_CHECK_STATIC_METHOD(openOptionsMenuMethodID, appClass, "openOptionsMenu", "()V");
jclass clazz;
FIND_AND_CHECK_CLASS("android/view/Menu");

View File

@ -55,6 +55,7 @@ class QWindow;
namespace QtAndroidMenu
{
// Menu support
void openOptionsMenu();
void showContextMenu(QAndroidPlatformMenu *menu, JNIEnv *env = 0);
void hideContextMenu(QAndroidPlatformMenu *menu);
void syncMenu(QAndroidPlatformMenu *menu);

View File

@ -39,6 +39,7 @@
**
****************************************************************************/
#include "androidjnimenu.h"
#include "qandroidplatformtheme.h"
#include "qandroidplatformmenubar.h"
#include "qandroidplatformmenu.h"
@ -104,6 +105,11 @@ QPlatformMenuItem *QAndroidPlatformTheme::createPlatformMenuItem() const
return new QAndroidPlatformMenuItem;
}
void QAndroidPlatformTheme::showPlatformMenuBar()
{
QtAndroidMenu::openOptionsMenu();
}
static inline int paletteType(QPlatformTheme::Palette type)
{
switch (type) {

View File

@ -55,6 +55,7 @@ public:
virtual QPlatformMenuBar *createPlatformMenuBar() const;
virtual QPlatformMenu *createPlatformMenu() const;
virtual QPlatformMenuItem *createPlatformMenuItem() const;
virtual void showPlatformMenuBar();
virtual const QPalette *palette(Palette type = SystemPalette) const;
virtual const QFont *font(Font type = SystemFont) const;
virtual QVariant themeHint(ThemeHint hint) const;