mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Replaced Checkbox with SettingsButton for chat participant statuses.
This commit is contained in:
parent
642554828c
commit
21cd1555f0
2 changed files with 85 additions and 82 deletions
|
@ -619,7 +619,6 @@ adminLogFilterUserCheckbox: Checkbox(defaultBoxCheckbox) {
|
||||||
margin: margins(8px, 6px, 8px, 6px);
|
margin: margins(8px, 6px, 8px, 6px);
|
||||||
checkPosition: point(8px, 6px);
|
checkPosition: point(8px, 6px);
|
||||||
}
|
}
|
||||||
|
|
||||||
rightsCheckbox: Checkbox(defaultCheckbox) {
|
rightsCheckbox: Checkbox(defaultCheckbox) {
|
||||||
textPosition: point(10px, 1px);
|
textPosition: point(10px, 1px);
|
||||||
rippleBg: attentionButtonBgOver;
|
rippleBg: attentionButtonBgOver;
|
||||||
|
@ -634,6 +633,14 @@ rightsToggle: Toggle(defaultToggle) {
|
||||||
stroke: 2px;
|
stroke: 2px;
|
||||||
duration: 120;
|
duration: 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rightsButton: SettingsButton(defaultSettingsButton) {
|
||||||
|
padding: margins(22px, 8px, 22px, 8px);
|
||||||
|
|
||||||
|
toggle: rightsToggle;
|
||||||
|
toggleOver: rightsToggle;
|
||||||
|
toggleSkip: 19px;
|
||||||
|
}
|
||||||
rightsDividerHeight: boxDividerHeight;
|
rightsDividerHeight: boxDividerHeight;
|
||||||
rightsDividerMargin: margins(0px, 0px, 0px, 20px);
|
rightsDividerMargin: margins(0px, 0px, 0px, 20px);
|
||||||
rightsHeaderMargin: margins(22px, 0px, 22px, 8px);
|
rightsHeaderMargin: margins(22px, 0px, 22px, 8px);
|
||||||
|
|
|
@ -52,59 +52,6 @@ int SlowmodeDelayByIndex(int index) {
|
||||||
Unexpected("Index in SlowmodeDelayByIndex.");
|
Unexpected("Index in SlowmodeDelayByIndex.");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename CheckboxesMap, typename DependenciesMap>
|
|
||||||
void ApplyDependencies(
|
|
||||||
const CheckboxesMap &checkboxes,
|
|
||||||
const DependenciesMap &dependencies,
|
|
||||||
QPointer<Ui::Checkbox> changed) {
|
|
||||||
const auto checkAndApply = [&](
|
|
||||||
auto &¤t,
|
|
||||||
auto dependency,
|
|
||||||
bool isChecked) {
|
|
||||||
for (auto &&checkbox : checkboxes) {
|
|
||||||
if ((checkbox.first & dependency)
|
|
||||||
&& (checkbox.second->checked() == isChecked)) {
|
|
||||||
current->setChecked(isChecked);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
const auto applySomeDependency = [&] {
|
|
||||||
auto result = false;
|
|
||||||
for (auto &&entry : checkboxes) {
|
|
||||||
if (entry.second == changed) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto isChecked = entry.second->checked();
|
|
||||||
for (auto &&dependency : dependencies) {
|
|
||||||
const auto check = isChecked
|
|
||||||
? dependency.first
|
|
||||||
: dependency.second;
|
|
||||||
if (entry.first & check) {
|
|
||||||
if (checkAndApply(
|
|
||||||
entry.second,
|
|
||||||
(isChecked
|
|
||||||
? dependency.second
|
|
||||||
: dependency.first),
|
|
||||||
!isChecked)) {
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto maxFixesCount = int(checkboxes.size());
|
|
||||||
for (auto i = 0; i != maxFixesCount; ++i) {
|
|
||||||
if (!applySomeDependency()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto Dependencies(ChatRestrictions)
|
auto Dependencies(ChatRestrictions)
|
||||||
-> std::vector<std::pair<ChatRestriction, ChatRestriction>> {
|
-> std::vector<std::pair<ChatRestriction, ChatRestriction>> {
|
||||||
using Flag = ChatRestriction;
|
using Flag = ChatRestriction;
|
||||||
|
@ -207,22 +154,17 @@ ChatRestrictions DisabledByAdminRights(not_null<PeerData*> peer) {
|
||||||
: Flag::ChangeInfo);
|
: Flag::ChangeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<Ui::Checkbox*> AddDefaultCheckbox(
|
not_null<Ui::SettingsButton*> AddDefaultCheckbox(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
const QString &text,
|
const QString &text,
|
||||||
bool toggled,
|
bool toggled,
|
||||||
bool locked) {
|
bool locked) {
|
||||||
auto toggle = std::make_unique<Ui::ToggleView>(
|
const auto button = Settings::AddButton(
|
||||||
st::rightsToggle,
|
container,
|
||||||
toggled);
|
rpl::single(text),
|
||||||
toggle->setLocked(locked);
|
st::rightsButton);
|
||||||
return container->add(
|
button->setToggleLocked(locked);
|
||||||
object_ptr<Ui::Checkbox>(
|
return button;
|
||||||
container,
|
|
||||||
text,
|
|
||||||
st::rightsCheckbox,
|
|
||||||
std::move(toggle)),
|
|
||||||
st::rightsToggleMargin);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <
|
template <
|
||||||
|
@ -237,13 +179,20 @@ template <
|
||||||
const DisabledMessagePairs &disabledMessagePairs,
|
const DisabledMessagePairs &disabledMessagePairs,
|
||||||
const FlagLabelPairs &flagLabelPairs,
|
const FlagLabelPairs &flagLabelPairs,
|
||||||
CheckboxFactory checkboxFactory) {
|
CheckboxFactory checkboxFactory) {
|
||||||
const auto checkboxes = container->lifetime(
|
struct FlagCheck final {
|
||||||
).make_state<std::map<Flags, QPointer<Ui::Checkbox>>>();
|
QPointer<Ui::SettingsButton> widget;
|
||||||
|
rpl::event_stream<bool> checkChanges;
|
||||||
|
};
|
||||||
|
struct State final {
|
||||||
|
std::map<Flags, FlagCheck> checkboxes;
|
||||||
|
rpl::event_stream<> anyChanges;
|
||||||
|
};
|
||||||
|
const auto state = container->lifetime().make_state<State>();
|
||||||
|
|
||||||
const auto value = [=] {
|
const auto value = [=] {
|
||||||
auto result = Flags(0);
|
auto result = Flags(0);
|
||||||
for (const auto &[flags, checkbox] : *checkboxes) {
|
for (const auto &[flags, checkbox] : state->checkboxes) {
|
||||||
if (checkbox->checked()) {
|
if (checkbox.widget->toggled()) {
|
||||||
result |= flags;
|
result |= flags;
|
||||||
} else {
|
} else {
|
||||||
result &= ~flags;
|
result &= ~flags;
|
||||||
|
@ -252,12 +201,55 @@ template <
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto changes = container->lifetime(
|
const auto applyDependencies = [=](Ui::SettingsButton *changed) {
|
||||||
).make_state<rpl::event_stream<>>();
|
|
||||||
|
|
||||||
const auto applyDependencies = [=](Ui::Checkbox *control) {
|
|
||||||
static const auto dependencies = Dependencies(Flags());
|
static const auto dependencies = Dependencies(Flags());
|
||||||
ApplyDependencies(*checkboxes, dependencies, control);
|
|
||||||
|
const auto checkAndApply = [&](
|
||||||
|
auto ¤t,
|
||||||
|
auto dependency,
|
||||||
|
bool isChecked) {
|
||||||
|
for (const auto &checkbox : state->checkboxes) {
|
||||||
|
if ((checkbox.first & dependency)
|
||||||
|
&& (checkbox.second.widget->toggled() == isChecked)) {
|
||||||
|
current.checkChanges.fire_copy(isChecked);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
const auto applySomeDependency = [&] {
|
||||||
|
auto result = false;
|
||||||
|
for (auto &entry : state->checkboxes) {
|
||||||
|
if (entry.second.widget.data() == changed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto isChecked = entry.second.widget->toggled();
|
||||||
|
for (const auto &dependency : dependencies) {
|
||||||
|
const auto check = isChecked
|
||||||
|
? dependency.first
|
||||||
|
: dependency.second;
|
||||||
|
if (entry.first & check) {
|
||||||
|
if (checkAndApply(
|
||||||
|
entry.second,
|
||||||
|
(isChecked
|
||||||
|
? dependency.second
|
||||||
|
: dependency.first),
|
||||||
|
!isChecked)) {
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto maxFixesCount = int(state->checkboxes.size());
|
||||||
|
for (auto i = 0; i != maxFixesCount; ++i) {
|
||||||
|
if (!applySomeDependency()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
container->add(
|
container->add(
|
||||||
|
@ -280,7 +272,11 @@ template <
|
||||||
text,
|
text,
|
||||||
toggled,
|
toggled,
|
||||||
locked.has_value());
|
locked.has_value());
|
||||||
control->checkedChanges(
|
const auto flagCheck = state->checkboxes.emplace(
|
||||||
|
flags,
|
||||||
|
FlagCheck{ .widget = Ui::MakeWeak(control) }).first;
|
||||||
|
control->toggleOn(flagCheck->second.checkChanges.events());
|
||||||
|
control->toggledChanges(
|
||||||
) | rpl::start_with_next([=](bool checked) {
|
) | rpl::start_with_next([=](bool checked) {
|
||||||
if (locked.has_value()) {
|
if (locked.has_value()) {
|
||||||
if (checked != toggled) {
|
if (checked != toggled) {
|
||||||
|
@ -288,30 +284,30 @@ template <
|
||||||
.parentOverride = container,
|
.parentOverride = container,
|
||||||
.text = { *locked },
|
.text = { *locked },
|
||||||
});
|
});
|
||||||
control->setChecked(toggled);
|
flagCheck->second.checkChanges.fire_copy(toggled);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
InvokeQueued(control, [=] {
|
InvokeQueued(control, [=] {
|
||||||
applyDependencies(control);
|
applyDependencies(control);
|
||||||
changes->fire({});
|
state->anyChanges.fire({});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, control->lifetime());
|
}, control->lifetime());
|
||||||
checkboxes->emplace(flags, control);
|
flagCheck->second.checkChanges.fire_copy(toggled);
|
||||||
};
|
};
|
||||||
for (const auto &[flags, label] : flagLabelPairs) {
|
for (const auto &[flags, label] : flagLabelPairs) {
|
||||||
addCheckbox(flags, label);
|
addCheckbox(flags, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyDependencies(nullptr);
|
applyDependencies(nullptr);
|
||||||
for (const auto &[flags, checkbox] : *checkboxes) {
|
for (const auto &[flags, checkbox] : state->checkboxes) {
|
||||||
checkbox->finishAnimating();
|
checkbox.widget->finishAnimating();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nullptr,
|
nullptr,
|
||||||
value,
|
value,
|
||||||
changes->events() | rpl::map(value)
|
state->anyChanges.events() | rpl::map(value)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue