mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Add rpl::take(count).
This commit is contained in:
@@ -20,8 +20,20 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
*/
|
||||
#include "ui/abstract_button.h"
|
||||
|
||||
#include <rpl/filter.h>
|
||||
#include <rpl/mappers.h>
|
||||
|
||||
namespace Ui {
|
||||
|
||||
AbstractButton::AbstractButton(QWidget *parent) : RpWidget(parent) {
|
||||
setMouseTracking(true);
|
||||
|
||||
using namespace rpl::mappers;
|
||||
shownValue()
|
||||
| rpl::filter($1 == false)
|
||||
| rpl::start_with_next([this] { clearState(); }, lifetime());
|
||||
}
|
||||
|
||||
void AbstractButton::leaveEventHook(QEvent *e) {
|
||||
if (_state & StateFlag::Down) return;
|
||||
|
||||
|
@@ -30,9 +30,7 @@ class AbstractButton : public RpWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AbstractButton(QWidget *parent) : RpWidget(parent) {
|
||||
setMouseTracking(true);
|
||||
}
|
||||
AbstractButton(QWidget *parent);
|
||||
|
||||
Qt::KeyboardModifiers clickModifiers() const {
|
||||
return _modifiers;
|
||||
@@ -58,13 +56,6 @@ public:
|
||||
_clickedCallback = std::move(callback);
|
||||
}
|
||||
|
||||
void setVisible(bool visible) override {
|
||||
TWidget::setVisible(visible);
|
||||
if (!visible) {
|
||||
clearState();
|
||||
}
|
||||
}
|
||||
|
||||
auto clicks() const {
|
||||
return _clicks.events();
|
||||
}
|
||||
|
@@ -100,7 +100,6 @@ void FadeAnimation::stopAnimation() {
|
||||
_animation.finish();
|
||||
if (!_cache.isNull()) {
|
||||
_cache = QPixmap();
|
||||
updateCallback();
|
||||
if (_visible) {
|
||||
_widget->showChildren();
|
||||
}
|
||||
|
@@ -76,6 +76,10 @@ public:
|
||||
virtual rpl::producer<int> desiredHeightValue() const {
|
||||
return heightValue();
|
||||
}
|
||||
auto shownValue() const {
|
||||
auto &stream = eventStreams().shown;
|
||||
return stream.events_starting_with(!this->isHidden());
|
||||
}
|
||||
|
||||
auto paintRequest() const {
|
||||
return eventStreams().paint.events();
|
||||
@@ -85,6 +89,17 @@ public:
|
||||
return eventStreams().alive.events();
|
||||
}
|
||||
|
||||
void setVisible(bool visible) final override {
|
||||
auto wasVisible = !this->isHidden();
|
||||
Parent::setVisible(visible);
|
||||
auto nowVisible = !this->isHidden();
|
||||
if (nowVisible != wasVisible) {
|
||||
if (auto streams = _eventStreams.get()) {
|
||||
streams->shown.fire_copy(nowVisible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Error, typename Generator>
|
||||
void showOn(rpl::producer<bool, Error, Generator> &&shown) {
|
||||
std::move(shown)
|
||||
@@ -133,6 +148,7 @@ private:
|
||||
struct EventStreams {
|
||||
rpl::event_stream<QRect> geometry;
|
||||
rpl::event_stream<QRect> paint;
|
||||
rpl::event_stream<bool> shown;
|
||||
rpl::event_stream<> alive;
|
||||
};
|
||||
struct LifetimeHolder {
|
||||
|
Reference in New Issue
Block a user