| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /*
- This file is part of Telegram Desktop,
- the official desktop application for the Telegram messaging service.
- For license and copyright information please follow this link:
- https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
- */
- #include "ui/controls/silent_toggle.h"
- #include "ui/effects/ripple_animation.h"
- #include "data/notify/data_notify_settings.h"
- #include "data/data_session.h"
- #include "data/data_channel.h"
- #include "lang/lang_keys.h"
- #include "ui/ui_utility.h"
- #include "styles/style_chat.h"
- #include "styles/style_chat_helpers.h"
- namespace Ui {
- SilentToggle::SilentToggle(QWidget *parent, not_null<ChannelData*> channel)
- : RippleButton(parent, st::historySilentToggle.ripple)
- , _st(st::historySilentToggle)
- , _channel(channel)
- , _checked(channel->owner().notifySettings().silentPosts(_channel)) {
- Expects(!channel->owner().notifySettings().silentPostsUnknown(_channel));
- resize(_st.width, _st.height);
- setMouseTracking(true);
- clicks(
- ) | rpl::start_with_next([=] {
- setChecked(!_checked);
- Ui::Tooltip::Show(0, this);
- _channel->owner().notifySettings().update(_channel, {}, _checked);
- }, lifetime());
- }
- void SilentToggle::paintEvent(QPaintEvent *e) {
- auto p = QPainter(this);
- paintRipple(p, _st.rippleAreaPosition, nullptr);
- //const auto checked = _crossLineAnimation.value(_checked ? 1. : 0.);
- const auto over = isOver();
- (_checked
- ? (over
- ? st::historySilentToggleOnOver
- : st::historySilentToggleOn)
- : (over
- ? st::historySilentToggle.iconOver
- : st::historySilentToggle.icon)).paintInCenter(p, rect());
- }
- void SilentToggle::mouseMoveEvent(QMouseEvent *e) {
- RippleButton::mouseMoveEvent(e);
- if (rect().contains(e->pos())) {
- Ui::Tooltip::Show(1000, this);
- } else {
- Ui::Tooltip::Hide();
- }
- }
- void SilentToggle::setChecked(bool checked) {
- if (_checked != checked) {
- _checked = checked;
- update();
- // _crossLineAnimation.start(
- // [=] { update(); },
- // _checked ? 0. : 1.,
- // _checked ? 1. : 0.,
- // kAnimationDuration);
- }
- }
- void SilentToggle::leaveEventHook(QEvent *e) {
- RippleButton::leaveEventHook(e);
- Ui::Tooltip::Hide();
- }
- QString SilentToggle::tooltipText() const {
- return _checked
- ? tr::lng_wont_be_notified(tr::now)
- : tr::lng_will_be_notified(tr::now);
- }
- QPoint SilentToggle::tooltipPos() const {
- return QCursor::pos();
- }
- bool SilentToggle::tooltipWindowActive() const {
- 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
|