mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
unused since commit c302219
This commit is contained in:
parent
b198c9b975
commit
bffd852b4e
2 changed files with 0 additions and 439 deletions
|
@ -1,167 +0,0 @@
|
||||||
/*
|
|
||||||
This file is part of Telegram Desktop,
|
|
||||||
the official desktop application for the Telegram messaging service.
|
|
||||||
|
|
||||||
For license and copyright information please follow this link:
|
|
||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
||||||
*/
|
|
||||||
#include "ui/effects/widget_slide_wrap.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
|
|
||||||
PaddingWrap<RpWidget>::PaddingWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child,
|
|
||||||
const style::margins &padding)
|
|
||||||
: Parent(parent, std::move(child))
|
|
||||||
, _padding(padding) {
|
|
||||||
if (auto weak = wrapped()) {
|
|
||||||
auto margins = weak->getMargins();
|
|
||||||
weak->sizeValue()
|
|
||||||
| rpl::on_next([this](QSize&&) { updateSize(); })
|
|
||||||
| rpl::start(lifetime());
|
|
||||||
weak->moveToLeft(_padding.left() + margins.left(), _padding.top() + margins.top());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PaddingWrap<RpWidget>::updateSize() {
|
|
||||||
auto inner = [this] {
|
|
||||||
if (auto weak = wrapped()) {
|
|
||||||
return weak->rect();
|
|
||||||
}
|
|
||||||
return QRect(0, 0, _innerWidth, 0);
|
|
||||||
}();
|
|
||||||
resize(inner.marginsAdded(_padding).size());
|
|
||||||
}
|
|
||||||
|
|
||||||
int PaddingWrap<RpWidget>::naturalWidth() const {
|
|
||||||
auto inner = [this] {
|
|
||||||
if (auto weak = wrapped()) {
|
|
||||||
return weak->naturalWidth();
|
|
||||||
}
|
|
||||||
return RpWidget::naturalWidth();
|
|
||||||
}();
|
|
||||||
return (inner < 0)
|
|
||||||
? inner
|
|
||||||
: (_padding.left() + inner + _padding.right());
|
|
||||||
}
|
|
||||||
|
|
||||||
int PaddingWrap<RpWidget>::resizeGetHeight(int newWidth) {
|
|
||||||
_innerWidth = newWidth;
|
|
||||||
if (auto weak = wrapped()) {
|
|
||||||
weak->resizeToWidth(newWidth
|
|
||||||
- _padding.left()
|
|
||||||
- _padding.right());
|
|
||||||
} else {
|
|
||||||
updateSize();
|
|
||||||
}
|
|
||||||
return height();
|
|
||||||
}
|
|
||||||
|
|
||||||
SlideWrap<RpWidget>::SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child)
|
|
||||||
: SlideWrap(
|
|
||||||
parent,
|
|
||||||
std::move(child),
|
|
||||||
style::margins(),
|
|
||||||
st::slideWrapDuration) {
|
|
||||||
}
|
|
||||||
|
|
||||||
SlideWrap<RpWidget>::SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child,
|
|
||||||
const style::margins &padding)
|
|
||||||
: SlideWrap(
|
|
||||||
parent,
|
|
||||||
std::move(child),
|
|
||||||
padding,
|
|
||||||
st::slideWrapDuration) {
|
|
||||||
}
|
|
||||||
|
|
||||||
SlideWrap<RpWidget>::SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child,
|
|
||||||
int duration)
|
|
||||||
: SlideWrap(parent, std::move(child), style::margins(), duration) {
|
|
||||||
}
|
|
||||||
|
|
||||||
SlideWrap<RpWidget>::SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child,
|
|
||||||
const style::margins &padding,
|
|
||||||
int duration)
|
|
||||||
: Parent(parent, object_ptr<PaddingWrap<RpWidget>>(parent, std::move(child), padding))
|
|
||||||
, _duration(duration * 10) {
|
|
||||||
if (auto weak = wrapped()) {
|
|
||||||
weak->heightValue()
|
|
||||||
| rpl::on_next([this](int newHeight) {
|
|
||||||
if (_slideAnimation.animating()) {
|
|
||||||
animationStep();
|
|
||||||
} else if (_visible) {
|
|
||||||
resize(width(), newHeight);
|
|
||||||
}
|
|
||||||
}) | rpl::start(lifetime());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideWrap<RpWidget>::animationStep() {
|
|
||||||
if (wrapped()) {
|
|
||||||
auto margins = getMargins();
|
|
||||||
wrapped()->moveToLeft(margins.left(), margins.top());
|
|
||||||
}
|
|
||||||
auto current = _slideAnimation.current(_visible ? 1. : 0.);
|
|
||||||
auto newHeight = wrapped()
|
|
||||||
? (_slideAnimation.animating()
|
|
||||||
? anim::interpolate(0, wrapped()->heightNoMargins(), current)
|
|
||||||
: (_visible ? wrapped()->height() : 0))
|
|
||||||
: 0;
|
|
||||||
if (newHeight != height()) {
|
|
||||||
resize(width(), newHeight);
|
|
||||||
}
|
|
||||||
auto shouldBeHidden = !_visible && !_slideAnimation.animating();
|
|
||||||
if (shouldBeHidden != isHidden()) {
|
|
||||||
setVisible(!shouldBeHidden);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideWrap<RpWidget>::toggleAnimated(bool visible) {
|
|
||||||
if (_visible == visible) {
|
|
||||||
animationStep();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_visible = visible;
|
|
||||||
_slideAnimation.start(
|
|
||||||
[this] { animationStep(); },
|
|
||||||
_visible ? 0. : 1.,
|
|
||||||
_visible ? 1. : 0.,
|
|
||||||
_duration,
|
|
||||||
anim::linear);
|
|
||||||
animationStep();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideWrap<RpWidget>::toggleFast(bool visible) {
|
|
||||||
_visible = visible;
|
|
||||||
finishAnimations();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SlideWrap<RpWidget>::finishAnimations() {
|
|
||||||
_slideAnimation.finish();
|
|
||||||
animationStep();
|
|
||||||
}
|
|
||||||
|
|
||||||
QMargins SlideWrap<RpWidget>::getMargins() const {
|
|
||||||
auto result = wrapped()->getMargins();
|
|
||||||
return (animating() || !_visible)
|
|
||||||
? QMargins(result.left(), 0, result.right(), 0)
|
|
||||||
: result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SlideWrap<RpWidget>::resizeGetHeight(int newWidth) {
|
|
||||||
if (wrapped()) {
|
|
||||||
wrapped()->resizeToWidth(newWidth);
|
|
||||||
}
|
|
||||||
return height();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Ui
|
|
|
@ -1,272 +0,0 @@
|
||||||
/*
|
|
||||||
This file is part of Telegram Desktop,
|
|
||||||
the official desktop application for the Telegram messaging service.
|
|
||||||
|
|
||||||
For license and copyright information please follow this link:
|
|
||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "styles/style_widgets.h"
|
|
||||||
#include "ui/rp_widget.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
|
|
||||||
template <typename Widget, typename ParentType = RpWidget>
|
|
||||||
class Wrap;
|
|
||||||
|
|
||||||
namespace details {
|
|
||||||
|
|
||||||
struct UnwrapHelper {
|
|
||||||
struct Large {
|
|
||||||
char data[2];
|
|
||||||
};
|
|
||||||
static char Check(...);
|
|
||||||
template <typename Widget, typename Parent>
|
|
||||||
static Large Check(Wrap<Widget, Parent>*);
|
|
||||||
template <typename Widget, typename Parent>
|
|
||||||
static Large Check(const Wrap<Widget, Parent>*);
|
|
||||||
|
|
||||||
template <typename Entity>
|
|
||||||
static constexpr bool Is() {
|
|
||||||
return sizeof(Check(std::declval<Entity>()))
|
|
||||||
== sizeof(Large);
|
|
||||||
}
|
|
||||||
template <typename Entity>
|
|
||||||
static auto Unwrap(Entity *entity, std::true_type) {
|
|
||||||
return entity
|
|
||||||
? entity->entity()
|
|
||||||
: nullptr;
|
|
||||||
}
|
|
||||||
template <typename Entity>
|
|
||||||
static Entity *Unwrap(Entity *entity, std::false_type) {
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
template <typename Entity>
|
|
||||||
static auto Unwrap(Entity *entity) {
|
|
||||||
return Unwrap(
|
|
||||||
entity,
|
|
||||||
std::integral_constant<bool, Is<Entity*>()>());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace details
|
|
||||||
|
|
||||||
template <typename Widget>
|
|
||||||
class Wrap<Widget, RpWidget> : public RpWidget {
|
|
||||||
public:
|
|
||||||
Wrap(QWidget *parent, object_ptr<Widget> child);
|
|
||||||
|
|
||||||
Widget *wrapped() {
|
|
||||||
return _wrapped;
|
|
||||||
}
|
|
||||||
const Widget *wrapped() const {
|
|
||||||
return _wrapped;
|
|
||||||
}
|
|
||||||
auto entity() {
|
|
||||||
return details::UnwrapHelper::Unwrap(wrapped());
|
|
||||||
}
|
|
||||||
auto entity() const {
|
|
||||||
return details::UnwrapHelper::Unwrap(wrapped());
|
|
||||||
}
|
|
||||||
|
|
||||||
QMargins getMargins() const override {
|
|
||||||
if (auto weak = wrapped()) {
|
|
||||||
return weak->getMargins();
|
|
||||||
}
|
|
||||||
return RpWidget::getMargins();
|
|
||||||
}
|
|
||||||
int naturalWidth() const override {
|
|
||||||
if (auto weak = wrapped()) {
|
|
||||||
return weak->naturalWidth();
|
|
||||||
}
|
|
||||||
return RpWidget::naturalWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
object_ptr<Widget> _wrapped;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Widget>
|
|
||||||
Wrap<Widget, RpWidget>::Wrap(QWidget *parent, object_ptr<Widget> child)
|
|
||||||
: RpWidget(parent)
|
|
||||||
, _wrapped(std::move(child)) {
|
|
||||||
if (_wrapped) {
|
|
||||||
resize(_wrapped->size());
|
|
||||||
AttachParentChild(this, _wrapped);
|
|
||||||
_wrapped->move(0, 0);
|
|
||||||
_wrapped->alive()
|
|
||||||
| rpl::on_done([this] {
|
|
||||||
_wrapped->setParent(nullptr);
|
|
||||||
_wrapped = nullptr;
|
|
||||||
delete this;
|
|
||||||
})
|
|
||||||
| rpl::start(lifetime());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Widget, typename ParentType>
|
|
||||||
class Wrap : public ParentType {
|
|
||||||
public:
|
|
||||||
using ParentType::ParentType;
|
|
||||||
|
|
||||||
Widget *wrapped() {
|
|
||||||
return static_cast<Widget*>(ParentType::wrapped());
|
|
||||||
}
|
|
||||||
const Widget *wrapped() const {
|
|
||||||
return static_cast<const Widget*>(ParentType::wrapped());
|
|
||||||
}
|
|
||||||
auto entity() {
|
|
||||||
return details::UnwrapHelper::Unwrap(wrapped());
|
|
||||||
}
|
|
||||||
auto entity() const {
|
|
||||||
return details::UnwrapHelper::Unwrap(wrapped());
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Widget>
|
|
||||||
class PaddingWrap;
|
|
||||||
|
|
||||||
template <>
|
|
||||||
class PaddingWrap<RpWidget> : public Wrap<RpWidget> {
|
|
||||||
using Parent = Wrap<RpWidget>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
PaddingWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child,
|
|
||||||
const style::margins &padding);
|
|
||||||
|
|
||||||
PaddingWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
const style::margins &padding)
|
|
||||||
: PaddingWrap(parent, nullptr, padding) {
|
|
||||||
}
|
|
||||||
|
|
||||||
int naturalWidth() const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int resizeGetHeight(int newWidth) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void updateSize();
|
|
||||||
|
|
||||||
int _innerWidth = 0;
|
|
||||||
style::margins _padding;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Widget>
|
|
||||||
class PaddingWrap : public Wrap<Widget, PaddingWrap<RpWidget>> {
|
|
||||||
using Parent = Wrap<Widget, PaddingWrap<RpWidget>>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
PaddingWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<Widget> child,
|
|
||||||
const style::margins &padding)
|
|
||||||
: Parent(parent, std::move(child), padding) {
|
|
||||||
}
|
|
||||||
|
|
||||||
PaddingWrap(QWidget *parent, const style::margins &padding)
|
|
||||||
: Parent(parent, padding) {
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Widget>
|
|
||||||
class SlideWrap;
|
|
||||||
|
|
||||||
template <>
|
|
||||||
class SlideWrap<RpWidget> : public Wrap<PaddingWrap<RpWidget>> {
|
|
||||||
using Parent = Wrap<PaddingWrap<RpWidget>>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SlideWrap(QWidget *parent, object_ptr<RpWidget> child);
|
|
||||||
SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child,
|
|
||||||
const style::margins &padding);
|
|
||||||
SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child,
|
|
||||||
int duration);
|
|
||||||
SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<RpWidget> child,
|
|
||||||
const style::margins &padding,
|
|
||||||
int duration);
|
|
||||||
|
|
||||||
void toggleAnimated(bool visible);
|
|
||||||
void toggleFast(bool visible);
|
|
||||||
|
|
||||||
void showAnimated() {
|
|
||||||
toggleAnimated(true);
|
|
||||||
}
|
|
||||||
void hideAnimated() {
|
|
||||||
toggleAnimated(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void showFast() {
|
|
||||||
toggleFast(true);
|
|
||||||
}
|
|
||||||
void hideFast() {
|
|
||||||
toggleFast(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool animating() const {
|
|
||||||
return _slideAnimation.animating();
|
|
||||||
}
|
|
||||||
void finishAnimations();
|
|
||||||
|
|
||||||
QMargins getMargins() const override;
|
|
||||||
|
|
||||||
bool isHiddenOrHiding() const {
|
|
||||||
return !_visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int resizeGetHeight(int newWidth) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void animationStep();
|
|
||||||
|
|
||||||
bool _visible = true;
|
|
||||||
Animation _slideAnimation;
|
|
||||||
int _duration = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Widget>
|
|
||||||
class SlideWrap : public Wrap<PaddingWrap<Widget>, SlideWrap<RpWidget>> {
|
|
||||||
using Parent = Wrap<PaddingWrap<Widget>, SlideWrap<RpWidget>>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SlideWrap(QWidget *parent, object_ptr<Widget> child)
|
|
||||||
: Parent(parent, std::move(child)) {
|
|
||||||
}
|
|
||||||
SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<Widget> child,
|
|
||||||
const style::margins &padding)
|
|
||||||
: Parent(parent, std::move(child), padding) {
|
|
||||||
}
|
|
||||||
SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<Widget> child,
|
|
||||||
int duration)
|
|
||||||
: Parent(parent, std::move(child), duration) {
|
|
||||||
}
|
|
||||||
SlideWrap(
|
|
||||||
QWidget *parent,
|
|
||||||
object_ptr<Widget> child,
|
|
||||||
const style::margins &padding,
|
|
||||||
int duration)
|
|
||||||
: Parent(parent, std::move(child), padding, duration) {
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Ui
|
|
Loading…
Add table
Reference in a new issue