SceneSwitcher/src/utils/source-selection.hpp
WarmUpTill d759ded64d 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.
2023-07-15 11:05:19 +02:00

73 lines
1.7 KiB
C++

#pragma once
#include "variable.hpp"
#include "filter-combo-box.hpp"
#include "utility.hpp"
namespace advss {
class SourceSelection {
public:
void Save(obs_data_t *obj, const char *name = "source") const;
void Load(obs_data_t *obj, const char *name = "source");
enum class Type {
SOURCE,
VARIABLE,
};
Type GetType() const { return _type; }
OBSWeakSource GetSource() const;
void SetSource(OBSWeakSource);
std::string ToString(bool resolve = false) const;
bool operator==(const SourceSelection &) const;
private:
// TODO: Remove in future version
// Used for backwards compatability to older settings versions
void LoadFallback(obs_data_t *obj, const char *name);
OBSWeakSource _source;
std::weak_ptr<Variable> _variable;
Type _type = Type::SOURCE;
friend class SourceSelectionWidget;
};
class SourceSelectionWidget : public FilterComboBox {
Q_OBJECT
public:
SourceSelectionWidget(QWidget *parent, const QStringList &sourceNames,
bool addVariables = true);
void SetSource(const SourceSelection &);
void SetSourceNameList(const QStringList &);
signals:
void SourceChanged(const SourceSelection &);
private slots:
void SelectionChanged(int);
void ItemAdd(const QString &name);
void ItemRemove(const QString &name);
void ItemRename(const QString &oldName, const QString &newName);
private:
void Reset();
SourceSelection CurrentSelection();
void PopulateSelection();
bool NameUsed(const QString &name);
bool _addVariables;
QStringList _sourceNames;
SourceSelection _currentSelection;
// Order of entries
// 1. "select entry" entry
// 2. Variables
// 3. Regular sources
const int _selectIdx = 0;
int _variablesEndIdx = -1;
int _sourcesEndIdx = -1;
};
} // namespace advss