diff --git a/UI/properties-view.cpp b/UI/properties-view.cpp index 47a0295ae..b048d75e9 100644 --- a/UI/properties-view.cpp +++ b/UI/properties-view.cpp @@ -310,6 +310,50 @@ QWidget *OBSPropertiesView::AddText(obs_property_t *prop, QFormLayout *layout, connect(edit, SIGNAL(textEdited(const QString &)), info, SLOT(ControlChanged())); return nullptr; + } else if (type == OBS_TEXT_INFO) { + QString desc = QT_UTF8(obs_property_description(prop)); + const char *long_desc = obs_property_long_description(prop); + obs_text_info_type info_type = + obs_property_text_info_type(prop); + + QLabel *info_label = new QLabel(QT_UTF8(val)); + + if (info_label->text().isEmpty() && long_desc == NULL) { + label = nullptr; + info_label->setText(desc); + } else + label = new QLabel(desc); + + if (long_desc != NULL && !info_label->text().isEmpty()) { + QString file = !App()->IsThemeDark() + ? ":/res/images/help.svg" + : ":/res/images/help_light.svg"; + QString lStr = "%1 "; + + info_label->setText(lStr.arg(info_label->text(), file)); + info_label->setToolTip(QT_UTF8(long_desc)); + } else if (long_desc != NULL) { + info_label->setText(QT_UTF8(long_desc)); + } + + info_label->setOpenExternalLinks(true); + info_label->setWordWrap(obs_property_text_info_word_wrap(prop)); + + if (info_type == OBS_TEXT_INFO_WARNING) + info_label->setObjectName("warningLabel"); + else if (info_type == OBS_TEXT_INFO_ERROR) + info_label->setObjectName("errorLabel"); + + if (label) + label->setObjectName(info_label->objectName()); + + WidgetInfo *info = new WidgetInfo(this, prop, info_label); + children.emplace_back(info); + + layout->addRow(label, info_label); + + return nullptr; } QLineEdit *edit = new QLineEdit(); diff --git a/docs/sphinx/reference-properties.rst b/docs/sphinx/reference-properties.rst index 1d3bad688..b8d4b8a4f 100644 --- a/docs/sphinx/reference-properties.rst +++ b/docs/sphinx/reference-properties.rst @@ -144,9 +144,17 @@ Property Object Functions - **OBS_TEXT_DEFAULT** - Single line of text - **OBS_TEXT_PASSWORD** - Single line of text (passworded) - **OBS_TEXT_MULTILINE** - Multi-line text + - **OBS_TEXT_INFO** - Read-only informative text, behaves differently + depending on wether description, string value and long description + are set :return: The property + Important Related Functions: + + - :c:func:`obs_property_text_set_info_type` + - :c:func:`obs_property_text_set_info_word_wrap` + --------------------- .. function:: obs_property_t *obs_properties_add_path(obs_properties_t *props, const char *name, const char *description, enum obs_path_type type, const char *filter, const char *default_path) @@ -437,6 +445,20 @@ Property Enumeration Functions --------------------- +.. function:: enum obs_text_info_type obs_property_text_info_type(obs_property_t *p) + + :return: One of the following values: + + - OBS_TEXT_INFO_NORMAL + - OBS_TEXT_INFO_WARNING + - OBS_TEXT_INFO_ERROR + +--------------------- + +.. function:: bool obs_property_text_info_word_wrap(obs_property_t *p) + +--------------------- + .. function:: enum obs_path_type obs_property_path_type(obs_property_t *p) --------------------- @@ -603,6 +625,20 @@ Property Modification Functions --------------------- +.. function:: void obs_property_text_set_info_type(obs_property_t *p, enum obs_text_info_type type) + + :param type: Can be one of the following values: + + - **OBS_TEXT_INFO_NORMAL** - To show a basic message + - **OBS_TEXT_INFO_WARNING** - To show a warning + - **OBS_TEXT_INFO_ERROR** - To show an error + +--------------------- + +.. function:: void obs_property_text_set_info_word_wrap(obs_property_t *p, bool word_wrap) + +--------------------- + .. function:: void obs_property_list_clear(obs_property_t *p) --------------------- diff --git a/libobs/obs-properties.c b/libobs/obs-properties.c index 2b4c0a046..d9a1c6b05 100644 --- a/libobs/obs-properties.c +++ b/libobs/obs-properties.c @@ -56,6 +56,8 @@ struct path_data { struct text_data { enum obs_text_type type; bool monospace; + enum obs_text_info_type info_type; + bool info_word_wrap; }; struct list_data { @@ -600,6 +602,8 @@ obs_property_t *obs_properties_add_text(obs_properties_t *props, struct obs_property *p = new_prop(props, name, desc, OBS_PROPERTY_TEXT); struct text_data *data = get_property_data(p); data->type = type; + data->info_type = OBS_TEXT_INFO_NORMAL; + data->info_word_wrap = true; return p; } @@ -1022,6 +1026,18 @@ bool obs_property_text_monospace(obs_property_t *p) return data ? data->monospace : false; } +enum obs_text_info_type obs_property_text_info_type(obs_property_t *p) +{ + struct text_data *data = get_type_data(p, OBS_PROPERTY_TEXT); + return data ? data->info_type : OBS_TEXT_INFO_NORMAL; +} + +bool obs_property_text_info_word_wrap(obs_property_t *p) +{ + struct text_data *data = get_type_data(p, OBS_PROPERTY_TEXT); + return data ? data->info_word_wrap : true; +} + enum obs_path_type obs_property_path_type(obs_property_t *p) { struct path_data *data = get_type_data(p, OBS_PROPERTY_PATH); @@ -1104,6 +1120,25 @@ void obs_property_text_set_monospace(obs_property_t *p, bool monospace) data->monospace = monospace; } +void obs_property_text_set_info_type(obs_property_t *p, + enum obs_text_info_type type) +{ + struct text_data *data = get_type_data(p, OBS_PROPERTY_TEXT); + if (!data) + return; + + data->info_type = type; +} + +void obs_property_text_set_info_word_wrap(obs_property_t *p, bool word_wrap) +{ + struct text_data *data = get_type_data(p, OBS_PROPERTY_TEXT); + if (!data) + return; + + data->info_word_wrap = word_wrap; +} + void obs_property_button_set_type(obs_property_t *p, enum obs_button_type type) { struct button_data *data = get_type_data(p, OBS_PROPERTY_BUTTON); diff --git a/libobs/obs-properties.h b/libobs/obs-properties.h index dcda3ab46..636616ebb 100644 --- a/libobs/obs-properties.h +++ b/libobs/obs-properties.h @@ -88,6 +88,13 @@ enum obs_text_type { OBS_TEXT_DEFAULT, OBS_TEXT_PASSWORD, OBS_TEXT_MULTILINE, + OBS_TEXT_INFO, +}; + +enum obs_text_info_type { + OBS_TEXT_INFO_NORMAL, + OBS_TEXT_INFO_WARNING, + OBS_TEXT_INFO_ERROR, }; enum obs_number_type { @@ -324,6 +331,8 @@ EXPORT enum obs_number_type obs_property_float_type(obs_property_t *p); EXPORT const char *obs_property_float_suffix(obs_property_t *p); EXPORT enum obs_text_type obs_property_text_type(obs_property_t *p); EXPORT bool obs_property_text_monospace(obs_property_t *p); +EXPORT enum obs_text_info_type obs_property_text_info_type(obs_property_t *p); +EXPORT bool obs_property_text_info_word_wrap(obs_property_t *p); EXPORT enum obs_path_type obs_property_path_type(obs_property_t *p); EXPORT const char *obs_property_path_filter(obs_property_t *p); EXPORT const char *obs_property_path_default_path(obs_property_t *p); @@ -338,6 +347,10 @@ EXPORT void obs_property_int_set_suffix(obs_property_t *p, const char *suffix); EXPORT void obs_property_float_set_suffix(obs_property_t *p, const char *suffix); EXPORT void obs_property_text_set_monospace(obs_property_t *p, bool monospace); +EXPORT void obs_property_text_set_info_type(obs_property_t *p, + enum obs_text_info_type type); +EXPORT void obs_property_text_set_info_word_wrap(obs_property_t *p, + bool word_wrap); EXPORT void obs_property_button_set_type(obs_property_t *p, enum obs_button_type type);