From 1cac120c0b6b460899add3546d013b628d6b54bc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 13 Jul 2018 19:39:15 +0200 Subject: WIP --- main-window/CMakeLists.txt | 4 ++ main-window/export.hpp | 11 ++++ main-window/lang/nl_NL.ts | 4 ++ main-window/lang/ru_RU.ts | 4 ++ main-window/lang/stub.ts | 4 ++ main-window/lang/zh_CN.ts | 4 ++ main-window/mixin-traits.cpp | 39 ++++++++++++ main-window/mixin-traits.hpp | 63 ++++++++++++++++++++ main-window/mixins.hpp | 13 ++++ main-window/module-mixin.cpp | 132 +++++++++++++++++++++++++++++++++++++++++ main-window/module-mixin.hpp | 58 ++++++++++++++++++ main-window/tracking-mixin.cpp | 5 ++ main-window/tracking-mixin.hpp | 19 ++++++ 13 files changed, 360 insertions(+) create mode 100644 main-window/CMakeLists.txt create mode 100644 main-window/export.hpp create mode 100644 main-window/lang/nl_NL.ts create mode 100644 main-window/lang/ru_RU.ts create mode 100644 main-window/lang/stub.ts create mode 100644 main-window/lang/zh_CN.ts create mode 100644 main-window/mixin-traits.cpp create mode 100644 main-window/mixin-traits.hpp create mode 100644 main-window/mixins.hpp create mode 100644 main-window/module-mixin.cpp create mode 100644 main-window/module-mixin.hpp create mode 100644 main-window/tracking-mixin.cpp create mode 100644 main-window/tracking-mixin.hpp (limited to 'main-window') diff --git a/main-window/CMakeLists.txt b/main-window/CMakeLists.txt new file mode 100644 index 00000000..3edd241b --- /dev/null +++ b/main-window/CMakeLists.txt @@ -0,0 +1,4 @@ +otr_module(main-window BIN) +foreach(k user-interface logic pose-widget migration spline) + target_link_libraries(${self} opentrack-${k}) +endforeach() diff --git a/main-window/export.hpp b/main-window/export.hpp new file mode 100644 index 00000000..184cf035 --- /dev/null +++ b/main-window/export.hpp @@ -0,0 +1,11 @@ +// generates export.hpp for each module from compat/linkage.hpp + +#pragma once + +#include "compat/linkage-macros.hpp" + +#ifdef BUILD_MAIN_WINDOW +# define OTR_MAIN_EXPORT OTR_GENERIC_EXPORT +#else +# define OTR_MAIN_EXPORT OTR_GENERIC_IMPORT +#endif diff --git a/main-window/lang/nl_NL.ts b/main-window/lang/nl_NL.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/main-window/lang/nl_NL.ts @@ -0,0 +1,4 @@ + + + + diff --git a/main-window/lang/ru_RU.ts b/main-window/lang/ru_RU.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/main-window/lang/ru_RU.ts @@ -0,0 +1,4 @@ + + + + diff --git a/main-window/lang/stub.ts b/main-window/lang/stub.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/main-window/lang/stub.ts @@ -0,0 +1,4 @@ + + + + diff --git a/main-window/lang/zh_CN.ts b/main-window/lang/zh_CN.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/main-window/lang/zh_CN.ts @@ -0,0 +1,4 @@ + + + + diff --git a/main-window/mixin-traits.cpp b/main-window/mixin-traits.cpp new file mode 100644 index 00000000..4b34eb5b --- /dev/null +++ b/main-window/mixin-traits.cpp @@ -0,0 +1,39 @@ +#pragma once + +#define MIXIN_TRAIT_TESTS + +#ifdef MIXIN_TRAIT_TESTS +# include "mixin-traits.hpp" + +namespace mixins::traits_detail { + +struct A {}; +struct B : A {}; +struct C {}; + +template<> struct mixin_traits +{ + using depends = tuple; +}; + +template<> struct mixin_traits +{ + using depends = tuple; +}; + +template<> struct mixin_traits +{ + using depends = tuple; +}; + +extern void test1(); + +void test1() +{ + //impl fail1; + impl ok1; +} + +} // ns mixins::traits_detail + +#endif diff --git a/main-window/mixin-traits.hpp b/main-window/mixin-traits.hpp new file mode 100644 index 00000000..e7d02c85 --- /dev/null +++ b/main-window/mixin-traits.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include "compat/linkage-macros.hpp" +#include "compat/macros.hpp" +#include "compat/meta.hpp" + +#include + +namespace mixins::traits_detail { + + using namespace meta; + template + using tuple = meta::detail::tuple; + + template + struct mixin_traits { + using depends = tuple<>; + }; + + template struct check_depends_; + + template + struct check_depends_ + { + static constexpr bool recurse() { return true; } + }; + + template + struct check_depends_ + { + static constexpr bool recurse() + { + using depends = typename mixin_traits::depends; + + return (std::is_base_of_v || std::is_same_v) && + check_depends_::recurse() && + lift>::recurse(); + } + }; + +#if 0 + template + static constexpr void check_depends_recursively() + { + std::is_base_of_v && + assert_depends::check_depends() + + using depends = typename mixin_traits::depends; + static_assert(lift>::check_depends()); + + using car = first; + using cdr = rest; + + check_depends_recursively(); + } +#endif + + template + class impl + { + static_assert(lift::depends>>::recurse()); + }; +} // ns mixins::traits_detail diff --git a/main-window/mixins.hpp b/main-window/mixins.hpp new file mode 100644 index 00000000..b85e6498 --- /dev/null +++ b/main-window/mixins.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "export.hpp" + +// XXX TODO add is_base_of and void_t stuff + +#define OTR_MIXIN_NS(name) \ + mixins :: detail :: name + +#define OTR_DECLARE_MIXIN(name) \ + namespace mixins { \ + using name = :: OTR_MIXIN_NS(name) :: name; \ + } diff --git a/main-window/module-mixin.cpp b/main-window/module-mixin.cpp new file mode 100644 index 00000000..67485ba2 --- /dev/null +++ b/main-window/module-mixin.cpp @@ -0,0 +1,132 @@ +#include "module-mixin.hpp" + +#include + +namespace OTR_MIXIN_NS(module_mixin) { + +std::tuple +module_mixin::module_by_name(const QString& name, const dylib_list& list) const +{ + auto it = std::find_if(list.cbegin(), list.cend(), [&name](const dylib_ptr& lib) { + if (!lib) + return name.isEmpty(); + else + return name == lib->module_name; + }); + + if (it == list.cend()) + return { nullptr, -1 }; + else + return { *it, int(std::distance(list.cbegin(), it)) }; +} + +static void show_window(QWidget& d, bool fresh) +{ + if (fresh) + { + d.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | d.windowFlags()); + d.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + d.show(); + d.adjustSize(); + d.raise(); + } + else + { + d.show(); + d.raise(); + } +} + +template +static bool mk_window_common(std::unique_ptr& d, F&& fun) +{ + bool fresh = false; + + if (!d) + d = fun(), fresh = !!d; + + if (d) + show_window(*d, fresh); + + return fresh; +} + +template +static bool mk_dialog(std::unique_ptr& place, const std::shared_ptr& lib) +{ + using u = std::unique_ptr; + + return mk_window_common(place, [&] { + if (lib && lib->Dialog) + return u{ (t*)lib->Dialog() }; + else + return nullptr; + }); +} + +dylib_ptr module_mixin::current_tracker() +{ + auto [ptr, idx] = module_by_name(s.tracker_dll, modules.trackers()); + return ptr; +} + +dylib_ptr module_mixin::current_protocol() +{ + auto [ptr, idx] = module_by_name(s.protocol_dll, modules.protocols()); + return ptr; +} + +dylib_ptr module_mixin::current_filter() +{ + auto [ptr, idx] = module_by_name(s.filter_dll, modules.filters()); + return ptr; +} + +void module_mixin::show_tracker_settings() +{ +#if 0 + if (mk_dialog(tracker_dialog, current_tracker()) && work && work->libs.pTracker) + tracker_dialog->register_tracker(work->libs.pTracker.get()); + if (tracker_dialog) + QObject::connect(tracker_dialog.get(), &ITrackerDialog::closing, + this, [this] { tracker_dialog = nullptr; }); +#endif +} + +void module_mixin::show_proto_settings() +{ +#if 0 + if (mk_dialog(proto_dialog, current_protocol()) && work && work->libs.pProtocol) + proto_dialog->register_protocol(work->libs.pProtocol.get()); + if (proto_dialog) + QObject::connect(proto_dialog.get(), &IProtocolDialog::closing, + this, [this] { proto_dialog = nullptr; }); +#endif +} + +void module_mixin::show_filter_settings() +{ +#if 0 + if (mk_dialog(filter_dialog, current_filter()) && work && work->libs.pFilter) + filter_dialog->register_filter(work->libs.pFilter.get()); + if (filter_dialog) + QObject::connect(filter_dialog.get(), &IFilterDialog::closing, + this, [this] { filter_dialog = nullptr; }); +#endif +} + +template +static bool mk_window(std::unique_ptr& place, Args&&... params) +{ + return mk_window_common(place, [&] { + return std::make_unique(params...); + }); +} + +module_mixin::module_mixin() = default; +module_mixin::~module_mixin() = default; + +module_settings::module_settings() = default; + +} // ns diff --git a/main-window/module-mixin.hpp b/main-window/module-mixin.hpp new file mode 100644 index 00000000..307d79b8 --- /dev/null +++ b/main-window/module-mixin.hpp @@ -0,0 +1,58 @@ +#pragma once + +#include "mixins.hpp" +#include "compat/library-path.hpp" +#include "api/plugin-api.hpp" +#include "logic/extensions.hpp" +#include "logic/work.hpp" + +#include +#include + +#include +#include + +namespace OTR_MIXIN_NS(module_mixin) { + +using namespace options; + +using dylib_ptr = Modules::dylib_ptr; +using dylib_list = Modules::dylib_list; + +struct OTR_MAIN_EXPORT module_settings final +{ + bundle b { make_bundle("modules") }; + value tracker_dll { b, "tracker-dll", "pt" }, + filter_dll { b, "filter-dll", "accela" }, + protocol_dll { b, "protocol-dll", "freetrack" }; + module_settings(); +}; + +struct OTR_MAIN_EXPORT module_mixin +{ + module_mixin(); + virtual ~module_mixin(); + + std::unique_ptr tracker_dialog; + std::unique_ptr proto_dialog; + std::unique_ptr filter_dialog; + + std::tuple module_by_name(const QString& name, const dylib_list& list) const; + + dylib_ptr current_tracker(); + dylib_ptr current_protocol(); + dylib_ptr current_filter(); + + void show_tracker_settings(); + void show_proto_settings(); + void show_filter_settings(); + +private: + Modules modules { OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH }; + event_handler ev { modules.extensions() }; + module_settings s; +}; + +} + +OTR_DECLARE_MIXIN(module_mixin) diff --git a/main-window/tracking-mixin.cpp b/main-window/tracking-mixin.cpp new file mode 100644 index 00000000..1ec6f3d5 --- /dev/null +++ b/main-window/tracking-mixin.cpp @@ -0,0 +1,5 @@ +#include "tracking-mixin.hpp" + +using namespace OTR_MIXIN_NS(tracking_mixin); + +has_work::has_work::~has_work() = default; diff --git a/main-window/tracking-mixin.hpp b/main-window/tracking-mixin.hpp new file mode 100644 index 00000000..e48ca630 --- /dev/null +++ b/main-window/tracking-mixin.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "mixins.hpp" + +#include "logic/work.hpp" + +#include + +namespace OTR_MIXIN_NS(tracking_mixin) { + +using work_ptr = std::shared_ptr; + +struct OTR_MAIN_EXPORT has_work { + virtual explicit operator work_ptr() = 0; + inline has_work() = default; + virtual ~has_work(); +}; + +} -- cgit v1.2.3