mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 05:52:38 +02:00
handle back key press in GVRMainWindow
This commit is contained in:
parent
30a9f6159b
commit
3f50311d04
4 changed files with 70 additions and 17 deletions
|
@ -17,19 +17,18 @@
|
|||
#include <QtAndroidExtras/QAndroidJniEnvironment>
|
||||
#include <QtAndroidExtras/QAndroidJniObject>
|
||||
|
||||
#endif
|
||||
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtWidgets/QMenuBar>
|
||||
|
||||
#ifdef HAVE_LIBOVR
|
||||
|
||||
#include <GlUtils.h>
|
||||
#include <VrApi/LocalPreferences.h>
|
||||
#include <VrApi/VrApi.h>
|
||||
#include <VrApi/VrApi_local.h>
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtWidgets/QMenuBar>
|
||||
|
||||
#include "GVRMainWindow.h"
|
||||
#include "RenderingClient.h"
|
||||
|
|
|
@ -14,12 +14,13 @@
|
|||
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
class RenderingClient;
|
||||
|
||||
#ifdef HAVE_LIBOVR
|
||||
#if defined(ANDROID) && defined(HAVE_LIBOVR)
|
||||
class ovrMobile;
|
||||
class ovrHmdInfo;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class RenderingClient;
|
||||
class QKeyEvent;
|
||||
|
||||
#if defined(qApp)
|
||||
#undef qApp
|
||||
|
@ -29,10 +30,12 @@ class ovrHmdInfo;
|
|||
class GVRInterface : public QApplication {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GVRInterface(int argc, char* argv[]);
|
||||
|
||||
GVRInterface(int argc, char* argv[]);
|
||||
RenderingClient* getClient() { return _client; }
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
|
||||
private slots:
|
||||
void handleApplicationStateChange(Qt::ApplicationState state);
|
||||
void idle();
|
||||
|
@ -41,13 +44,13 @@ private:
|
|||
void enterVRMode();
|
||||
void leaveVRMode();
|
||||
|
||||
RenderingClient* _client;
|
||||
bool _inVRMode;
|
||||
|
||||
#ifdef HAVE_LIBOVR
|
||||
#if defined(ANDROID) && defined(HAVE_LIBOVR)
|
||||
ovrMobile* _ovr;
|
||||
ovrHmdInfo* _hmdInfo;
|
||||
#endif
|
||||
|
||||
RenderingClient* _client;
|
||||
bool _inVRMode;
|
||||
};
|
||||
|
||||
#endif // hifi_GVRInterface_h
|
||||
|
|
|
@ -9,13 +9,18 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
#include <QtWidgets/QInputDialog>
|
||||
#include <QtWidgets/QMenuBar>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
|
||||
#ifndef ANDROID
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
#else
|
||||
#ifdef HAVE_LIBOVR
|
||||
#include <OVR_CAPI.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <AddressManager.h>
|
||||
|
@ -25,8 +30,16 @@
|
|||
|
||||
#include "GVRMainWindow.h"
|
||||
|
||||
const float LIBOVR_DOUBLE_TAP_DURATION = 0.25f;
|
||||
const float LIBOVR_LONG_PRESS_DURATION = 0.75f;
|
||||
|
||||
GVRMainWindow::GVRMainWindow(QWidget* parent) :
|
||||
QMainWindow(parent),
|
||||
#if defined(ANDROID) && defined(HAVE_LIBOVR)
|
||||
_backKeyState(LIBOVR_DOUBLE_TAP_DURATION, LIBOVR_LONG_PRESS_DURATION),
|
||||
_wasBackKeyDown(false),
|
||||
#endif
|
||||
_mainLayout(NULL),
|
||||
_menuBar(NULL)
|
||||
{
|
||||
|
||||
|
@ -57,6 +70,31 @@ GVRMainWindow::~GVRMainWindow() {
|
|||
delete _menuBar;
|
||||
}
|
||||
|
||||
void GVRMainWindow::keyPressEvent(QKeyEvent* event) {
|
||||
#ifdef ANDROID
|
||||
if (event->key() == Qt::Key_Back) {
|
||||
// got the Android back key, hand off to OVR KeyState
|
||||
_backKeyState.HandleEvent(ovr_GetTimeInSeconds(), true, (_wasBackKeyDown ? 1 : 0));
|
||||
_wasBackKeyDown = true;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
void GVRMainWindow::keyReleaseEvent(QKeyEvent* event) {
|
||||
#ifdef ANDROID
|
||||
if (event->key() == Qt::Key_Back) {
|
||||
// release on the Android back key, hand off to OVR KeyState
|
||||
_backKeyState.HandleEvent(ovr_GetTimeInSeconds(), false, 0);
|
||||
_wasBackKeyDown = false;
|
||||
|
||||
auto backEvent = _backKeyState.Update(ovr_GetTimeInSeconds());
|
||||
}
|
||||
#endif
|
||||
QWidget::keyReleaseEvent(event);
|
||||
}
|
||||
|
||||
void GVRMainWindow::setupMenuBar() {
|
||||
QMenu* fileMenu = new QMenu("File");
|
||||
QMenu* helpMenu = new QMenu("Help");
|
||||
|
|
|
@ -14,6 +14,11 @@
|
|||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
|
||||
#if defined(ANDROID) && defined(HAVE_LIBOVR)
|
||||
#include <KeyState.h>
|
||||
#endif
|
||||
|
||||
class QKeyEvent;
|
||||
class QMenuBar;
|
||||
class QVBoxLayout;
|
||||
|
||||
|
@ -24,9 +29,17 @@ public:
|
|||
~GVRMainWindow();
|
||||
public slots:
|
||||
void showAddressBar();
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void keyReleaseEvent(QKeyEvent* event);
|
||||
private:
|
||||
void setupMenuBar();
|
||||
|
||||
#if defined(ANDROID) && defined(HAVE_LIBOVR)
|
||||
OVR::KeyState _backKeyState;
|
||||
bool _wasBackKeyDown;
|
||||
#endif
|
||||
|
||||
QVBoxLayout* _mainLayout;
|
||||
QMenuBar* _menuBar;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue