Regex config improvements

* Use icon instead of checkbox
* Enable use of custom save name
* Allow access to functions modifying the enable state
This commit is contained in:
WarmUpTill 2023-05-13 17:17:31 +02:00 committed by WarmUpTill
parent d45d4ded99
commit 5332ed6bef
4 changed files with 41 additions and 14 deletions

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" version="1.1">
<!-- Created with SVG-edit - https://github.com/SVG-Edit/svgedit-->
<g class="layer">
<title>Layer 1</title>
<text fill="#fefefe" font-family="Serif" font-size="24" id="svg_1" stroke="#fefefe" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" stroke-opacity="null" stroke-width="0" text-anchor="middle" transform="matrix(1.0974, 0, 0, 1.0974, -4.98544, 4.97639)" x="14" xml:space="preserve" y="13">*</text>
<rect fill="#fefefe" height="3.3" id="svg_2" stroke="#fefefe" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" transform="matrix(1, 0, 0, 1, 0, 0)" width="5" x="1" y="12"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 815 B

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet" version="1.1">
<!-- Created with SVG-edit - https://github.com/SVG-Edit/svgedit-->
<g class="layer">
<title>Layer 1</title>
<text fill="#202020" font-family="Serif" font-size="24" id="svg_1" stroke="#000000" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" stroke-opacity="null" stroke-width="0" text-anchor="middle" transform="matrix(1.0974, 0, 0, 1.0974, -4.98544, 4.97639)" x="14" xml:space="preserve" y="13">*</text>
<rect fill="#202020" height="3.3" id="svg_2" stroke="#202020" stroke-dasharray="null" stroke-linecap="null" stroke-linejoin="null" transform="matrix(1, 0, 0, 1, 0, 0)" width="5" x="1" y="12"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 815 B

View File

@ -6,19 +6,19 @@
namespace advss {
void RegexConfig::Save(obs_data_t *obj) const
void RegexConfig::Save(obs_data_t *obj, const char *name) const
{
auto data = obs_data_create();
obs_data_set_bool(data, "enable", _enable);
obs_data_set_bool(data, "partial", _partialMatch);
obs_data_set_int(data, "options", _options);
obs_data_set_obj(obj, "regexConfig", data);
obs_data_set_obj(obj, name, data);
obs_data_release(data);
}
void RegexConfig::Load(obs_data_t *obj)
void RegexConfig::Load(obs_data_t *obj, const char *name)
{
auto data = obs_data_get_obj(obj, "regexConfig");
auto data = obs_data_get_obj(obj, name);
_enable = obs_data_get_bool(data, "enable");
_partialMatch = obs_data_get_bool(data, "partial");
_options = static_cast<QRegularExpression::PatternOption>(
@ -59,15 +59,21 @@ RegexConfig RegexConfig::PartialMatchRegexConfig()
RegexConfigWidget::RegexConfigWidget(QWidget *parent)
: QWidget(parent),
_openSettings(new QPushButton()),
_enable(new QCheckBox(
obs_module_text("AdvSceneSwitcher.regex.enable")))
_enable(new QPushButton())
{
_openSettings->setMaximumWidth(22);
SetButtonIcon(_openSettings, ":/settings/images/settings/general.svg");
_openSettings->setFlat(true);
QWidget::connect(_enable, SIGNAL(stateChanged(int)), this,
SLOT(EnableChanged(int)));
_enable->setToolTip(obs_module_text("AdvSceneSwitcher.regex.enable"));
_enable->setMaximumWidth(22);
_enable->setCheckable(true);
const auto path = GetDataFilePath("res/images/" + GetThemeTypeName() +
"Regex.svg");
SetButtonIcon(_enable, path.c_str());
QWidget::connect(_enable, SIGNAL(clicked(bool)), this,
SLOT(EnableChanged(bool)));
QWidget::connect(_openSettings, SIGNAL(clicked()), this,
SLOT(OpenSettingsClicked()));
@ -101,7 +107,7 @@ void RegexConfigWidget::SetVisibility()
updateGeometry();
}
void RegexConfigWidget::EnableChanged(int value)
void RegexConfigWidget::EnableChanged(bool value)
{
_config._enable = value;
SetVisibility();

View File

@ -15,10 +15,11 @@ class RegexConfigDialog;
class RegexConfig {
public:
void Save(obs_data_t *obj) const;
void Load(obs_data_t *obj);
void Save(obs_data_t *obj, const char *name = "regexConfig") const;
void Load(obs_data_t *obj, const char *name = "regexConfig");
bool Enabled() const { return _enable; }
void SetEnabled(bool enable) { _enable = enable; }
void CreateBackwardsCompatibleRegex(bool, bool = true);
QRegularExpression::PatternOptions GetPatternOptions() const
{
@ -44,8 +45,8 @@ public:
RegexConfigWidget(QWidget *parent = nullptr);
void SetRegexConfig(const RegexConfig &);
private slots:
void EnableChanged(int);
public slots:
void EnableChanged(bool);
void OpenSettingsClicked();
signals:
void RegexConfigChanged(RegexConfig);
@ -54,7 +55,7 @@ private:
void SetVisibility();
QPushButton *_openSettings;
QCheckBox *_enable;
QPushButton *_enable;
RegexConfig _config;
};