mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support silent video volume toggle state.
This commit is contained in:
parent
7d067d4924
commit
150cbe2866
1 changed files with 17 additions and 4 deletions
|
@ -31,8 +31,9 @@ namespace {
|
||||||
|
|
||||||
constexpr auto kNameOpacity = 1.;
|
constexpr auto kNameOpacity = 1.;
|
||||||
constexpr auto kDateOpacity = 0.8;
|
constexpr auto kDateOpacity = 0.8;
|
||||||
constexpr auto kControlOpacity = 0.6;
|
constexpr auto kControlOpacity = 0.65;
|
||||||
constexpr auto kControlOpacityOver = 1.;
|
constexpr auto kControlOpacityOver = 1.;
|
||||||
|
constexpr auto kControlOpacityDisabled = 0.45;
|
||||||
constexpr auto kVolumeHideTimeoutShort = crl::time(20);
|
constexpr auto kVolumeHideTimeoutShort = crl::time(20);
|
||||||
constexpr auto kVolumeHideTimeoutLong = crl::time(200);
|
constexpr auto kVolumeHideTimeoutLong = crl::time(200);
|
||||||
|
|
||||||
|
@ -427,20 +428,27 @@ void Header::createPlayPause() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Header::createVolumeToggle() {
|
void Header::createVolumeToggle() {
|
||||||
|
Expects(_data.has_value());
|
||||||
|
|
||||||
struct VolumeState {
|
struct VolumeState {
|
||||||
base::Timer hideTimer;
|
base::Timer hideTimer;
|
||||||
bool over = false;
|
bool over = false;
|
||||||
|
bool silent = false;
|
||||||
bool dropdownOver = false;
|
bool dropdownOver = false;
|
||||||
};
|
};
|
||||||
_volumeToggle = std::make_unique<Ui::RpWidget>(_widget.get());
|
_volumeToggle = std::make_unique<Ui::RpWidget>(_widget.get());
|
||||||
auto &lifetime = _volumeToggle->lifetime();
|
auto &lifetime = _volumeToggle->lifetime();
|
||||||
const auto state = lifetime.make_state<VolumeState>();
|
const auto state = lifetime.make_state<VolumeState>();
|
||||||
|
state->silent = _data->silent;
|
||||||
state->hideTimer.setCallback([=] {
|
state->hideTimer.setCallback([=] {
|
||||||
_volume->toggle(false, anim::type::normal);
|
_volume->toggle(false, anim::type::normal);
|
||||||
});
|
});
|
||||||
|
|
||||||
_volumeToggle->events(
|
_volumeToggle->events(
|
||||||
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||||
|
if (state->silent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto type = e->type();
|
const auto type = e->type();
|
||||||
if (type == QEvent::Enter || type == QEvent::Leave) {
|
if (type == QEvent::Enter || type == QEvent::Leave) {
|
||||||
const auto over = (e->type() == QEvent::Enter);
|
const auto over = (e->type() == QEvent::Enter);
|
||||||
|
@ -458,7 +466,9 @@ void Header::createVolumeToggle() {
|
||||||
|
|
||||||
_volumeToggle->paintRequest() | rpl::start_with_next([=] {
|
_volumeToggle->paintRequest() | rpl::start_with_next([=] {
|
||||||
auto p = QPainter(_volumeToggle.get());
|
auto p = QPainter(_volumeToggle.get());
|
||||||
p.setOpacity(kControlOpacity);
|
p.setOpacity(state->silent
|
||||||
|
? kControlOpacityDisabled
|
||||||
|
: kControlOpacity);
|
||||||
_volumeIcon.current()->paint(
|
_volumeIcon.current()->paint(
|
||||||
p,
|
p,
|
||||||
st::storiesVolumeButton.iconPosition,
|
st::storiesVolumeButton.iconPosition,
|
||||||
|
@ -469,6 +479,7 @@ void Header::createVolumeToggle() {
|
||||||
_volume = std::make_unique<Ui::FadeWrap<Ui::RpWidget>>(
|
_volume = std::make_unique<Ui::FadeWrap<Ui::RpWidget>>(
|
||||||
_widget->parentWidget(),
|
_widget->parentWidget(),
|
||||||
object_ptr<Ui::RpWidget>(_widget->parentWidget()));
|
object_ptr<Ui::RpWidget>(_widget->parentWidget()));
|
||||||
|
_volume->toggle(false, anim::type::instant);
|
||||||
_volume->events(
|
_volume->events(
|
||||||
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||||
const auto type = e->type();
|
const auto type = e->type();
|
||||||
|
@ -505,7 +516,9 @@ void Header::createVolumeToggle() {
|
||||||
st::storiesVolumeButton.width,
|
st::storiesVolumeButton.width,
|
||||||
st::storiesVolumeButton.height);
|
st::storiesVolumeButton.height);
|
||||||
_volumeToggle->show();
|
_volumeToggle->show();
|
||||||
_volumeToggle->setCursor(style::cur_pointer);
|
if (!state->silent) {
|
||||||
|
_volumeToggle->setCursor(style::cur_pointer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Header::rebuildVolumeControls(
|
void Header::rebuildVolumeControls(
|
||||||
|
@ -600,7 +613,7 @@ void Header::updatePauseState() {
|
||||||
|
|
||||||
void Header::updateVolumeIcon() {
|
void Header::updateVolumeIcon() {
|
||||||
const auto volume = _controller->currentVolume();
|
const auto volume = _controller->currentVolume();
|
||||||
_volumeIcon = (volume <= 0.)
|
_volumeIcon = (volume <= 0. || (_data && _data->silent))
|
||||||
? &st::mediaviewVolumeIcon0Over
|
? &st::mediaviewVolumeIcon0Over
|
||||||
: (volume < 1 / 2.)
|
: (volume < 1 / 2.)
|
||||||
? &st::mediaviewVolumeIcon1Over
|
? &st::mediaviewVolumeIcon1Over
|
||||||
|
|
Loading…
Add table
Reference in a new issue