/* Copyright (c) 2015-2016, 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 "export.hpp" #include "value.hpp" #include #include #include #include #include #include #include #include #include #if defined __GNUG__ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wattributes" #endif namespace options { template std::enable_if_t::value> tie_setting(value& v, QComboBox* cb) { cb->setCurrentIndex(cb->findData(int(static_cast(v)))); v = static_cast(cb->currentData().toInt()); base_value::connect(cb, static_cast(&QComboBox::currentIndexChanged), &v, [&v, cb](int idx) { run_in_thread_sync(cb, [&]() { v = static_cast(cb->itemData(idx).toInt()); }); }, v.DIRECT_CONNTYPE); base_value::connect(&v, static_cast(&base_value::valueChanged), cb, [cb](int x) { cb->setCurrentIndex(cb->findData(x)); }, v.SAFE_CONNTYPE); } template void tie_setting(value& v, QLabel* lb, const QString& format, const xs&... args) { auto closure = [=](const t& x) { lb->setText(format.arg(x, args...)); }; closure(v()); base_value::connect(&v, static_cast(&base_value::valueChanged), lb, closure, v.SAFE_CONNTYPE); } template decltype((void)((std::declval())(std::declval()))) tie_setting(value& v, QLabel* lb, F&& fun, const QString& fmt, const xs&... args) { auto closure = [=](const t& x) { lb->setText(fmt.arg(fun(x), args...)); }; closure(v()); base_value::connect(&v, static_cast(&base_value::valueChanged), lb, closure, v.SAFE_CONNTYPE); } template decltype((void)((std::declval())(std::declval()))) tie_setting(value& v, QLabel* lb, F&& fun) { tie_setting(v, lb, fun, QStringLiteral("%1")); } OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QCheckBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QDoubleSpinBox* dsb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QSpinBox* sb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QSlider* sl); OTR_OPTIONS_EXPORT void tie_setting(value& v, QLineEdit* le); OTR_OPTIONS_EXPORT void tie_setting(value& v, QLabel* lb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QTabWidget* t); OTR_OPTIONS_EXPORT void tie_setting(value& v, QSlider* w); } // ns options #if defined __GNUG__ # pragma GCC diagnostic pop #endif