1
0
Эх сурвалжийг харах

libobs/UI: Support monospace font in multiline text property

Matt Gajownik 5 жил өмнө
parent
commit
62504dc651

+ 6 - 0
UI/properties-view.cpp

@@ -235,6 +235,7 @@ QWidget *OBSPropertiesView::AddText(obs_property_t *prop, QFormLayout *layout,
 {
 	const char *name = obs_property_name(prop);
 	const char *val = obs_data_get_string(settings, name);
+	const bool monospace = obs_property_text_monospace(prop);
 	obs_text_type type = obs_property_text_type(prop);
 
 	if (type == OBS_TEXT_MULTILINE) {
@@ -244,6 +245,11 @@ QWidget *OBSPropertiesView::AddText(obs_property_t *prop, QFormLayout *layout,
 #else
 		edit->setTabStopWidth(40);
 #endif
+		if (monospace) {
+			QFont f("Courier");
+			f.setStyleHint(QFont::Monospace);
+			edit->setFont(f);
+		}
 		return NewWidget(prop, edit, SIGNAL(textChanged()));
 
 	} else if (type == OBS_TEXT_PASSWORD) {

+ 16 - 0
libobs/obs-properties.c

@@ -55,6 +55,7 @@ struct path_data {
 
 struct text_data {
 	enum obs_text_type type;
+	bool monospace;
 };
 
 struct list_data {
@@ -978,6 +979,12 @@ enum obs_text_type obs_property_text_type(obs_property_t *p)
 	return data ? data->type : OBS_TEXT_DEFAULT;
 }
 
+enum obs_text_type obs_property_text_monospace(obs_property_t *p)
+{
+	struct text_data *data = get_type_data(p, OBS_PROPERTY_TEXT);
+	return data ? data->monospace : false;
+}
+
 enum obs_path_type obs_property_path_type(obs_property_t *p)
 {
 	struct path_data *data = get_type_data(p, OBS_PROPERTY_PATH);
@@ -1051,6 +1058,15 @@ void obs_property_float_set_suffix(obs_property_t *p, const char *suffix)
 	data->suffix = bstrdup(suffix);
 }
 
+void obs_property_text_set_monospace(obs_property_t *p, bool monospace)
+{
+	struct text_data *data = get_type_data(p, OBS_PROPERTY_TEXT);
+	if (!data)
+		return;
+
+	data->monospace = monospace;
+}
+
 void obs_property_list_clear(obs_property_t *p)
 {
 	struct list_data *data = get_list_data(p);

+ 2 - 0
libobs/obs-properties.h

@@ -313,6 +313,7 @@ EXPORT double obs_property_float_step(obs_property_t *p);
 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 enum obs_text_type obs_property_text_monospace(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);
@@ -326,6 +327,7 @@ EXPORT void obs_property_float_set_limits(obs_property_t *p, double min,
 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_list_clear(obs_property_t *p);