Add Leap Motion settings

This commit is contained in:
David Rowe 2017-06-16 10:58:11 +12:00
parent 170cf8156f
commit febd0eaf98
4 changed files with 84 additions and 2 deletions
interface/resources/qml/hifi
plugins/hifiLeapMotion/src

View file

@ -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

View file

@ -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"]
}
}

View file

@ -12,12 +12,21 @@
#include <QLoggingCategory>
#include <controllers/UserInputMapper.h>
#include <Preferences.h>
#include <SettingHandle.h>
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<Preferences>();
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<controller::UserInputMapper>();
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
}

View file

@ -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> _inputDevice{ std::make_shared<InputDevice>() };