2022-12-19 11:48:24 +00:00
|
|
|
/*
|
|
|
|
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 "styles/style_chat.h"
|
2023-06-01 16:01:29 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2022-12-19 11:48:24 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-07-31 22:45:36 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
|
|
|
clicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
setChecked(!_checked);
|
|
|
|
Ui::Tooltip::Show(0, this);
|
|
|
|
_channel->owner().notifySettings().update(_channel, {}, _checked);
|
2022-12-19 11:48:24 +00:00
|
|
|
}, lifetime());
|
2023-07-31 22:45:36 +00:00
|
|
|
}
|
2022-12-19 11:48:24 +00:00
|
|
|
|
2023-07-31 22:45:36 +00:00
|
|
|
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());
|
2022-12-19 11:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2023-07-31 22:45:36 +00:00
|
|
|
update();
|
|
|
|
// _crossLineAnimation.start(
|
|
|
|
// [=] { update(); },
|
|
|
|
// _checked ? 0. : 1.,
|
|
|
|
// _checked ? 1. : 0.,
|
|
|
|
// kAnimationDuration);
|
2022-12-19 11:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|