mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-06-14 02:39:52 -04:00
Make properties-view reflect autoselect settings (for property lists)
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <QStandardItem>
|
||||
#include "qt-wrappers.hpp"
|
||||
#include "properties-view.hpp"
|
||||
#include "obs-app.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
@@ -172,6 +173,39 @@ static void AddComboItem(QComboBox *combo, obs_property_t prop,
|
||||
item->setFlags(Qt::NoItemFlags);
|
||||
}
|
||||
|
||||
template <long long get_int(obs_data_t, const char*),
|
||||
double get_double(obs_data_t, const char*),
|
||||
const char *get_string(obs_data_t, const char*)>
|
||||
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<obs_data_getint, obs_data_getdouble,
|
||||
obs_data_getstring>(data, name, format);
|
||||
}
|
||||
|
||||
static string from_obs_data_autoselect(obs_data_t data, const char *name,
|
||||
obs_combo_format format)
|
||||
{
|
||||
return from_obs_data<obs_data_get_autoselect_int,
|
||||
obs_data_get_autoselect_double,
|
||||
obs_data_get_autoselect_string>(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()));
|
||||
string value = from_obs_data(settings, name, format);
|
||||
|
||||
} 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()));
|
||||
|
||||
} 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 &&
|
||||
|
||||
Reference in New Issue
Block a user