mirror of https://github.com/procxx/kepka.git
Save section expand state in Info memento.
This commit is contained in:
parent
c6c75a1980
commit
76b8078bd9
|
@ -288,7 +288,10 @@ void showPeerHistory(
|
|||
auto ms = getms();
|
||||
LOG(("Show Peer Start"));
|
||||
if (auto m = App::main()) {
|
||||
m->ui_showPeerHistory(peer, Window::SectionShow(), msgId);
|
||||
m->ui_showPeerHistory(
|
||||
peer,
|
||||
Window::SectionShow::Way::ClearStack,
|
||||
msgId);
|
||||
}
|
||||
LOG(("Show Peer End: %1").arg(getms() - ms));
|
||||
}
|
||||
|
|
|
@ -437,7 +437,8 @@ void Widget::onScroll() {
|
|||
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
||||
}
|
||||
|
||||
void Widget::showAnimatedHook() {
|
||||
void Widget::showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) {
|
||||
_fixedBar->setAnimatingMode(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,8 @@ protected:
|
|||
void resizeEvent(QResizeEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
void showAnimatedHook() override;
|
||||
void showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) override;
|
||||
void showFinishedHook() override;
|
||||
void doSetInnerFocus() override;
|
||||
|
||||
|
|
|
@ -99,7 +99,27 @@ void WrapWidget::createTabs() {
|
|||
}
|
||||
|
||||
void WrapWidget::showTab(Tab tab) {
|
||||
showContent(createContent(tab));
|
||||
Expects(_content != nullptr);
|
||||
auto direction = (tab > _tab)
|
||||
? SlideDirection::FromRight
|
||||
: SlideDirection::FromLeft;
|
||||
auto newAnotherMemento = _content->createMemento();
|
||||
auto newContent = _anotherTabMemento
|
||||
? createContent(_anotherTabMemento.get())
|
||||
: createContent(tab);
|
||||
auto animationParams = SectionSlideParams();
|
||||
// animationParams.withFade = (wrap() == Wrap::Layer);
|
||||
animationParams.withTabs = true;
|
||||
animationParams.withTopBarShadow = hasTopBarShadow()
|
||||
&& newContent->hasTopBarShadow();
|
||||
animationParams.oldContentCache = grabForShowAnimation(
|
||||
animationParams);
|
||||
|
||||
showContent(std::move(newContent));
|
||||
|
||||
showAnimated(direction, animationParams);
|
||||
|
||||
_anotherTabMemento = std::move(newAnotherMemento);
|
||||
}
|
||||
|
||||
void WrapWidget::setupTabbedTop(const Section §ion) {
|
||||
|
@ -276,11 +296,27 @@ QPixmap WrapWidget::grabForShowAnimation(
|
|||
} else {
|
||||
_topShadow->toggle(_topShadow->toggled(), anim::type::instant);
|
||||
}
|
||||
if (params.withTabs && _topTabs) {
|
||||
_topTabs->hide();
|
||||
}
|
||||
auto result = myGrab(this);
|
||||
if (params.withTopBarShadow) _topShadow->setVisible(true);
|
||||
if (params.withTopBarShadow) {
|
||||
_topShadow->setVisible(true);
|
||||
}
|
||||
if (params.withTabs && _topTabs) {
|
||||
_topTabs->show();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void WrapWidget::showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) {
|
||||
if (params.withTabs && _topTabs) {
|
||||
_topTabs->show();
|
||||
_topTabsBackground->show();
|
||||
}
|
||||
}
|
||||
|
||||
void WrapWidget::doSetInnerFocus() {
|
||||
_content->setInnerFocus();
|
||||
}
|
||||
|
@ -334,12 +370,14 @@ void WrapWidget::showNewContent(
|
|||
auto needAnimation = (_content != nullptr)
|
||||
&& (params.animated != anim::type::instant);
|
||||
auto animationParams = SectionSlideParams();
|
||||
auto newContent = object_ptr<ContentWidget>(nullptr);
|
||||
if (needAnimation) {
|
||||
auto newContent = createContent(memento);
|
||||
newContent = createContent(memento);
|
||||
animationParams.withTopBarShadow = hasTopBarShadow()
|
||||
&& newContent->hasTopBarShadow();
|
||||
animationParams.oldContentCache = grabForShowAnimation(
|
||||
animationParams);
|
||||
// animationParams.withFade = (wrap() == Wrap::Layer);
|
||||
}
|
||||
if (saveToStack) {
|
||||
auto item = StackItem();
|
||||
|
@ -351,7 +389,12 @@ void WrapWidget::showNewContent(
|
|||
} else if (params.way == Window::SectionShow::Way::ClearStack) {
|
||||
_historyStack.clear();
|
||||
}
|
||||
showNewContent(memento);
|
||||
if (newContent) {
|
||||
setupTop(newContent->section(), newContent->peer()->id);
|
||||
showContent(std::move(newContent));
|
||||
} else {
|
||||
showNewContent(memento);
|
||||
}
|
||||
if (animationParams) {
|
||||
showAnimated(
|
||||
saveToStack
|
||||
|
|
|
@ -106,6 +106,8 @@ public:
|
|||
bool hasTopBarShadow() const override;
|
||||
QPixmap grabForShowAnimation(
|
||||
const Window::SectionSlideParams ¶ms) override;
|
||||
void showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) override;
|
||||
|
||||
bool showInternal(
|
||||
not_null<Window::SectionMemento*> memento,
|
||||
|
|
|
@ -20,6 +20,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
*/
|
||||
#include "info/media/info_media_inner_widget.h"
|
||||
|
||||
#include "ui/widgets/labels.h"
|
||||
|
||||
namespace Info {
|
||||
namespace Media {
|
||||
|
||||
|
@ -30,6 +32,16 @@ InnerWidget::InnerWidget(
|
|||
: RpWidget(parent)
|
||||
, _peer(peer)
|
||||
, _type(type) {
|
||||
auto text = qsl("Media Overview\n\n");
|
||||
auto label = object_ptr<Ui::FlatLabel>(this);
|
||||
label->setText(text.repeated(50));
|
||||
widthValue() | rpl::start_with_next([inner = label.data()](int w) {
|
||||
inner->resizeToWidth(w);
|
||||
}, lifetime());
|
||||
label->heightValue() | rpl::start_with_next([this](int h) {
|
||||
_rowsHeightFake = h;
|
||||
resizeToWidth(width());
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void InnerWidget::visibleTopBottomUpdated(
|
||||
|
@ -46,8 +58,7 @@ void InnerWidget::restoreState(not_null<Memento*> memento) {
|
|||
}
|
||||
|
||||
int InnerWidget::resizeGetHeight(int newWidth) {
|
||||
auto rowsHeight = _rowsHeightFake;
|
||||
return qMax(rowsHeight, _minHeight);
|
||||
return _rowsHeightFake;
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
|
|
|
@ -41,11 +41,6 @@ public:
|
|||
return _type;
|
||||
}
|
||||
|
||||
void resizeToWidth(int newWidth, int minHeight) {
|
||||
_minHeight = minHeight;
|
||||
return RpWidget::resizeToWidth(newWidth);
|
||||
}
|
||||
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
|
@ -62,7 +57,6 @@ private:
|
|||
int _rowsHeightFake = 0;
|
||||
int _visibleTop = 0;
|
||||
int _visibleBottom = 0;
|
||||
int _minHeight = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -184,6 +184,16 @@ SectionWithToggle *SectionWithToggle::setToggleShown(
|
|||
return this;
|
||||
}
|
||||
|
||||
void SectionWithToggle::toggle(bool toggled) {
|
||||
if (_toggle) {
|
||||
_toggle->setChecked(toggled);
|
||||
}
|
||||
}
|
||||
|
||||
bool SectionWithToggle::toggled() const {
|
||||
return _toggle ? _toggle->checked() : false;
|
||||
}
|
||||
|
||||
rpl::producer<bool> SectionWithToggle::toggledValue() const {
|
||||
if (_toggle) {
|
||||
return rpl::single(_toggle->checked())
|
||||
|
|
|
@ -45,6 +45,8 @@ public:
|
|||
using FixedHeightWidget::FixedHeightWidget;
|
||||
|
||||
SectionWithToggle *setToggleShown(rpl::producer<bool> &&shown);
|
||||
void toggle(bool toggled);
|
||||
bool toggled() const;
|
||||
rpl::producer<bool> toggledValue() const;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
|
||||
#include <rpl/combine.h>
|
||||
#include <rpl/flatten_latest.h>
|
||||
#include "info/info_memento.h"
|
||||
#include "info/profile/info_profile_button.h"
|
||||
#include "info/profile/info_profile_widget.h"
|
||||
#include "info/profile/info_profile_text.h"
|
||||
|
@ -64,7 +65,7 @@ InnerWidget::InnerWidget(
|
|||
, _content(setupContent(this, std::move(wrapValue))) {
|
||||
_content->heightValue()
|
||||
| rpl::start_with_next([this](int height) {
|
||||
TWidget::resizeToWidth(width());
|
||||
resizeToWidth(width());
|
||||
_desiredHeight.fire(countDesiredHeight());
|
||||
}, lifetime());
|
||||
}
|
||||
|
@ -83,18 +84,17 @@ object_ptr<Ui::RpWidget> InnerWidget::setupContent(
|
|||
RpWidget *parent,
|
||||
rpl::producer<Wrap> &&wrapValue) {
|
||||
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
||||
auto cover = result->add(object_ptr<Cover>(
|
||||
_cover = result->add(object_ptr<Cover>(
|
||||
result,
|
||||
_peer)
|
||||
);
|
||||
cover->setOnlineCount(rpl::single(0));
|
||||
_peer));
|
||||
_cover->setOnlineCount(rpl::single(0));
|
||||
auto details = setupDetails(parent);
|
||||
if (canHideDetailsEver()) {
|
||||
cover->setToggleShown(canHideDetails());
|
||||
result->add(object_ptr<Ui::SlideWrap<>>(
|
||||
_cover->setToggleShown(canHideDetails());
|
||||
_infoWrap = result->add(object_ptr<Ui::SlideWrap<>>(
|
||||
result,
|
||||
std::move(details))
|
||||
)->toggleOn(cover->toggledValue());
|
||||
)->toggleOn(_cover->toggledValue());
|
||||
} else {
|
||||
result->add(std::move(details));
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ void InnerWidget::setupUserButtons(
|
|||
}
|
||||
|
||||
object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
||||
RpWidget *parent) const {
|
||||
RpWidget *parent) {
|
||||
using namespace rpl::mappers;
|
||||
|
||||
auto content = object_ptr<Ui::VerticalLayout>(parent);
|
||||
|
@ -308,8 +308,9 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
|||
[phrase = mediaText(type)](int count) {
|
||||
return phrase(lt_count, count);
|
||||
}
|
||||
)->entity()->addClickHandler([peer = _peer, type] {
|
||||
SharedMediaShowOverview(type, App::history(peer));
|
||||
)->entity()->addClickHandler([this, peer = _peer, type] {
|
||||
_controller->showSection(
|
||||
Info::Memento(peer->id, Section(type)));
|
||||
});
|
||||
};
|
||||
auto addCommonGroupsButton = [&](not_null<UserData*> user) {
|
||||
|
@ -343,13 +344,13 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
|||
auto layout = result->entity();
|
||||
|
||||
layout->add(object_ptr<BoxContentDivider>(result));
|
||||
auto cover = layout->add(object_ptr<SharedMediaCover>(layout));
|
||||
_sharedMediaCover = layout->add(object_ptr<SharedMediaCover>(layout));
|
||||
if (canHideDetailsEver()) {
|
||||
cover->setToggleShown(canHideDetails());
|
||||
layout->add(object_ptr<Ui::SlideWrap<>>(
|
||||
_sharedMediaCover->setToggleShown(canHideDetails());
|
||||
_sharedMediaWrap = layout->add(object_ptr<Ui::SlideWrap<>>(
|
||||
layout,
|
||||
std::move(content))
|
||||
)->toggleOn(cover->toggledValue());
|
||||
)->toggleOn(_sharedMediaCover->toggledValue());
|
||||
} else {
|
||||
layout->add(std::move(content));
|
||||
}
|
||||
|
@ -483,15 +484,25 @@ void InnerWidget::visibleTopBottomUpdated(
|
|||
}
|
||||
|
||||
void InnerWidget::saveState(not_null<Memento*> memento) {
|
||||
memento->setInfoExpanded(_cover->toggled());
|
||||
memento->setMediaExpanded(_sharedMediaCover->toggled());
|
||||
}
|
||||
|
||||
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
||||
_cover->toggle(memento->infoExpanded());
|
||||
if (_infoWrap) {
|
||||
_infoWrap->finishAnimating();
|
||||
}
|
||||
_sharedMediaCover->toggle(memento->mediaExpanded());
|
||||
if (_sharedMediaWrap) {
|
||||
_sharedMediaWrap->finishAnimating();
|
||||
}
|
||||
}
|
||||
|
||||
int InnerWidget::resizeGetHeight(int newWidth) {
|
||||
_content->resizeToWidth(newWidth);
|
||||
_content->moveToLeft(0, 0);
|
||||
return qMax(_content->heightNoMargins(), _minHeight);
|
||||
return _content->heightNoMargins();
|
||||
}
|
||||
|
||||
} // namespace Profile
|
||||
|
|
|
@ -42,6 +42,8 @@ namespace Profile {
|
|||
|
||||
class Memento;
|
||||
class Members;
|
||||
class Cover;
|
||||
class SharedMediaCover;
|
||||
|
||||
class InnerWidget final : public Ui::RpWidget {
|
||||
public:
|
||||
|
@ -55,11 +57,6 @@ public:
|
|||
return _peer;
|
||||
}
|
||||
|
||||
void resizeToWidth(int newWidth, int minHeight) {
|
||||
_minHeight = minHeight;
|
||||
return RpWidget::resizeToWidth(newWidth);
|
||||
}
|
||||
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
|
@ -82,7 +79,7 @@ private:
|
|||
RpWidget *parent,
|
||||
rpl::producer<Wrap> &&wrapValue);
|
||||
object_ptr<RpWidget> setupDetails(RpWidget *parent) const;
|
||||
object_ptr<RpWidget> setupSharedMedia(RpWidget *parent) const;
|
||||
object_ptr<RpWidget> setupSharedMedia(RpWidget *parent);
|
||||
object_ptr<RpWidget> setupMuteToggle(RpWidget *parent) const;
|
||||
object_ptr<RpWidget> setupInfo(RpWidget *parent) const;
|
||||
void setupUserButtons(
|
||||
|
@ -104,9 +101,11 @@ private:
|
|||
not_null<Window::Controller*> _controller;
|
||||
not_null<PeerData*> _peer;
|
||||
|
||||
int _minHeight = 0;
|
||||
|
||||
Members *_members = nullptr;
|
||||
Cover *_cover = nullptr;
|
||||
Ui::SlideWrap<RpWidget> *_infoWrap = nullptr;
|
||||
SharedMediaCover *_sharedMediaCover = nullptr;
|
||||
Ui::SlideWrap<RpWidget> *_sharedMediaWrap = nullptr;
|
||||
object_ptr<RpWidget> _content;
|
||||
|
||||
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
|
||||
|
|
|
@ -43,15 +43,22 @@ public:
|
|||
return Section(Section::Type::Profile);
|
||||
}
|
||||
|
||||
void setScrollTop(int scrollTop) {
|
||||
_scrollTop = scrollTop;
|
||||
void setInfoExpanded(bool expanded) {
|
||||
_infoExpanded = expanded;
|
||||
}
|
||||
int scrollTop() const {
|
||||
return _scrollTop;
|
||||
bool infoExpanded() const {
|
||||
return _infoExpanded;
|
||||
}
|
||||
void setMediaExpanded(bool expanded) {
|
||||
_mediaExpanded = expanded;
|
||||
}
|
||||
bool mediaExpanded() const {
|
||||
return _mediaExpanded;
|
||||
}
|
||||
|
||||
private:
|
||||
int _scrollTop = 0;
|
||||
bool _infoExpanded = false;
|
||||
bool _mediaExpanded = false;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -449,7 +449,8 @@ void Widget::onScroll() {
|
|||
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
||||
}
|
||||
|
||||
void Widget::showAnimatedHook() {
|
||||
void Widget::showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) {
|
||||
_fixedBar->setAnimatingMode(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -201,7 +201,8 @@ public:
|
|||
protected:
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
void showAnimatedHook() override;
|
||||
void showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) override;
|
||||
void showFinishedHook() override;
|
||||
void doSetInnerFocus() override;
|
||||
|
||||
|
|
|
@ -145,7 +145,8 @@ void Widget::onScroll() {
|
|||
updateScrollState();
|
||||
}
|
||||
|
||||
void Widget::showAnimatedHook() {
|
||||
void Widget::showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) {
|
||||
_fixedBar->setAnimatingMode(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,8 @@ public:
|
|||
protected:
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
void showAnimatedHook() override;
|
||||
void showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) override;
|
||||
void showFinishedHook() override;
|
||||
void doSetInnerFocus() override;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ void SectionWidget::showAnimated(
|
|||
showChildren();
|
||||
auto myContentCache = grabForShowAnimation(params);
|
||||
hideChildren();
|
||||
showAnimatedHook();
|
||||
showAnimatedHook(params);
|
||||
|
||||
_showAnimation = std::make_unique<SlideAnimation>();
|
||||
_showAnimation->setDirection(direction);
|
||||
|
@ -69,6 +69,7 @@ void SectionWidget::showAnimated(
|
|||
params.oldContentCache,
|
||||
myContentCache);
|
||||
_showAnimation->setTopBarShadow(params.withTopBarShadow);
|
||||
_showAnimation->setWithFade(params.withFade);
|
||||
_showAnimation->start();
|
||||
|
||||
show();
|
||||
|
|
|
@ -70,6 +70,8 @@ class SectionMemento;
|
|||
struct SectionSlideParams {
|
||||
QPixmap oldContentCache;
|
||||
bool withTopBarShadow = false;
|
||||
bool withTabs = false;
|
||||
bool withFade = false;
|
||||
|
||||
explicit operator bool() const {
|
||||
return !oldContentCache.isNull();
|
||||
|
@ -147,7 +149,8 @@ protected:
|
|||
}
|
||||
|
||||
// Called after the hideChildren() call in showAnimated().
|
||||
virtual void showAnimatedHook() {
|
||||
virtual void showAnimatedHook(
|
||||
const Window::SectionSlideParams ¶ms) {
|
||||
}
|
||||
|
||||
// Called after the showChildren() call in showFinished().
|
||||
|
|
|
@ -45,7 +45,7 @@ struct SectionShow {
|
|||
ClearStack,
|
||||
};
|
||||
SectionShow(
|
||||
Way way = Way::ClearStack,
|
||||
Way way = Way::Forward,
|
||||
anim::type animated = anim::type::normal,
|
||||
anim::activation activation = anim::activation::normal)
|
||||
: way(way)
|
||||
|
@ -127,26 +127,26 @@ public:
|
|||
|
||||
void showPeerHistory(
|
||||
PeerId peerId,
|
||||
const SectionShow ¶ms = SectionShow(),
|
||||
const SectionShow ¶ms = SectionShow::Way::ClearStack,
|
||||
MsgId msgId = ShowAtUnreadMsgId);
|
||||
void showPeerHistory(
|
||||
not_null<PeerData*> peer,
|
||||
const SectionShow ¶ms = SectionShow(),
|
||||
const SectionShow ¶ms = SectionShow::Way::ClearStack,
|
||||
MsgId msgId = ShowAtUnreadMsgId);
|
||||
void showPeerHistory(
|
||||
not_null<History*> history,
|
||||
const SectionShow ¶ms = SectionShow(),
|
||||
const SectionShow ¶ms = SectionShow::Way::ClearStack,
|
||||
MsgId msgId = ShowAtUnreadMsgId);
|
||||
|
||||
void showPeerInfo(
|
||||
PeerId peerId,
|
||||
const SectionShow ¶ms = SectionShow::Way::Forward);
|
||||
const SectionShow ¶ms = SectionShow());
|
||||
void showPeerInfo(
|
||||
not_null<PeerData*> peer,
|
||||
const SectionShow ¶ms = SectionShow::Way::Forward);
|
||||
const SectionShow ¶ms = SectionShow());
|
||||
void showPeerInfo(
|
||||
not_null<History*> history,
|
||||
const SectionShow ¶ms = SectionShow::Way::Forward);
|
||||
const SectionShow ¶ms = SectionShow());
|
||||
|
||||
void clearSectionStack(
|
||||
const SectionShow ¶ms = SectionShow::Way::ClearStack) {
|
||||
|
|
|
@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "window/window_slide_animation.h"
|
||||
|
||||
#include "styles/style_window.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
namespace Window {
|
||||
|
||||
|
@ -29,18 +30,47 @@ void SlideAnimation::paintContents(Painter &p, const QRect &update) const {
|
|||
|
||||
// Animation callback can destroy "this", so we don't pass "ms".
|
||||
auto progress = _animation.current((_direction == SlideDirection::FromLeft) ? 0. : 1.);
|
||||
auto coordUnder = anim::interpolate(0, -st::slideShift, progress);
|
||||
auto coordOver = anim::interpolate(_cacheOver.width() / cIntRetinaFactor(), 0, progress);
|
||||
if (coordOver) {
|
||||
p.drawPixmap(QRect(0, 0, coordOver, _cacheUnder.height() / retina), _cacheUnder, QRect(-coordUnder * retina, 0, coordOver * retina, _cacheUnder.height()));
|
||||
p.setOpacity(progress);
|
||||
p.fillRect(0, 0, coordOver, _cacheUnder.height() / retina, st::slideFadeOutBg);
|
||||
p.setOpacity(1);
|
||||
}
|
||||
p.drawPixmap(QRect(coordOver, 0, _cacheOver.width() / retina, _cacheOver.height() / retina), _cacheOver, QRect(0, 0, _cacheOver.width(), _cacheOver.height()));
|
||||
p.setOpacity(progress);
|
||||
st::slideShadow.fill(p, QRect(coordOver - st::slideShadow.width(), 0, st::slideShadow.width(), _cacheOver.height() / retina));
|
||||
if (_withFade) {
|
||||
p.fillRect(update, st::boxBg);
|
||||
|
||||
auto slideLeft = (_direction == SlideDirection::FromLeft);
|
||||
auto dt = slideLeft
|
||||
? (1. - progress)
|
||||
: progress;
|
||||
auto easeOut = anim::easeOutCirc(1., dt);
|
||||
auto easeIn = anim::easeInCirc(1., dt);
|
||||
auto arrivingAlpha = easeIn;
|
||||
auto departingAlpha = 1. - easeOut;
|
||||
auto leftWidthFull = _cacheUnder.width() / cIntRetinaFactor();
|
||||
auto rightWidthFull = _cacheOver.width() / cIntRetinaFactor();
|
||||
auto leftCoord = (slideLeft ? anim::interpolate(-leftWidthFull, 0, easeOut) : anim::interpolate(0, -leftWidthFull, easeIn));
|
||||
auto leftAlpha = (slideLeft ? arrivingAlpha : departingAlpha);
|
||||
auto rightCoord = (slideLeft ? anim::interpolate(0, rightWidthFull, easeIn) : anim::interpolate(rightWidthFull, 0, easeOut));
|
||||
auto rightAlpha = (slideLeft ? departingAlpha : arrivingAlpha);
|
||||
|
||||
auto leftWidth = (leftWidthFull + leftCoord);
|
||||
if (leftWidth > 0) {
|
||||
p.setOpacity(leftAlpha);
|
||||
p.drawPixmap(0, 0, leftWidth, _cacheUnder.height() / retina, _cacheUnder, (_cacheUnder.width() - leftWidth * cIntRetinaFactor()), 0, leftWidth * cIntRetinaFactor(), _cacheUnder.height());
|
||||
}
|
||||
auto rightWidth = rightWidthFull - rightCoord;
|
||||
if (rightWidth > 0) {
|
||||
p.setOpacity(rightAlpha);
|
||||
p.drawPixmap(rightCoord, 0, _cacheOver, 0, 0, rightWidth * cIntRetinaFactor(), _cacheOver.height());
|
||||
}
|
||||
} else {
|
||||
auto coordUnder = anim::interpolate(0, -st::slideShift, progress);
|
||||
auto coordOver = anim::interpolate(_cacheOver.width() / cIntRetinaFactor(), 0, progress);
|
||||
if (coordOver) {
|
||||
p.drawPixmap(QRect(0, 0, coordOver, _cacheUnder.height() / retina), _cacheUnder, QRect(-coordUnder * retina, 0, coordOver * retina, _cacheUnder.height()));
|
||||
p.setOpacity(progress);
|
||||
p.fillRect(0, 0, coordOver, _cacheUnder.height() / retina, st::slideFadeOutBg);
|
||||
p.setOpacity(1);
|
||||
}
|
||||
p.drawPixmap(QRect(coordOver, 0, _cacheOver.width() / retina, _cacheOver.height() / retina), _cacheOver, QRect(0, 0, _cacheOver.width(), _cacheOver.height()));
|
||||
p.setOpacity(progress);
|
||||
st::slideShadow.fill(p, QRect(coordOver - st::slideShadow.width(), 0, st::slideShadow.width(), _cacheOver.height() / retina));
|
||||
}
|
||||
if (_topBarShadowEnabled) {
|
||||
p.setOpacity(1);
|
||||
p.fillRect(0, st::topBarHeight, _cacheOver.width() / retina, st::lineWidth, st::shadowFg);
|
||||
|
@ -60,6 +90,10 @@ void SlideAnimation::setTopBarShadow(bool enabled) {
|
|||
_topBarShadowEnabled = enabled;
|
||||
}
|
||||
|
||||
void SlideAnimation::setWithFade(bool withFade) {
|
||||
_withFade = withFade;
|
||||
}
|
||||
|
||||
void SlideAnimation::setRepaintCallback(RepaintCallback &&callback) {
|
||||
_repaintCallback = std::move(callback);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
void setDirection(SlideDirection direction);
|
||||
void setPixmaps(const QPixmap &oldContentCache, const QPixmap &newContentCache);
|
||||
void setTopBarShadow(bool enabled);
|
||||
void setWithFade(bool withFade);
|
||||
|
||||
using RepaintCallback = base::lambda<void()>;
|
||||
void setRepaintCallback(RepaintCallback &&callback);
|
||||
|
@ -52,6 +53,7 @@ private:
|
|||
|
||||
SlideDirection _direction = SlideDirection::FromRight;
|
||||
bool _topBarShadowEnabled = false;
|
||||
bool _withFade = false;
|
||||
|
||||
mutable Animation _animation;
|
||||
QPixmap _cacheUnder, _cacheOver;
|
||||
|
|
Loading…
Reference in New Issue