2017-09-30 18:26:45 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-30 18:26:45 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-30 18:26:45 +00:00
|
|
|
*/
|
|
|
|
#include "ui/wrap/fade_wrap.h"
|
|
|
|
|
|
|
|
#include "ui/widgets/shadow.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
FadeWrap<RpWidget>::FadeWrap(
|
|
|
|
QWidget *parent,
|
|
|
|
object_ptr<RpWidget> &&child,
|
2017-11-27 11:43:57 +00:00
|
|
|
float64 scale)
|
2017-09-30 18:26:45 +00:00
|
|
|
: Parent(parent, std::move(child))
|
2017-11-27 11:43:57 +00:00
|
|
|
, _animation(this, scale)
|
2017-10-10 08:01:19 +00:00
|
|
|
, _duration(st::fadeWrapDuration) {
|
2017-10-03 13:05:58 +00:00
|
|
|
if (auto weak = wrapped()) {
|
|
|
|
weak->show();
|
|
|
|
}
|
2017-09-30 18:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FadeWrap<RpWidget> *FadeWrap<RpWidget>::setDuration(int duration) {
|
|
|
|
_duration = duration;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
FadeWrap<RpWidget> *FadeWrap<RpWidget>::toggle(
|
|
|
|
bool shown,
|
|
|
|
anim::type animated) {
|
2017-10-01 08:15:40 +00:00
|
|
|
auto changed = (shown != _animation.visible());
|
2017-09-30 18:26:45 +00:00
|
|
|
if (shown) {
|
2017-09-30 19:20:40 +00:00
|
|
|
if (animated == anim::type::normal) {
|
2018-04-06 16:23:09 +00:00
|
|
|
if (!_animation.animating()) {
|
|
|
|
wrapped()->show();
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
_animation.fadeIn(_duration);
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_animation.animating()) {
|
|
|
|
wrapped()->hide();
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
} else {
|
|
|
|
_animation.show();
|
2018-04-06 16:23:09 +00:00
|
|
|
if (!_animation.animating()) {
|
|
|
|
wrapped()->show();
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
}
|
2017-09-30 18:26:45 +00:00
|
|
|
} else {
|
2017-09-30 19:20:40 +00:00
|
|
|
if (animated == anim::type::normal) {
|
2018-04-06 16:23:09 +00:00
|
|
|
if (!_animation.animating()) {
|
|
|
|
wrapped()->show();
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
_animation.fadeOut(_duration);
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_animation.animating()) {
|
|
|
|
wrapped()->hide();
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
} else {
|
|
|
|
_animation.hide();
|
2018-04-06 16:23:09 +00:00
|
|
|
if (!_animation.animating()) {
|
|
|
|
wrapped()->show();
|
|
|
|
}
|
2017-09-30 19:20:40 +00:00
|
|
|
}
|
2017-09-30 18:26:45 +00:00
|
|
|
}
|
2017-10-01 08:15:40 +00:00
|
|
|
if (changed) {
|
2017-09-30 19:20:40 +00:00
|
|
|
_toggledChanged.fire_copy(shown);
|
2017-09-30 18:26:45 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
FadeWrap<RpWidget> *FadeWrap<RpWidget>::finishAnimating() {
|
2017-09-30 18:26:45 +00:00
|
|
|
_animation.finish();
|
2018-04-06 16:23:09 +00:00
|
|
|
wrapped()->show();
|
2017-09-30 18:26:45 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
FadeWrap<RpWidget> *FadeWrap<RpWidget>::toggleOn(
|
|
|
|
rpl::producer<bool> &&shown) {
|
2017-12-22 07:05:20 +00:00
|
|
|
std::move(
|
|
|
|
shown
|
|
|
|
) | rpl::start_with_next([this](bool shown) {
|
|
|
|
toggle(shown, anim::type::normal);
|
|
|
|
}, lifetime());
|
2017-09-30 19:20:40 +00:00
|
|
|
finishAnimating();
|
2017-09-30 18:26:45 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FadeWrap<RpWidget>::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2018-04-06 16:23:09 +00:00
|
|
|
if (_animation.paint(p)) {
|
|
|
|
if (!_animation.animating() && _animation.visible()) {
|
|
|
|
crl::on_main(this, [=] {
|
|
|
|
if (!_animation.animating() && _animation.visible()) {
|
|
|
|
wrapped()->show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_animation.animating()) {
|
|
|
|
wrapped()->show();
|
|
|
|
}
|
2017-09-30 18:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FadeShadow::FadeShadow(QWidget *parent)
|
|
|
|
: FadeShadow(parent, st::shadowFg) {
|
|
|
|
}
|
|
|
|
|
|
|
|
FadeShadow::FadeShadow(QWidget *parent, style::color color)
|
|
|
|
: Parent(parent, object_ptr<PlainShadow>(parent, color)) {
|
2017-09-30 19:20:40 +00:00
|
|
|
hide(anim::type::instant);
|
2017-09-30 18:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Ui
|
|
|
|
|