mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-05 00:35:46 -05:00
Use FilterComboBox instead of regular QComboBox
This required the following adjustments: Instead of having a dedicated entry indicating the empty selection the setPlaceholderText() mechanism is used. Thus the locations where the 1st entry was assumed to be the empty selection would have to be adjusted. Additional checks for the empty string / index -1 have been added. FindIdxInRagne() was adjusted to return -1 instead of 0 in case the given string was not found. Switched to index based singal instead of text based signal to be notified about selection changes.
This commit is contained in:
parent
0b2e1b88cc
commit
d759ded64d
|
|
@ -78,7 +78,7 @@ MacroActionEdit::MacroActionEdit(QWidget *parent,
|
|||
std::shared_ptr<MacroAction> *entryData,
|
||||
const std::string &id)
|
||||
: MacroSegmentEdit(switcher->macroProperties._highlightActions, parent),
|
||||
_actionSelection(new QComboBox()),
|
||||
_actionSelection(new FilterComboBox()),
|
||||
_entryData(entryData)
|
||||
{
|
||||
QWidget::connect(_actionSelection,
|
||||
|
|
@ -115,10 +115,14 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text)
|
|||
return;
|
||||
}
|
||||
|
||||
std::string id = MacroActionFactory::GetIdByName(text);
|
||||
if (id.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HeaderInfoChanged("");
|
||||
auto idx = _entryData->get()->GetIndex();
|
||||
auto macro = _entryData->get()->GetMacro();
|
||||
std::string id = MacroActionFactory::GetIdByName(text);
|
||||
HeaderInfoChanged("");
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->reset();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include "macro-action.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <memory>
|
||||
|
||||
namespace advss {
|
||||
|
|
@ -48,7 +48,7 @@ private slots:
|
|||
private:
|
||||
std::shared_ptr<MacroSegment> Data();
|
||||
|
||||
QComboBox *_actionSelection;
|
||||
FilterComboBox *_actionSelection;
|
||||
|
||||
std::shared_ptr<MacroAction> *_entryData;
|
||||
bool _loading = true;
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ MacroConditionEdit::MacroConditionEdit(
|
|||
: MacroSegmentEdit(switcher->macroProperties._highlightConditions,
|
||||
parent),
|
||||
_logicSelection(new QComboBox()),
|
||||
_conditionSelection(new QComboBox()),
|
||||
_conditionSelection(new FilterComboBox()),
|
||||
_dur(new DurationModifierEdit()),
|
||||
_entryData(entryData),
|
||||
_isRoot(root)
|
||||
|
|
@ -295,13 +295,16 @@ void MacroConditionEdit::ConditionSelectionChanged(const QString &text)
|
|||
return;
|
||||
}
|
||||
|
||||
auto idx = _entryData->get()->GetIndex();
|
||||
auto macro = _entryData->get()->GetMacro();
|
||||
std::string id = MacroConditionFactory::GetIdByName(text);
|
||||
if (id.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto temp = DurationModifier();
|
||||
_dur->SetValue(temp);
|
||||
HeaderInfoChanged("");
|
||||
auto idx = _entryData->get()->GetIndex();
|
||||
auto macro = _entryData->get()->GetMacro();
|
||||
{
|
||||
auto lock = LockContext();
|
||||
auto logic = (*_entryData)->GetLogicType();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "macro-condition.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -77,7 +78,7 @@ private:
|
|||
std::shared_ptr<MacroSegment> Data();
|
||||
|
||||
QComboBox *_logicSelection;
|
||||
QComboBox *_conditionSelection;
|
||||
FilterComboBox *_conditionSelection;
|
||||
DurationModifierEdit *_dur;
|
||||
|
||||
std::shared_ptr<MacroCondition> *_entryData;
|
||||
|
|
|
|||
|
|
@ -8,18 +8,10 @@
|
|||
|
||||
namespace advss {
|
||||
|
||||
MacroSelection::MacroSelection(QWidget *parent) : QComboBox(parent)
|
||||
MacroSelection::MacroSelection(QWidget *parent)
|
||||
: FilterComboBox(parent,
|
||||
obs_module_text("AdvSceneSwitcher.selectMacro"))
|
||||
{
|
||||
addItem(obs_module_text("AdvSceneSwitcher.selectMacro"));
|
||||
|
||||
QStandardItemModel *model =
|
||||
qobject_cast<QStandardItemModel *>(this->model());
|
||||
QModelIndex firstIndex =
|
||||
model->index(0, modelColumn(), rootModelIndex());
|
||||
QStandardItem *firstItem = model->itemFromIndex(firstIndex);
|
||||
firstItem->setSelectable(false);
|
||||
firstItem->setEnabled(false);
|
||||
|
||||
for (const auto &m : switcher->macros) {
|
||||
if (m->IsGroup()) {
|
||||
continue;
|
||||
|
|
@ -139,8 +131,9 @@ bool MacroSelectionDialog::AskForMacro(QWidget *parent, std::string ¯oName)
|
|||
if (dialog.exec() != DialogCode::Accepted) {
|
||||
return false;
|
||||
}
|
||||
macroName = dialog._macroSelection->currentText().toUtf8().constData();
|
||||
if (macroName == obs_module_text("AdvSceneSwitcher.selectMacro")) {
|
||||
macroName = dialog._macroSelection->currentText().toStdString();
|
||||
if (macroName == obs_module_text("AdvSceneSwitcher.selectMacro") ||
|
||||
macroName.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <QComboBox>
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace advss {
|
||||
|
|
@ -7,7 +8,7 @@ namespace advss {
|
|||
class Macro;
|
||||
class MacroRef;
|
||||
|
||||
class MacroSelection : public QComboBox {
|
||||
class MacroSelection : public FilterComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -113,6 +113,9 @@ FilterSelection FilterSelectionWidget::CurrentSelection()
|
|||
FilterSelection s;
|
||||
const int idx = currentIndex();
|
||||
const auto name = currentText();
|
||||
if (idx == -1 || name.isEmpty()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
if (idx < _variablesEndIdx) {
|
||||
s._type = FilterSelection::Type::VARIABLE;
|
||||
|
|
@ -136,10 +139,6 @@ void FilterSelectionWidget::PopulateSelection()
|
|||
{
|
||||
const QSignalBlocker b(this);
|
||||
clear();
|
||||
AddSelectionEntry(this,
|
||||
obs_module_text("AdvSceneSwitcher.selectFilter"));
|
||||
insertSeparator(count());
|
||||
|
||||
if (_addVariables) {
|
||||
const QStringList variables = GetVariablesNameList();
|
||||
AddSelectionGroup(this, variables);
|
||||
|
|
@ -151,18 +150,20 @@ void FilterSelectionWidget::PopulateSelection()
|
|||
|
||||
// Remove last separator
|
||||
removeItem(count() - 1);
|
||||
setCurrentIndex(0);
|
||||
setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
FilterSelectionWidget::FilterSelectionWidget(QWidget *parent,
|
||||
SourceSelectionWidget *sources,
|
||||
bool addVariables)
|
||||
: QComboBox(parent), _addVariables(addVariables)
|
||||
: FilterComboBox(parent,
|
||||
obs_module_text("AdvSceneSwitcher.selectFilter")),
|
||||
_addVariables(addVariables)
|
||||
{
|
||||
setDuplicatesEnabled(true);
|
||||
|
||||
QWidget::connect(this, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(SelectionChanged(const QString &)));
|
||||
QWidget::connect(this, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(SelectionChanged(int)));
|
||||
QWidget::connect(sources,
|
||||
SIGNAL(SourceChanged(const SourceSelection &)), this,
|
||||
SLOT(SourceChanged(const SourceSelection &)));
|
||||
|
|
@ -184,12 +185,12 @@ void FilterSelectionWidget::SetFilter(const SourceSelection &source,
|
|||
_source = source;
|
||||
PopulateSelection();
|
||||
|
||||
int idx = 0;
|
||||
int idx = -1;
|
||||
|
||||
switch (filter.GetType()) {
|
||||
case FilterSelection::Type::SOURCE: {
|
||||
if (_filterEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
idx = FindIdxInRagne(this, _variablesEndIdx, _filterEndIdx,
|
||||
|
|
@ -198,14 +199,14 @@ void FilterSelectionWidget::SetFilter(const SourceSelection &source,
|
|||
}
|
||||
case FilterSelection::Type::VARIABLE: {
|
||||
if (_variablesEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
idx = FindIdxInRagne(this, _selectIdx, _variablesEndIdx,
|
||||
filter.ToString());
|
||||
break;
|
||||
default:
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -224,9 +225,10 @@ void FilterSelectionWidget::SourceChanged(const SourceSelection &source)
|
|||
emit FilterChanged(_currentSelection);
|
||||
}
|
||||
|
||||
void FilterSelectionWidget::SelectionChanged(const QString &)
|
||||
void FilterSelectionWidget::SelectionChanged(int)
|
||||
{
|
||||
emit FilterChanged(CurrentSelection());
|
||||
_currentSelection = CurrentSelection();
|
||||
emit FilterChanged(_currentSelection);
|
||||
}
|
||||
|
||||
void FilterSelectionWidget::ItemAdd(const QString &)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "source-selection.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ private:
|
|||
friend class FilterSelectionWidget;
|
||||
};
|
||||
|
||||
class FilterSelectionWidget : public QComboBox {
|
||||
class FilterSelectionWidget : public FilterComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
@ -47,7 +48,7 @@ signals:
|
|||
public slots:
|
||||
void SourceChanged(const SourceSelection &);
|
||||
private slots:
|
||||
void SelectionChanged(const QString &name);
|
||||
void SelectionChanged(int);
|
||||
void ItemAdd(const QString &name);
|
||||
void ItemRemove(const QString &name);
|
||||
void ItemRename(const QString &oldName, const QString &newName);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ ItemSelection::ItemSelection(std::deque<std::shared_ptr<Item>> &items,
|
|||
std::string_view select, std::string_view add,
|
||||
QWidget *parent)
|
||||
: QWidget(parent),
|
||||
_selection(new QComboBox),
|
||||
_selection(new FilterComboBox(this, obs_module_text(select.data()))),
|
||||
_modify(new QPushButton),
|
||||
_create(create),
|
||||
_askForSettings(callback),
|
||||
|
|
@ -77,7 +77,6 @@ ItemSelection::ItemSelection(std::deque<std::shared_ptr<Item>> &items,
|
|||
_selection->addItem(QString::fromStdString(i->_name));
|
||||
}
|
||||
_selection->model()->sort(0);
|
||||
AddSelectionEntry(_selection, obs_module_text(_selectStr.data()));
|
||||
_selection->insertSeparator(_selection->count());
|
||||
_selection->addItem(obs_module_text(_addStr.data()));
|
||||
}
|
||||
|
|
@ -230,7 +229,7 @@ void ItemSelection::RemoveItem(const QString &name)
|
|||
{
|
||||
const int idx = _selection->findText(name);
|
||||
if (idx == _selection->currentIndex()) {
|
||||
_selection->setCurrentIndex(0);
|
||||
_selection->setCurrentIndex(-1);
|
||||
}
|
||||
_selection->removeItem(idx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
|
@ -93,7 +93,7 @@ signals:
|
|||
protected:
|
||||
Item *GetCurrentItem();
|
||||
|
||||
QComboBox *_selection;
|
||||
FilterComboBox *_selection;
|
||||
QPushButton *_modify;
|
||||
CreateItemFunc _create;
|
||||
SettingsCallback _askForSettings;
|
||||
|
|
|
|||
|
|
@ -265,10 +265,6 @@ void SceneItemSelectionWidget::Reset()
|
|||
void SceneItemSelectionWidget::PopulateItemSelection()
|
||||
{
|
||||
_sceneItems->clear();
|
||||
AddSelectionEntry(_sceneItems,
|
||||
obs_module_text("AdvSceneSwitcher.selectItem"));
|
||||
_sceneItems->insertSeparator(_sceneItems->count());
|
||||
|
||||
const QStringList variables = GetVariablesNameList();
|
||||
AddSelectionGroup(_sceneItems, variables);
|
||||
_variablesEndIdx = _sceneItems->count();
|
||||
|
|
@ -276,7 +272,7 @@ void SceneItemSelectionWidget::PopulateItemSelection()
|
|||
const QStringList sceneItmes = GetSceneItemsList(_scene);
|
||||
AddSelectionGroup(_sceneItems, sceneItmes, false);
|
||||
_itemsEndIdx = _sceneItems->count();
|
||||
_sceneItems->setCurrentIndex(0);
|
||||
_sceneItems->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
SceneItemSelectionWidget::SceneItemSelectionWidget(QWidget *parent,
|
||||
|
|
@ -284,7 +280,8 @@ SceneItemSelectionWidget::SceneItemSelectionWidget(QWidget *parent,
|
|||
Placeholder type)
|
||||
: QWidget(parent), _hasPlaceholderEntry(showAll), _placeholder(type)
|
||||
{
|
||||
_sceneItems = new QComboBox();
|
||||
_sceneItems = new FilterComboBox(
|
||||
this, obs_module_text("AdvSceneSwitcher.selectItem"));
|
||||
_idx = new QComboBox();
|
||||
|
||||
_sceneItems->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
|
|
@ -292,9 +289,8 @@ SceneItemSelectionWidget::SceneItemSelectionWidget(QWidget *parent,
|
|||
|
||||
populateSceneItemSelection(_sceneItems);
|
||||
|
||||
QWidget::connect(_sceneItems,
|
||||
SIGNAL(currentTextChanged(const QString &)), this,
|
||||
SLOT(SelectionChanged(const QString &)));
|
||||
QWidget::connect(_sceneItems, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(SelectionChanged(int)));
|
||||
QWidget::connect(_idx, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(IdxChanged(int)));
|
||||
// Variables
|
||||
|
|
@ -317,7 +313,7 @@ SceneItemSelectionWidget::SceneItemSelectionWidget(QWidget *parent,
|
|||
|
||||
void SceneItemSelectionWidget::SetSceneItem(const SceneItemSelection &item)
|
||||
{
|
||||
int itemIdx = 0;
|
||||
int itemIdx = -1;
|
||||
switch (item._type) {
|
||||
case SceneItemSelection::Type::SOURCE: {
|
||||
int idx = item._idx;
|
||||
|
|
@ -379,7 +375,7 @@ void SceneItemSelectionWidget::SetPlaceholderType(Placeholder t,
|
|||
{
|
||||
_placeholder = t;
|
||||
if (resetSelection) {
|
||||
_sceneItems->setCurrentIndex(0);
|
||||
_sceneItems->setCurrentIndex(-1);
|
||||
} else {
|
||||
auto count = _idx->count() - 1;
|
||||
const QSignalBlocker b(_idx);
|
||||
|
|
@ -393,9 +389,12 @@ void SceneItemSelectionWidget::SceneChanged(const SceneSelection &s)
|
|||
adjustSize();
|
||||
}
|
||||
|
||||
void SceneItemSelectionWidget::SelectionChanged(const QString &name)
|
||||
SceneItemSelection SceneItemSelectionWidget::CurrentSelection()
|
||||
{
|
||||
SceneItemSelection s;
|
||||
const int idx = _sceneItems->currentIndex();
|
||||
const auto name = _sceneItems->currentText();
|
||||
|
||||
int sceneItemCount =
|
||||
getCountOfSceneItemOccurance(_scene, name.toStdString());
|
||||
if (sceneItemCount > 1) {
|
||||
|
|
@ -416,7 +415,10 @@ void SceneItemSelectionWidget::SelectionChanged(const QString &name)
|
|||
}
|
||||
}
|
||||
|
||||
const int idx = _sceneItems->currentIndex();
|
||||
if (idx == -1 || name.isEmpty()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
if (idx < _variablesEndIdx) {
|
||||
s._type = SceneItemSelection::Type::VARIABLE;
|
||||
s._variable = GetWeakVariableByQString(name);
|
||||
|
|
@ -425,8 +427,13 @@ void SceneItemSelectionWidget::SelectionChanged(const QString &name)
|
|||
s._sceneItem = GetWeakSourceByQString(name);
|
||||
}
|
||||
|
||||
_currentSelection = s;
|
||||
emit SceneItemChanged(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
void SceneItemSelectionWidget::SelectionChanged(int)
|
||||
{
|
||||
_currentSelection = CurrentSelection();
|
||||
emit SceneItemChanged(_currentSelection);
|
||||
}
|
||||
|
||||
void SceneItemSelectionWidget::IdxChanged(int idx)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
#include "scene-selection.hpp"
|
||||
#include "variable.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <obs-data.h>
|
||||
|
||||
namespace advss {
|
||||
|
|
@ -57,7 +57,7 @@ signals:
|
|||
|
||||
private slots:
|
||||
void SceneChanged(const SceneSelection &);
|
||||
void SelectionChanged(const QString &name);
|
||||
void SelectionChanged(int);
|
||||
void IdxChanged(int);
|
||||
void ItemAdd(const QString &name);
|
||||
void ItemRemove(const QString &name);
|
||||
|
|
@ -65,10 +65,11 @@ private slots:
|
|||
|
||||
private:
|
||||
void Reset();
|
||||
SceneItemSelection CurrentSelection();
|
||||
void PopulateItemSelection();
|
||||
void SetupIdxSelection(int);
|
||||
|
||||
QComboBox *_sceneItems;
|
||||
FilterComboBox *_sceneItems;
|
||||
QComboBox *_idx;
|
||||
|
||||
SceneSelection _scene;
|
||||
|
|
|
|||
|
|
@ -178,6 +178,9 @@ SceneSelection SceneSelectionWidget::CurrentSelection()
|
|||
SceneSelection s;
|
||||
const int idx = currentIndex();
|
||||
const auto name = currentText();
|
||||
if (idx == -1 || name.isEmpty()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
if (idx < _placeholderEndIdx) {
|
||||
if (IsCurrentSceneSelected(name)) {
|
||||
|
|
@ -251,10 +254,6 @@ void SceneSelectionWidget::Reset()
|
|||
void SceneSelectionWidget::PopulateSelection()
|
||||
{
|
||||
clear();
|
||||
AddSelectionEntry(this,
|
||||
obs_module_text("AdvSceneSwitcher.selectScene"));
|
||||
insertSeparator(count());
|
||||
|
||||
if (_current || _previous) {
|
||||
const QStringList order =
|
||||
getOrderList(_current, _previous, _preview);
|
||||
|
|
@ -280,13 +279,14 @@ void SceneSelectionWidget::PopulateSelection()
|
|||
|
||||
// Remove last separator
|
||||
removeItem(count() - 1);
|
||||
setCurrentIndex(0);
|
||||
setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
SceneSelectionWidget::SceneSelectionWidget(QWidget *parent, bool variables,
|
||||
bool sceneGroups, bool previous,
|
||||
bool current, bool preview)
|
||||
: QComboBox(parent),
|
||||
: FilterComboBox(parent,
|
||||
obs_module_text("AdvSceneSwitcher.selectScene")),
|
||||
_current(current),
|
||||
_previous(previous),
|
||||
_preview(preview),
|
||||
|
|
@ -296,8 +296,8 @@ SceneSelectionWidget::SceneSelectionWidget(QWidget *parent, bool variables,
|
|||
setDuplicatesEnabled(true);
|
||||
PopulateSelection();
|
||||
|
||||
QWidget::connect(this, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(SelectionChanged(const QString &)));
|
||||
QWidget::connect(this, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(SelectionChanged(int)));
|
||||
|
||||
// Scene groups
|
||||
QWidget::connect(window(), SIGNAL(SceneGroupAdded(const QString &)),
|
||||
|
|
@ -322,12 +322,12 @@ SceneSelectionWidget::SceneSelectionWidget(QWidget *parent, bool variables,
|
|||
|
||||
void SceneSelectionWidget::SetScene(const SceneSelection &s)
|
||||
{
|
||||
int idx = 0;
|
||||
int idx = -1;
|
||||
|
||||
switch (s.GetType()) {
|
||||
case SceneSelection::Type::SCENE: {
|
||||
if (_scenesEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
idx = FindIdxInRagne(this, _groupsEndIdx, _scenesEndIdx,
|
||||
|
|
@ -336,7 +336,7 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s)
|
|||
}
|
||||
case SceneSelection::Type::GROUP: {
|
||||
if (_groupsEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
idx = FindIdxInRagne(this, _variablesEndIdx, _groupsEndIdx,
|
||||
|
|
@ -345,7 +345,7 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s)
|
|||
}
|
||||
case SceneSelection::Type::PREVIOUS: {
|
||||
if (_placeholderEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +357,7 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s)
|
|||
}
|
||||
case SceneSelection::Type::CURRENT: {
|
||||
if (_placeholderEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -368,7 +368,7 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s)
|
|||
}
|
||||
case SceneSelection::Type::PREVIEW: {
|
||||
if (_placeholderEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -379,14 +379,14 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s)
|
|||
}
|
||||
case SceneSelection::Type::VARIABLE: {
|
||||
if (_variablesEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
idx = FindIdxInRagne(this, _placeholderEndIdx, _variablesEndIdx,
|
||||
s.ToString());
|
||||
break;
|
||||
default:
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -412,7 +412,7 @@ bool SceneSelectionWidget::IsPreviewSceneSelected(const QString &name)
|
|||
"AdvSceneSwitcher.selectPreviewScene")));
|
||||
}
|
||||
|
||||
void SceneSelectionWidget::SelectionChanged(const QString &)
|
||||
void SceneSelectionWidget::SelectionChanged(int)
|
||||
{
|
||||
_currentSelection = CurrentSelection();
|
||||
emit SceneChanged(_currentSelection);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
#pragma once
|
||||
#include "scene-group.hpp"
|
||||
#include "variable.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
namespace advss {
|
||||
|
||||
class SceneSelection {
|
||||
|
|
@ -34,7 +33,7 @@ private:
|
|||
friend class SceneSelectionWidget;
|
||||
};
|
||||
|
||||
class SceneSelectionWidget : public QComboBox {
|
||||
class SceneSelectionWidget : public FilterComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
@ -46,7 +45,7 @@ signals:
|
|||
void SceneChanged(const SceneSelection &);
|
||||
|
||||
private slots:
|
||||
void SelectionChanged(const QString &name);
|
||||
void SelectionChanged(int);
|
||||
void ItemAdd(const QString &name);
|
||||
void ItemRemove(const QString &name);
|
||||
void ItemRename(const QString &oldName, const QString &newName);
|
||||
|
|
|
|||
|
|
@ -125,6 +125,9 @@ SourceSelection SourceSelectionWidget::CurrentSelection()
|
|||
SourceSelection s;
|
||||
const int idx = currentIndex();
|
||||
const auto name = currentText();
|
||||
if (idx == -1 || name.isEmpty()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
if (idx < _variablesEndIdx) {
|
||||
s._type = SourceSelection::Type::VARIABLE;
|
||||
|
|
@ -146,10 +149,6 @@ void SourceSelectionWidget::Reset()
|
|||
void SourceSelectionWidget::PopulateSelection()
|
||||
{
|
||||
clear();
|
||||
AddSelectionEntry(this,
|
||||
obs_module_text("AdvSceneSwitcher.selectSource"));
|
||||
insertSeparator(count());
|
||||
|
||||
if (_addVariables) {
|
||||
const QStringList variables = GetVariablesNameList();
|
||||
AddSelectionGroup(this, variables);
|
||||
|
|
@ -161,21 +160,22 @@ void SourceSelectionWidget::PopulateSelection()
|
|||
|
||||
// Remove last separator
|
||||
removeItem(count() - 1);
|
||||
setCurrentIndex(0);
|
||||
setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
SourceSelectionWidget::SourceSelectionWidget(QWidget *parent,
|
||||
const QStringList &sourceNames,
|
||||
bool addVariables)
|
||||
: QComboBox(parent),
|
||||
: FilterComboBox(parent,
|
||||
obs_module_text("AdvSceneSwitcher.selectSource")),
|
||||
_addVariables(addVariables),
|
||||
_sourceNames(sourceNames)
|
||||
{
|
||||
setDuplicatesEnabled(true);
|
||||
PopulateSelection();
|
||||
|
||||
QWidget::connect(this, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(SelectionChanged(const QString &)));
|
||||
QWidget::connect(this, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(SelectionChanged(int)));
|
||||
|
||||
// Variables
|
||||
QWidget::connect(window(), SIGNAL(VariableAdded(const QString &)), this,
|
||||
|
|
@ -190,12 +190,12 @@ SourceSelectionWidget::SourceSelectionWidget(QWidget *parent,
|
|||
|
||||
void SourceSelectionWidget::SetSource(const SourceSelection &s)
|
||||
{
|
||||
int idx = 0;
|
||||
int idx = -1;
|
||||
|
||||
switch (s.GetType()) {
|
||||
case SourceSelection::Type::SOURCE: {
|
||||
if (_sourcesEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
idx = FindIdxInRagne(this, _variablesEndIdx, _sourcesEndIdx,
|
||||
|
|
@ -204,14 +204,14 @@ void SourceSelectionWidget::SetSource(const SourceSelection &s)
|
|||
}
|
||||
case SourceSelection::Type::VARIABLE: {
|
||||
if (_variablesEndIdx == -1) {
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
idx = FindIdxInRagne(this, _selectIdx, _variablesEndIdx,
|
||||
s.ToString());
|
||||
break;
|
||||
default:
|
||||
idx = 0;
|
||||
idx = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -225,7 +225,7 @@ void SourceSelectionWidget::SetSourceNameList(const QStringList &list)
|
|||
Reset();
|
||||
}
|
||||
|
||||
void SourceSelectionWidget::SelectionChanged(const QString &)
|
||||
void SourceSelectionWidget::SelectionChanged(int)
|
||||
{
|
||||
_currentSelection = CurrentSelection();
|
||||
emit SourceChanged(_currentSelection);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "variable.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
namespace advss {
|
||||
|
||||
class SourceSelection {
|
||||
|
|
@ -35,7 +33,7 @@ private:
|
|||
friend class SourceSelectionWidget;
|
||||
};
|
||||
|
||||
class SourceSelectionWidget : public QComboBox {
|
||||
class SourceSelectionWidget : public FilterComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
@ -47,7 +45,7 @@ signals:
|
|||
void SourceChanged(const SourceSelection &);
|
||||
|
||||
private slots:
|
||||
void SelectionChanged(const QString &name);
|
||||
void SelectionChanged(int);
|
||||
void ItemAdd(const QString &name);
|
||||
void ItemRemove(const QString &name);
|
||||
void ItemRename(const QString &oldName, const QString &newName);
|
||||
|
|
|
|||
|
|
@ -67,10 +67,11 @@ std::string TransitionSelection::ToString() const
|
|||
|
||||
TransitionSelectionWidget::TransitionSelectionWidget(QWidget *parent,
|
||||
bool current, bool any)
|
||||
: QComboBox(parent)
|
||||
: FilterComboBox(parent,
|
||||
obs_module_text("AdvSceneSwitcher.selectTransition"))
|
||||
{
|
||||
setDuplicatesEnabled(true);
|
||||
PopulateTransitionSelection(this, current, any);
|
||||
PopulateTransitionSelection(this, current, any, false);
|
||||
|
||||
QWidget::connect(this, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(SelectionChanged(const QString &)));
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
#pragma once
|
||||
#include "filter-combo-box.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
namespace advss {
|
||||
|
||||
class TransitionSelection {
|
||||
|
|
@ -28,7 +27,7 @@ private:
|
|||
friend class TransitionSelectionWidget;
|
||||
};
|
||||
|
||||
class TransitionSelectionWidget : public QComboBox {
|
||||
class TransitionSelectionWidget : public FilterComboBox {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1149,19 +1149,18 @@ int FindIdxInRagne(QComboBox *list, int start, int stop,
|
|||
const std::string &value, Qt::MatchFlags flags)
|
||||
{
|
||||
if (value.empty()) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
auto model = list->model();
|
||||
auto startIdx = model->index(start, 0);
|
||||
auto match = model->match(startIdx, Qt::DisplayRole,
|
||||
QString::fromStdString(value), 1,
|
||||
flags);
|
||||
QString::fromStdString(value), 1, flags);
|
||||
if (match.isEmpty()) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
int foundIdx = match.first().row();
|
||||
if (foundIdx > stop) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
return foundIdx;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user