mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Improve settings button selection handling
Will now try to keep the current button selection if possible. This can be useful when switching between source of the same time.
This commit is contained in:
parent
8dfe81f522
commit
7de28eedd3
|
|
@ -215,7 +215,7 @@ MacroActionFilterEdit::MacroActionFilterEdit(
|
|||
_settingsString(new VariableTextEdit(this)),
|
||||
_refreshSettingSelection(new QPushButton(
|
||||
obs_module_text("AdvSceneSwitcher.action.filter.refresh"))),
|
||||
_settingsButtons(new QComboBox())
|
||||
_settingsButtons(new SourceSettingsButtonSelection(this))
|
||||
{
|
||||
_filters->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
|
||||
|
|
@ -253,8 +253,10 @@ MacroActionFilterEdit::MacroActionFilterEdit(
|
|||
SLOT(SelectionChanged(const SourceSetting &)));
|
||||
QWidget::connect(_refreshSettingSelection, SIGNAL(clicked()), this,
|
||||
SLOT(RefreshVariableSourceSelectionValue()));
|
||||
QWidget::connect(_settingsButtons, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(ButtonChanged(int)));
|
||||
QWidget::connect(_settingsButtons,
|
||||
SIGNAL(SelectionChanged(const SourceSettingButton &)),
|
||||
this,
|
||||
SLOT(ButtonChanged(const SourceSettingButton &)));
|
||||
|
||||
const std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{sources}}", _sources},
|
||||
|
|
@ -311,9 +313,7 @@ void MacroActionFilterEdit::UpdateEntryData()
|
|||
static_cast<int>(_entryData->_settingsInputMethod)));
|
||||
_tempVars->SetVariable(_entryData->_tempVar);
|
||||
_manualSettingValue->setPlainText(_entryData->_manualSettingValue);
|
||||
PopulateSourceButtonSelection(_settingsButtons, firstFilter);
|
||||
_settingsButtons->setCurrentText(
|
||||
QString::fromStdString(_entryData->_button.ToString()));
|
||||
_settingsButtons->SetSelection(firstFilter, _entryData->_button);
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
|
|
@ -337,11 +337,13 @@ void MacroActionFilterEdit::FilterChanged(const FilterSelection &filter)
|
|||
auto lock = LockContext();
|
||||
_entryData->_filter = filter;
|
||||
}
|
||||
|
||||
const auto filters =
|
||||
_entryData->_filter.GetFilters(_entryData->_source);
|
||||
OBSWeakSource firstFilter = filters.empty() ? nullptr : filters.at(0);
|
||||
_filterSettings->SetSource(firstFilter);
|
||||
PopulateSourceButtonSelection(_settingsButtons, firstFilter);
|
||||
_settingsButtons->SetSource(firstFilter);
|
||||
|
||||
SetWidgetVisibility();
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
|
|
@ -457,15 +459,14 @@ void MacroActionFilterEdit::RefreshVariableSourceSelectionValue()
|
|||
_filterSettings->SetSource(filters.empty() ? nullptr : filters.at(0));
|
||||
}
|
||||
|
||||
void MacroActionFilterEdit::ButtonChanged(int idx)
|
||||
void MacroActionFilterEdit::ButtonChanged(const SourceSettingButton &button)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_button = qvariant_cast<SourceSettingButton>(
|
||||
_settingsButtons->itemData(idx));
|
||||
_entryData->_button = button;
|
||||
}
|
||||
|
||||
void MacroActionFilterEdit::SetWidgetVisibility()
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ private slots:
|
|||
void SelectionChanged(const SourceSetting &);
|
||||
void ManualSettingsValueChanged();
|
||||
void RefreshVariableSourceSelectionValue();
|
||||
void ButtonChanged(int idx);
|
||||
void ButtonChanged(const SourceSettingButton &);
|
||||
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
|
@ -100,7 +100,7 @@ private:
|
|||
SourceSettingSelection *_filterSettings;
|
||||
VariableTextEdit *_settingsString;
|
||||
QPushButton *_refreshSettingSelection;
|
||||
QComboBox *_settingsButtons;
|
||||
SourceSettingsButtonSelection *_settingsButtons;
|
||||
|
||||
std::shared_ptr<MacroActionFilter> _entryData;
|
||||
bool _loading = true;
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ MacroActionSourceEdit::MacroActionSourceEdit(
|
|||
: QWidget(parent),
|
||||
_sources(new SourceSelectionWidget(this, QStringList(), true)),
|
||||
_actions(new QComboBox()),
|
||||
_settingsButtons(new QComboBox()),
|
||||
_settingsButtons(new SourceSettingsButtonSelection(this)),
|
||||
_settingsLayout(new QHBoxLayout()),
|
||||
_settingsInputMethods(new QComboBox(this)),
|
||||
_manualSettingValue(new VariableTextEdit(this, 5, 1, 1)),
|
||||
|
|
@ -323,8 +323,10 @@ MacroActionSourceEdit::MacroActionSourceEdit(
|
|||
|
||||
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(ActionChanged(int)));
|
||||
QWidget::connect(_settingsButtons, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(ButtonChanged(int)));
|
||||
QWidget::connect(_settingsButtons,
|
||||
SIGNAL(SelectionChanged(const SourceSettingButton &)),
|
||||
this,
|
||||
SLOT(ButtonChanged(const SourceSettingButton &)));
|
||||
QWidget::connect(_sources,
|
||||
SIGNAL(SourceChanged(const SourceSelection &)), this,
|
||||
SLOT(SourceChanged(const SourceSelection &)));
|
||||
|
|
@ -394,14 +396,12 @@ void MacroActionSourceEdit::UpdateEntryData()
|
|||
return;
|
||||
}
|
||||
|
||||
PopulateSourceButtonSelection(_settingsButtons,
|
||||
_entryData->_source.GetSource());
|
||||
const auto weakSource = _entryData->_source.GetSource();
|
||||
_settingsButtons->SetSelection(weakSource, _entryData->_button);
|
||||
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
|
||||
_sources->SetSource(_entryData->_source);
|
||||
_sourceSettings->SetSource(_entryData->_source.GetSource());
|
||||
_sourceSettings->SetSource(weakSource);
|
||||
_sourceSettings->SetSetting(_entryData->_setting);
|
||||
_settingsButtons->setCurrentText(
|
||||
QString::fromStdString(_entryData->_button.ToString()));
|
||||
_settingsString->setPlainText(_entryData->_settingsString);
|
||||
_deinterlaceMode->setCurrentIndex(_deinterlaceMode->findData(
|
||||
static_cast<int>(_entryData->_deinterlaceMode)));
|
||||
|
|
@ -425,9 +425,10 @@ void MacroActionSourceEdit::SourceChanged(const SourceSelection &source)
|
|||
auto lock = LockContext();
|
||||
_entryData->_source = source;
|
||||
}
|
||||
PopulateSourceButtonSelection(_settingsButtons,
|
||||
_entryData->_source.GetSource());
|
||||
_sourceSettings->SetSource(_entryData->_source.GetSource());
|
||||
|
||||
const auto weakSource = _entryData->_source.GetSource();
|
||||
_sourceSettings->SetSource(weakSource);
|
||||
_settingsButtons->SetSource(weakSource);
|
||||
SetWidgetVisibility();
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
|
|
@ -444,15 +445,14 @@ void MacroActionSourceEdit::ActionChanged(int value)
|
|||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroActionSourceEdit::ButtonChanged(int idx)
|
||||
void MacroActionSourceEdit::ButtonChanged(const SourceSettingButton &button)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
_entryData->_button = qvariant_cast<SourceSettingButton>(
|
||||
_settingsButtons->itemData(idx));
|
||||
_entryData->_button = button;
|
||||
}
|
||||
|
||||
void MacroActionSourceEdit::GetSettingsClicked()
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public:
|
|||
private slots:
|
||||
void SourceChanged(const SourceSelection &);
|
||||
void ActionChanged(int value);
|
||||
void ButtonChanged(int idx);
|
||||
void ButtonChanged(const SourceSettingButton &);
|
||||
void GetSettingsClicked();
|
||||
void SettingsStringChanged();
|
||||
void DeinterlaceModeChanged(int);
|
||||
|
|
@ -99,7 +99,7 @@ private:
|
|||
|
||||
SourceSelectionWidget *_sources;
|
||||
QComboBox *_actions;
|
||||
QComboBox *_settingsButtons;
|
||||
SourceSettingsButtonSelection *_settingsButtons;
|
||||
QHBoxLayout *_settingsLayout;
|
||||
QComboBox *_settingsInputMethods;
|
||||
VariableTextEdit *_manualSettingValue;
|
||||
|
|
|
|||
|
|
@ -76,19 +76,46 @@ void PressSourceButton(const SourceSettingButton &button, obs_source_t *source)
|
|||
obs_properties_destroy(sourceProperties);
|
||||
}
|
||||
|
||||
void PopulateSourceButtonSelection(QComboBox *list, OBSWeakSource source)
|
||||
SourceSettingsButtonSelection::SourceSettingsButtonSelection(QWidget *parent)
|
||||
: FilterComboBox(parent)
|
||||
{
|
||||
list->clear();
|
||||
connect(this, &FilterComboBox::currentIndexChanged, [this](int idx) {
|
||||
emit SelectionChanged(
|
||||
qvariant_cast<SourceSettingButton>(itemData(idx)));
|
||||
});
|
||||
}
|
||||
|
||||
void SourceSettingsButtonSelection::SetSource(const OBSWeakSource &source,
|
||||
bool restorePreviousSelection)
|
||||
{
|
||||
const auto previousSelection = currentText();
|
||||
PopulateSelection(source);
|
||||
if (restorePreviousSelection) {
|
||||
setCurrentIndex(findText(previousSelection));
|
||||
}
|
||||
}
|
||||
|
||||
void SourceSettingsButtonSelection::SetSelection(
|
||||
const OBSWeakSource &source, const SourceSettingButton &button)
|
||||
{
|
||||
SetSource(source, false);
|
||||
setCurrentText(QString::fromStdString(button.ToString()));
|
||||
}
|
||||
|
||||
void SourceSettingsButtonSelection::PopulateSelection(
|
||||
const OBSWeakSource &source)
|
||||
{
|
||||
const QSignalBlocker b(this);
|
||||
clear();
|
||||
auto buttons = GetSourceButtons(source);
|
||||
if (buttons.empty()) {
|
||||
list->addItem(
|
||||
obs_module_text("AdvSceneSwitcher.noSettingsButtons"));
|
||||
addItem(obs_module_text("AdvSceneSwitcher.noSettingsButtons"));
|
||||
}
|
||||
|
||||
for (const auto &button : buttons) {
|
||||
QVariant value;
|
||||
value.setValue(button);
|
||||
list->addItem(QString::fromStdString(button.ToString()), value);
|
||||
addItem(QString::fromStdString(button.ToString()), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
#pragma once
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <QComboBox>
|
||||
#include <qmetatype.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace advss {
|
||||
|
||||
class SourceSelection;
|
||||
class FilterSelection;
|
||||
|
||||
struct SourceSettingButton {
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
|
|
@ -18,7 +22,23 @@ struct SourceSettingButton {
|
|||
|
||||
std::vector<SourceSettingButton> GetSourceButtons(OBSWeakSource source);
|
||||
void PressSourceButton(const SourceSettingButton &button, obs_source_t *source);
|
||||
void PopulateSourceButtonSelection(QComboBox *list, OBSWeakSource source);
|
||||
|
||||
class SourceSettingsButtonSelection : public FilterComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SourceSettingsButtonSelection(QWidget *parent = nullptr);
|
||||
void SetSource(const OBSWeakSource &source,
|
||||
bool restorePreviousSelection = true);
|
||||
void SetSelection(const OBSWeakSource &source,
|
||||
const SourceSettingButton &button);
|
||||
|
||||
signals:
|
||||
void SelectionChanged(const SourceSettingButton &);
|
||||
|
||||
private:
|
||||
void PopulateSelection(const OBSWeakSource &source);
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user