2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Add button to show all pinned messages.

This commit is contained in:
John Preston
2020-10-20 21:31:47 +03:00
parent 6b38b94db4
commit d742fa32de
13 changed files with 99 additions and 224 deletions

View File

@@ -361,6 +361,10 @@ historyReplyCancel: IconButton {
color: windowBgOver;
}
}
historyPinnedShowAll: IconButton(historyReplyCancel) {
icon: icon {{ "pinned_show_all", historyReplyCancelFg }};
iconOver: icon {{ "pinned_show_all", historyReplyCancelFgOver }};
}
msgBotKbDuration: 200;
msgBotKbFont: semiboldFont;

View File

@@ -19,14 +19,8 @@ namespace Ui {
PinnedBar::PinnedBar(
not_null<QWidget*> parent,
rpl::producer<MessageBarContent> content,
bool withClose)
rpl::producer<MessageBarContent> content)
: _wrap(parent, object_ptr<RpWidget>(parent))
, _close(withClose
? std::make_unique<IconButton>(
_wrap.entity(),
st::historyReplyCancel)
: nullptr)
, _shadow(std::make_unique<PlainShadow>(_wrap.parentWidget())) {
_wrap.hide(anim::type::instant);
_shadow->hide();
@@ -73,7 +67,33 @@ PinnedBar::PinnedBar(
}, lifetime());
}
PinnedBar::~PinnedBar() = default;
PinnedBar::~PinnedBar() {
_rightButton.destroy();
}
void PinnedBar::setRightButton(object_ptr<Ui::RpWidget> button) {
_rightButton.destroy();
_rightButton = std::move(button);
if (_rightButton) {
_rightButton->setParent(_wrap.entity());
_rightButton->show();
}
if (_bar) {
updateControlsGeometry(_wrap.geometry());
}
}
void PinnedBar::updateControlsGeometry(QRect wrapGeometry) {
_bar->widget()->resizeToWidth(
wrapGeometry.width() - (_rightButton ? _rightButton->width() : 0));
const auto hidden = _wrap.isHidden() || !wrapGeometry.height();
if (_shadow->isHidden() != hidden) {
_shadow->setVisible(!hidden);
}
if (_rightButton) {
_rightButton->moveToRight(0, 0);
}
}
void PinnedBar::setShadowGeometryPostprocess(Fn<QRect(QRect)> postprocess) {
_shadowGeometryPostprocess = std::move(postprocess);
@@ -97,8 +117,8 @@ void PinnedBar::createControls() {
_bar = std::make_unique<MessageBar>(
_wrap.entity(),
st::defaultMessageBar);
if (_close) {
_close->raise();
if (_rightButton) {
_rightButton->raise();
}
// Clicks.
@@ -126,15 +146,7 @@ void PinnedBar::createControls() {
_wrap.geometryValue(
) | rpl::start_with_next([=](QRect rect) {
updateShadowGeometry(rect);
_bar->widget()->resizeToWidth(
rect.width() - (_close ? _close->width() : 0));
const auto hidden = _wrap.isHidden() || !rect.height();
if (_shadow->isHidden() != hidden) {
_shadow->setVisible(!hidden);
}
if (_close) {
_close->moveToRight(0, 0);
}
updateControlsGeometry(rect);
}, _bar->widget()->lifetime());
_wrap.shownValue(
@@ -198,12 +210,6 @@ rpl::producer<int> PinnedBar::heightValue() const {
return _wrap.heightValue();
}
rpl::producer<> PinnedBar::closeClicks() const {
return !_close
? (rpl::never<>() | rpl::type_erased())
: (_close->clicks() | rpl::map([] { return rpl::empty_value(); }));
}
rpl::producer<> PinnedBar::barClicks() const {
return _barClicks.events();
}

View File

@@ -6,7 +6,9 @@ For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/wrap/slide_wrap.h"
#include "base/object_ptr.h"
namespace Ui {
@@ -14,13 +16,13 @@ struct MessageBarContent;
class MessageBar;
class IconButton;
class PlainShadow;
class RpWidget;
class PinnedBar final {
public:
PinnedBar(
not_null<QWidget*> parent,
rpl::producer<Ui::MessageBarContent> content,
bool withClose = false);
rpl::producer<Ui::MessageBarContent> content);
~PinnedBar();
void show();
@@ -30,11 +32,12 @@ public:
void setShadowGeometryPostprocess(Fn<QRect(QRect)> postprocess);
void setRightButton(object_ptr<Ui::RpWidget> button);
void move(int x, int y);
void resizeToWidth(int width);
[[nodiscard]] int height() const;
[[nodiscard]] rpl::producer<int> heightValue() const;
[[nodiscard]] rpl::producer<> closeClicks() const;
[[nodiscard]] rpl::producer<> barClicks() const;
[[nodiscard]] rpl::lifetime &lifetime() {
@@ -44,10 +47,11 @@ public:
private:
void createControls();
void updateShadowGeometry(QRect wrapGeometry);
void updateControlsGeometry(QRect wrapGeometry);
Ui::SlideWrap<> _wrap;
std::unique_ptr<Ui::MessageBar> _bar;
std::unique_ptr<Ui::IconButton> _close;
object_ptr<Ui::RpWidget> _rightButton = { nullptr };
std::unique_ptr<Ui::PlainShadow> _shadow;
rpl::event_stream<> _barClicks;
Fn<QRect(QRect)> _shadowGeometryPostprocess;