Added animation to toggle silent broadcast button.

This commit is contained in:
23rd 2021-02-01 09:33:32 +03:00 committed by John Preston
parent 0cb8f2cc85
commit 0aaa88cb79
6 changed files with 71 additions and 23 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 572 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -418,8 +418,14 @@ historySilentToggle: IconButton(historyBotKeyboardShow) {
icon: icon {{ "send_control_silent_off", historyComposeIconFg }}; icon: icon {{ "send_control_silent_off", historyComposeIconFg }};
iconOver: icon {{ "send_control_silent_off", historyComposeIconFgOver }}; iconOver: icon {{ "send_control_silent_off", historyComposeIconFgOver }};
} }
historySilentToggleOn: icon {{ "send_control_silent_on", historyComposeIconFg }};
historySilentToggleOnOver: icon {{ "send_control_silent_on", historyComposeIconFgOver }}; historySilentToggleCrossLine: CrossLineAnimation {
fg: historyComposeIconFg;
icon: icon {{ "send_control_silent_off", historyComposeIconFg }};
startPosition: point(5px, 3px);
endPosition: point(21px, 18px);
stroke: 2px;
}
historyReplySkip: 51px; historyReplySkip: 51px;
historyReplyNameFg: windowActiveTextFg; historyReplyNameFg: windowActiveTextFg;

View file

@ -43,6 +43,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui { namespace Ui {
namespace { namespace {
constexpr auto kAnimationDuration = crl::time(120);
QString CropTitle(not_null<PeerData*> peer) { QString CropTitle(not_null<PeerData*> peer) {
if (peer->isChat() || peer->isMegagroup()) { if (peer->isChat() || peer->isMegagroup()) {
return tr::lng_create_group_crop(tr::now); return tr::lng_create_group_crop(tr::now);
@ -858,19 +860,43 @@ void UserpicButton::prepareUserpicPixmap() {
//} //}
SilentToggle::SilentToggle(QWidget *parent, not_null<ChannelData*> channel) SilentToggle::SilentToggle(QWidget *parent, not_null<ChannelData*> channel)
: IconButton(parent, st::historySilentToggle) : RippleButton(parent, st::historySilentToggle.ripple)
, _st(st::historySilentToggle)
, _colorOver(st::historyComposeIconFgOver->c)
, _channel(channel) , _channel(channel)
, _checked(channel->owner().notifySilentPosts(_channel)) { , _checked(channel->owner().notifySilentPosts(_channel))
, _crossLine(st::historySilentToggleCrossLine) {
Expects(!channel->owner().notifySilentPostsUnknown(_channel)); Expects(!channel->owner().notifySilentPostsUnknown(_channel));
if (_checked) { resize(_st.width, _st.height);
refreshIconOverrides();
} style::PaletteChanged(
) | rpl::start_with_next([=] {
_crossLine.invalidate();
}, lifetime());
paintRequest(
) | rpl::start_with_next([=](const QRect &clip) {
Painter p(this);
paintRipple(p, _st.rippleAreaPosition, nullptr);
_crossLine.paint(
p,
(width() - _st.icon.width()) / 2,
(height() - _st.icon.height()) / 2,
_crossLineAnimation.value(_checked ? 1. : 0.),
// Since buttons of the compose controls have no duration
// for the over animation, we can skip this animation here.
isOver()
? std::make_optional<QColor>(_colorOver)
: std::nullopt);
}, lifetime());
setMouseTracking(true); setMouseTracking(true);
} }
void SilentToggle::mouseMoveEvent(QMouseEvent *e) { void SilentToggle::mouseMoveEvent(QMouseEvent *e) {
IconButton::mouseMoveEvent(e); RippleButton::mouseMoveEvent(e);
if (rect().contains(e->pos())) { if (rect().contains(e->pos())) {
Ui::Tooltip::Show(1000, this); Ui::Tooltip::Show(1000, this);
} else { } else {
@ -881,28 +907,22 @@ void SilentToggle::mouseMoveEvent(QMouseEvent *e) {
void SilentToggle::setChecked(bool checked) { void SilentToggle::setChecked(bool checked) {
if (_checked != checked) { if (_checked != checked) {
_checked = checked; _checked = checked;
refreshIconOverrides(); _crossLineAnimation.start(
[=] { update(); },
_checked ? 0. : 1.,
_checked ? 1. : 0.,
kAnimationDuration);
} }
} }
void SilentToggle::refreshIconOverrides() {
const auto iconOverride = _checked
? &st::historySilentToggleOn
: nullptr;
const auto iconOverOverride = _checked
? &st::historySilentToggleOnOver
: nullptr;
setIconOverride(iconOverride, iconOverOverride);
}
void SilentToggle::leaveEventHook(QEvent *e) { void SilentToggle::leaveEventHook(QEvent *e) {
IconButton::leaveEventHook(e); RippleButton::leaveEventHook(e);
Ui::Tooltip::Hide(); Ui::Tooltip::Hide();
} }
void SilentToggle::mouseReleaseEvent(QMouseEvent *e) { void SilentToggle::mouseReleaseEvent(QMouseEvent *e) {
setChecked(!_checked); setChecked(!_checked);
IconButton::mouseReleaseEvent(e); RippleButton::mouseReleaseEvent(e);
Ui::Tooltip::Show(0, this); Ui::Tooltip::Show(0, this);
_channel->owner().updateNotifySettings( _channel->owner().updateNotifySettings(
_channel, _channel,
@ -924,4 +944,18 @@ bool SilentToggle::tooltipWindowActive() const {
return Ui::AppInFocus() && InFocusChain(window()); return Ui::AppInFocus() && InFocusChain(window());
} }
QPoint SilentToggle::prepareRippleStartPosition() const {
const auto result = mapFromGlobal(QCursor::pos())
- _st.rippleAreaPosition;
const auto rect = QRect(0, 0, _st.rippleAreaSize, _st.rippleAreaSize);
return rect.contains(result)
? result
: DisabledRippleStartPosition();
}
QImage SilentToggle::prepareRippleMask() const {
return RippleAnimation::ellipseMask(
QSize(_st.rippleAreaSize, _st.rippleAreaSize));
}
} // namespace Ui } // namespace Ui

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/tooltip.h" #include "ui/widgets/tooltip.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/cross_line.h"
#include "styles/style_window.h" #include "styles/style_window.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
@ -183,7 +184,7 @@ private:
//}; //};
class SilentToggle class SilentToggle
: public Ui::IconButton : public Ui::RippleButton
, public Ui::AbstractTooltipShower { , public Ui::AbstractTooltipShower {
public: public:
SilentToggle(QWidget *parent, not_null<ChannelData*> channel); SilentToggle(QWidget *parent, not_null<ChannelData*> channel);
@ -203,12 +204,19 @@ protected:
void mouseReleaseEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override;
void leaveEventHook(QEvent *e) override; void leaveEventHook(QEvent *e) override;
QImage prepareRippleMask() const override;
QPoint prepareRippleStartPosition() const override;
private: private:
void refreshIconOverrides(); const style::IconButton &_st;
const QColor &_colorOver;
not_null<ChannelData*> _channel; not_null<ChannelData*> _channel;
bool _checked = false; bool _checked = false;
Ui::CrossLineAnimation _crossLine;
Ui::Animations::Simple _crossLineAnimation;
}; };
} // namespace Ui } // namespace Ui