mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-07-01 00:41:07 -05:00
Add MacroSegmentSelection
Utility class to enable selection of index of a macro segments. Add description of selected segment. Highlights segment if selected macro is current macro.
This commit is contained in:
parent
52811e44f4
commit
9eef581161
|
|
@ -263,6 +263,8 @@ target_sources(
|
|||
src/utils/filter-selection.hpp
|
||||
src/utils/macro-list.cpp
|
||||
src/utils/macro-list.hpp
|
||||
src/utils/macro-segment-selection.cpp
|
||||
src/utils/macro-segment-selection.hpp
|
||||
src/utils/math-helpers.cpp
|
||||
src/utils/math-helpers.hpp
|
||||
src/utils/mouse-wheel-guard.cpp
|
||||
|
|
|
|||
|
|
@ -992,6 +992,8 @@ AdvSceneSwitcher.item.emptyName="Empty name not allowed!"
|
|||
AdvSceneSwitcher.item.nameNotAvailable="Name not available!"
|
||||
AdvSceneSwitcher.item.nameReserved="Name reserved!"
|
||||
|
||||
AdvSceneSwitcher.macroSegmentSelection.invalid="Invalid selection!"
|
||||
|
||||
AdvSceneSwitcher.variable.select="--select variable--"
|
||||
AdvSceneSwitcher.variable.add="Add new variable"
|
||||
AdvSceneSwitcher.variable.name="Name:"
|
||||
|
|
|
|||
140
src/utils/macro-segment-selection.cpp
Normal file
140
src/utils/macro-segment-selection.cpp
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#include "macro-segment-selection.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
MacroSegmentSelection::MacroSegmentSelection(QWidget *parent, Type type,
|
||||
bool allowVariables)
|
||||
: QWidget(parent),
|
||||
_index(new VariableSpinBox()),
|
||||
_description(new QLabel()),
|
||||
_type(type)
|
||||
{
|
||||
_index->setMinimum(0);
|
||||
_index->setMaximum(99);
|
||||
_index->specialValueText("-");
|
||||
if (!allowVariables) {
|
||||
_index->DisableVariableSelection();
|
||||
}
|
||||
SetupDescription();
|
||||
|
||||
QWidget::connect(
|
||||
_index,
|
||||
SIGNAL(NumberVariableChanged(const NumberVariable<int> &)),
|
||||
this, SLOT(IndexChanged(const NumberVariable<int> &)));
|
||||
QWidget::connect(window(), SIGNAL(MacroSegmentOrderChanged()), this,
|
||||
SLOT(MacroSegmentOrderChanged()));
|
||||
|
||||
auto layout = new QHBoxLayout;
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(_index);
|
||||
layout->addWidget(_description);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void MacroSegmentSelection::SetMacro(const std::shared_ptr<Macro> ¯o)
|
||||
{
|
||||
_macro = macro.get();
|
||||
SetupDescription();
|
||||
}
|
||||
|
||||
void MacroSegmentSelection::SetMacro(Macro *macro)
|
||||
{
|
||||
_macro = macro;
|
||||
SetupDescription();
|
||||
}
|
||||
|
||||
void MacroSegmentSelection::SetValue(const IntVariable &value)
|
||||
{
|
||||
_index->SetValue(value);
|
||||
SetupDescription();
|
||||
}
|
||||
|
||||
void MacroSegmentSelection::SetType(const Type &value)
|
||||
{
|
||||
_type = value;
|
||||
SetupDescription();
|
||||
}
|
||||
|
||||
void MacroSegmentSelection::MacroSegmentOrderChanged()
|
||||
{
|
||||
SetupDescription();
|
||||
}
|
||||
|
||||
void MacroSegmentSelection::SetupDescription() const
|
||||
{
|
||||
if (!_macro) {
|
||||
_description->setText("");
|
||||
_description->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
auto index = _index->Value();
|
||||
if (index.GetType() == IntVariable::Type::VARIABLE || index == 0) {
|
||||
_description->setText("");
|
||||
_description->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
QString description;
|
||||
if (IsValidMacroSegmentIndex(_macro, index - 1,
|
||||
_type == Type::CONDITION)) {
|
||||
description = GetMacroSegmentDescription(
|
||||
_macro, index - 1, _type == Type::CONDITION);
|
||||
} else {
|
||||
description = obs_module_text(
|
||||
"AdvSceneSwitcher.macroSegmentSelection.invalid");
|
||||
}
|
||||
|
||||
if (!description.isEmpty()) {
|
||||
description = "(" + description + ")";
|
||||
_description->setText(description);
|
||||
_description->show();
|
||||
} else {
|
||||
_description->setText("");
|
||||
_description->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void MacroSegmentSelection::IndexChanged(const IntVariable &value)
|
||||
{
|
||||
SetupDescription();
|
||||
MarkSelectedSegment();
|
||||
emit(SelectionChanged(value));
|
||||
}
|
||||
|
||||
void MacroSegmentSelection::MarkSelectedSegment()
|
||||
{
|
||||
if (!GetSwitcher() || GetSwitcher()->disableHints) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_macro || !AdvSceneSwitcher::window ||
|
||||
_macro != AdvSceneSwitcher::window->GetSelectedMacro().get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto index = _index->Value();
|
||||
if (index.GetType() == IntVariable::Type::VARIABLE) {
|
||||
return;
|
||||
}
|
||||
if (!IsValidMacroSegmentIndex(_macro, index - 1,
|
||||
_type == Type::CONDITION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_type == Type::CONDITION) {
|
||||
AdvSceneSwitcher::window->HighlightCondition(
|
||||
index - 1, QColor(Qt::lightGray));
|
||||
} else {
|
||||
AdvSceneSwitcher::window->HighlightAction(
|
||||
index - 1, QColor(Qt::lightGray));
|
||||
}
|
||||
|
||||
PulseWidget(this, QColor(Qt::lightGray), QColor(0, 0, 0, 0), true);
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
37
src/utils/macro-segment-selection.hpp
Normal file
37
src/utils/macro-segment-selection.hpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
#include "variable-spinbox.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
class Macro;
|
||||
|
||||
class MacroSegmentSelection : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class Type { CONDITION, ACTION };
|
||||
|
||||
MacroSegmentSelection(QWidget *parent, Type type,
|
||||
bool allowVariables = true);
|
||||
void SetMacro(const std::shared_ptr<Macro> ¯o);
|
||||
void SetMacro(Macro *macro);
|
||||
void SetValue(const IntVariable &value);
|
||||
void SetType(const Type &value);
|
||||
|
||||
private slots:
|
||||
void IndexChanged(const NumberVariable<int> &value);
|
||||
void MacroSegmentOrderChanged();
|
||||
signals:
|
||||
void SelectionChanged(const IntVariable &value);
|
||||
|
||||
private:
|
||||
void SetupDescription() const;
|
||||
void MarkSelectedSegment();
|
||||
|
||||
VariableSpinBox *_index;
|
||||
QLabel *_description;
|
||||
|
||||
Type _type;
|
||||
Macro *_macro = nullptr;
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
Loading…
Reference in New Issue
Block a user