From 72f67705edce8b41c489e441f98298c573baced1 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Tue, 1 Jun 2021 21:10:50 +0200 Subject: [PATCH] Collapse time restriction to clock symbol if no restriction is set --- data/res/time.svg | 3 +++ src/duration-control.cpp | 23 +++++++++++++++++++++-- src/headers/duration-control.hpp | 5 +++++ src/headers/utility.hpp | 3 +-- src/utility.cpp | 10 ++++------ 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 data/res/time.svg diff --git a/data/res/time.svg b/data/res/time.svg new file mode 100644 index 00000000..cafc173a --- /dev/null +++ b/data/res/time.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/duration-control.cpp b/src/duration-control.cpp index bd896f23..3eee43eb 100644 --- a/src/duration-control.cpp +++ b/src/duration-control.cpp @@ -209,21 +209,28 @@ DurationConstraintEdit::DurationConstraintEdit(QWidget *parent) { _condition = new QComboBox(parent); _duration = new DurationSelection(parent); + _toggle = new QPushButton(parent); + _toggle->setMaximumSize(22, 22); + _toggle->setIcon( + QIcon(QString::fromStdString(getDataFilePath("res/time.svg")))); populateConditions(_condition); QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)), this, SLOT(_ConditionChanged(int))); - QObject::connect(_duration, &DurationSelection::DurationChanged, this, &DurationConstraintEdit::DurationChanged); QObject::connect(_duration, &DurationSelection::UnitChanged, this, &DurationConstraintEdit::UnitChanged); + QWidget::connect(_toggle, SIGNAL(clicked()), this, + SLOT(ToggleClicked())); QHBoxLayout *layout = new QHBoxLayout; layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(11); + layout->addWidget(_toggle); layout->addWidget(_condition); layout->addWidget(_duration); setLayout(layout); + Collapse(true); } void DurationConstraintEdit::SetValue(DurationConstraint &value) @@ -246,6 +253,18 @@ void DurationConstraintEdit::SetDuration(const Duration &d) void DurationConstraintEdit::_ConditionChanged(int value) { auto cond = static_cast(value); - _duration->setVisible(cond != DurationCondition::NONE); + Collapse(cond == DurationCondition::NONE); emit ConditionChanged(cond); } + +void DurationConstraintEdit::ToggleClicked() +{ + Collapse(false); +} + +void DurationConstraintEdit::Collapse(bool collapse) +{ + _toggle->setVisible(collapse); + _duration->setVisible(!collapse); + _condition->setVisible(!collapse); +} diff --git a/src/headers/duration-control.hpp b/src/headers/duration-control.hpp index 59b4d9e0..3ff1d774 100644 --- a/src/headers/duration-control.hpp +++ b/src/headers/duration-control.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "obs-data.h" @@ -94,12 +95,16 @@ public: private slots: void _ConditionChanged(int value); + void ToggleClicked(); signals: void DurationChanged(double value); void UnitChanged(DurationUnit u); void ConditionChanged(DurationCondition value); private: + void Collapse(bool collapse); + DurationSelection *_duration; QComboBox *_condition; + QPushButton *_toggle; }; diff --git a/src/headers/utility.hpp b/src/headers/utility.hpp index 2a461120..6a54c970 100644 --- a/src/headers/utility.hpp +++ b/src/headers/utility.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include "scene-group.hpp" bool WeakSourceValid(obs_weak_source_t *ws); @@ -23,7 +22,7 @@ OBSWeakSource GetWeakFilterByName(OBSWeakSource source, const char *name); OBSWeakSource GetWeakFilterByQString(OBSWeakSource source, const QString &name); bool compareIgnoringLineEnding(QString &s1, QString &s2); std::string getSourceSettings(OBSWeakSource ws); -std::filesystem::path getDataFilePath(const std::string &file); +std::string getDataFilePath(const std::string &file); /** * Populate layout with labels and widgets based on provided text diff --git a/src/utility.cpp b/src/utility.cpp index 1f2283d2..8f06f9a5 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -218,13 +218,11 @@ std::string getSourceSettings(OBSWeakSource ws) return settings; } -std::filesystem::path getDataFilePath(const std::string &file) +std::string getDataFilePath(const std::string &file) { - const char *root_path = obs_get_module_data_path(obs_current_module()); - if (root_path) { - auto ret = std::filesystem::u8path(root_path); - ret.append(file.data()); - return ret; + std::string root_path = obs_get_module_data_path(obs_current_module()); + if (!root_path.empty()) { + return root_path + "/" + file; } return ""; }