0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00

libobs, UI: Add support for button properties as links

This adds support for a button property that opens a URL, after showing
a confirmation dialog to the user. Both the Type and URL must be set.
This commit is contained in:
Matt Gajownik 2020-10-14 12:58:41 +11:00 committed by Dillon Pentz
parent 712478f48c
commit 74c3781554
5 changed files with 105 additions and 0 deletions

View File

@ -544,6 +544,9 @@ Basic.PropertiesWindow.EditEditableListEntry="Edit entry from '%1'"
Basic.PropertiesView.FPS.Simple="Simple FPS Values"
Basic.PropertiesView.FPS.Rational="Rational FPS Values"
Basic.PropertiesView.FPS.ValidFPSRanges="Valid FPS Ranges:"
Basic.PropertiesView.UrlButton.Text="Open this link in your default web browser?"
Basic.PropertiesView.UrlButton.Text.Url="URL: %1"
Basic.PropertiesView.UrlButton.OpenUrl="Open URL"
# interaction window
Basic.InteractionWindow="Interacting with '%1'"

View File

@ -17,10 +17,12 @@
#include <QPlainTextEdit>
#include <QDialogButtonBox>
#include <QMenu>
#include <QMessageBox>
#include <QStackedWidget>
#include <QDir>
#include <QGroupBox>
#include <QObject>
#include <QDesktopServices>
#include "double-slider.hpp"
#include "slider-ignorewheel.hpp"
#include "spinbox-ignorewheel.hpp"
@ -1881,6 +1883,30 @@ void WidgetInfo::EditableListChanged()
void WidgetInfo::ButtonClicked()
{
obs_button_type type = obs_property_button_type(property);
const char *savedUrl = obs_property_button_url(property);
if (type == OBS_BUTTON_URL && strcmp(savedUrl, "") != 0) {
QUrl url(savedUrl, QUrl::StrictMode);
if (url.isValid() && (url.scheme().compare("http") == 0 ||
url.scheme().compare("https") == 0)) {
QString msg(
QTStr("Basic.PropertiesView.UrlButton.Text"));
msg += "\n\n";
msg += QString(QTStr("Basic.PropertiesView.UrlButton.Text.Url"))
.arg(savedUrl);
QMessageBox::StandardButton button = OBSMessageBox::question(
view->window(),
QTStr("Basic.PropertiesView.UrlButton.OpenUrl"),
msg, QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (button == QMessageBox::Yes)
QDesktopServices::openUrl(url);
}
return;
}
if (obs_property_button_clicked(property, view->obj)) {
QMetaObject::invokeMethod(view, "RefreshProperties",
Qt::QueuedConnection);

View File

@ -240,6 +240,11 @@ Property Object Functions
:param description: Localized name shown to user
:return: The property
Important Related Functions:
- :c:func:`obs_property_button_set_type`
- :c:func:`obs_property_button_set_url`
Relevant data types used with this function:
.. code:: cpp
@ -512,6 +517,19 @@ Property Enumeration Functions
---------------------
.. function:: enum obs_button_type obs_property_button_type(obs_property_t *p)
:return: One of the following values:
- OBS_BUTTON_DEFAULT
- OBS_BUTTON_URL
---------------------
.. function:: const char *obs_property_button_url(obs_property_t *p)
---------------------
.. function:: enum obs_group_type obs_property_group_type(obs_property_t *p)
:return: One of the following values:
@ -658,3 +676,17 @@ Property Modification Functions
---------------------
.. function:: void obs_property_frame_rate_fps_range_insert(obs_property_t *p, size_t idx, struct media_frames_per_second min, struct media_frames_per_second max)
---------------------
.. function:: void obs_property_button_set_type(obs_property_t *p, enum obs_button_type type)
:param type: Can be one of the following values:
- **OBS_BUTTON_DEFAULT** - Standard button
- **OBS_BUTTON_URL** - Button that opens a URL
:return: The property
---------------------
.. function:: void obs_property_button_set_url(obs_property_t *p, char *url)

View File

@ -72,6 +72,8 @@ struct editable_list_data {
struct button_data {
obs_property_clicked_t callback;
enum obs_button_type type;
char *url;
};
struct frame_rate_option {
@ -1102,6 +1104,24 @@ void obs_property_text_set_monospace(obs_property_t *p, bool monospace)
data->monospace = monospace;
}
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);
if (!data)
return;
data->type = type;
}
void obs_property_button_set_url(obs_property_t *p, char *url)
{
struct button_data *data = get_type_data(p, OBS_PROPERTY_BUTTON);
if (!data)
return;
data->url = url;
}
void obs_property_list_clear(obs_property_t *p)
{
struct list_data *data = get_list_data(p);
@ -1435,3 +1455,15 @@ obs_properties_t *obs_property_group_content(obs_property_t *p)
struct group_data *data = get_type_data(p, OBS_PROPERTY_GROUP);
return data ? data->content : NULL;
}
enum obs_button_type obs_property_button_type(obs_property_t *p)
{
struct button_data *data = get_type_data(p, OBS_PROPERTY_BUTTON);
return data ? data->type : OBS_BUTTON_DEFAULT;
}
const char *obs_property_button_url(obs_property_t *p)
{
struct button_data *data = get_type_data(p, OBS_PROPERTY_BUTTON);
return data ? data->url : "";
}

View File

@ -101,6 +101,11 @@ enum obs_group_type {
OBS_GROUP_CHECKABLE,
};
enum obs_button_type {
OBS_BUTTON_DEFAULT,
OBS_BUTTON_URL,
};
#define OBS_FONT_BOLD (1 << 0)
#define OBS_FONT_ITALIC (1 << 1)
#define OBS_FONT_UNDERLINE (1 << 2)
@ -334,6 +339,10 @@ 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_button_set_type(obs_property_t *p,
enum obs_button_type type);
EXPORT void obs_property_button_set_url(obs_property_t *p, char *url);
EXPORT void obs_property_list_clear(obs_property_t *p);
EXPORT size_t obs_property_list_add_string(obs_property_t *p, const char *name,
@ -401,6 +410,9 @@ obs_property_frame_rate_fps_range_max(obs_property_t *p, size_t idx);
EXPORT enum obs_group_type obs_property_group_type(obs_property_t *p);
EXPORT obs_properties_t *obs_property_group_content(obs_property_t *p);
EXPORT enum obs_button_type obs_property_button_type(obs_property_t *p);
EXPORT const char *obs_property_button_url(obs_property_t *p);
#ifndef SWIG
OBS_DEPRECATED
EXPORT enum obs_text_type obs_proprety_text_type(obs_property_t *p);