summaryrefslogtreecommitdiffhomepage
path: root/variant/default
diff options
context:
space:
mode:
Diffstat (limited to 'variant/default')
-rw-r--r--variant/default/main-window.cpp74
-rw-r--r--variant/default/main-window.hpp44
2 files changed, 63 insertions, 55 deletions
diff --git a/variant/default/main-window.cpp b/variant/default/main-window.cpp
index b3895976..44f6c892 100644
--- a/variant/default/main-window.cpp
+++ b/variant/default/main-window.cpp
@@ -31,7 +31,11 @@ extern "C" const char* const opentrack_version;
using namespace options::globals;
using namespace options;
-main_window::main_window() : State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH)
+main_window::main_window() : State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH),
+ start_tracker{this, &main_window::start_tracker_, Qt::QueuedConnection},
+ stop_tracker{this, &main_window::stop_tracker_, Qt::QueuedConnection},
+ toggle_tracker{this, &main_window::toggle_tracker_, Qt::QueuedConnection},
+ restart_tracker{this, &main_window::restart_tracker_, Qt::QueuedConnection}
{
ui.setupUi(this);
@@ -57,30 +61,15 @@ main_window::main_window() : State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH)
else
setVisible(false);
- connect(&pose_update_timer, &QTimer::timeout, this, &main_window::show_pose, Qt::DirectConnection);
-
- connect(&det_timer, SIGNAL(timeout()), this, SLOT(maybe_start_profile_from_executable()));
+ connect(&pose_update_timer, &QTimer::timeout,
+ this, &main_window::show_pose, Qt::DirectConnection);
+ connect(&det_timer, &QTimer::timeout,
+ this, &main_window::maybe_start_profile_from_executable);
det_timer.start(1000);
}
void main_window::init_shortcuts()
{
- connect(this, &main_window::start_tracker,
- this, [&] { qDebug() << "start tracker"; start_tracker_(); },
- Qt::QueuedConnection);
-
- connect(this, &main_window::stop_tracker,
- this, [&] { qDebug() << "stop tracker"; stop_tracker_(); },
- Qt::QueuedConnection);
-
- connect(this, &main_window::toggle_tracker,
- this, [&] { qDebug() << "toggle tracker"; if (work) stop_tracker_(); else start_tracker_(); },
- Qt::QueuedConnection);
-
- connect(this, &main_window::restart_tracker,
- this, [&] { qDebug() << "restart tracker"; stop_tracker_(); start_tracker_(); },
- Qt::QueuedConnection);
-
register_shortcuts();
// ctrl+q exits
@@ -164,16 +153,16 @@ void main_window::init_profiles()
set_profile(ini_filename());
// profile menu
- profile_menu.addAction(tr("Create new empty config"), this, SLOT(make_empty_config()));
- profile_menu.addAction(tr("Create new copied config"), this, SLOT(make_copied_config()));
- profile_menu.addAction(tr("Open configuration directory"), this, SLOT(open_config_directory()));
+ profile_menu.addAction(tr("Create new empty config"), this, &main_window::make_empty_config);
+ profile_menu.addAction(tr("Create new copied config"), this, &main_window::make_copied_config);
+ profile_menu.addAction(tr("Open configuration directory"), this, &main_window::open_config_directory);
ui.profile_button->setMenu(&profile_menu);
- connect(&config_list_timer, &QTimer::timeout, this, [this] { refresh_config_list(); });
+ connect(&config_list_timer, &QTimer::timeout, this, &main_window::refresh_config_list);
config_list_timer.start(1000 * 5);
connect(ui.iconcomboProfile, &QComboBox::currentTextChanged,
- this, [this](const QString& x) { set_profile(x); });
+ this, [this](const QString& x) { main_window::set_profile(x); });
}
void main_window::init_tray_menu()
@@ -232,8 +221,7 @@ void main_window::init_tray_menu()
QObject::connect(&menu_action_exit, &QAction::triggered, this, &main_window::exit);
tray_menu.addAction(&menu_action_exit);
- connect(&s.tray_enabled,
- static_cast<void (value_::*)(bool) const>(&value_::valueChanged),
+ connect(&s.tray_enabled, value_::value_changed<bool>(),
this, &main_window::ensure_tray);
ensure_tray();
@@ -242,13 +230,13 @@ void main_window::init_tray_menu()
void main_window::init_buttons()
{
update_button_state(false, false);
- connect(ui.btnEditCurves, SIGNAL(clicked()), this, SLOT(show_mapping_window()));
- connect(ui.btnShortcuts, SIGNAL(clicked()), this, SLOT(show_options_dialog()));
- connect(ui.btnShowEngineControls, SIGNAL(clicked()), this, SLOT(show_tracker_settings()));
- connect(ui.btnShowServerControls, SIGNAL(clicked()), this, SLOT(show_proto_settings()));
- connect(ui.btnShowFilterControls, SIGNAL(clicked()), this, SLOT(show_filter_settings()));
- connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(start_tracker_()));
- connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stop_tracker_()));
+ connect(ui.btnEditCurves, &QPushButton::clicked, this, &main_window::show_mapping_window);
+ connect(ui.btnShortcuts, &QPushButton::clicked, this, &main_window::show_options_dialog);
+ connect(ui.btnShowEngineControls, &QPushButton::clicked, this, &main_window::show_tracker_settings);
+ connect(ui.btnShowServerControls, &QPushButton::clicked, this, &main_window::show_proto_settings);
+ connect(ui.btnShowFilterControls, &QPushButton::clicked, this, &main_window::show_filter_settings);
+ connect(ui.btnStartTracker, &QPushButton::clicked, this, &main_window::start_tracker_);
+ connect(ui.btnStopTracker, &QPushButton::clicked, this, &main_window::stop_tracker_);
}
void main_window::register_shortcuts()
@@ -927,6 +915,24 @@ void main_window::set_profile_in_registry(const QString &profile)
});
}
+void main_window::restart_tracker_()
+{
+ qDebug() << "restart tracker";
+
+ stop_tracker_();
+ start_tracker_();
+}
+
+void main_window::toggle_tracker_()
+{
+ qDebug() << "toggle tracker";
+
+ if (work)
+ stop_tracker_();
+ else
+ start_tracker_();
+}
+
#if !defined _WIN32
# include <unistd.h>
void main_window::annoy_if_root()
diff --git a/variant/default/main-window.hpp b/variant/default/main-window.hpp
index cde6be04..e9fdbf57 100644
--- a/variant/default/main-window.hpp
+++ b/variant/default/main-window.hpp
@@ -18,6 +18,7 @@
#include "logic/work.hpp"
#include "logic/state.hpp"
#include "options/options.hpp"
+#include "compat/qt-signal.hpp"
#include <QApplication>
#include <QMainWindow>
@@ -39,7 +40,7 @@
class main_window final : public QMainWindow, private State
{
- Q_OBJECT
+ Q_DECLARE_TR_FUNCTIONS(main_window)
Ui::main_window ui;
@@ -95,24 +96,25 @@ class main_window final : public QMainWindow, private State
void init_shortcuts();
void init_buttons();
- void changeEvent(QEvent* e) override;
- bool event(QEvent *event) override;
- bool maybe_hide_to_tray(QEvent* e);
#if !defined _WIN32
void annoy_if_root();
#endif
+ void changeEvent(QEvent* e) override;
+ bool event(QEvent *event) override;
+ bool maybe_hide_to_tray(QEvent* e);
+
void closeEvent(QCloseEvent *event) override;
void die_on_config_not_writable();
bool is_tray_enabled();
bool start_in_tray();
-private slots:
- void save_modules();
- void exit(int status = EXIT_SUCCESS);
+ void refresh_config_list();
- void set_profile(const QString& new_name, bool migrate = true);
+ void make_empty_config();
+ void make_copied_config();
+ void open_config_directory();
void show_tracker_settings();
void show_proto_settings();
@@ -121,26 +123,26 @@ private slots:
void show_mapping_window();
void show_pose();
- void maybe_start_profile_from_executable();
-
- void make_empty_config();
- void make_copied_config();
- void open_config_directory();
- void refresh_config_list();
-
void start_tracker_();
void stop_tracker_();
+ void restart_tracker_();
+ void toggle_tracker_();
- void ensure_tray();
+ void set_profile(const QString& new_name, bool migrate = true);
+ void maybe_start_profile_from_executable();
+ void ensure_tray();
void toggle_restore_from_tray(QSystemTrayIcon::ActivationReason e);
+
+ void save_modules();
+ void exit(int status = EXIT_SUCCESS);
+
static void set_working_directory();
-signals:
- void start_tracker();
- void stop_tracker();
- void toggle_tracker();
- void restart_tracker();
+ qt_sig::nullary start_tracker;
+ qt_sig::nullary stop_tracker;
+ qt_sig::nullary toggle_tracker;
+ qt_sig::nullary restart_tracker;
public:
main_window();