Wed, 22 Jun 2022 23:51:06 +0300
Add widgets to object editor
#ifndef SETTINGS_H #define SETTINGS_H #include <QSettings> #include <QMdiArea> #include "libraries.h" #include "gl/common.h" template<class> struct SettingInfo{}; #define SETTING(NAME, DEFVALUE) \ namespace Setting { class NAME; } \ template<> \ struct SettingInfo<Setting::NAME> \ { \ using type = decltype((DEFVALUE)); \ static constexpr char name[] = #NAME; \ static const auto& defaultValue() { \ static const auto value = DEFVALUE; \ return value; \ } \ }; // ----------------------------------------------------------------------------- // Setting definitions // Rendering options SETTING(Locale, QString{"system"}) SETTING(BackgroundColor, (QColor{48, 48, 48})) SETTING(MainColor, (QColor{255, 255, 64})) SETTING(SelectedColor, (QColor{32, 32, 224})) SETTING(LineThickness, 2.0f) SETTING(LineAntiAliasing, true) SETTING(RenderStyle, gl::RenderStyle::Normal) SETTING(Wireframe, false) SETTING(DrawAxes, true) SETTING(MainWindowGeometry, QByteArray{}) SETTING(MainWindowState, QByteArray{}) SETTING(MainSplitterState, QByteArray{}) SETTING(RecentFiles, QStringList{}) SETTING(ViewMode, QMdiArea::TabbedView) SETTING(LogOpenGLDebugMessages, false) // File management options SETTING(Libraries, QVector<Library>{}) // End of setting definitions // ----------------------------------------------------------------------------- #undef SETTING template<class X> using SettingType_t = typename SettingInfo<X>::type; static_assert(std::is_same_v<SettingType_t<Setting::DrawAxes>, bool>); template<class X> const char* settingName = SettingInfo<X>::name; template<class X> inline auto settingDefaultValue() { return SettingInfo<X>::defaultValue(); } // get() - get setting by enumerator template<class X> inline SettingType_t<X> setting() { static const QVariant defvariant = QVariant::fromValue(settingDefaultValue<X>()); const QVariant var = QSettings{}.value(settingName<X>, defvariant); return var.value<SettingType_t<X>>(); } // setSetting() - set value of setting template<class X> inline void setSetting(const SettingType_t<X>& value) { if (value == settingDefaultValue<X>()) { QSettings{}.remove(settingName<X>); } else { QSettings{}.setValue(settingName<X>, QVariant::fromValue(value)); } } #endif // SETTINGS_H