obs source的属性框的创建过程

来源:互联网 发布:excel同列不同数据分列 编辑:程序博客网 时间:2024/06/05 05:08

当你双击某个资源时,如图,此时会触发

void OBSBasic::on_sources_itemDoubleClicked(QListWidgetItem *witem){if (!witem)return;OBSSceneItem item = GetSceneItem(witem);OBSSource source = obs_sceneitem_get_source(item);if (source)CreatePropertiesWindow(source);}

根据List的Item获得源 的item,然后根据该item,获得该source,然后创建该source的property

window-basic-properties.cpp中的定义了source的属性类OBSBasicProperties

该类的构造函数中会创建OBSPropertiesView,然后调用RefreshProperties,添加相应的属性

void OBSPropertiesView::RefreshProperties(){//obs_property_t *property = obs_properties_first(properties.get());bool hasNoProperties = !property;while (property) {AddProperty(property, layout);obs_property_next(&property);}/////}
获得属性的类型,根据不同的类型 动态创建相应的控件

void OBSPropertiesView::AddProperty(obs_property_t *property,QFormLayout *layout){const char        *name = obs_property_name(property);obs_property_type type  = obs_property_get_type(property);if (!obs_property_visible(property))return;QLabel  *label  = nullptr;QWidget *widget = nullptr;bool    warning = false;switch (type) {case OBS_PROPERTY_INVALID:return;case OBS_PROPERTY_BOOL:widget = AddCheckbox(property);break;case OBS_PROPERTY_INT:AddInt(property, layout, &label);break;case OBS_PROPERTY_FLOAT:AddFloat(property, layout, &label);break;case OBS_PROPERTY_TEXT:widget = AddText(property, layout, label);break;case OBS_PROPERTY_PATH:AddPath(property, layout, &label);break;case OBS_PROPERTY_LIST:widget = AddList(property, warning);break;case OBS_PROPERTY_COLOR:AddColor(property, layout, label);break;case OBS_PROPERTY_FONT:AddFont(property, layout, label);break;case OBS_PROPERTY_BUTTON:widget = AddButton(property);break;case OBS_PROPERTY_EDITABLE_LIST:AddEditableList(property, layout, label);break;case OBS_PROPERTY_FRAME_RATE:AddFrameRate(property, warning, layout, label);break;}if (widget && !obs_property_enabled(property))widget->setEnabled(false);if (!label &&    type != OBS_PROPERTY_BOOL &&    type != OBS_PROPERTY_BUTTON)label = new QLabel(QT_UTF8(obs_property_description(property)));if (warning && label) //TODO: select color based on background colorlabel->setStyleSheet("QLabel { color: red; }");if (label && minSize) {label->setMinimumWidth(minSize);label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);}if (!widget)return;layout->addRow(label, widget);if (!lastFocused.empty())if (lastFocused.compare(name) == 0)lastWidget = widget;}

例如 音频的设备Device,是个QComboBox,type=OBS_PROPERTY_LIST,此时会调用

QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning){const char       *name  = obs_property_name(prop);QComboBox        *combo = new QComboBox();obs_combo_type   type   = obs_property_list_type(prop);obs_combo_format format = obs_property_list_format(prop);size_t           count  = obs_property_list_item_count(prop);int              idx    = -1;for (size_t i = 0; i < count; i++)AddComboItem(combo, prop, format, i);if (type == OBS_COMBO_TYPE_EDITABLE)combo->setEditable(true);combo->setMaxVisibleItems(40);combo->setToolTip(QT_UTF8(obs_property_long_description(prop)));string value = from_obs_data(settings, name, format);if (format == OBS_COMBO_FORMAT_STRING &&type == OBS_COMBO_TYPE_EDITABLE) {combo->lineEdit()->setText(QT_UTF8(value.c_str()));} else {idx = combo->findData(QByteArray(value.c_str()));}if (type == OBS_COMBO_TYPE_EDITABLE)return NewWidget(prop, combo,SIGNAL(editTextChanged(const QString &)));if (idx != -1)combo->setCurrentIndex(idx);if (obs_data_has_autoselect_value(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 &&model->flags(model->index(idx, 0)) == Qt::NoItemFlags;WidgetInfo *info = new WidgetInfo(this, prop, combo);connect(combo, SIGNAL(currentIndexChanged(int)), info,SLOT(ControlChanged()));children.emplace_back(info);/* trigger a settings update if the index was not found */if (idx == -1)info->ControlChanged();return combo;}

注意obs内部的字符编码是UTF8,如果你直接用const char*接受返回的设备名字,会出现无效字符,此时记着UTF8转换为Unicode


0 0
原创粉丝点击