/* 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 "compat/run-in-thread.hpp" #include #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> tie_setting(value& v, QComboBox* cb) { cb->setCurrentIndex(cb->findData(int(static_cast(v)))); v = static_cast(cb->currentData().toInt()); v.connect_from(cb, static_cast(&QComboBox::currentIndexChanged), [&v, cb](int idx) { v = static_cast(cb->itemData(idx).toInt()); }); v.connect_to(cb, [cb](int x) { cb->setCurrentIndex(cb->findData(x)); }); } template void tie_setting(value& v, QComboBox* cb, From&& fn_to_index, To&& fn_to_value) { cb->setCurrentIndex(fn_to_index(v)); v = fn_to_value(cb->currentIndex(), cb->currentData()); v.connect_from(cb, static_cast(&QComboBox::currentIndexChanged), [&v, cb, fn = std::forward(fn_to_value)](int idx) { v = fn(idx, cb->currentData()); }); v.connect_to(cb, [cb, fn = std::forward(fn_to_index)](detail::cv_qualified v) { cb->setCurrentIndex(fn(v)); }); } template void tie_setting(value& v, QLabel* lb, F&& fun) { auto closure = [lb, fn = std::forward(fun)](detail::cv_qualified v) { lb->setText(fn(v)); }; closure(v()); v.connect_to(lb, std::move(closure)); } template void tie_setting(value& v, QObject* obj, F&& fun) { if (obj == nullptr) abort(); fun(v()); v.connect_to(obj, std::forward(fun)); } 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, QRadioButton* 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, 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