diff --git a/build/data/obs-studio/locale/en.txt b/build/data/obs-studio/locale/en.txt index cf981b9b427448fe9186baa1a4f5120354640321..fb1d3d05f39f5f9ed647603c0566748149fe7b9e 100644 --- a/build/data/obs-studio/locale/en.txt +++ b/build/data/obs-studio/locale/en.txt @@ -66,6 +66,9 @@ Basic.Main.DefaultSceneName.Text="Scene %1" Basic.SourceSelect.CreateNew="Create new" Basic.SourceSelect.AddExisting="Add Existing" +# properties window +Basic.PropertiesWindow.AutoSelectFormat="%1 (unsupported; autoselect: %2)" + # transform window Basic.TransformWindow="Scene Item Transform" Basic.TransformWindow.Position="Position" diff --git a/obs/properties-view.cpp b/obs/properties-view.cpp index 39cb8e3d3bffa35b03ee2d83232c721598c15ebb..cc7d540fd8956c6c4251e21b4f62e5cfdd39759d 100644 --- a/obs/properties-view.cpp +++ b/obs/properties-view.cpp @@ -9,6 +9,7 @@ #include #include "qt-wrappers.hpp" #include "properties-view.hpp" +#include "obs-app.hpp" #include using namespace std; @@ -172,6 +173,39 @@ static void AddComboItem(QComboBox *combo, obs_property_t prop, item->setFlags(Qt::NoItemFlags); } +template +static string from_obs_data(obs_data_t data, const char *name, + obs_combo_format format) +{ + switch (format) { + case OBS_COMBO_FORMAT_INT: + return to_string(get_int(data, name)); + case OBS_COMBO_FORMAT_FLOAT: + return to_string(get_double(data, name)); + case OBS_COMBO_FORMAT_STRING: + return get_string(data, name); + default: + return ""; + } +} + +static string from_obs_data(obs_data_t data, const char *name, + obs_combo_format format) +{ + return from_obs_data(data, name, format); +} + +static string from_obs_data_autoselect(obs_data_t data, const char *name, + obs_combo_format format) +{ + return from_obs_data(data, name, format); +} + QWidget *OBSPropertiesView::AddList(obs_property_t prop, bool &warning) { const char *name = obs_property_name(prop); @@ -187,24 +221,13 @@ QWidget *OBSPropertiesView::AddList(obs_property_t prop, bool &warning) if (type == OBS_COMBO_TYPE_EDITABLE) combo->setEditable(true); - if (format == OBS_COMBO_FORMAT_INT) { - int val = (int)obs_data_getint(settings, name); - string valString = to_string(val); - idx = combo->findData(QT_UTF8(valString.c_str())); - - } else if (format == OBS_COMBO_FORMAT_FLOAT) { - double val = obs_data_getdouble(settings, name); - string valString = to_string(val); - idx = combo->findData(QT_UTF8(valString.c_str())); + string value = from_obs_data(settings, name, format); - } else if (format == OBS_COMBO_FORMAT_STRING) { - const char *val = obs_data_getstring(settings, name); - - if (type == OBS_COMBO_TYPE_EDITABLE) - combo->lineEdit()->setText(val); - else - idx = combo->findData(QT_UTF8(val)); - } + if (format == OBS_COMBO_FORMAT_STRING && + type == OBS_COMBO_TYPE_EDITABLE) + combo->lineEdit()->setText(QT_UTF8(value.c_str())); + else + idx = combo->findData(QT_UTF8(value.c_str())); if (type == OBS_COMBO_TYPE_EDITABLE) return NewWidget(prop, combo, @@ -212,6 +235,22 @@ QWidget *OBSPropertiesView::AddList(obs_property_t prop, bool &warning) if (idx != -1) combo->setCurrentIndex(idx); + + if (obs_data_has_autoselect(settings, name)) { + string autoselect = + from_obs_data_autoselect(settings, name, format); + int id = combo->findData(QT_UTF8(autoselect.c_str())); + + if (id != -1 && id != idx) { + QString actual = combo->itemText(id); + QString selected = combo->itemText(idx); + QString combined = QTStr( + "Basic.PropertiesWindow.AutoSelectFormat"); + combo->setItemText(idx, + combined.arg(selected).arg(actual)); + } + } + QAbstractItemModel *model = combo->model(); warning = idx != -1 &&