summaryrefslogtreecommitdiffhomepage
path: root/variant/default
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-07-14 09:08:45 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-07-14 09:09:36 +0200
commit90e7bf2962a798a0a89c92a31a2141946221012a (patch)
treee89009c30adc5459c4045da20e89fced5698bcab /variant/default
parenta42fefc9c0bbc7aafeff58ae2898c326f9aaab11 (diff)
opentrack: move macros away from header file
Diffstat (limited to 'variant/default')
-rw-r--r--variant/default/main-window.cpp83
-rw-r--r--variant/default/main-window.hpp14
2 files changed, 47 insertions, 50 deletions
diff --git a/variant/default/main-window.cpp b/variant/default/main-window.cpp
index 5e90d287..76a6d404 100644
--- a/variant/default/main-window.cpp
+++ b/variant/default/main-window.cpp
@@ -17,7 +17,9 @@
#include "compat/library-path.hpp"
#include "compat/math.hpp"
+#include <algorithm>
#include <iterator>
+#include <utility>
#include <QMessageBox>
#include <QDesktopServices>
@@ -367,7 +369,7 @@ bool main_window::maybe_die_on_config_not_writable(const QString& current, QStri
return false;
const bool open = QFile(ini_combine(current)).open(QFile::ReadWrite);
- const QStringList list = ini_list();
+ QStringList list = ini_list();
if (!list.contains(current) || !open)
{
@@ -376,7 +378,7 @@ bool main_window::maybe_die_on_config_not_writable(const QString& current, QStri
}
if (ini_list_ != nullptr)
- *ini_list_ = list;
+ *ini_list_ = std::move(list);
return false;
}
@@ -692,53 +694,62 @@ void main_window::show_pose()
display_pose(mapped, raw);
}
-template<typename t, typename F>
-bool main_window::mk_window_common(std::unique_ptr<t>& d, F&& ctor)
+template<typename t, typename... Args>
+bool mk_window(std::unique_ptr<t>& place, Args&&... params)
{
- if (d)
- {
- d->show();
- d->raise();
+ return mk_window_common(place, [&] {
+ return std::make_unique<t>(params...);
+ });
+}
- return false;
- }
- else if ((d = std::unique_ptr<t>(ctor())))
- {
- QWidget& w = *d;
+template<typename t>
+bool mk_dialog(std::unique_ptr<t>& place, const std::shared_ptr<dylib>& lib)
+{
+ using u = std::unique_ptr<t>;
- w.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | w.windowFlags());
- w.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ return mk_window_common(place, [&] {
+ if (lib && lib->Dialog)
+ return u{ (t*)lib->Dialog() };
+ else
+ return u{};
+ });
+}
- w.show();
- w.adjustSize();
+template<typename t, typename F>
+bool mk_window_common(std::unique_ptr<t>& d, F&& fun)
+{
+ bool fresh = false;
- return true;
- }
+ if (!d)
+ d = fun(), fresh = !!d;
- return false;
-}
+ if (d)
+ show_window(*d, fresh);
-template<typename t, typename... Args>
-inline bool main_window::mk_window(std::unique_ptr<t>& place, Args&&... params)
-{
- return mk_window_common(place, [&] { return new t(params...); });
+ return fresh;
}
-template<typename t>
-bool main_window::mk_dialog(const std::shared_ptr<dylib>& lib, std::unique_ptr<t>& d)
+void show_window(QWidget& d, bool fresh)
{
- const bool just_created = mk_window_common(d, [&]() -> t* {
- if (lib && lib->Dialog)
- return (t*) lib->Dialog();
- return nullptr;
- });
+ if (fresh)
+ {
+ d.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | d.windowFlags());
+ d.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- return just_created;
+ d.show();
+ d.adjustSize();
+ d.raise();
+ }
+ else
+ {
+ d.show();
+ d.raise();
+ }
}
void main_window::show_tracker_settings()
{
- if (mk_dialog(current_tracker(), pTrackerDialog) && work && work->libs.pTracker)
+ if (mk_dialog(pTrackerDialog, current_tracker()) && work && work->libs.pTracker)
pTrackerDialog->register_tracker(work->libs.pTracker.get());
if (pTrackerDialog)
QObject::connect(pTrackerDialog.get(), &ITrackerDialog::closing,
@@ -747,7 +758,7 @@ void main_window::show_tracker_settings()
void main_window::show_proto_settings()
{
- if (mk_dialog(current_protocol(), pProtocolDialog) && work && work->libs.pProtocol)
+ if (mk_dialog(pProtocolDialog, current_protocol()) && work && work->libs.pProtocol)
pProtocolDialog->register_protocol(work->libs.pProtocol.get());
if (pProtocolDialog)
QObject::connect(pProtocolDialog.get(), &IProtocolDialog::closing,
@@ -756,7 +767,7 @@ void main_window::show_proto_settings()
void main_window::show_filter_settings()
{
- if (mk_dialog(current_filter(), pFilterDialog) && work && work->libs.pFilter)
+ if (mk_dialog(pFilterDialog, current_filter()) && work && work->libs.pFilter)
pFilterDialog->register_filter(work->libs.pFilter.get());
if (pFilterDialog)
QObject::connect(pFilterDialog.get(), &IFilterDialog::closing,
diff --git a/variant/default/main-window.hpp b/variant/default/main-window.hpp
index 823c5191..3c55be9e 100644
--- a/variant/default/main-window.hpp
+++ b/variant/default/main-window.hpp
@@ -32,8 +32,6 @@
#include <QEvent>
#include <QCloseEvent>
-#include <algorithm>
-#include <vector>
#include <tuple>
#include <memory>
@@ -98,18 +96,6 @@ class main_window final : public QMainWindow, private State
void annoy_if_root();
#endif
- // only use in impl file since no definition in header!
- template<typename t>
- bool mk_dialog(const std::shared_ptr<dylib>& lib, std::unique_ptr<t>& d);
-
- // idem
- template<typename t, typename... Args>
- inline bool mk_window(std::unique_ptr<t>& place, Args&&... params);
-
- // idem
- template<typename t, typename F>
- bool mk_window_common(std::unique_ptr<t>& d, F&& ctor);
-
void closeEvent(QCloseEvent *event) override;
bool maybe_die_on_config_not_writable(const QString& current, QStringList* ini_list);