From a7195519a25b715a5786383450a25f0420f7aeb5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 30 Dec 2013 08:19:24 +0100 Subject: initial ng options impl, untested --- facetracknoir/options.hpp | 200 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 facetracknoir/options.hpp (limited to 'facetracknoir') diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp new file mode 100644 index 00000000..7db75941 --- /dev/null +++ b/facetracknoir/options.hpp @@ -0,0 +1,200 @@ +/* Copyright (c) 2013 Stanislaw Halik + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace options { + template + inline T qcruft_to_t(const QVariant& t); + + template<> + inline int qcruft_to_t(const QVariant& t) + { + return t.toInt(); + } + + template<> + inline bool qcruft_to_t(const QVariant& t) + { + return t.toBool(); + } + + template<> + inline double qcruft_to_t(const QVariant& t) + { + return t.toDouble(); + } + + template<> + inline float qcruft_to_t(const QVariant& t) + { + return t.toFloat(); + } + + // snapshot of qsettings group at given time + class group { + private: + QMap map; + QString name; + public: + group(const QString& name, QSettings& s) : name(name) + { + s.beginGroup(name); + for (auto& k : s.childKeys()) + map[k] = s.value(k); + s.endGroup(); + } + static constexpr const char* org = "opentrack"; + void save() { + QSettings s(org); + s.beginGroup(name); + for (auto& k : map.keys()) + s.setValue(k, map[k]); + s.endGroup(); + } + template + T get(const QString& k) { + return qcruft_to_t(map.value(k)); + } + + void put(const QString& s, const QVariant& d) + { + map[s] = d; + } + }; + + class bundle { + private: + const QString group_name; + group saved; + group transient; + bundle(const bundle&) = delete; + bundle& operator=(const bundle&) = delete; + bool modified; + public: + bundle(const QString& group_name, QSettings& s) : + group_name(group_name), + saved(group_name, s), + transient(saved), + modified(false) + { + } + std::shared_ptr make(const QString& name, QSettings& s) { + assert(s.format() == QSettings::IniFormat); + return std::make_shared(name, s); + } + void store(QString& name, QVariant& datum) + { + modified = true; + transient.put(name, datum); + } + template + T get(QString& name) { + transient.get(name); + } + void save() + { + modified = false; + saved = transient; + transient.save(); + } + void revert() + { + modified = false; + transient = saved; + } + }; + + typedef std::shared_ptr pbundle; + + class QCruft : public QObject { + }; + + template + class value : public QCruft { + private: + const QString self_name; + pbundle b; + public: + value(const pbundle& b, const QString& name) : + self_name(name), + b(b) + { + } + operator T() { return b->get(self_name); } + T& operator=(const T& datum) { + b->store(self_name, datum); + emit valueChanged(datum); + return datum; + } + public slots: + void setValue(const T datum) { + this->operator =(datum); + } + signals: + void valueChanged(T datum); + }; + + template + inline void tie(value&, Q*); + + template<> + inline void tie(value& v, QComboBox* cb) + { + QObject::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int))); + QObject::connect(&v, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); + } + + template<> + inline void tie(value& v, QComboBox* cb) + { + QObject::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(QString))); + QObject::connect(&v, SIGNAL(valueChanged(QString)), &v, SLOT(setValue(QString))); + } + + template<> + inline void tie(value& v, QCheckBox* cb) + { + QObject::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool))); + QObject::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool))); + } + + template<> + inline void tie(value& v, QDoubleSpinBox* dsb) + { + QObject::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double))); + QObject::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double))); + } + + template<> + inline void tie(value& v, QSpinBox* sb) + { + QObject::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); + QObject::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int))); + } + + template<> + inline void tie(value& v, QSlider* sl) + { + QObject::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); + QObject::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int))); + } +} -- cgit v1.2.3 From 40d5a72739ff9f650e05c3193a60a6bbcd2ea69c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 30 Dec 2013 08:27:38 +0100 Subject: const correctness --- facetracknoir/options.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp index 7db75941..ef3437ad 100644 --- a/facetracknoir/options.hpp +++ b/facetracknoir/options.hpp @@ -101,7 +101,7 @@ namespace options { assert(s.format() == QSettings::IniFormat); return std::make_shared(name, s); } - void store(QString& name, QVariant& datum) + void store(const QString& name, QVariant& datum) { modified = true; transient.put(name, datum); -- cgit v1.2.3 From 598a7ebfb4672ab96a5f0b8693cfab3d954ea6a6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 30 Dec 2013 08:27:50 +0100 Subject: impl default value --- facetracknoir/options.hpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp index ef3437ad..49367831 100644 --- a/facetracknoir/options.hpp +++ b/facetracknoir/options.hpp @@ -79,6 +79,10 @@ namespace options { { map[s] = d; } + bool contains(const QString& s) + { + return map.contains(s); + } }; class bundle { @@ -106,6 +110,10 @@ namespace options { modified = true; transient.put(name, datum); } + bool contains(const QString& name) + { + return transient.contains(name); + } template T get(QString& name) { transient.get(name); @@ -131,13 +139,18 @@ namespace options { template class value : public QCruft { private: - const QString self_name; + QString self_name; pbundle b; public: - value(const pbundle& b, const QString& name) : + value(const pbundle& b, const QString& name, T def) : self_name(name), b(b) { + if (!b->contains(name)) + { + QVariant cruft(def); + b->store(self_name, cruft); + } } operator T() { return b->get(self_name); } T& operator=(const T& datum) { -- cgit v1.2.3 From 6e16b672ac49db35d1d0365991de01831d29a0dc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 30 Dec 2013 09:55:19 +0100 Subject: M-x valium-mode on Fix Qt's moronicity the hard way --- facetracknoir/options.hpp | 138 ++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 55 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp index 49367831..16946e88 100644 --- a/facetracknoir/options.hpp +++ b/facetracknoir/options.hpp @@ -43,28 +43,31 @@ namespace options { return t.toDouble(); } - template<> - inline float qcruft_to_t(const QVariant& t) - { - return t.toFloat(); - } - // snapshot of qsettings group at given time class group { private: QMap map; QString name; public: - group(const QString& name, QSettings& s) : name(name) + group(const QString& name) : name(name) { - s.beginGroup(name); - for (auto& k : s.childKeys()) - map[k] = s.value(k); - s.endGroup(); + QSettings settings(group::org); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings iniFile(currentFile, QSettings::IniFormat); + iniFile.beginGroup(name); + for (auto& k : iniFile.childKeys()) + map[k] = iniFile.value(k); + iniFile.endGroup(); } static constexpr const char* org = "opentrack"; void save() { - QSettings s(org); + QSettings settings(group::org); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings s(currentFile, QSettings::IniFormat); s.beginGroup(name); for (auto& k : map.keys()) s.setValue(k, map[k]); @@ -85,27 +88,32 @@ namespace options { } }; - class bundle { + class impl_bundle { private: const QString group_name; group saved; group transient; - bundle(const bundle&) = delete; - bundle& operator=(const bundle&) = delete; + impl_bundle(const impl_bundle&) = delete; + impl_bundle& operator=(const impl_bundle&) = delete; bool modified; public: - bundle(const QString& group_name, QSettings& s) : + impl_bundle(const QString& group_name) : group_name(group_name), - saved(group_name, s), + saved(group_name), transient(saved), modified(false) { } - std::shared_ptr make(const QString& name, QSettings& s) { - assert(s.format() == QSettings::IniFormat); - return std::make_shared(name, s); + /* keep in mind doesn't fire signals */ + void reload() { + saved = group(group_name); + transient = saved; } - void store(const QString& name, QVariant& datum) + + std::shared_ptr make(const QString& name) { + return std::make_shared(name); + } + void store(const QString& name, const QVariant& datum) { modified = true; transient.put(name, datum); @@ -116,7 +124,7 @@ namespace options { } template T get(QString& name) { - transient.get(name); + return transient.get(name); } void save() { @@ -129,15 +137,32 @@ namespace options { modified = false; transient = saved; } + + bool modifiedp() const { return modified; } }; - typedef std::shared_ptr pbundle; + typedef std::shared_ptr pbundle; - class QCruft : public QObject { + class base_value : public QObject { + Q_OBJECT + public: + virtual QVariant operator=(const QVariant& datum) = 0; + public slots: +#define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(datum); } + DEFINE_SLOT(double) + DEFINE_SLOT(int) + DEFINE_SLOT(QString) + DEFINE_SLOT(bool) + signals: +#define DEFINE_SIGNAL(t) void valueChanged(t); + DEFINE_SIGNAL(double) + DEFINE_SIGNAL(int) + DEFINE_SIGNAL(QString) + DEFINE_SIGNAL(bool) }; template - class value : public QCruft { + class value : public base_value { private: QString self_name; pbundle b; @@ -153,61 +178,64 @@ namespace options { } } operator T() { return b->get(self_name); } - T& operator=(const T& datum) { + QVariant operator=(const QVariant& datum) { b->store(self_name, datum); - emit valueChanged(datum); - return datum; - } - public slots: - void setValue(const T datum) { - this->operator =(datum); + switch (datum.type()) + { +#define BRANCH_ON(e, m) case QVariant::e: return valueChanged(datum.m()), datum + BRANCH_ON(Int, toInt); + BRANCH_ON(Double, toDouble); + BRANCH_ON(String, toString); + BRANCH_ON(Bool, toBool); + default: abort(); + } } - signals: - void valueChanged(T datum); }; template - inline void tie(value&, Q*); + inline void tie_setting(value&, Q*); template<> - inline void tie(value& v, QComboBox* cb) + inline void tie_setting(value& v, QComboBox* cb) { - QObject::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int))); - QObject::connect(&v, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); + base_value::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int))); + base_value::connect(&v, SIGNAL(valueChanged(int)), cb, SLOT(setCurrentIndex(int))); + cb->setCurrentIndex(v); } template<> - inline void tie(value& v, QComboBox* cb) + inline void tie_setting(value& v, QCheckBox* cb) { - QObject::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(QString))); - QObject::connect(&v, SIGNAL(valueChanged(QString)), &v, SLOT(setValue(QString))); + base_value::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool))); + base_value::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool))); + cb->setChecked(v); } template<> - inline void tie(value& v, QCheckBox* cb) + inline void tie_setting(value& v, QDoubleSpinBox* dsb) { - QObject::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool))); - QObject::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool))); + base_value::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double))); + base_value::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double))); + dsb->setValue(v); } template<> - inline void tie(value& v, QDoubleSpinBox* dsb) + inline void tie_setting(value& v, QSpinBox* sb) { - QObject::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double))); - QObject::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double))); + base_value::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); + base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int))); + sb->setValue(v); } template<> - inline void tie(value& v, QSpinBox* sb) + inline void tie_setting(value& v, QSlider* sl) { - QObject::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); - QObject::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int))); + base_value::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); + base_value::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int))); + sl->setValue(v); } - template<> - inline void tie(value& v, QSlider* sl) - { - QObject::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); - QObject::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int))); + inline pbundle bundle(const QString& group) { + return std::make_shared(group); } } -- cgit v1.2.3 From eaeb86205a04a2159de3e55fb7105195962249db Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 30 Dec 2013 10:58:26 +0100 Subject: don't mark as dirty by accident --- facetracknoir/options.hpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp index 16946e88..67c0958d 100644 --- a/facetracknoir/options.hpp +++ b/facetracknoir/options.hpp @@ -43,6 +43,12 @@ namespace options { return t.toDouble(); } + template<> + inline QVariant qcruft_to_t(const QVariant& t) + { + return t; + } + // snapshot of qsettings group at given time class group { private: @@ -115,8 +121,11 @@ namespace options { } void store(const QString& name, const QVariant& datum) { - modified = true; - transient.put(name, datum); + if (!transient.contains(name) || datum != transient.get(name)) + { + modified = true; + transient.put(name, datum); + } } bool contains(const QString& name) { -- cgit v1.2.3 From d93d2a4f373f79e86e855c43815edf26cc455e3d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 30 Dec 2013 11:29:28 +0100 Subject: support QLineEdit --- facetracknoir/options.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp index 67c0958d..c9a982bc 100644 --- a/facetracknoir/options.hpp +++ b/facetracknoir/options.hpp @@ -20,10 +20,11 @@ #include #include #include +#include namespace options { template - inline T qcruft_to_t(const QVariant& t); + inline T qcruft_to_t (const QVariant& t); template<> inline int qcruft_to_t(const QVariant& t) @@ -31,6 +32,12 @@ namespace options { return t.toInt(); } + template<> + inline QString qcruft_to_t(const QVariant& t) + { + return t.toString(); + } + template<> inline bool qcruft_to_t(const QVariant& t) { @@ -244,6 +251,14 @@ namespace options { sl->setValue(v); } + template<> + inline void tie_setting(value& v, QLineEdit* le) + { + base_value::connect(le, SIGNAL(textChanged(QString)), &v, SLOT(setValue(QString))); + base_value::connect(&v, SIGNAL(valueChanged(QString)),le, SLOT(setText(QString))); + le->setText(v); + } + inline pbundle bundle(const QString& group) { return std::make_shared(group); } -- cgit v1.2.3 From 76c48c14b4f5f5b22532016b5963e600fbebb610 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 30 Dec 2013 12:56:11 +0100 Subject: add option of tying combobox to its text value --- facetracknoir/options.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp index c9a982bc..900f06c0 100644 --- a/facetracknoir/options.hpp +++ b/facetracknoir/options.hpp @@ -183,7 +183,7 @@ namespace options { QString self_name; pbundle b; public: - value(const pbundle& b, const QString& name, T def) : + value(pbundle& b, const QString& name, T def) : self_name(name), b(b) { @@ -219,6 +219,14 @@ namespace options { cb->setCurrentIndex(v); } + template<> + inline void tie_setting(value& v, QComboBox* cb) + { + base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(int))); + base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString))); + cb->setCurrentText(v); + } + template<> inline void tie_setting(value& v, QCheckBox* cb) { -- cgit v1.2.3 From 904add389667ff9d97cde3930a881fae89c3fb50 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 31 Dec 2013 08:40:02 +0100 Subject: options: fix some bugs --- facetracknoir/options.hpp | 96 +++++++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 33 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp index 900f06c0..1305bd0a 100644 --- a/facetracknoir/options.hpp +++ b/facetracknoir/options.hpp @@ -7,11 +7,13 @@ #pragma once -#include +#include #include #include #include #include +#include +#include #include #include #include @@ -21,6 +23,13 @@ #include #include #include +#include + +#ifdef __GNUC__ +# define ov override +#else +# define ov +#endif namespace options { template @@ -101,8 +110,10 @@ namespace options { } }; - class impl_bundle { + class impl_bundle : public QObject { + Q_OBJECT private: + QMutex mtx; const QString group_name; group saved; group transient; @@ -111,6 +122,7 @@ namespace options { bool modified; public: impl_bundle(const QString& group_name) : + mtx(QMutex::Recursive), group_name(group_name), saved(group_name), transient(saved), @@ -119,8 +131,10 @@ namespace options { } /* keep in mind doesn't fire signals */ void reload() { + QMutexLocker l(&mtx); saved = group(group_name); transient = saved; + emit reloaded(); } std::shared_ptr make(const QString& name) { @@ -128,33 +142,46 @@ namespace options { } void store(const QString& name, const QVariant& datum) { + QMutexLocker l(&mtx); if (!transient.contains(name) || datum != transient.get(name)) { modified = true; transient.put(name, datum); + emit bundleChanged(); } } bool contains(const QString& name) { + QMutexLocker l(&mtx); return transient.contains(name); } template - T get(QString& name) { + T get(const QString& name) { + QMutexLocker l(&mtx); return transient.get(name); } void save() { + QMutexLocker l(&mtx); modified = false; saved = transient; transient.save(); } void revert() { + QMutexLocker l(&mtx); modified = false; transient = saved; + emit bundleChanged(); } - bool modifiedp() const { return modified; } + bool modifiedp() { + QMutexLocker l(&mtx); + return modified; + } + signals: + void bundleChanged(); + void reloaded(); }; typedef std::shared_ptr pbundle; @@ -162,7 +189,18 @@ namespace options { class base_value : public QObject { Q_OBJECT public: + base_value(pbundle b, const QString& name) : b(b), self_name(name) { + connect(b.get(), SIGNAL(reloaded()), this, SLOT(reread_value())); + } virtual QVariant operator=(const QVariant& datum) = 0; + protected: + pbundle b; + QString self_name; + public slots: + void reread_value() + { + this->operator=(b->get(self_name)); + } public slots: #define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(datum); } DEFINE_SLOT(double) @@ -179,13 +217,11 @@ namespace options { template class value : public base_value { - private: - QString self_name; - pbundle b; + private: T def; public: - value(pbundle& b, const QString& name, T def) : - self_name(name), - b(b) + static constexpr const Qt::ConnectionType CONNTYPE = Qt::QueuedConnection; + value(pbundle b, const QString& name, T def) : + base_value(b, name), def(def) { if (!b->contains(name)) { @@ -196,15 +232,9 @@ namespace options { operator T() { return b->get(self_name); } QVariant operator=(const QVariant& datum) { b->store(self_name, datum); - switch (datum.type()) - { -#define BRANCH_ON(e, m) case QVariant::e: return valueChanged(datum.m()), datum - BRANCH_ON(Int, toInt); - BRANCH_ON(Double, toDouble); - BRANCH_ON(String, toString); - BRANCH_ON(Bool, toBool); - default: abort(); - } + auto foo = qcruft_to_t(datum); + emit valueChanged(foo); + return datum; } }; @@ -214,56 +244,56 @@ namespace options { template<> inline void tie_setting(value& v, QComboBox* cb) { - base_value::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int))); - base_value::connect(&v, SIGNAL(valueChanged(int)), cb, SLOT(setCurrentIndex(int))); + base_value::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), cb, SLOT(setCurrentIndex(int)), v.CONNTYPE); cb->setCurrentIndex(v); } template<> inline void tie_setting(value& v, QComboBox* cb) { - base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(int))); - base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString))); + base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(QString)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString)), v.CONNTYPE); cb->setCurrentText(v); } template<> inline void tie_setting(value& v, QCheckBox* cb) { - base_value::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool))); - base_value::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool))); + base_value::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool)), v.CONNTYPE); cb->setChecked(v); } template<> inline void tie_setting(value& v, QDoubleSpinBox* dsb) { - base_value::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double))); - base_value::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double))); + base_value::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double)), v.CONNTYPE); dsb->setValue(v); } template<> inline void tie_setting(value& v, QSpinBox* sb) { - base_value::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); - base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int))); + base_value::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int)), v.CONNTYPE); sb->setValue(v); } template<> inline void tie_setting(value& v, QSlider* sl) { - base_value::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int))); - base_value::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int))); + base_value::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int)), v.CONNTYPE); sl->setValue(v); } template<> inline void tie_setting(value& v, QLineEdit* le) { - base_value::connect(le, SIGNAL(textChanged(QString)), &v, SLOT(setValue(QString))); - base_value::connect(&v, SIGNAL(valueChanged(QString)),le, SLOT(setText(QString))); + base_value::connect(le, SIGNAL(textChanged(QString)), &v, SLOT(setValue(QString)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(QString)),le, SLOT(setText(QString)), v.CONNTYPE); le->setText(v); } -- cgit v1.2.3 From 54892e5f6a15c1ce0aba364039174eda3d1a6b8b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 31 Dec 2013 08:40:27 +0100 Subject: main: use settings framework --- facetracknoir/curve-config.cpp | 161 +++--------- facetracknoir/facetracknoir.cpp | 397 ++++++++++-------------------- facetracknoir/facetracknoir.h | 38 +-- facetracknoir/ftnoir_curves.ui | 4 +- facetracknoir/ftnoir_keyboardshortcuts.ui | 53 +--- facetracknoir/main.cpp | 7 +- facetracknoir/shortcuts.cpp | 148 ++--------- facetracknoir/shortcuts.h | 9 +- facetracknoir/tracker.cpp | 25 +- facetracknoir/tracker.h | 51 ++-- 10 files changed, 224 insertions(+), 669 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/curve-config.cpp b/facetracknoir/curve-config.cpp index 2e731892..4b07a165 100644 --- a/facetracknoir/curve-config.cpp +++ b/facetracknoir/curve-config.cpp @@ -14,7 +14,23 @@ CurveConfigurationDialog::CurveConfigurationDialog(FaceTrackNoIR *ftnoir, QWidge // Connect Qt signals to member-functions connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(curveChanged(int))); + + tie_setting(mainApp->s.a_x.altp, ui.tx_altp); + tie_setting(mainApp->s.a_y.altp, ui.ty_altp); + tie_setting(mainApp->s.a_z.altp, ui.tz_altp); + tie_setting(mainApp->s.a_yaw.altp, ui.rx_altp); + tie_setting(mainApp->s.a_pitch.altp, ui.ry_altp); + tie_setting(mainApp->s.a_roll.altp, ui.rz_altp); + + tie_setting(mainApp->s.tcomp_p, ui.tcomp_enable); + tie_setting(mainApp->s.tcomp_tz, ui.tcomp_rz); + + tie_setting(mainApp->s.a_x.zero, ui.pos_tx); + tie_setting(mainApp->s.a_y.zero, ui.pos_ty); + tie_setting(mainApp->s.a_z.zero, ui.pos_tz); + tie_setting(mainApp->s.a_yaw.zero, ui.pos_rx); + tie_setting(mainApp->s.a_pitch.zero, ui.pos_ry); + tie_setting(mainApp->s.a_roll.zero, ui.pos_rz); // Load the settings from the current .INI-file loadSettings(); @@ -47,7 +63,7 @@ void CurveConfigurationDialog::doCancel() { // // Ask if changed Settings should be saved // - if (settingsDirty) { + if (settingsDirty || mainApp->s.b->modifiedp()) { int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard ); qDebug() << "doCancel says: answer =" << ret; @@ -58,6 +74,7 @@ void CurveConfigurationDialog::doCancel() { this->close(); break; case QMessageBox::Discard: + mainApp->s.b->revert(); this->close(); break; case QMessageBox::Cancel: @@ -77,67 +94,6 @@ void CurveConfigurationDialog::doCancel() { // Load the current Settings from the currently 'active' INI-file. // void CurveConfigurationDialog::loadSettings() { - qDebug() << "CurveConfigurationDialog::loadSettings says: Starting "; - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - qDebug() << "CurveConfigurationDialog::loadSettings says: iniFile = " << currentFile; - - static const char* names[] = { - "tx_alt", - "ty_alt", - "tz_alt", - "rx_alt", - "ry_alt", - "rz_alt" - }; - - iniFile.beginGroup("Tracking"); - - ui.tcomp_rz->setChecked(iniFile.value("tcomp-rz", false).toBool()); - ui.checkBox->setChecked(iniFile.value("compensate", true).toBool()); - - for (int i = 0; i < 6; i++) - mainApp->axis(i).altp = iniFile.value(names[i], false).toBool(); - - QCheckBox* widgets[] = { - ui.tx_altp, - ui.ty_altp, - ui.tz_altp, - ui.rx_altp, - ui.ry_altp, - ui.rz_altp - }; - - for (int i = 0; i < 6; i++) - widgets[i]->setChecked(mainApp->axis(i).altp); - - QDoubleSpinBox* widgets2[] = { - ui.pos_tx, - ui.pos_ty, - ui.pos_tz, - ui.pos_tx, - ui.pos_ry, - ui.pos_rz - }; - - const char* names2[] = { - "zero_tx", - "zero_ty", - "zero_tz", - "zero_rx", - "zero_ry", - "zero_rz" - }; - - - for (int i = 0; i < 6; i++) - widgets2[i]->setValue(iniFile.value(names2[i], 0).toDouble()); - - iniFile.endGroup(); - QFunctionConfigurator* configs[6] = { ui.txconfig, ui.tyconfig, @@ -156,23 +112,10 @@ void CurveConfigurationDialog::loadSettings() { ui.rzconfig_alt }; - QCheckBox* checkboxes[6] = { - ui.rx_altp, - ui.ry_altp, - ui.rz_altp, - ui.tx_altp, - ui.ty_altp, - ui.tz_altp - }; - - QDoubleSpinBox* widgets3[] = { - ui.pos_tx, - ui.pos_ty, - ui.pos_tz, - ui.pos_tx, - ui.pos_ry, - ui.pos_rz - }; + QSettings settings("opentrack"); + QString currentFile = settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ) + .toString(); for (int i = 0; i < 6; i++) { @@ -182,8 +125,6 @@ void CurveConfigurationDialog::loadSettings() { alt_configs[i]->loadSettings(currentFile); connect(configs[i], SIGNAL(CurveChanged(bool)), this, SLOT(curveChanged(bool)), Qt::UniqueConnection); connect(alt_configs[i], SIGNAL(CurveChanged(bool)), this, SLOT(curveChanged(bool)), Qt::UniqueConnection); - connect(checkboxes[i], SIGNAL(stateChanged(int)), this, SLOT(curveChanged(int)), Qt::UniqueConnection); - mainApp->axis(i).zero = widgets3[i]->value(); } settingsDirty = false; @@ -196,9 +137,11 @@ void CurveConfigurationDialog::save() { qDebug() << "save() says: started"; - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings settings("opentrack"); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ) + .toString(); ui.rxconfig->saveSettings(currentFile); ui.ryconfig->saveSettings(currentFile); @@ -214,53 +157,5 @@ void CurveConfigurationDialog::save() { ui.ryconfig_alt->saveSettings(currentFile); ui.rzconfig_alt->saveSettings(currentFile); - bool tcomp_rz = false, compensate = true; - - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - iniFile.beginGroup("Tracking"); - - iniFile.setValue("tcomp-rz", tcomp_rz = ui.tcomp_rz->checkState() != Qt::Unchecked); - iniFile.setValue("compensate", compensate = (bool) !!ui.checkBox->isChecked()); - - if (mainApp->tracker) - { - mainApp->tracker->compensate = compensate; - mainApp->tracker->tcomp_rz = tcomp_rz; - } - - iniFile.setValue("rx_alt", ui.rx_altp->checkState() != Qt::Unchecked); - iniFile.setValue("ry_alt", ui.ry_altp->checkState() != Qt::Unchecked); - iniFile.setValue("rz_alt", ui.rz_altp->checkState() != Qt::Unchecked); - iniFile.setValue("tx_alt", ui.tx_altp->checkState() != Qt::Unchecked); - iniFile.setValue("ty_alt", ui.ty_altp->checkState() != Qt::Unchecked); - iniFile.setValue("tz_alt", ui.tz_altp->checkState() != Qt::Unchecked); - - QDoubleSpinBox* widgets2[] = { - ui.pos_tx, - ui.pos_ty, - ui.pos_tz, - ui.pos_tx, - ui.pos_ry, - ui.pos_rz - }; - - const char* names2[] = { - "zero_tx", - "zero_ty", - "zero_tz", - "zero_rx", - "zero_ry", - "zero_rz" - }; - - for (int i = 0; i < 6; i++) - { - iniFile.setValue(names2[i], widgets2[i]->value()); - mainApp->axis(i).zero = widgets2[i]->value(); - } - - iniFile.endGroup(); - settingsDirty = false; } diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index 75ac737d..b98c6085 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -95,6 +95,9 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : keyCenter(this), keyToggle(this), #endif + b(bundle("opentrack-ui")), + s(b), + pose(std::vector{&s.a_x, &s.a_y, &s.a_z, &s.a_yaw, &s.a_pitch, &s.a_roll}), timUpdateHeadPose(this), pTrackerDialog(NULL), pSecondTrackerDialog(NULL), @@ -111,6 +114,16 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : tracker = 0; + CurveConfigurationDialog* ccd; + + if (!_curve_config) + { + ccd = new CurveConfigurationDialog( this, this ); + _curve_config = ccd; + } else { + ccd = dynamic_cast(_curve_config); + } + QDir::setCurrent(QCoreApplication::applicationDirPath()); connect(ui.btnLoad, SIGNAL(clicked()), this, SLOT(open())); @@ -124,18 +137,6 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : connect(ui.btnShowServerControls, SIGNAL(clicked()), this, SLOT(showServerControls())); connect(ui.btnShowFilterControls, SIGNAL(clicked()), this, SLOT(showFilterControls())); - connect(ui.chkInvertYaw, SIGNAL(stateChanged(int)), this, SLOT(setInvertYaw(int))); - connect(ui.chkInvertRoll, SIGNAL(stateChanged(int)), this, SLOT(setInvertRoll(int))); - connect(ui.chkInvertPitch, SIGNAL(stateChanged(int)), this, SLOT(setInvertPitch(int))); - connect(ui.chkInvertX, SIGNAL(stateChanged(int)), this, SLOT(setInvertX(int))); - connect(ui.chkInvertY, SIGNAL(stateChanged(int)), this, SLOT(setInvertY(int))); - connect(ui.chkInvertZ, SIGNAL(stateChanged(int)), this, SLOT(setInvertZ(int))); - - connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(startTracker())); - connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stopTracker())); - - GetCameraNameDX(); - ui.cbxSecondTrackerSource->addItem(QIcon(), "None"); dlopen_filters.push_back((DynamicLibrary*) NULL); ui.iconcomboFilter->addItem(QIcon(), "None"); @@ -144,11 +145,25 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : fill_combobox("opentrack-tracker-*.", dlopen_trackers, ui.iconcomboTrackerSource, ui.cbxSecondTrackerSource); fill_combobox("opentrack-filter-*.", dlopen_filters, ui.iconcomboFilter, NULL); + tie_setting(s.a_yaw.invert, ui.chkInvertYaw); + tie_setting(s.a_pitch.invert, ui.chkInvertPitch); + tie_setting(s.a_roll.invert, ui.chkInvertRoll); + tie_setting(s.a_x.invert, ui.chkInvertX); + tie_setting(s.a_y.invert, ui.chkInvertY); + tie_setting(s.a_z.invert, ui.chkInvertZ); + tie_setting(s.tracker_dll, ui.iconcomboTrackerSource); + tie_setting(s.tracker2_dll, ui.cbxSecondTrackerSource); + tie_setting(s.protocol_dll, ui.iconcomboProtocol); + tie_setting(s.filter_dll, ui.iconcomboFilter); + + connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(startTracker())); + connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stopTracker())); + + GetCameraNameDX(); + connect(ui.iconcomboProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(profileSelected(int))); connect(&timUpdateHeadPose, SIGNAL(timeout()), this, SLOT(showHeadPose())); - loadSettings(); - #ifndef _WIN32 connect(&keyCenter, SIGNAL(activated()), this, SLOT(shortcutRecentered())); connect(&keyToggle, SIGNAL(activated()), this, SLOT(shortcutToggled())); @@ -156,6 +171,8 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : connect(&kbd_quit, SIGNAL(activated()), this, SLOT(exit())); kbd_quit.setEnabled(true); + + fill_profile_cbx(); } FaceTrackNoIR::~FaceTrackNoIR() { @@ -250,45 +267,14 @@ void FaceTrackNoIR::open() { } void FaceTrackNoIR::save() { - QSettings settings("opentrack"); + b->save(); - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); - - iniFile.beginGroup ( "Tracking" ); - - iniFile.setValue ( "invertYaw", ui.chkInvertYaw->isChecked() ); - iniFile.setValue ( "invertPitch", ui.chkInvertPitch->isChecked() ); - iniFile.setValue ( "invertRoll", ui.chkInvertRoll->isChecked() ); - iniFile.setValue ( "invertX", ui.chkInvertX->isChecked() ); - iniFile.setValue ( "invertY", ui.chkInvertY->isChecked() ); - iniFile.setValue ( "invertZ", ui.chkInvertZ->isChecked() ); - iniFile.endGroup (); - - iniFile.beginGroup ( "GameProtocol" ); - { - DynamicLibrary* proto = dlopen_protocols.value( ui.iconcomboProtocol->currentIndex(), (DynamicLibrary*) NULL); - iniFile.setValue ( "DLL", proto == NULL ? "" : proto->filename); - } - iniFile.endGroup (); - - iniFile.beginGroup ( "TrackerSource" ); - { - DynamicLibrary* tracker = dlopen_trackers.value( ui.iconcomboTrackerSource->currentIndex(), (DynamicLibrary*) NULL); - iniFile.setValue ( "DLL", tracker == NULL ? "" : tracker->filename); - } - { - DynamicLibrary* tracker = dlopen_trackers.value( ui.cbxSecondTrackerSource->currentIndex() - 1, (DynamicLibrary*) NULL); - iniFile.setValue ( "2ndDLL", tracker == NULL ? "" : tracker->filename); - } - iniFile.endGroup (); + QSettings settings("opentrack"); - iniFile.beginGroup ( "Filter" ); - { - DynamicLibrary* filter = dlopen_filters.value( ui.iconcomboFilter->currentIndex(), (DynamicLibrary*) NULL); - iniFile.setValue ( "DLL", filter == NULL ? "" : filter->filename); - } - iniFile.endGroup (); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini") + .toString(); #if defined(__unix) || defined(__linux) QByteArray bytes = QFile::encodeName(currentFile); @@ -308,8 +294,7 @@ void FaceTrackNoIR::saveAs() QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"), oldFile, -// QCoreApplication::applicationDirPath() + "/settings", - tr("Settings file (*.ini);;All Files (*)")); + tr("Settings file (*.ini);;All Files (*)")); if (!fileName.isEmpty()) { QFileInfo newFileInfo ( fileName ); @@ -325,117 +310,40 @@ void FaceTrackNoIR::saveAs() } settings.setValue ("SettingsFile", fileName); - save(); - - loadSettings(); - } + save(); + } } void FaceTrackNoIR::loadSettings() { - if (looping) - return; - looping = true; - qDebug() << "loadSettings says: Starting "; - QSettings settings("opentrack"); - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - qDebug() << "Config file now" << currentFile; - QSettings iniFile( currentFile, QSettings::IniFormat ); - - QFileInfo pathInfo ( currentFile ); - setWindowTitle(QString( OPENTRACK_VERSION " :: ") + pathInfo.fileName()); - - QDir settingsDir( pathInfo.dir() ); - QStringList filters; - filters << "*.ini"; - iniFileList.clear(); - iniFileList = settingsDir.entryList( filters, QDir::Files, QDir::Name ); - - ui.iconcomboProfile->clear(); - for ( int i = 0; i < iniFileList.size(); i++) { - ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), iniFileList.at(i)); - if (iniFileList.at(i) == pathInfo.fileName()) { - ui.iconcomboProfile->setItemIcon(i, QIcon(":/images/settingsopen16.png")); - ui.iconcomboProfile->setCurrentIndex( i ); - } - } - - qDebug() << "loadSettings says: iniFile = " << currentFile; - - iniFile.beginGroup ( "Tracking" ); - ui.chkInvertYaw->setChecked (iniFile.value ( "invertYaw", 0 ).toBool()); - ui.chkInvertPitch->setChecked (iniFile.value ( "invertPitch", 0 ).toBool()); - ui.chkInvertRoll->setChecked (iniFile.value ( "invertRoll", 0 ).toBool()); - ui.chkInvertX->setChecked (iniFile.value ( "invertX", 0 ).toBool()); - ui.chkInvertY->setChecked (iniFile.value ( "invertY", 0 ).toBool()); - ui.chkInvertZ->setChecked (iniFile.value ( "invertZ", 0 ).toBool()); - iniFile.endGroup (); - - iniFile.beginGroup ( "GameProtocol" ); - QString selectedProtocolName = iniFile.value ( "DLL", "" ).toString(); - iniFile.endGroup (); - - for ( int i = 0; i < dlopen_protocols.size(); i++) { - if (dlopen_protocols.at(i)->filename.compare( selectedProtocolName, Qt::CaseInsensitive ) == 0) { - ui.iconcomboProtocol->setCurrentIndex( i ); - break; - } - } - - iniFile.beginGroup ( "TrackerSource" ); - QString selectedTrackerName = iniFile.value ( "DLL", "" ).toString(); - qDebug() << "loadSettings says: selectedTrackerName = " << selectedTrackerName; - QString secondTrackerName = iniFile.value ( "2ndDLL", "None" ).toString(); - qDebug() << "loadSettings says: secondTrackerName = " << secondTrackerName; - iniFile.endGroup (); - - for ( int i = 0; i < dlopen_trackers.size(); i++) { - DynamicLibrary* foo = dlopen_trackers.at(i); - if (foo && foo->filename.compare( selectedTrackerName, Qt::CaseInsensitive ) == 0) { - ui.iconcomboTrackerSource->setCurrentIndex( i ); - } - if (foo && foo->filename.compare( secondTrackerName, Qt::CaseInsensitive ) == 0) { - ui.cbxSecondTrackerSource->setCurrentIndex( i + 1 ); - } - } - - iniFile.beginGroup ( "Filter" ); - QString selectedFilterName = iniFile.value ( "DLL", "" ).toString(); - qDebug() << "createIconGroupBox says: selectedFilterName = " << selectedFilterName; - iniFile.endGroup (); - - for ( int i = 0; i < dlopen_filters.size(); i++) { - DynamicLibrary* foo = dlopen_filters.at(i); - if (foo && foo->filename.compare( selectedFilterName, Qt::CaseInsensitive ) == 0) { - ui.iconcomboFilter->setCurrentIndex( i ); - break; - } - } - - CurveConfigurationDialog* ccd; - - if (!_curve_config) - { - ccd = new CurveConfigurationDialog( this, this ); - _curve_config = ccd; - } else { - ccd = dynamic_cast(_curve_config); - } - - ccd->loadSettings(); + b->reload(); + (dynamic_cast(_curve_config))->loadSettings(); +} - looping = false; +void FaceTrackNoIR::updateButtonState(bool running) +{ + bool e = !running; + ui.iconcomboProfile->setEnabled ( e ); + ui.btnLoad->setEnabled ( e ); + ui.btnSaveAs->setEnabled ( e ); + ui.btnShowFilterControls->setEnabled ( e ); + ui.btnStartTracker->setEnabled ( e ); + ui.btnStopTracker->setEnabled ( running ); + + ui.iconcomboTrackerSource->setEnabled ( e ); + ui.cbxSecondTrackerSource->setEnabled ( e ); + ui.iconcomboProtocol->setEnabled ( e ); + ui.btnShowServerControls->setEnabled ( e ); + ui.iconcomboFilter->setEnabled ( e ); + + ui.btnStartTracker->setEnabled(e); + ui.btnStopTracker->setEnabled(running); } -void FaceTrackNoIR::startTracker( ) { +void FaceTrackNoIR::startTracker( ) { + b->save(); + loadSettings(); bindKeyboardShortcuts(); - ui.iconcomboProfile->setEnabled ( false ); - ui.btnLoad->setEnabled ( false ); - ui.btnSave->setEnabled ( false ); - ui.btnSaveAs->setEnabled ( false ); - ui.btnShowFilterControls->setEnabled ( true ); - if (Libraries) delete Libraries; Libraries = new SelectedLibraries(this); @@ -457,54 +365,19 @@ void FaceTrackNoIR::startTracker( ) { delete tracker; } - QSettings settings("opentrack"); - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); - - for (int i = 0; i < 6; i++) { - axis(i).curve.loadSettings(iniFile); - axis(i).curveAlt.loadSettings(iniFile); - } + QSettings settings("opentrack"); + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings iniFile( currentFile, QSettings::IniFormat ); - static const char* names[] = { - "tx_alt", - "ty_alt", - "tz_alt", - "rx_alt", - "ry_alt", - "rz_alt", - }; - - static const char* invert_names[] = { - "invertX", - "invertY", - "invertZ", - "invertYaw", - "invertPitch", - "invertRoll" - }; - - iniFile.beginGroup("Tracking"); - - for (int i = 0; i < 6; i++) { - axis(i).altp = iniFile.value(names[i], false).toBool(); - axis(i).invert = iniFile.value(invert_names[i], false).toBool() ? 1 : -1; + for (int i = 0; i < 6; i++) + { + axis(i).curve.loadSettings(iniFile); + axis(i).curveAlt.loadSettings(iniFile); + } } - tracker = new Tracker ( this ); - - tracker->compensate = iniFile.value("compensate", true).toBool(); - tracker->tcomp_rz = iniFile.value("tcomp-rz", false).toBool(); - - iniFile.endGroup(); - - tracker->setInvertAxis(Yaw, ui.chkInvertYaw->isChecked() ); - tracker->setInvertAxis(Pitch, ui.chkInvertPitch->isChecked() ); - tracker->setInvertAxis(Roll, ui.chkInvertRoll->isChecked() ); - tracker->setInvertAxis(TX, ui.chkInvertX->isChecked() ); - tracker->setInvertAxis(TY, ui.chkInvertY->isChecked() ); - tracker->setInvertAxis(TZ, ui.chkInvertZ->isChecked() ); + tracker = new Tracker ( this, s ); if (pTrackerDialog && Libraries->pTracker) { pTrackerDialog->registerTracker( Libraries->pTracker ); @@ -517,21 +390,12 @@ void FaceTrackNoIR::startTracker( ) { ui.video_frame->show(); - ui.btnStartTracker->setEnabled ( false ); - ui.btnStopTracker->setEnabled ( true ); - - ui.iconcomboTrackerSource->setEnabled ( false ); - ui.cbxSecondTrackerSource->setEnabled ( false ); - ui.iconcomboProtocol->setEnabled ( false ); - ui.btnShowServerControls->setEnabled ( false ); - ui.iconcomboFilter->setEnabled ( false ); - - GetCameraNameDX(); - timUpdateHeadPose.start(50); + + updateButtonState(true); } -void FaceTrackNoIR::stopTracker( ) { +void FaceTrackNoIR::stopTracker( ) { ui.game_name->setText("Not connected"); #if defined(_WIN32) if (keybindingWorker) @@ -555,39 +419,16 @@ void FaceTrackNoIR::stopTracker( ) { pFilterDialog->unregisterFilter(); if ( tracker ) { - qDebug() << "Done with tracking"; tracker->should_quit = true; tracker->wait(); - - qDebug() << "stopTracker says: Deleting tracker!"; delete tracker; - qDebug() << "stopTracker says: Tracker deleted!"; tracker = 0; if (Libraries) { delete Libraries; Libraries = NULL; } } - ui.btnStartTracker->setEnabled ( true ); - ui.btnStopTracker->setEnabled ( false ); - ui.iconcomboProtocol->setEnabled ( true ); - ui.iconcomboTrackerSource->setEnabled ( true ); - ui.cbxSecondTrackerSource->setEnabled ( true ); - ui.iconcomboFilter->setEnabled ( true ); - - ui.btnShowServerControls->setEnabled ( true ); - ui.video_frame->hide(); - - ui.iconcomboProfile->setEnabled ( true ); - ui.btnLoad->setEnabled ( true ); - ui.btnSave->setEnabled ( true ); - ui.btnSaveAs->setEnabled ( true ); - ui.btnShowFilterControls->setEnabled ( true ); -} - -void FaceTrackNoIR::setInvertAxis(Axis axis, int invert ) { - if (tracker) - tracker->setInvertAxis (axis, (invert != 0)?true:false ); + updateButtonState(false); } void FaceTrackNoIR::showHeadPose() { @@ -625,7 +466,6 @@ void FaceTrackNoIR::showHeadPose() { } } -/** toggles Engine Controls Dialog **/ void FaceTrackNoIR::showTrackerSettings() { if (pTrackerDialog) { delete pTrackerDialog; @@ -641,7 +481,7 @@ void FaceTrackNoIR::showTrackerSettings() { foo->setFixedSize(foo->size()); if (Libraries && Libraries->pTracker) pTrackerDialog->registerTracker(Libraries->pTracker); - pTrackerDialog->Initialize(this); + dynamic_cast(pTrackerDialog)->show(); } } } @@ -661,7 +501,7 @@ void FaceTrackNoIR::showSecondTrackerSettings() { foo->setFixedSize(foo->size()); if (Libraries && Libraries->pSecondTracker) pSecondTrackerDialog->registerTracker(Libraries->pSecondTracker); - pSecondTrackerDialog->Initialize(this); + dynamic_cast(pSecondTrackerDialog)->show(); } } } @@ -679,7 +519,7 @@ void FaceTrackNoIR::showServerControls() { if (pProtocolDialog) { auto foo = dynamic_cast(pProtocolDialog); foo->setFixedSize(foo->size()); - pProtocolDialog->Initialize(this); + dynamic_cast(pProtocolDialog)->show(); } } } @@ -697,9 +537,9 @@ void FaceTrackNoIR::showFilterControls() { if (pFilterDialog) { auto foo = dynamic_cast(pFilterDialog); foo->setFixedSize(foo->size()); - pFilterDialog->Initialize(this); if (Libraries && Libraries->pFilter) pFilterDialog->registerFilter(Libraries->pFilter); + dynamic_cast(pFilterDialog)->show(); } } } @@ -730,34 +570,61 @@ void FaceTrackNoIR::exit() { QCoreApplication::exit(0); } -void FaceTrackNoIR::profileSelected(int index) +void FaceTrackNoIR::fill_profile_cbx() { if (looping) return; + looping = true; + QSettings settings("opentrack"); + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + qDebug() << "Config file now" << currentFile; + QFileInfo pathInfo ( currentFile ); + setWindowTitle(QString( OPENTRACK_VERSION " :: ") + pathInfo.fileName()); + QDir settingsDir( pathInfo.dir() ); + QStringList filters; + filters << "*.ini"; + auto iniFileList = settingsDir.entryList( filters, QDir::Files, QDir::Name ); + ui.iconcomboProfile->clear(); + for ( int i = 0; i < iniFileList.size(); i++) { + ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), iniFileList.at(i)); + if (iniFileList.at(i) == pathInfo.fileName()) { + ui.iconcomboProfile->setItemIcon(i, QIcon(":/images/settingsopen16.png")); + ui.iconcomboProfile->setCurrentIndex( i ); + } + } + looping = false; +} + +void FaceTrackNoIR::profileSelected(int index) +{ QSettings settings("opentrack"); QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); QFileInfo pathInfo ( currentFile ); - - settings.setValue ("SettingsFile", pathInfo.absolutePath() + "/" + iniFileList.value(index, "")); + settings.setValue ("SettingsFile", pathInfo.absolutePath() + "/" + ui.iconcomboProfile->itemText(index)); loadSettings(); + if (looping) + return; + looping = true; + fill_profile_cbx(); + looping = false; } #if !defined(_WIN32) -void FaceTrackNoIR::bind_keyboard_shortcut(QxtGlobalShortcut& key, const QString label, QSettings& iniFile) +void FaceTrackNoIR::bind_keyboard_shortcut(QxtGlobalShortcut& key, key_opts& k) { - const int idx = iniFile.value("Key_index_" + label, 0).toInt(); key.setShortcut(QKeySequence::fromString("")); key.setDisabled(); - QString seq(global_key_sequences.value(idx, "")); + const int idx = k.key_index; if (idx > 0) { + QString seq(global_key_sequences.value(idx, "")); if (!seq.isEmpty()) { - if (iniFile.value(QString("Shift_%1").arg(label), false).toBool()) + if (k.shift) seq = "Shift+" + seq; - if (iniFile.value(QString("Alt_%1").arg(label), false).toBool()) + if (k.alt) seq = "Alt+" + seq; - if (iniFile.value(QString("Ctrl_%1").arg(label), false).toBool()) + if (k.ctrl) seq = "Ctrl+" + seq; key.setShortcut(QKeySequence::fromString(seq, QKeySequence::PortableText)); key.setEnabled(); @@ -767,39 +634,31 @@ void FaceTrackNoIR::bind_keyboard_shortcut(QxtGlobalShortcut& key, const QString } } #else -static void bind_keyboard_shortcut(Key& key, const QString label, QSettings& iniFile) +static void bind_keyboard_shortcut(Key& key, const key& k) { - const int idx = iniFile.value("Key_index_" + label, 0).toInt(); + const int idx = k.key_index; if (idx > 0) { key.keycode = 0; key.shift = key.alt = key.ctrl = 0; if (idx < global_windows_key_sequences.size()) key.keycode = global_windows_key_sequences[idx]; - key.shift = iniFile.value(QString("Shift_%1").arg(label), false).toBool(); - key.alt = iniFile.value(QString("Alt_%1").arg(label), false).toBool(); - key.ctrl = iniFile.value(QString("Ctrl_%1").arg(label), false).toBool(); + key.shift = k.shift; + key.alt = k.alt; + key.ctrl = k.ctrl; } } #endif void FaceTrackNoIR::bindKeyboardShortcuts() { - QSettings settings("opentrack"); - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); - iniFile.beginGroup ( "KB_Shortcuts" ); - #if !defined(_WIN32) - bind_keyboard_shortcut(keyCenter, "Center", iniFile); - bind_keyboard_shortcut(keyToggle, "Toggle", iniFile); + bind_keyboard_shortcut(keyCenter, s.center_key); + bind_keyboard_shortcut(keyToggle, s.toggle_key); #else - bind_keyboard_shortcut(keyCenter, "Center", iniFile); - bind_keyboard_shortcut(keyToggle, "Toggle", iniFile); + bind_keyboard_shortcut(keyCenter, s.center_key); + bind_keyboard_shortcut(keyToggle, s.toggle_key); #endif - iniFile.endGroup (); - if (tracker) /* running already */ { #if defined(_WIN32) @@ -822,9 +681,7 @@ void FaceTrackNoIR::shortcutRecentered() qDebug() << "Center"; if (tracker) - { tracker->do_center = true; - } } void FaceTrackNoIR::shortcutToggled() @@ -832,7 +689,5 @@ void FaceTrackNoIR::shortcutToggled() QApplication::beep(); qDebug() << "Toggle"; if (tracker) - { tracker->enabled = !tracker->enabled; - } } diff --git a/facetracknoir/facetracknoir.h b/facetracknoir/facetracknoir.h index 72ccebd8..b1279697 100644 --- a/facetracknoir/facetracknoir.h +++ b/facetracknoir/facetracknoir.h @@ -39,6 +39,7 @@ #include #include #include +#include #if !defined(_WIN32) # include "qxt-mini/QxtGlobalShortcut" #else @@ -50,6 +51,11 @@ #include "ui_facetracknoir.h" +#include "facetracknoir/options.hpp" +using namespace options; + +#include "facetracknoir/main-settings.hpp" + #include "global-settings.h" #include "tracker.h" #include "facetracknoir/shortcuts.h" @@ -100,6 +106,8 @@ public: QxtGlobalShortcut keyCenter; QxtGlobalShortcut keyToggle; #endif + pbundle b; + main_settings s; public slots: void shortcutRecentered(); void shortcutToggled(); @@ -108,7 +116,6 @@ private: HeadPoseData pose; Ui::OpentrackUI ui; QTimer timUpdateHeadPose; // Timer to display headpose - QStringList iniFileList; // List of INI-files, that are present in the Settings folder ITrackerDialog* pTrackerDialog; // Pointer to Tracker dialog instance (in DLL) ITrackerDialog* pSecondTrackerDialog; // Pointer to the second Tracker dialog instance (in DLL) @@ -122,6 +129,7 @@ private: void GetCameraNameDX(); void loadSettings(); + void updateButtonState(bool); QList dlopen_filters; QList dlopen_trackers; @@ -129,18 +137,18 @@ private: QShortcut kbd_quit; #ifndef _WIN32 - void bind_keyboard_shortcut(QxtGlobalShortcut& key, const QString label, QSettings& iniFile); + void bind_keyboard_shortcut(QxtGlobalShortcut&, key_opts& k); #endif - volatile bool looping; + bool looping; + + void fill_profile_cbx(); private slots: - //file menu void open(); void save(); void saveAs(); void exit(); - // void setIcon(int index); void profileSelected(int index); void showTrackerSettings(); @@ -151,30 +159,10 @@ private slots: void showKeyboardShortcuts(); void showCurveConfiguration(); - void setInvertAxis( Axis axis, int invert ); - void setInvertYaw(int invert) { - setInvertAxis(Yaw, invert); - } - void setInvertPitch(int invert) { - setInvertAxis(Pitch, invert); - } - void setInvertRoll(int invert) { - setInvertAxis(Roll, invert); - } - void setInvertX(int invert) { - setInvertAxis(TX, invert); - } - void setInvertY(int invert) { - setInvertAxis(TY, invert); - } - void setInvertZ(int invert) { - setInvertAxis(TZ, invert); - } void showHeadPose(); void startTracker(); void stopTracker(); - }; #endif // FaceTrackNoIR_H diff --git a/facetracknoir/ftnoir_curves.ui b/facetracknoir/ftnoir_curves.ui index 77df9a20..f96df044 100644 --- a/facetracknoir/ftnoir_curves.ui +++ b/facetracknoir/ftnoir_curves.ui @@ -761,7 +761,7 @@ - + 0 @@ -816,7 +816,7 @@ tx_altp ty_altp tz_altp - checkBox + tcomp_enable tabWidget pos_tx buttonBox diff --git a/facetracknoir/ftnoir_keyboardshortcuts.ui b/facetracknoir/ftnoir_keyboardshortcuts.ui index 565c0e77..1477d56d 100644 --- a/facetracknoir/ftnoir_keyboardshortcuts.ui +++ b/facetracknoir/ftnoir_keyboardshortcuts.ui @@ -6,8 +6,8 @@ 0 0 - 335 - 120 + 360 + 124 @@ -191,53 +191,10 @@ - - - - - 0 - 0 - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - Cancel - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - OK + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/facetracknoir/main.cpp b/facetracknoir/main.cpp index 5ba3fcd5..3143a093 100644 --- a/facetracknoir/main.cpp +++ b/facetracknoir/main.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #if defined(_WIN32) && defined(_MSC_VER) # include @@ -61,11 +62,9 @@ int main(int argc, char** argv) #endif QApplication::setAttribute(Qt::AA_X11InitThreads, true); QApplication app(argc, argv); - FaceTrackNoIR w; - QDesktopWidget desktop; + auto w = std::make_shared(); - w.move(desktop.screenGeometry().width()/2-w.width()/2, 100); - w.show(); + w->show(); app.exec(); return 0; diff --git a/facetracknoir/shortcuts.cpp b/facetracknoir/shortcuts.cpp index 6a972aa3..2f117ea4 100644 --- a/facetracknoir/shortcuts.cpp +++ b/facetracknoir/shortcuts.cpp @@ -12,63 +12,55 @@ KeyboardShortcutDialog::KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget * mainApp = ftnoir; // Preserve a pointer to FTNoIR // Connect Qt signals to member-functions - connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); - connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); for ( int i = 0; i < global_key_sequences.size(); i++) { ui.cbxCenterKey->addItem(global_key_sequences.at(i)); ui.cbxToggleKey->addItem(global_key_sequences.at(i)); } - loadSettings(); -} + tie_setting(mainApp->s.center_key.key_index, ui.cbxCenterKey); + tie_setting(mainApp->s.center_key.alt, ui.chkCenterAlt); + tie_setting(mainApp->s.center_key.shift, ui.chkCenterShift); + tie_setting(mainApp->s.center_key.ctrl, ui.chkCenterCtrl); -// -// Destructor for server-dialog -// -KeyboardShortcutDialog::~KeyboardShortcutDialog() { - qDebug() << "~KeyboardShortcutDialog() says: started"; + tie_setting(mainApp->s.toggle_key.key_index, ui.cbxToggleKey); + tie_setting(mainApp->s.toggle_key.alt, ui.chkToggleAlt); + tie_setting(mainApp->s.toggle_key.shift, ui.chkToggleShift); + tie_setting(mainApp->s.toggle_key.ctrl, ui.chkToggleCtrl); } // // OK clicked on server-dialog // void KeyboardShortcutDialog::doOK() { - save(); + mainApp->b->save(); this->close(); if (mainApp->tracker) mainApp->bindKeyboardShortcuts(); } -void KeyboardShortcutDialog::showEvent ( QShowEvent * ) { - loadSettings(); -} - -// -// Cancel clicked on server-dialog -// void KeyboardShortcutDialog::doCancel() { // // Ask if changed Settings should be saved // - if (settingsDirty) { - int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard ); + if (mainApp->b->modifiedp()) { + int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); qDebug() << "doCancel says: answer =" << ret; switch (ret) { case QMessageBox::Save: - save(); + mainApp->b->save(); this->close(); break; case QMessageBox::Discard: - this->close(); + mainApp->b->revert(); + close(); break; case QMessageBox::Cancel: - // Cancel was clicked - break; default: - // should never be reached break; } } @@ -77,114 +69,6 @@ void KeyboardShortcutDialog::doCancel() { } } -void KeyboardShortcutDialog::loadSettings() { - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - qDebug() << "loadSettings says: iniFile = " << currentFile; - - iniFile.beginGroup ( "KB_Shortcuts" ); - - const char* names[] = { - "Center", "Toggle" - }; - - QComboBox* comboboxen[] = { - ui.cbxCenterKey, - ui.cbxToggleKey - }; - - QCheckBox* boxen[2][3] = { - { - ui.chkCenterShift, - ui.chkCenterCtrl, - ui.chkCenterAlt - }, - { - ui.chkToggleShift, - ui.chkToggleCtrl, - ui.chkToggleAlt - } - }; - - const char* modnames[] = { - "Shift", "Ctrl", "Alt" - }; - - const char* keynames[] = { - "Center", "Toggle" - }; - - const int KEY_COUNT = 2; - const int MODIFIERS = 3; - - for (int i = 0; i < KEY_COUNT; i++) - { - for (int m = 0; m < MODIFIERS; m++) - { - boxen[i][m]->setChecked (iniFile.value ( QString("%1_%2").arg(modnames[m], keynames[i]), 0).toBool()); - } - comboboxen[i]->setCurrentIndex(iniFile.value(QString("Key_index_%1").arg(names[i]), 0).toInt()); - } - - iniFile.endGroup (); - - settingsDirty = false; -} - -void KeyboardShortcutDialog::save() { - const char* keynames[] = { - "Center", "Toggle" - }; - - QComboBox* comboboxen[] = { - ui.cbxCenterKey, - ui.cbxToggleKey - }; - - const char* modnames[] = { - "Shift", "Ctrl", "Alt" - }; - - QCheckBox* boxen[2][3] = { - { - ui.chkCenterShift, - ui.chkCenterCtrl, - ui.chkCenterAlt - }, - { - ui.chkToggleShift, - ui.chkToggleCtrl, - ui.chkToggleAlt - } - }; - - const int MODIFIERS = 3; - const int KEY_COUNT = 2; - - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - iniFile.beginGroup ( "KB_Shortcuts" ); - - for (int i = 0; i < KEY_COUNT; i++) - { - for (int m = 0; m < MODIFIERS; m++) - { - iniFile.setValue(QString("%1_%2").arg(modnames[m], keynames[i]), boxen[i][m]->isChecked()); - } - iniFile.setValue(QString("Key_index_%1").arg(keynames[i]), comboboxen[i]->currentIndex()); - } - - iniFile.endGroup(); - - settingsDirty = false; -} - #if defined(_WIN32) #include diff --git a/facetracknoir/shortcuts.h b/facetracknoir/shortcuts.h index a98211a8..f8c34be7 100644 --- a/facetracknoir/shortcuts.h +++ b/facetracknoir/shortcuts.h @@ -15,16 +15,9 @@ class KeyboardShortcutDialog: public QWidget Q_OBJECT public: - explicit KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget *parent ); - virtual ~KeyboardShortcutDialog(); - void showEvent (QShowEvent *); - + KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget *parent ); private: Ui::UICKeyboardShortcutDialog ui; - void loadSettings(); - void save(); - - bool settingsDirty; FaceTrackNoIR *mainApp; private slots: diff --git a/facetracknoir/tracker.cpp b/facetracknoir/tracker.cpp index 590d44bf..ae4398ff 100644 --- a/facetracknoir/tracker.cpp +++ b/facetracknoir/tracker.cpp @@ -22,14 +22,13 @@ # include #endif -Tracker::Tracker( FaceTrackNoIR *parent ) : +Tracker::Tracker(FaceTrackNoIR *parent , main_settings& s) : + mainApp(parent), + s(s), should_quit(false), do_center(false), - enabled(true), - compensate(true), - tcomp_rz(false) + enabled(true) { - mainApp = parent; } Tracker::~Tracker() @@ -37,18 +36,18 @@ Tracker::~Tracker() } static void get_curve(double pos, double& out, THeadPoseDOF& axis) { - bool altp = (pos < 0) && axis.altp; + bool altp = (pos < 0) && axis.opts.altp; if (altp) { - out = axis.invert * axis.curveAlt.getValue(pos); + out = (axis.opts.invert ? -1 : 1) * axis.curveAlt.getValue(pos); axis.curve.setTrackingActive( false ); axis.curveAlt.setTrackingActive( true ); } else { - out = axis.invert * axis.curve.getValue(pos); + out = (axis.opts.invert ? -1 : 1) * axis.curve.getValue(pos); axis.curve.setTrackingActive( true ); axis.curveAlt.setTrackingActive( false ); } - out += axis.zero; + out += axis.opts.zero; } static void t_compensate(double* input, double* output, bool rz) @@ -131,7 +130,7 @@ void Tracker::run() { do_center = false; if (Libraries->pFilter) - Libraries->pFilter->Initialize(); + Libraries->pFilter->reset(); } T6DOF target_camera, target_camera2, new_camera; @@ -154,8 +153,8 @@ void Tracker::run() { get_curve(new_camera.axes[i], output_camera.axes[i], mainApp->axis(i)); } - if (compensate) - t_compensate(output_camera.axes, output_camera.axes, tcomp_rz); + if (mainApp->s.tcomp_p) + t_compensate(output_camera.axes, output_camera.axes, mainApp->s.tcomp_tz); if (Libraries->pProtocol) { Libraries->pProtocol->sendHeadposeToGame( output_camera.axes ); // degrees & centimeters @@ -188,5 +187,3 @@ void Tracker::getOutputHeadPose( double *data ) { for (int i = 0; i < 6; i++) data[i] = output_camera.axes[i]; } - -void Tracker::setInvertAxis(Axis axis, bool invert) { mainApp->axis(axis).invert = invert? -1.0 : 1.0; } diff --git a/facetracknoir/tracker.h b/facetracknoir/tracker.h index 987b5a24..b671ac7c 100644 --- a/facetracknoir/tracker.h +++ b/facetracknoir/tracker.h @@ -12,53 +12,43 @@ #include #include "global-settings.h" #include +#include #include #include "tracker_types.h" +#include "facetracknoir/main-settings.hpp" +#include "facetracknoir/options.hpp" +using namespace options; class FaceTrackNoIR; // pre-define parent-class to avoid circular includes class THeadPoseDOF { private: - THeadPoseDOF(const THeadPoseDOF &) {} - THeadPoseDOF& operator=(const THeadPoseDOF&) { return *this; } + THeadPoseDOF(const THeadPoseDOF &) = delete; + THeadPoseDOF& operator=(const THeadPoseDOF&) = delete; public: - THeadPoseDOF() : - headPos(0), - invert(0), - altp(false), - zero(0) - { - } - THeadPoseDOF(QString primary, QString secondary, int maxInput1, int maxOutput1, int maxInput2, - int maxOutput2) : + int maxOutput2, + axis_opts* opts) : headPos(0), - invert(1), curve(primary, maxInput1, maxOutput1), curveAlt(secondary, maxInput2, maxOutput2), - zero(0) + opts(*opts) { QSettings settings("opentrack"); QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); QSettings iniFile( currentFile, QSettings::IniFormat ); curve.loadSettings(iniFile); curveAlt.loadSettings(iniFile); - - iniFile.beginGroup("Tracking"); - altp = iniFile.value(secondary).toBool(); - iniFile.endGroup(); } volatile double headPos; - volatile float invert; FunctionConfig curve; FunctionConfig curveAlt; - volatile bool altp; - volatile double zero; + axis_opts& opts; }; class Tracker : public QThread { @@ -67,24 +57,21 @@ class Tracker : public QThread { private: FaceTrackNoIR *mainApp; QMutex mtx; + main_settings& s; protected: void run(); public: - Tracker( FaceTrackNoIR *parent ); + Tracker( FaceTrackNoIR *parent, main_settings& s); ~Tracker(); - void setInvertAxis(Axis axis, bool invert); - void getHeadPose(double *data); void getOutputHeadPose(double *data); volatile bool should_quit; volatile bool do_center; volatile bool enabled; - volatile bool compensate; - volatile bool tcomp_rz; T6DOF output_camera; }; @@ -92,14 +79,14 @@ public: class HeadPoseData { public: THeadPoseDOF* axes[6]; - HeadPoseData() + HeadPoseData(std::vector opts) { - axes[TX] = new THeadPoseDOF("tx","tx_alt", 25, 100, 25, 100); - axes[TY] = new THeadPoseDOF("ty","ty_alt", 25, 100, 25, 100); - axes[TZ] = new THeadPoseDOF("tz","tz_alt", 25, 100, 25, 100); - axes[Yaw] = new THeadPoseDOF("rx", "rx_alt", 180, 180, 180, 180); - axes[Pitch] = new THeadPoseDOF("ry", "ry_alt", 90, 90, 90, 90); - axes[Roll] = new THeadPoseDOF("rz", "rz_alt", 180, 180, 180, 180); + axes[TX] = new THeadPoseDOF("tx","tx_alt", 25, 100, 25, 100, opts[TX]); + axes[TY] = new THeadPoseDOF("ty","ty_alt", 25, 100, 25, 100, opts[TY]); + axes[TZ] = new THeadPoseDOF("tz","tz_alt", 25, 100, 25, 100, opts[TZ]); + axes[Yaw] = new THeadPoseDOF("rx", "rx_alt", 180, 180, 180, 180, opts[Yaw]); + axes[Pitch] = new THeadPoseDOF("ry", "ry_alt", 90, 90, 90, 90, opts[Pitch]); + axes[Roll] = new THeadPoseDOF("rz", "rz_alt", 180, 180, 180, 180, opts[Roll]); } ~HeadPoseData() { -- cgit v1.2.3 From d498588f59c5b33a30bd63cd5d7f55ef8d209ecd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 31 Dec 2013 08:43:02 +0100 Subject: add forgotten settings file for main ui --- facetracknoir/main-settings.hpp | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 facetracknoir/main-settings.hpp (limited to 'facetracknoir') diff --git a/facetracknoir/main-settings.hpp b/facetracknoir/main-settings.hpp new file mode 100644 index 00000000..05c75398 --- /dev/null +++ b/facetracknoir/main-settings.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include +#include "facetracknoir/options.hpp" +using namespace options; + +struct key_opts { + value key_index; + value ctrl, alt, shift; + key_opts(pbundle b, const QString& name) : + key_index(b, QString("key-index-%1").arg(name), 0), + ctrl(b, QString("key-ctrl-%1").arg(name), 0), + alt(b, QString("key-alt-%1").arg(name), 0), + shift(b, QString("key-shift-%1").arg(name), 0) + {} +}; + +struct axis_opts { + value zero; + value invert, altp; + axis_opts(pbundle b, QString pfx) : + zero(b, n(pfx, "zero-pos"), 0), + invert(b, n(pfx, "invert-axis"), false), + altp(b, n(pfx, "alt-axis-sign"), false) + {} +private: + static inline QString n(QString pfx, QString name) { + return QString("%1-%2").arg(pfx, name); + } +}; + +struct main_settings { + pbundle b; + key_opts center_key; + key_opts toggle_key; + value tracker_dll, tracker2_dll, filter_dll, protocol_dll; + axis_opts a_x, a_y, a_z, a_yaw, a_pitch, a_roll; + value tcomp_p, tcomp_tz; + main_settings(pbundle b) : + b(b), + center_key(b, "center"), + toggle_key(b, "toggle"), + tracker_dll(b, "tracker-dll", ""), + tracker2_dll(b, "tracker2-dll", ""), + filter_dll(b, "filter-dll", ""), + protocol_dll(b, "protocol-dll", ""), + a_x(b, "x"), + a_y(b, "y"), + a_z(b, "z"), + a_yaw(b, "yaw"), + a_pitch(b, "pitch"), + a_roll(b, "roll"), + tcomp_p(b, "compensate-translation", true), + tcomp_tz(b, "compensate-translation-disable-z-axis", false) + {} +}; -- cgit v1.2.3 From f460f501d169df9e21825ebe31c9c21fb2692dfa Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 31 Dec 2013 12:40:10 +0100 Subject: rename --- facetracknoir/options.h | 303 ++++++++++++++++++++++++++++++++++++++++++++++ facetracknoir/options.hpp | 303 ---------------------------------------------- 2 files changed, 303 insertions(+), 303 deletions(-) create mode 100644 facetracknoir/options.h delete mode 100644 facetracknoir/options.hpp (limited to 'facetracknoir') diff --git a/facetracknoir/options.h b/facetracknoir/options.h new file mode 100644 index 00000000..1305bd0a --- /dev/null +++ b/facetracknoir/options.h @@ -0,0 +1,303 @@ +/* Copyright (c) 2013 Stanislaw Halik + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __GNUC__ +# define ov override +#else +# define ov +#endif + +namespace options { + template + inline T qcruft_to_t (const QVariant& t); + + template<> + inline int qcruft_to_t(const QVariant& t) + { + return t.toInt(); + } + + template<> + inline QString qcruft_to_t(const QVariant& t) + { + return t.toString(); + } + + template<> + inline bool qcruft_to_t(const QVariant& t) + { + return t.toBool(); + } + + template<> + inline double qcruft_to_t(const QVariant& t) + { + return t.toDouble(); + } + + template<> + inline QVariant qcruft_to_t(const QVariant& t) + { + return t; + } + + // snapshot of qsettings group at given time + class group { + private: + QMap map; + QString name; + public: + group(const QString& name) : name(name) + { + QSettings settings(group::org); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings iniFile(currentFile, QSettings::IniFormat); + iniFile.beginGroup(name); + for (auto& k : iniFile.childKeys()) + map[k] = iniFile.value(k); + iniFile.endGroup(); + } + static constexpr const char* org = "opentrack"; + void save() { + QSettings settings(group::org); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings s(currentFile, QSettings::IniFormat); + s.beginGroup(name); + for (auto& k : map.keys()) + s.setValue(k, map[k]); + s.endGroup(); + } + template + T get(const QString& k) { + return qcruft_to_t(map.value(k)); + } + + void put(const QString& s, const QVariant& d) + { + map[s] = d; + } + bool contains(const QString& s) + { + return map.contains(s); + } + }; + + class impl_bundle : public QObject { + Q_OBJECT + private: + QMutex mtx; + const QString group_name; + group saved; + group transient; + impl_bundle(const impl_bundle&) = delete; + impl_bundle& operator=(const impl_bundle&) = delete; + bool modified; + public: + impl_bundle(const QString& group_name) : + mtx(QMutex::Recursive), + group_name(group_name), + saved(group_name), + transient(saved), + modified(false) + { + } + /* keep in mind doesn't fire signals */ + void reload() { + QMutexLocker l(&mtx); + saved = group(group_name); + transient = saved; + emit reloaded(); + } + + std::shared_ptr make(const QString& name) { + return std::make_shared(name); + } + void store(const QString& name, const QVariant& datum) + { + QMutexLocker l(&mtx); + if (!transient.contains(name) || datum != transient.get(name)) + { + modified = true; + transient.put(name, datum); + emit bundleChanged(); + } + } + bool contains(const QString& name) + { + QMutexLocker l(&mtx); + return transient.contains(name); + } + template + T get(const QString& name) { + QMutexLocker l(&mtx); + return transient.get(name); + } + void save() + { + QMutexLocker l(&mtx); + modified = false; + saved = transient; + transient.save(); + } + void revert() + { + QMutexLocker l(&mtx); + modified = false; + transient = saved; + emit bundleChanged(); + } + + bool modifiedp() { + QMutexLocker l(&mtx); + return modified; + } + signals: + void bundleChanged(); + void reloaded(); + }; + + typedef std::shared_ptr pbundle; + + class base_value : public QObject { + Q_OBJECT + public: + base_value(pbundle b, const QString& name) : b(b), self_name(name) { + connect(b.get(), SIGNAL(reloaded()), this, SLOT(reread_value())); + } + virtual QVariant operator=(const QVariant& datum) = 0; + protected: + pbundle b; + QString self_name; + public slots: + void reread_value() + { + this->operator=(b->get(self_name)); + } + public slots: +#define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(datum); } + DEFINE_SLOT(double) + DEFINE_SLOT(int) + DEFINE_SLOT(QString) + DEFINE_SLOT(bool) + signals: +#define DEFINE_SIGNAL(t) void valueChanged(t); + DEFINE_SIGNAL(double) + DEFINE_SIGNAL(int) + DEFINE_SIGNAL(QString) + DEFINE_SIGNAL(bool) + }; + + template + class value : public base_value { + private: T def; + public: + static constexpr const Qt::ConnectionType CONNTYPE = Qt::QueuedConnection; + value(pbundle b, const QString& name, T def) : + base_value(b, name), def(def) + { + if (!b->contains(name)) + { + QVariant cruft(def); + b->store(self_name, cruft); + } + } + operator T() { return b->get(self_name); } + QVariant operator=(const QVariant& datum) { + b->store(self_name, datum); + auto foo = qcruft_to_t(datum); + emit valueChanged(foo); + return datum; + } + }; + + template + inline void tie_setting(value&, Q*); + + template<> + inline void tie_setting(value& v, QComboBox* cb) + { + base_value::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), cb, SLOT(setCurrentIndex(int)), v.CONNTYPE); + cb->setCurrentIndex(v); + } + + template<> + inline void tie_setting(value& v, QComboBox* cb) + { + base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(QString)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString)), v.CONNTYPE); + cb->setCurrentText(v); + } + + template<> + inline void tie_setting(value& v, QCheckBox* cb) + { + base_value::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool)), v.CONNTYPE); + cb->setChecked(v); + } + + template<> + inline void tie_setting(value& v, QDoubleSpinBox* dsb) + { + base_value::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double)), v.CONNTYPE); + dsb->setValue(v); + } + + template<> + inline void tie_setting(value& v, QSpinBox* sb) + { + base_value::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int)), v.CONNTYPE); + sb->setValue(v); + } + + template<> + inline void tie_setting(value& v, QSlider* sl) + { + base_value::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int)), v.CONNTYPE); + sl->setValue(v); + } + + template<> + inline void tie_setting(value& v, QLineEdit* le) + { + base_value::connect(le, SIGNAL(textChanged(QString)), &v, SLOT(setValue(QString)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(QString)),le, SLOT(setText(QString)), v.CONNTYPE); + le->setText(v); + } + + inline pbundle bundle(const QString& group) { + return std::make_shared(group); + } +} diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp deleted file mode 100644 index 1305bd0a..00000000 --- a/facetracknoir/options.hpp +++ /dev/null @@ -1,303 +0,0 @@ -/* Copyright (c) 2013 Stanislaw Halik - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __GNUC__ -# define ov override -#else -# define ov -#endif - -namespace options { - template - inline T qcruft_to_t (const QVariant& t); - - template<> - inline int qcruft_to_t(const QVariant& t) - { - return t.toInt(); - } - - template<> - inline QString qcruft_to_t(const QVariant& t) - { - return t.toString(); - } - - template<> - inline bool qcruft_to_t(const QVariant& t) - { - return t.toBool(); - } - - template<> - inline double qcruft_to_t(const QVariant& t) - { - return t.toDouble(); - } - - template<> - inline QVariant qcruft_to_t(const QVariant& t) - { - return t; - } - - // snapshot of qsettings group at given time - class group { - private: - QMap map; - QString name; - public: - group(const QString& name) : name(name) - { - QSettings settings(group::org); - QString currentFile = - settings.value("SettingsFile", - QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile(currentFile, QSettings::IniFormat); - iniFile.beginGroup(name); - for (auto& k : iniFile.childKeys()) - map[k] = iniFile.value(k); - iniFile.endGroup(); - } - static constexpr const char* org = "opentrack"; - void save() { - QSettings settings(group::org); - QString currentFile = - settings.value("SettingsFile", - QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings s(currentFile, QSettings::IniFormat); - s.beginGroup(name); - for (auto& k : map.keys()) - s.setValue(k, map[k]); - s.endGroup(); - } - template - T get(const QString& k) { - return qcruft_to_t(map.value(k)); - } - - void put(const QString& s, const QVariant& d) - { - map[s] = d; - } - bool contains(const QString& s) - { - return map.contains(s); - } - }; - - class impl_bundle : public QObject { - Q_OBJECT - private: - QMutex mtx; - const QString group_name; - group saved; - group transient; - impl_bundle(const impl_bundle&) = delete; - impl_bundle& operator=(const impl_bundle&) = delete; - bool modified; - public: - impl_bundle(const QString& group_name) : - mtx(QMutex::Recursive), - group_name(group_name), - saved(group_name), - transient(saved), - modified(false) - { - } - /* keep in mind doesn't fire signals */ - void reload() { - QMutexLocker l(&mtx); - saved = group(group_name); - transient = saved; - emit reloaded(); - } - - std::shared_ptr make(const QString& name) { - return std::make_shared(name); - } - void store(const QString& name, const QVariant& datum) - { - QMutexLocker l(&mtx); - if (!transient.contains(name) || datum != transient.get(name)) - { - modified = true; - transient.put(name, datum); - emit bundleChanged(); - } - } - bool contains(const QString& name) - { - QMutexLocker l(&mtx); - return transient.contains(name); - } - template - T get(const QString& name) { - QMutexLocker l(&mtx); - return transient.get(name); - } - void save() - { - QMutexLocker l(&mtx); - modified = false; - saved = transient; - transient.save(); - } - void revert() - { - QMutexLocker l(&mtx); - modified = false; - transient = saved; - emit bundleChanged(); - } - - bool modifiedp() { - QMutexLocker l(&mtx); - return modified; - } - signals: - void bundleChanged(); - void reloaded(); - }; - - typedef std::shared_ptr pbundle; - - class base_value : public QObject { - Q_OBJECT - public: - base_value(pbundle b, const QString& name) : b(b), self_name(name) { - connect(b.get(), SIGNAL(reloaded()), this, SLOT(reread_value())); - } - virtual QVariant operator=(const QVariant& datum) = 0; - protected: - pbundle b; - QString self_name; - public slots: - void reread_value() - { - this->operator=(b->get(self_name)); - } - public slots: -#define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(datum); } - DEFINE_SLOT(double) - DEFINE_SLOT(int) - DEFINE_SLOT(QString) - DEFINE_SLOT(bool) - signals: -#define DEFINE_SIGNAL(t) void valueChanged(t); - DEFINE_SIGNAL(double) - DEFINE_SIGNAL(int) - DEFINE_SIGNAL(QString) - DEFINE_SIGNAL(bool) - }; - - template - class value : public base_value { - private: T def; - public: - static constexpr const Qt::ConnectionType CONNTYPE = Qt::QueuedConnection; - value(pbundle b, const QString& name, T def) : - base_value(b, name), def(def) - { - if (!b->contains(name)) - { - QVariant cruft(def); - b->store(self_name, cruft); - } - } - operator T() { return b->get(self_name); } - QVariant operator=(const QVariant& datum) { - b->store(self_name, datum); - auto foo = qcruft_to_t(datum); - emit valueChanged(foo); - return datum; - } - }; - - template - inline void tie_setting(value&, Q*); - - template<> - inline void tie_setting(value& v, QComboBox* cb) - { - base_value::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(int)), cb, SLOT(setCurrentIndex(int)), v.CONNTYPE); - cb->setCurrentIndex(v); - } - - template<> - inline void tie_setting(value& v, QComboBox* cb) - { - base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(QString)), v.CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString)), v.CONNTYPE); - cb->setCurrentText(v); - } - - template<> - inline void tie_setting(value& v, QCheckBox* cb) - { - base_value::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool)), v.CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool)), v.CONNTYPE); - cb->setChecked(v); - } - - template<> - inline void tie_setting(value& v, QDoubleSpinBox* dsb) - { - base_value::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double)), v.CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double)), v.CONNTYPE); - dsb->setValue(v); - } - - template<> - inline void tie_setting(value& v, QSpinBox* sb) - { - base_value::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int)), v.CONNTYPE); - sb->setValue(v); - } - - template<> - inline void tie_setting(value& v, QSlider* sl) - { - base_value::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int)), v.CONNTYPE); - sl->setValue(v); - } - - template<> - inline void tie_setting(value& v, QLineEdit* le) - { - base_value::connect(le, SIGNAL(textChanged(QString)), &v, SLOT(setValue(QString)), v.CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(QString)),le, SLOT(setText(QString)), v.CONNTYPE); - le->setText(v); - } - - inline pbundle bundle(const QString& group) { - return std::make_shared(group); - } -} -- cgit v1.2.3 From 85129ee6fcabee8821e301ae64fec81f12df788d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 31 Dec 2013 12:40:55 +0100 Subject: fix doze --- facetracknoir/facetracknoir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index b98c6085..2006f831 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -634,9 +634,9 @@ void FaceTrackNoIR::bind_keyboard_shortcut(QxtGlobalShortcut& key, key_opts& k) } } #else -static void bind_keyboard_shortcut(Key& key, const key& k) +static void bind_keyboard_shortcut(Key& key, key_opts& k) { - const int idx = k.key_index; + int idx = k.key_index; if (idx > 0) { key.keycode = 0; -- cgit v1.2.3 From 77412f01c387ffce47d42bcaad3cf26816591350 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 31 Dec 2013 12:41:12 +0100 Subject: finish rename --- FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h | 2 +- facetracknoir/facetracknoir.h | 2 +- facetracknoir/main-settings.hpp | 2 +- facetracknoir/tracker.h | 2 +- ftnoir_filter_accela/ftnoir_filter_accela.h | 2 +- ftnoir_filter_ewma2/ftnoir_filter_ewma2.h | 2 +- ftnoir_filter_kalman/ftnoir_filter_kalman.h | 2 +- ftnoir_protocol_fg/ftnoir_protocol_fg.h | 2 +- ftnoir_tracker_aruco/ftnoir_tracker_aruco.h | 2 +- ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h | 2 +- ftnoir_tracker_ht/ftnoir_tracker_ht.h | 2 +- ftnoir_tracker_hydra/ftnoir_tracker_hydra.h | 2 +- ftnoir_tracker_rift/ftnoir_tracker_rift.h | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'facetracknoir') diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h index 8c590db2..a828ea48 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h @@ -11,7 +11,7 @@ #include #include "point_tracker.h" -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; struct settings diff --git a/facetracknoir/facetracknoir.h b/facetracknoir/facetracknoir.h index b1279697..53b83754 100644 --- a/facetracknoir/facetracknoir.h +++ b/facetracknoir/facetracknoir.h @@ -51,7 +51,7 @@ #include "ui_facetracknoir.h" -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; #include "facetracknoir/main-settings.hpp" diff --git a/facetracknoir/main-settings.hpp b/facetracknoir/main-settings.hpp index 05c75398..c9b5ff66 100644 --- a/facetracknoir/main-settings.hpp +++ b/facetracknoir/main-settings.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; struct key_opts { diff --git a/facetracknoir/tracker.h b/facetracknoir/tracker.h index b671ac7c..404a8f24 100644 --- a/facetracknoir/tracker.h +++ b/facetracknoir/tracker.h @@ -17,7 +17,7 @@ #include #include "tracker_types.h" #include "facetracknoir/main-settings.hpp" -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; class FaceTrackNoIR; // pre-define parent-class to avoid circular includes diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.h b/ftnoir_filter_accela/ftnoir_filter_accela.h index 1aaa039f..e8f077c3 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.h +++ b/ftnoir_filter_accela/ftnoir_filter_accela.h @@ -10,7 +10,7 @@ #define ACCELA_SECOND_ORDER_ALPHA 100.0 #define ACCELA_THIRD_ORDER_ALPHA 180.0 -#include "facetracknoir/options.hpp" +#include using namespace options; struct settings { diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h index 6e9a7f9a..e50a4284 100644 --- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h @@ -31,7 +31,7 @@ #include "ui_ftnoir_ewma_filtercontrols.h" #include #include -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; struct settings { diff --git a/ftnoir_filter_kalman/ftnoir_filter_kalman.h b/ftnoir_filter_kalman/ftnoir_filter_kalman.h index 8f5bcd8b..25f0a0ad 100644 --- a/ftnoir_filter_kalman/ftnoir_filter_kalman.h +++ b/ftnoir_filter_kalman/ftnoir_filter_kalman.h @@ -21,7 +21,7 @@ #include #include #include -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; class FTNOIR_FILTER_BASE_EXPORT FTNoIR_Filter : public IFilter diff --git a/ftnoir_protocol_fg/ftnoir_protocol_fg.h b/ftnoir_protocol_fg/ftnoir_protocol_fg.h index 13aaeab4..dca1f245 100644 --- a/ftnoir_protocol_fg/ftnoir_protocol_fg.h +++ b/ftnoir_protocol_fg/ftnoir_protocol_fg.h @@ -33,7 +33,7 @@ #include #include #include "facetracknoir/global-settings.h" -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; struct settings { diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h index 23598f4d..2ff40c77 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h @@ -18,7 +18,7 @@ #include #include #include -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; struct settings { diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h index 8739394f..4c0fcb8d 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h @@ -8,7 +8,7 @@ #pragma once #include -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" #include using namespace options; diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.h b/ftnoir_tracker_ht/ftnoir_tracker_ht.h index b3c89136..583249dc 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.h +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.h @@ -15,7 +15,7 @@ #include "ht_video_widget.h" #include "compat/compat.h" #include -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; struct settings { diff --git a/ftnoir_tracker_hydra/ftnoir_tracker_hydra.h b/ftnoir_tracker_hydra/ftnoir_tracker_hydra.h index 8d91dfbb..e569efab 100644 --- a/ftnoir_tracker_hydra/ftnoir_tracker_hydra.h +++ b/ftnoir_tracker_hydra/ftnoir_tracker_hydra.h @@ -5,7 +5,7 @@ #include #include #include "facetracknoir/global-settings.h" -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; struct settings { diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.h b/ftnoir_tracker_rift/ftnoir_tracker_rift.h index b1f96bf2..dd673308 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift.h +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.h @@ -8,7 +8,7 @@ #include "facetracknoir/global-settings.h" #include "OVR.h" #include -#include "facetracknoir/options.hpp" +#include "facetracknoir/options.h" using namespace options; struct settings { -- cgit v1.2.3 From ef92acc3d03d46818317118655bac8574dfb9340 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 31 Dec 2013 13:51:44 +0100 Subject: add qlabel one-way transfer option --- facetracknoir/options.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'facetracknoir') diff --git a/facetracknoir/options.h b/facetracknoir/options.h index 1305bd0a..e77988c7 100644 --- a/facetracknoir/options.h +++ b/facetracknoir/options.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #ifdef __GNUC__ @@ -297,6 +298,13 @@ namespace options { le->setText(v); } + template<> + inline void tie_setting(value& v, QLabel* lb) + { + base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.CONNTYPE); + lb->setText(v); + } + inline pbundle bundle(const QString& group) { return std::make_shared(group); } -- cgit v1.2.3 From 478923fa291949af2ce1f307f9dd592f451508df Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 12:13:25 +0100 Subject: fix qvariant saying invalid when they're not --- facetracknoir/options.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.h b/facetracknoir/options.h index e77988c7..7ecf6280 100644 --- a/facetracknoir/options.h +++ b/facetracknoir/options.h @@ -32,6 +32,8 @@ # define ov #endif +#include + namespace options { template inline T qcruft_to_t (const QVariant& t); @@ -193,8 +195,8 @@ namespace options { base_value(pbundle b, const QString& name) : b(b), self_name(name) { connect(b.get(), SIGNAL(reloaded()), this, SLOT(reread_value())); } - virtual QVariant operator=(const QVariant& datum) = 0; protected: + virtual QVariant operator=(const QVariant& datum) = 0; pbundle b; QString self_name; public slots: @@ -203,7 +205,7 @@ namespace options { this->operator=(b->get(self_name)); } public slots: -#define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(datum); } +#define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(qVariantFromValue(datum)); } DEFINE_SLOT(double) DEFINE_SLOT(int) DEFINE_SLOT(QString) @@ -218,24 +220,29 @@ namespace options { template class value : public base_value { - private: T def; + private: + T def; + protected: + QVariant operator=(const QVariant& datum) { + auto foo = qcruft_to_t(datum); + b->store(self_name, qVariantFromValue(foo)); + emit valueChanged(foo); + return datum; + } public: static constexpr const Qt::ConnectionType CONNTYPE = Qt::QueuedConnection; value(pbundle b, const QString& name, T def) : base_value(b, name), def(def) { - if (!b->contains(name)) + if (!b->contains(name) || b->get(name).type() == QVariant::Invalid) { - QVariant cruft(def); - b->store(self_name, cruft); + this->operator=(qVariantFromValue(def)); } } operator T() { return b->get(self_name); } - QVariant operator=(const QVariant& datum) { - b->store(self_name, datum); - auto foo = qcruft_to_t(datum); - emit valueChanged(foo); - return datum; + QVariant operator=(const T& datum) + { + return this->operator =(qVariantFromValue(datum)); } }; -- cgit v1.2.3 From e18f6c36733b206167470619bf97040fa4a3b99f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 12:24:25 +0100 Subject: reload profile combobox at appropriate time and place --- facetracknoir/facetracknoir.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index 2006f831..6e97080d 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -262,6 +262,7 @@ void FaceTrackNoIR::open() { QSettings settings("opentrack"); settings.setValue ("SettingsFile", QFileInfo(fileName).absoluteFilePath()); } + fill_profile_cbx(); loadSettings(); } } @@ -587,10 +588,6 @@ void FaceTrackNoIR::fill_profile_cbx() ui.iconcomboProfile->clear(); for ( int i = 0; i < iniFileList.size(); i++) { ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), iniFileList.at(i)); - if (iniFileList.at(i) == pathInfo.fileName()) { - ui.iconcomboProfile->setItemIcon(i, QIcon(":/images/settingsopen16.png")); - ui.iconcomboProfile->setCurrentIndex( i ); - } } looping = false; } @@ -602,11 +599,6 @@ void FaceTrackNoIR::profileSelected(int index) QFileInfo pathInfo ( currentFile ); settings.setValue ("SettingsFile", pathInfo.absolutePath() + "/" + ui.iconcomboProfile->itemText(index)); loadSettings(); - if (looping) - return; - looping = true; - fill_profile_cbx(); - looping = false; } #if !defined(_WIN32) -- cgit v1.2.3 From ec3fe4414268acb83c04194247087389c3d1f7f2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 12:35:58 +0100 Subject: reload profile list when saving a new one --- facetracknoir/facetracknoir.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'facetracknoir') diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index 6e97080d..08cd9dfa 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -313,6 +313,8 @@ void FaceTrackNoIR::saveAs() settings.setValue ("SettingsFile", fileName); save(); } + + fill_profile_cbx(); } void FaceTrackNoIR::loadSettings() { -- cgit v1.2.3 From 36ca50cb9a5d575d3fb6ea1b5062c2f96a906b4b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 12:36:43 +0100 Subject: load right profile when using multiple ones (duh) --- facetracknoir/facetracknoir.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'facetracknoir') diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index 08cd9dfa..2bb36a78 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -590,6 +590,10 @@ void FaceTrackNoIR::fill_profile_cbx() ui.iconcomboProfile->clear(); for ( int i = 0; i < iniFileList.size(); i++) { ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), iniFileList.at(i)); + if (iniFileList.at(i) == pathInfo.fileName()) { + ui.iconcomboProfile->setItemIcon(i, QIcon(":/images/settingsopen16.png")); + ui.iconcomboProfile->setCurrentIndex( i ); + } } looping = false; } -- cgit v1.2.3 From e38d6ab7472e9adb6bac0550fdffebb748ac4353 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 12:41:29 +0100 Subject: get rid of useless active profile icon --- facetracknoir/facetracknoir.cpp | 1 - facetracknoir/images/settingsopen16.png | Bin 686 -> 0 bytes facetracknoir/main-facetracknoir.qrc | 1 - 3 files changed, 2 deletions(-) delete mode 100644 facetracknoir/images/settingsopen16.png (limited to 'facetracknoir') diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index 2bb36a78..309a4a93 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -591,7 +591,6 @@ void FaceTrackNoIR::fill_profile_cbx() for ( int i = 0; i < iniFileList.size(); i++) { ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), iniFileList.at(i)); if (iniFileList.at(i) == pathInfo.fileName()) { - ui.iconcomboProfile->setItemIcon(i, QIcon(":/images/settingsopen16.png")); ui.iconcomboProfile->setCurrentIndex( i ); } } diff --git a/facetracknoir/images/settingsopen16.png b/facetracknoir/images/settingsopen16.png deleted file mode 100644 index 5bf65f0d..00000000 Binary files a/facetracknoir/images/settingsopen16.png and /dev/null differ diff --git a/facetracknoir/main-facetracknoir.qrc b/facetracknoir/main-facetracknoir.qrc index eb5ad991..6cb2e300 100644 --- a/facetracknoir/main-facetracknoir.qrc +++ b/facetracknoir/main-facetracknoir.qrc @@ -2,7 +2,6 @@ uielements/tools.png images/settings16.png - images/settingsopen16.png uielements/curves.png images/facetracknoir.png -- cgit v1.2.3 From 9f0ba65825054b182d9a9c2b53dad955a90d4df1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 13:40:41 +0100 Subject: base spline widget size on config size --- facetracknoir/ftnoir_curves.ui | 12 ++++++------ qfunctionconfigurator/functionconfig.h | 2 ++ qfunctionconfigurator/qfunctionconfigurator.cpp | 7 +++++-- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/ftnoir_curves.ui b/facetracknoir/ftnoir_curves.ui index f96df044..9b5c8d07 100644 --- a/facetracknoir/ftnoir_curves.ui +++ b/facetracknoir/ftnoir_curves.ui @@ -325,7 +325,7 @@ 100 - 7 + 28 2 @@ -374,7 +374,7 @@ 100 - 7 + 28 2 @@ -415,7 +415,7 @@ 100 - 7 + 28 2 @@ -464,7 +464,7 @@ 100 - 7 + 28 2 @@ -505,7 +505,7 @@ 100 - 7 + 28 2 @@ -554,7 +554,7 @@ 100 - 7 + 28 2 diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h index d809259b..ab2d0d0c 100644 --- a/qfunctionconfigurator/functionconfig.h +++ b/qfunctionconfigurator/functionconfig.h @@ -32,6 +32,8 @@ private: int _max_Output; FunctionConfig(const FunctionConfig&) = delete; public: + const int maxInput() const { return _max_Input; } + const int maxOutput() const { return _max_Output; } // // Contructor(s) and destructor // diff --git a/qfunctionconfigurator/qfunctionconfigurator.cpp b/qfunctionconfigurator/qfunctionconfigurator.cpp index 4ad0a9a4..5a02a826 100644 --- a/qfunctionconfigurator/qfunctionconfigurator.cpp +++ b/qfunctionconfigurator/qfunctionconfigurator.cpp @@ -31,8 +31,7 @@ QFunctionConfigurator::QFunctionConfigurator(QWidget *parent) // // Defaults, for when the widget has no values different from the domXML() // - MaxInput = 50; // Maximum input limit - MaxOutput = 180; // Maximum output limit + pPerEGU_Output = 1; // Number of pixels, per EGU pPerEGU_Input = 4; // Number of pixels, per EGU gDistEGU_Input = 5; // Distance of gridlines @@ -74,6 +73,10 @@ void QFunctionConfigurator::setConfig(FunctionConfig* config, QString settingsFi setCaption(config->getTitle()); _draw_function = _draw_background = true; + + setmaxInputEGU(config->maxInput()); + setmaxOutputEGU(config->maxOutput()); + this->update(); } -- cgit v1.2.3 From 04709d458eb5449739648fedb6aa8e60fc9cf7f1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 14:00:38 +0100 Subject: don't gray out the wrong buttons when tracking --- facetracknoir/facetracknoir.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index 309a4a93..85207b53 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -328,15 +328,13 @@ void FaceTrackNoIR::updateButtonState(bool running) ui.iconcomboProfile->setEnabled ( e ); ui.btnLoad->setEnabled ( e ); ui.btnSaveAs->setEnabled ( e ); - ui.btnShowFilterControls->setEnabled ( e ); ui.btnStartTracker->setEnabled ( e ); ui.btnStopTracker->setEnabled ( running ); - - ui.iconcomboTrackerSource->setEnabled ( e ); - ui.cbxSecondTrackerSource->setEnabled ( e ); ui.iconcomboProtocol->setEnabled ( e ); ui.btnShowServerControls->setEnabled ( e ); ui.iconcomboFilter->setEnabled ( e ); + ui.iconcomboTrackerSource->setEnabled(e); + ui.cbxSecondTrackerSource->setEnabled(e); ui.btnStartTracker->setEnabled(e); ui.btnStopTracker->setEnabled(running); -- cgit v1.2.3 From 53d7258c0151893e95f569cf7f9386d269618672 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Jan 2014 14:37:15 +0100 Subject: remove outdated comment --- facetracknoir/options.h | 1 - 1 file changed, 1 deletion(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options.h b/facetracknoir/options.h index 7ecf6280..bc53a456 100644 --- a/facetracknoir/options.h +++ b/facetracknoir/options.h @@ -132,7 +132,6 @@ namespace options { modified(false) { } - /* keep in mind doesn't fire signals */ void reload() { QMutexLocker l(&mtx); saved = group(group_name); -- cgit v1.2.3 From 519434cd1abb8991635487c6d84bc0d85367fc42 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Jan 2014 10:57:02 +0100 Subject: How about an octopus instead? --- facetracknoir/facetracknoir.ico | Bin 23558 -> 67134 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/facetracknoir.ico b/facetracknoir/facetracknoir.ico index 5115066c..5cac8da1 100644 Binary files a/facetracknoir/facetracknoir.ico and b/facetracknoir/facetracknoir.ico differ -- cgit v1.2.3