From e52d2ff3426d767ba0909388c36dac7951a78f93 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Thu, 10 Oct 2019 20:57:30 -0700 Subject: [PATCH] fix mac TextFields --- .../resources/qml/HFControls/HFTextField.qml | 34 ++++++++++++++++++- launchers/qt/src/Launcher.cpp | 7 ++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/launchers/qt/resources/qml/HFControls/HFTextField.qml b/launchers/qt/resources/qml/HFControls/HFTextField.qml index a98e73c659..133107ddd6 100644 --- a/launchers/qt/resources/qml/HFControls/HFTextField.qml +++ b/launchers/qt/resources/qml/HFControls/HFTextField.qml @@ -1,4 +1,4 @@ -import QtQuick 2.3 +import QtQuick 2.5 import QtQuick.Controls 2.1 TextField { @@ -55,4 +55,36 @@ TextField { } } } + + Keys.onPressed: { + event.accepted = false; + + if (Platform === "MacOS") { + if (event.key == Qt.Key_Left) { + if (control.cursorPosition > 0) { + var index = control.cursorPosition - 1; + control.select(index, index); + } + event.accepted = true; + } + + if (event.key == Qt.Key_Right) { + if (control.cursorPosition < control.text.length) { + var index = control.cursorPosition + 1; + control.select(index, index); + } + event.accepted = true; + } + + if (event.modifiers & Qt.ControlModifier) { + if (event.key == Qt.Key_C) { + control.copy(); + event.accepted = true; + } else if (event.key == Qt.Key_V) { + control.paste(); + event.accepted = true; + } + } + } + } } diff --git a/launchers/qt/src/Launcher.cpp b/launchers/qt/src/Launcher.cpp index e2d660e782..edc52f6427 100644 --- a/launchers/qt/src/Launcher.cpp +++ b/launchers/qt/src/Launcher.cpp @@ -12,9 +12,16 @@ Launcher::Launcher(int& argc, char**argv) : QGuiApplication(argc, argv) { _launcherState = std::make_shared(); + QString platform; +#ifdef Q_OS_WIN + platform = "Windows"; +#elif defined(Q_OS_MACOS) + platform = "MacOS"; +#endif _launcherWindow = std::make_unique(); _launcherWindow->rootContext()->setContextProperty("LauncherState", _launcherState.get()); _launcherWindow->rootContext()->setContextProperty("PathUtils", new PathUtils()); + _launcherWindow->rootContext()->setContextProperty("Platform", platform); _launcherWindow->setTitle("High Fidelity"); _launcherWindow->setFlags(Qt::FramelessWindowHint | Qt::Window); _launcherWindow->setLauncherStatePtr(_launcherState);