Add current stories label to profile top bar.
This commit is contained in:
parent
91cc5f5284
commit
21a5e26250
|
@ -124,6 +124,9 @@ void TopBar::enableBackButton() {
|
||||||
if (_title) {
|
if (_title) {
|
||||||
_title->setAttribute(Qt::WA_TransparentForMouseEvents);
|
_title->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
}
|
}
|
||||||
|
if (_storiesWrap) {
|
||||||
|
_storiesWrap->raise();
|
||||||
|
}
|
||||||
updateControlsGeometry(width());
|
updateControlsGeometry(width());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,12 +390,16 @@ void TopBar::updateStoriesGeometry(int newWidth) {
|
||||||
button->moveToRight(right, 0, newWidth);
|
button->moveToRight(right, 0, newWidth);
|
||||||
right += button->width();
|
right += button->width();
|
||||||
}
|
}
|
||||||
const auto left = (_back ? _st.back.width : _st.titlePosition.x())
|
const auto &small = st::dialogsStories;
|
||||||
- st::dialogsStories.left - st::dialogsStories.photoLeft;
|
const auto wrapLeft = (_back ? _st.back.width : 0);
|
||||||
const auto top = (_st.height - st::dialogsStories.height) / 2;
|
const auto left = _back
|
||||||
_stories->resizeToWidth(newWidth - left - right);
|
? 0
|
||||||
_stories->moveToLeft(left, top, newWidth);
|
: (_st.titlePosition.x() - small.left - small.photoLeft);
|
||||||
_stories->entity()->setLayoutConstraints({ 0, 0 }, style::al_left);
|
const auto height = small.photo + 2 * small.photoTop;
|
||||||
|
const auto top = _st.titlePosition.y()
|
||||||
|
+ (_st.title.style.font->height - height) / 2;
|
||||||
|
_stories->setLayoutConstraints({ left, top }, style::al_left);
|
||||||
|
_storiesWrap->move(wrapLeft, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopBar::paintEvent(QPaintEvent *e) {
|
void TopBar::paintEvent(QPaintEvent *e) {
|
||||||
|
@ -447,36 +454,61 @@ void TopBar::updateControlsVisibility(anim::type animated) {
|
||||||
|
|
||||||
void TopBar::setStories(rpl::producer<Dialogs::Stories::Content> content) {
|
void TopBar::setStories(rpl::producer<Dialogs::Stories::Content> content) {
|
||||||
_storiesLifetime.destroy();
|
_storiesLifetime.destroy();
|
||||||
|
delete _storiesWrap.data();
|
||||||
if (content) {
|
if (content) {
|
||||||
using namespace Dialogs::Stories;
|
using namespace Dialogs::Stories;
|
||||||
|
|
||||||
auto last = std::move(
|
auto last = std::move(
|
||||||
content
|
content
|
||||||
) | rpl::start_spawning(_storiesLifetime);
|
) | rpl::start_spawning(_storiesLifetime);
|
||||||
delete _stories;
|
|
||||||
|
|
||||||
const auto stories = Ui::CreateChild<Ui::FadeWrap<List>>(
|
_storiesWrap = _storiesLifetime.make_state<
|
||||||
this,
|
Ui::FadeWrap<Ui::AbstractButton>
|
||||||
object_ptr<List>(
|
>(this, object_ptr<Ui::AbstractButton>(this), st::infoTopBarScale);
|
||||||
this,
|
|
||||||
st::dialogsStoriesListInfo,
|
|
||||||
rpl::duplicate(
|
|
||||||
last
|
|
||||||
) | rpl::filter([](const Content &content) {
|
|
||||||
return !content.elements.empty();
|
|
||||||
})),
|
|
||||||
st::infoTopBarScale);
|
|
||||||
registerToggleControlCallback(
|
registerToggleControlCallback(
|
||||||
stories,
|
_storiesWrap.data(),
|
||||||
[this] { return _storiesCount > 0; });
|
[this] { return _storiesCount > 0; });
|
||||||
stories->toggle(false, anim::type::instant);
|
_storiesWrap->toggle(false, anim::type::instant);
|
||||||
stories->setDuration(st::infoTopBarDuration);
|
_storiesWrap->setDuration(st::infoTopBarDuration);
|
||||||
|
|
||||||
|
const auto button = _storiesWrap->entity();
|
||||||
|
const auto stories = Ui::CreateChild<List>(
|
||||||
|
button,
|
||||||
|
st::dialogsStoriesListInfo,
|
||||||
|
rpl::duplicate(
|
||||||
|
last
|
||||||
|
) | rpl::filter([](const Content &content) {
|
||||||
|
return !content.elements.empty();
|
||||||
|
}));
|
||||||
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
|
button,
|
||||||
|
QString(),
|
||||||
|
_st.title);
|
||||||
|
stories->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
stories->geometryValue(
|
||||||
|
) | rpl::start_with_next([=](QRect geometry) {
|
||||||
|
const auto skip = _st.title.style.font->spacew;
|
||||||
|
label->move(
|
||||||
|
geometry.x() + geometry.width() + skip,
|
||||||
|
_st.titlePosition.y());
|
||||||
|
}, label->lifetime());
|
||||||
|
rpl::combine(
|
||||||
|
_storiesWrap->positionValue(),
|
||||||
|
label->geometryValue()
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
button->resize(
|
||||||
|
label->x() + label->width() + _st.titlePosition.x(),
|
||||||
|
_st.height);
|
||||||
|
}, button->lifetime());
|
||||||
|
|
||||||
_stories = stories;
|
_stories = stories;
|
||||||
_stories->entity()->clicks(
|
_stories->clicks(
|
||||||
) | rpl::start_to_stream(_storyClicks, _stories->lifetime());
|
) | rpl::start_to_stream(_storyClicks, _stories->lifetime());
|
||||||
if (_back) {
|
|
||||||
_back->raise();
|
button->setClickedCallback([=] {
|
||||||
}
|
_storyClicks.fire({});
|
||||||
|
});
|
||||||
|
|
||||||
rpl::duplicate(
|
rpl::duplicate(
|
||||||
last
|
last
|
||||||
|
@ -489,9 +521,20 @@ void TopBar::setStories(rpl::producer<Dialogs::Stories::Content> content) {
|
||||||
if (was != now) {
|
if (was != now) {
|
||||||
updateControlsVisibility(anim::type::normal);
|
updateControlsVisibility(anim::type::normal);
|
||||||
}
|
}
|
||||||
|
if (now) {
|
||||||
|
label->setText(
|
||||||
|
tr::lng_contacts_stories_status(
|
||||||
|
tr::now,
|
||||||
|
lt_count,
|
||||||
|
_storiesCount));
|
||||||
|
}
|
||||||
updateControlsGeometry(width());
|
updateControlsGeometry(width());
|
||||||
}
|
}
|
||||||
}, _storiesLifetime);
|
}, _storiesLifetime);
|
||||||
|
|
||||||
|
_storiesLifetime.add([weak = QPointer<QWidget>(label)] {
|
||||||
|
delete weak.data();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
_storiesCount = 0;
|
_storiesCount = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ class SessionNavigation;
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
class AbstractButton;
|
||||||
class IconButton;
|
class IconButton;
|
||||||
class FlatLabel;
|
class FlatLabel;
|
||||||
class InputField;
|
class InputField;
|
||||||
|
@ -175,7 +176,8 @@ private:
|
||||||
QPointer<Ui::FadeWrap<Ui::IconButton>> _toggleStoryPin;
|
QPointer<Ui::FadeWrap<Ui::IconButton>> _toggleStoryPin;
|
||||||
rpl::event_stream<SelectionAction> _selectionActionRequests;
|
rpl::event_stream<SelectionAction> _selectionActionRequests;
|
||||||
|
|
||||||
QPointer<Ui::FadeWrap<Dialogs::Stories::List>> _stories;
|
QPointer<Ui::FadeWrap<Ui::AbstractButton>> _storiesWrap;
|
||||||
|
QPointer<Dialogs::Stories::List> _stories;
|
||||||
rpl::lifetime _storiesLifetime;
|
rpl::lifetime _storiesLifetime;
|
||||||
int _storiesCount = 0;
|
int _storiesCount = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue