diff --git a/interface/resources/qml/hifi/dialogs/GeneralPreferencesDialog.qml b/interface/resources/qml/hifi/dialogs/GeneralPreferencesDialog.qml index 44cae95696..cabc09e49b 100644 --- a/interface/resources/qml/hifi/dialogs/GeneralPreferencesDialog.qml +++ b/interface/resources/qml/hifi/dialogs/GeneralPreferencesDialog.qml @@ -17,7 +17,7 @@ PreferencesDialog { id: root objectName: "GeneralPreferencesDialog" title: "General Settings" - showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect"] + showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect", "Leap Motion"] property var settings: Settings { category: root.objectName property alias x: root.x diff --git a/interface/resources/qml/hifi/tablet/TabletGeneralPreferences.qml b/interface/resources/qml/hifi/tablet/TabletGeneralPreferences.qml index fe043f6ac7..18e7898dd0 100644 --- a/interface/resources/qml/hifi/tablet/TabletGeneralPreferences.qml +++ b/interface/resources/qml/hifi/tablet/TabletGeneralPreferences.qml @@ -32,6 +32,6 @@ StackView { TabletPreferencesDialog { id: root objectName: "TabletGeneralPreferences" - showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect", "Vive Pucks Configuration"] + showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect", "Vive Pucks Configuration", "Leap Motion"] } } diff --git a/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp b/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp index e75019d389..f9cdf8a958 100644 --- a/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp +++ b/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp @@ -12,12 +12,21 @@ #include +#include +#include +#include + Q_DECLARE_LOGGING_CATEGORY(inputplugins) Q_LOGGING_CATEGORY(inputplugins, "hifi.inputplugins") const char* LeapMotionPlugin::NAME = "Leap Motion"; const char* LeapMotionPlugin::LEAPMOTION_ID_STRING = "Leap Motion"; +const bool DEFAULT_ENABLED = false; +const char* SENSOR_ON_DESKTOP = "Desktop"; +const char* SENSOR_ON_HMD = "HMD"; +const char* DEFAULT_SENSOR_LOCATION = SENSOR_ON_DESKTOP; + void LeapMotionPlugin::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { // TODO } @@ -29,3 +38,66 @@ controller::Input::NamedVector LeapMotionPlugin::InputDevice::getAvailableInputs return availableInputs; } + +void LeapMotionPlugin::init() { + loadSettings(); + + auto preferences = DependencyManager::get(); + static const QString LEAPMOTION_PLUGIN { "Leap Motion" }; + { + auto getter = [this]()->bool { return _enabled; }; + auto setter = [this](bool value) { + _enabled = value; + saveSettings(); + if (!_enabled) { + auto userInputMapper = DependencyManager::get(); + userInputMapper->withLock([&, this]() { + _inputDevice->clearState(); + }); + } + }; + auto preference = new CheckPreference(LEAPMOTION_PLUGIN, "Enabled", getter, setter); + preferences->addPreference(preference); + } + { + auto getter = [this]()->QString { return _sensorLocation; }; + auto setter = [this](QString value) { + _sensorLocation = value; + saveSettings(); + // TODO: Apply setting value. + }; + auto preference = new ComboBoxPreference(LEAPMOTION_PLUGIN, "Sensor location", getter, setter); + QStringList list = { SENSOR_ON_DESKTOP, SENSOR_ON_HMD }; + preference->setItems(list); + preferences->addPreference(preference); + } +} + +const char* SETTINGS_ENABLED_KEY = "enabled"; +const char* SETTINGS_SENSOR_LOCATION_KEY = "sensorLocation"; + +void LeapMotionPlugin::saveSettings() const { + Settings settings; + QString idString = getID(); + settings.beginGroup(idString); + { + settings.setValue(QString(SETTINGS_ENABLED_KEY), _enabled); + settings.setValue(QString(SETTINGS_SENSOR_LOCATION_KEY), _sensorLocation); + } + settings.endGroup(); +} + +void LeapMotionPlugin::loadSettings() { + Settings settings; + QString idString = getID(); + settings.beginGroup(idString); + { + _enabled = settings.value(SETTINGS_ENABLED_KEY, QVariant(DEFAULT_ENABLED)).toBool(); + _sensorLocation = settings.value(SETTINGS_SENSOR_LOCATION_KEY, QVariant(DEFAULT_SENSOR_LOCATION)).toString(); + } + settings.endGroup(); +} + +void LeapMotionPlugin::InputDevice::clearState() { + // TODO +} diff --git a/plugins/hifiLeapMotion/src/LeapMotionPlugin.h b/plugins/hifiLeapMotion/src/LeapMotionPlugin.h index aae0561e39..d6fe6d8a55 100644 --- a/plugins/hifiLeapMotion/src/LeapMotionPlugin.h +++ b/plugins/hifiLeapMotion/src/LeapMotionPlugin.h @@ -26,10 +26,18 @@ public: virtual const QString getName() const override { return NAME; } const QString getID() const override { return LEAPMOTION_ID_STRING; } + virtual void init() override; + + virtual void saveSettings() const override; + virtual void loadSettings() override; + protected: static const char* NAME; static const char* LEAPMOTION_ID_STRING; + bool _enabled { false }; + QString _sensorLocation; + class InputDevice : public controller::InputDevice { public: friend class LeapMotionPlugin; @@ -38,6 +46,8 @@ protected: // Device functions virtual controller::Input::NamedVector getAvailableInputs() const override; + + void clearState(); }; std::shared_ptr _inputDevice{ std::make_shared() };