2016-05-19 17:18:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-05-19 17:18:23 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-05-19 17:18:23 +00:00
|
|
|
*/
|
2017-03-07 09:17:37 +00:00
|
|
|
#include "ui/special_buttons.h"
|
2016-05-19 17:18:23 +00:00
|
|
|
|
2022-03-13 21:52:33 +00:00
|
|
|
#include "base/call_delayed.h"
|
2021-10-01 10:48:52 +00:00
|
|
|
#include "dialogs/ui/dialogs_layout.h"
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2018-05-04 16:57:50 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image_prepare.h"
|
2017-12-05 11:50:32 +00:00
|
|
|
#include "ui/empty_userpic.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2017-11-13 12:02:53 +00:00
|
|
|
#include "data/data_photo.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_session.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2020-05-28 14:32:10 +00:00
|
|
|
#include "data/data_cloud_file.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2020-07-03 11:57:22 +00:00
|
|
|
#include "data/data_user.h"
|
|
|
|
#include "data/data_streaming.h"
|
|
|
|
#include "data/data_file_origin.h"
|
2018-01-30 14:31:25 +00:00
|
|
|
#include "history/history.h"
|
2017-11-13 12:02:53 +00:00
|
|
|
#include "core/file_utilities.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2021-02-22 02:10:27 +00:00
|
|
|
#include "editor/photo_editor_layer_widget.h"
|
2020-07-03 11:57:22 +00:00
|
|
|
#include "media/streaming/media_streaming_instance.h"
|
|
|
|
#include "media/streaming/media_streaming_player.h"
|
|
|
|
#include "media/streaming/media_streaming_document.h"
|
2022-03-13 21:52:33 +00:00
|
|
|
#include "settings/settings_calls.h" // Calls::AddCameraSubsection.
|
|
|
|
#include "calls/calls_instance.h"
|
|
|
|
#include "webrtc/webrtc_media_devices.h" // Webrtc::GetVideoInputList.
|
|
|
|
#include "webrtc/webrtc_video_track.h"
|
|
|
|
#include "ui/widgets/popup_menu.h"
|
2021-02-22 02:10:27 +00:00
|
|
|
#include "window/window_controller.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-11-13 12:02:53 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2018-09-06 11:13:54 +00:00
|
|
|
#include "apiwrap.h"
|
2022-03-13 21:52:33 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_chat.h"
|
2016-05-19 17:18:23 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
2016-12-26 22:46:36 +00:00
|
|
|
namespace {
|
|
|
|
|
2021-02-01 06:33:32 +00:00
|
|
|
constexpr auto kAnimationDuration = crl::time(120);
|
|
|
|
|
2022-03-13 21:52:33 +00:00
|
|
|
bool IsCameraAvailable() {
|
|
|
|
return (Core::App().calls().currentCall() == nullptr)
|
|
|
|
&& !Webrtc::GetVideoInputList().empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CameraBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
Fn<void(QImage &&image)> &&doneCallback) {
|
|
|
|
using namespace Webrtc;
|
|
|
|
|
|
|
|
const auto track = Settings::Calls::AddCameraSubsection(
|
|
|
|
std::make_shared<Ui::BoxShow>(box),
|
|
|
|
box->verticalLayout(),
|
|
|
|
false);
|
|
|
|
if (!track) {
|
|
|
|
box->closeBox();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
track->stateValue(
|
|
|
|
) | rpl::start_with_next([=](const VideoState &state) {
|
|
|
|
if (state == VideoState::Inactive) {
|
|
|
|
box->closeBox();
|
|
|
|
}
|
|
|
|
}, box->lifetime());
|
|
|
|
|
|
|
|
auto done = [=, done = std::move(doneCallback)](QImage &&image) {
|
|
|
|
box->closeBox();
|
|
|
|
done(std::move(image));
|
|
|
|
};
|
|
|
|
|
|
|
|
box->setTitle(tr::lng_profile_camera_title());
|
|
|
|
box->addButton(tr::lng_continue(), [=, done = std::move(done)]() mutable {
|
|
|
|
Editor::PrepareProfilePhoto(
|
|
|
|
box,
|
|
|
|
controller,
|
|
|
|
std::move(done),
|
|
|
|
track->frame(FrameRequest()).mirrored(true, false));
|
|
|
|
});
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
|
|
}
|
|
|
|
|
2018-12-23 17:23:36 +00:00
|
|
|
QString CropTitle(not_null<PeerData*> peer) {
|
|
|
|
if (peer->isChat() || peer->isMegagroup()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_create_group_crop(tr::now);
|
2018-12-23 17:23:36 +00:00
|
|
|
} else if (peer->isChannel()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_create_channel_crop(tr::now);
|
2018-12-23 17:23:36 +00:00
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_settings_crop_profile(tr::now);
|
2018-12-23 17:23:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
template <typename Callback>
|
|
|
|
QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) {
|
|
|
|
auto size = QSize(width, width) * cIntRetinaFactor();
|
|
|
|
auto image = QImage(size, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
image.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
Painter p(&image);
|
|
|
|
paintCallback(p);
|
|
|
|
}
|
2021-05-07 14:33:53 +00:00
|
|
|
return Ui::PixmapFromImage(std::move(image));
|
2017-11-13 12:02:53 +00:00
|
|
|
};
|
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
} // namespace
|
2016-05-19 17:18:23 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
HistoryDownButton::HistoryDownButton(QWidget *parent, const style::TwoIconButton &st) : RippleButton(parent, st.ripple)
|
2016-12-07 13:32:25 +00:00
|
|
|
, _st(st) {
|
2016-11-16 16:04:25 +00:00
|
|
|
resize(_st.width, _st.height);
|
2016-05-19 17:18:23 +00:00
|
|
|
setCursor(style::cur_pointer);
|
2016-06-09 19:28:58 +00:00
|
|
|
|
|
|
|
hide();
|
2016-05-19 17:18:23 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
QImage HistoryDownButton::prepareRippleMask() const {
|
|
|
|
return Ui::RippleAnimation::ellipseMask(QSize(_st.rippleAreaSize, _st.rippleAreaSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint HistoryDownButton::prepareRippleStartPosition() const {
|
|
|
|
return mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition;
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:18:23 +00:00
|
|
|
void HistoryDownButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2016-06-09 19:28:58 +00:00
|
|
|
|
2018-11-22 12:48:50 +00:00
|
|
|
const auto over = isOver();
|
|
|
|
const auto down = isDown();
|
2016-11-16 16:04:25 +00:00
|
|
|
((over || down) ? _st.iconBelowOver : _st.iconBelow).paint(p, _st.iconPosition, width());
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y());
|
2016-11-16 16:04:25 +00:00
|
|
|
((over || down) ? _st.iconAboveOver : _st.iconAbove).paint(p, _st.iconPosition, width());
|
2016-06-03 12:45:33 +00:00
|
|
|
if (_unreadCount > 0) {
|
|
|
|
auto unreadString = QString::number(_unreadCount);
|
2016-06-21 15:58:07 +00:00
|
|
|
|
2021-10-01 10:57:24 +00:00
|
|
|
Dialogs::Ui::UnreadBadgeStyle st;
|
2016-06-21 15:58:07 +00:00
|
|
|
st.align = style::al_center;
|
|
|
|
st.font = st::historyToDownBadgeFont;
|
|
|
|
st.size = st::historyToDownBadgeSize;
|
2021-10-01 10:57:24 +00:00
|
|
|
st.sizeId = Dialogs::Ui::UnreadBadgeInHistoryToDown;
|
2022-01-26 11:47:23 +00:00
|
|
|
Dialogs::Ui::PaintUnreadBadge(p, unreadString, width(), 0, st, 4);
|
2016-06-03 12:45:33 +00:00
|
|
|
}
|
2016-05-19 17:18:23 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 12:45:33 +00:00
|
|
|
void HistoryDownButton::setUnreadCount(int unreadCount) {
|
2017-08-11 07:16:07 +00:00
|
|
|
if (_unreadCount != unreadCount) {
|
|
|
|
_unreadCount = unreadCount;
|
|
|
|
update();
|
|
|
|
}
|
2016-06-03 12:45:33 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
UserpicButton::UserpicButton(
|
|
|
|
QWidget *parent,
|
2021-02-22 02:10:27 +00:00
|
|
|
not_null<Window::Controller*> window,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Role role,
|
|
|
|
const style::UserpicButton &st)
|
|
|
|
: RippleButton(parent, st.changeButton.ripple)
|
|
|
|
, _st(st)
|
|
|
|
, _controller(window->sessionController())
|
|
|
|
, _window(window)
|
|
|
|
, _peer(peer)
|
|
|
|
, _cropTitle(CropTitle(peer))
|
|
|
|
, _role(role) {
|
|
|
|
Expects(_role == Role::ChangePhoto);
|
|
|
|
|
|
|
|
_waiting = false;
|
|
|
|
prepare();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserpicButton::UserpicButton(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::Controller*> window,
|
2018-12-23 17:23:36 +00:00
|
|
|
const QString &cropTitle,
|
2017-11-13 12:02:53 +00:00
|
|
|
Role role,
|
|
|
|
const style::UserpicButton &st)
|
|
|
|
: RippleButton(parent, st.changeButton.ripple)
|
|
|
|
, _st(st)
|
2021-02-22 02:10:27 +00:00
|
|
|
, _controller(window->sessionController())
|
|
|
|
, _window(window)
|
2018-12-23 17:23:36 +00:00
|
|
|
, _cropTitle(cropTitle)
|
2017-11-13 12:02:53 +00:00
|
|
|
, _role(role) {
|
2022-03-15 12:35:28 +00:00
|
|
|
Expects(_role == Role::ChangePhoto || _role == Role::ChoosePhoto);
|
2017-11-13 12:02:53 +00:00
|
|
|
|
|
|
|
_waiting = false;
|
|
|
|
prepare();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserpicButton::UserpicButton(
|
|
|
|
QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2017-11-13 12:02:53 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Role role,
|
|
|
|
const style::UserpicButton &st)
|
|
|
|
: RippleButton(parent, st.changeButton.ripple)
|
|
|
|
, _st(st)
|
|
|
|
, _controller(controller)
|
2021-02-22 02:10:27 +00:00
|
|
|
, _window(&controller->window())
|
2017-11-13 12:02:53 +00:00
|
|
|
, _peer(peer)
|
2018-12-23 17:23:36 +00:00
|
|
|
, _cropTitle(CropTitle(_peer))
|
2017-11-13 12:02:53 +00:00
|
|
|
, _role(role) {
|
|
|
|
processPeerPhoto();
|
|
|
|
prepare();
|
|
|
|
setupPeerViewers();
|
|
|
|
}
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
UserpicButton::UserpicButton(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Role role,
|
|
|
|
const style::UserpicButton &st)
|
|
|
|
: RippleButton(parent, st.changeButton.ripple)
|
|
|
|
, _st(st)
|
|
|
|
, _peer(peer)
|
2018-12-23 17:23:36 +00:00
|
|
|
, _cropTitle(CropTitle(_peer))
|
2018-03-31 01:45:40 +00:00
|
|
|
, _role(role) {
|
2021-03-16 14:57:46 +00:00
|
|
|
Expects(_role != Role::OpenProfile && _role != Role::OpenPhoto);
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
_waiting = false;
|
2021-03-16 14:57:46 +00:00
|
|
|
processPeerPhoto();
|
2018-03-31 01:45:40 +00:00
|
|
|
prepare();
|
2021-03-16 14:57:46 +00:00
|
|
|
setupPeerViewers();
|
2018-03-31 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void UserpicButton::prepare() {
|
|
|
|
resize(_st.size);
|
|
|
|
_notShownYet = _waiting;
|
|
|
|
if (!_waiting) {
|
|
|
|
prepareUserpicPixmap();
|
|
|
|
}
|
|
|
|
setClickHandlerByRole();
|
2022-03-15 12:35:28 +00:00
|
|
|
|
2022-03-27 14:55:45 +00:00
|
|
|
if (_role == Role::ChangePhoto || _role == Role::OpenPhoto) {
|
2022-03-15 12:35:28 +00:00
|
|
|
chosenImages(
|
|
|
|
) | rpl::start_with_next([=](QImage &&image) {
|
|
|
|
setImage(std::move(image));
|
|
|
|
if (_requestToUpload) {
|
|
|
|
_uploadPhotoRequests.fire({});
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
}
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::setClickHandlerByRole() {
|
|
|
|
switch (_role) {
|
2022-03-15 12:35:28 +00:00
|
|
|
case Role::ChoosePhoto:
|
|
|
|
addClickHandler([=] { choosePhotoLocally(); });
|
|
|
|
break;
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
case Role::ChangePhoto:
|
2022-03-13 21:52:33 +00:00
|
|
|
addClickHandler([=] { changePhotoLocally(); });
|
2017-11-13 12:02:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Role::OpenPhoto:
|
2022-03-27 14:55:45 +00:00
|
|
|
addClickHandler([=] { openPeerPhoto(); });
|
2017-11-13 12:02:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Role::OpenProfile:
|
|
|
|
addClickHandler([this] {
|
|
|
|
Expects(_controller != nullptr);
|
|
|
|
|
|
|
|
_controller->showPeerInfo(_peer);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 12:35:28 +00:00
|
|
|
void UserpicButton::changeTo(QImage &&image) {
|
|
|
|
setImage(std::move(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::choosePhotoLocally() {
|
2021-02-22 02:10:27 +00:00
|
|
|
if (!_window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto callback = [=](QImage &&image) {
|
2022-03-15 12:35:28 +00:00
|
|
|
_chosenImages.fire(std::move(image));
|
2021-02-22 02:10:27 +00:00
|
|
|
};
|
2022-03-13 21:52:33 +00:00
|
|
|
const auto chooseFile = [=] {
|
|
|
|
base::call_delayed(
|
|
|
|
_st.changeButton.ripple.hideDuration,
|
|
|
|
crl::guard(this, [=] {
|
2022-03-15 12:35:28 +00:00
|
|
|
Editor::PrepareProfilePhotoFromFile(
|
2022-03-13 21:52:33 +00:00
|
|
|
this,
|
|
|
|
_window,
|
|
|
|
callback);
|
2022-03-15 12:35:28 +00:00
|
|
|
}));
|
2022-03-13 21:52:33 +00:00
|
|
|
};
|
|
|
|
if (!IsCameraAvailable()) {
|
|
|
|
chooseFile();
|
|
|
|
} else {
|
|
|
|
_menu = base::make_unique_q<Ui::PopupMenu>(this);
|
|
|
|
_menu->addAction(tr::lng_attach_file(tr::now), chooseFile);
|
|
|
|
_menu->addAction(tr::lng_attach_camera(tr::now), [=] {
|
|
|
|
_window->show(Box(CameraBox, _window, callback));
|
|
|
|
});
|
|
|
|
_menu->popup(QCursor::pos());
|
|
|
|
}
|
2017-03-07 09:17:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 12:35:28 +00:00
|
|
|
void UserpicButton::changePhotoLocally(bool requestToUpload) {
|
|
|
|
_requestToUpload = requestToUpload;
|
|
|
|
choosePhotoLocally();
|
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void UserpicButton::openPeerPhoto() {
|
|
|
|
Expects(_peer != nullptr);
|
|
|
|
Expects(_controller != nullptr);
|
|
|
|
|
2017-11-13 17:12:36 +00:00
|
|
|
if (_changeOverlayEnabled && _cursorInChangeOverlay) {
|
2021-02-22 02:10:27 +00:00
|
|
|
changePhotoLocally(true);
|
2017-11-13 17:12:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-05 06:41:43 +00:00
|
|
|
const auto id = _peer->userpicPhotoId();
|
|
|
|
if (!id) {
|
2017-11-13 12:02:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto photo = _peer->owner().photo(id);
|
2021-06-16 20:24:35 +00:00
|
|
|
if (photo->date && _controller) {
|
|
|
|
_controller->openPhoto(photo, _peer);
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::setupPeerViewers() {
|
2020-06-12 12:12:34 +00:00
|
|
|
_peer->session().changes().peerUpdates(
|
2017-11-13 12:02:53 +00:00
|
|
|
_peer,
|
2020-06-12 12:12:34 +00:00
|
|
|
Data::PeerUpdate::Flag::Photo
|
2020-05-28 14:32:10 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2017-12-22 07:05:20 +00:00
|
|
|
processNewPeerPhoto();
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
2019-07-24 11:13:51 +00:00
|
|
|
|
2020-07-01 08:03:34 +00:00
|
|
|
_peer->session().downloaderTaskFinished(
|
2020-05-28 14:32:10 +00:00
|
|
|
) | rpl::filter([=] {
|
|
|
|
return _waiting;
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
if (!_userpicView || _userpicView->image()) {
|
2017-12-22 07:05:20 +00:00
|
|
|
_waiting = false;
|
|
|
|
startNewPhotoShowing();
|
|
|
|
}
|
|
|
|
}, lifetime());
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::paintEvent(QPaintEvent *e) {
|
2017-03-07 09:17:37 +00:00
|
|
|
Painter p(this);
|
2020-06-12 12:12:34 +00:00
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
if (!_waiting && _notShownYet) {
|
|
|
|
_notShownYet = false;
|
|
|
|
startAnimation();
|
|
|
|
}
|
2017-03-07 09:17:37 +00:00
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
auto photoPosition = countPhotoPosition();
|
|
|
|
auto photoLeft = photoPosition.x();
|
|
|
|
auto photoTop = photoPosition.y();
|
|
|
|
|
2017-12-05 11:50:32 +00:00
|
|
|
if (showSavedMessages()) {
|
|
|
|
Ui::EmptyUserpic::PaintSavedMessages(
|
|
|
|
p,
|
|
|
|
photoPosition.x(),
|
|
|
|
photoPosition.y(),
|
|
|
|
width(),
|
|
|
|
_st.photoSize);
|
2020-09-11 15:33:26 +00:00
|
|
|
} else if (showRepliesMessages()) {
|
|
|
|
Ui::EmptyUserpic::PaintRepliesMessages(
|
|
|
|
p,
|
|
|
|
photoPosition.x(),
|
|
|
|
photoPosition.y(),
|
|
|
|
width(),
|
|
|
|
_st.photoSize);
|
2017-12-05 11:50:32 +00:00
|
|
|
} else {
|
2019-04-02 09:13:30 +00:00
|
|
|
if (_a_appearance.animating()) {
|
2017-12-05 11:50:32 +00:00
|
|
|
p.drawPixmapLeft(photoPosition, width(), _oldUserpic);
|
2019-04-02 09:13:30 +00:00
|
|
|
p.setOpacity(_a_appearance.value(1.));
|
2017-12-05 11:50:32 +00:00
|
|
|
}
|
2020-07-03 11:57:22 +00:00
|
|
|
paintUserpicFrame(p, photoPosition);
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 12:35:28 +00:00
|
|
|
if (_role == Role::ChangePhoto || _role == Role::ChoosePhoto) {
|
2017-11-13 12:02:53 +00:00
|
|
|
auto over = isOver() || isDown();
|
|
|
|
if (over) {
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(_userpicHasImage
|
|
|
|
? st::msgDateImgBg
|
|
|
|
: _st.changeButton.textBgOver);
|
|
|
|
p.drawEllipse(
|
|
|
|
photoLeft,
|
|
|
|
photoTop,
|
|
|
|
_st.photoSize,
|
|
|
|
_st.photoSize);
|
|
|
|
}
|
|
|
|
paintRipple(
|
|
|
|
p,
|
|
|
|
photoLeft,
|
|
|
|
photoTop,
|
|
|
|
_userpicHasImage
|
|
|
|
? &st::shadowFg->c
|
|
|
|
: &_st.changeButton.ripple.color->c);
|
|
|
|
if (over || !_userpicHasImage) {
|
|
|
|
auto iconLeft = (_st.changeIconPosition.x() < 0)
|
|
|
|
? (_st.photoSize - _st.changeIcon.width()) / 2
|
|
|
|
: _st.changeIconPosition.x();
|
|
|
|
auto iconTop = (_st.changeIconPosition.y() < 0)
|
|
|
|
? (_st.photoSize - _st.changeIcon.height()) / 2
|
|
|
|
: _st.changeIconPosition.y();
|
|
|
|
_st.changeIcon.paint(
|
|
|
|
p,
|
|
|
|
photoLeft + iconLeft,
|
|
|
|
photoTop + iconTop,
|
|
|
|
width());
|
|
|
|
}
|
2017-11-13 17:12:36 +00:00
|
|
|
} else if (_changeOverlayEnabled) {
|
2019-04-02 09:13:30 +00:00
|
|
|
auto current = _changeOverlayShown.value(
|
2017-11-13 17:12:36 +00:00
|
|
|
(isOver() || isDown()) ? 1. : 0.);
|
|
|
|
auto barHeight = anim::interpolate(
|
|
|
|
0,
|
|
|
|
_st.uploadHeight,
|
|
|
|
current);
|
|
|
|
if (barHeight > 0) {
|
|
|
|
auto barLeft = photoLeft;
|
|
|
|
auto barTop = photoTop + _st.photoSize - barHeight;
|
|
|
|
auto rect = QRect(
|
|
|
|
barLeft,
|
|
|
|
barTop,
|
|
|
|
_st.photoSize,
|
|
|
|
barHeight);
|
|
|
|
p.setClipRect(rect);
|
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(_st.uploadBg);
|
|
|
|
p.drawEllipse(
|
|
|
|
photoLeft,
|
|
|
|
photoTop,
|
|
|
|
_st.photoSize,
|
|
|
|
_st.photoSize);
|
|
|
|
}
|
|
|
|
auto iconLeft = (_st.uploadIconPosition.x() < 0)
|
|
|
|
? (_st.photoSize - _st.uploadIcon.width()) / 2
|
|
|
|
: _st.uploadIconPosition.x();
|
|
|
|
auto iconTop = (_st.uploadIconPosition.y() < 0)
|
|
|
|
? (_st.uploadHeight - _st.uploadIcon.height()) / 2
|
|
|
|
: _st.uploadIconPosition.y();
|
|
|
|
if (iconTop < barHeight) {
|
|
|
|
_st.uploadIcon.paint(
|
|
|
|
p,
|
|
|
|
barLeft + iconLeft,
|
|
|
|
barTop + iconTop,
|
|
|
|
width());
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 11:57:22 +00:00
|
|
|
void UserpicButton::paintUserpicFrame(Painter &p, QPoint photoPosition) {
|
|
|
|
checkStreamedIsStarted();
|
|
|
|
if (_streamed
|
|
|
|
&& _streamed->player().ready()
|
|
|
|
&& !_streamed->player().videoSize().isEmpty()) {
|
2021-03-16 14:57:46 +00:00
|
|
|
const auto paused = _controller
|
|
|
|
? _controller->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::RoundPlaying)
|
|
|
|
: false;
|
2020-07-03 11:57:22 +00:00
|
|
|
auto request = Media::Streaming::FrameRequest();
|
|
|
|
auto size = QSize{ _st.photoSize, _st.photoSize };
|
|
|
|
request.outer = size * cIntRetinaFactor();
|
|
|
|
request.resize = size * cIntRetinaFactor();
|
|
|
|
request.radius = ImageRoundRadius::Ellipse;
|
|
|
|
p.drawImage(QRect(photoPosition, size), _streamed->frame(request));
|
|
|
|
if (!paused) {
|
|
|
|
_streamed->markFrameShown();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.drawPixmapLeft(photoPosition, width(), _userpic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
QPoint UserpicButton::countPhotoPosition() const {
|
|
|
|
auto photoLeft = (_st.photoPosition.x() < 0)
|
|
|
|
? (width() - _st.photoSize) / 2
|
|
|
|
: _st.photoPosition.x();
|
|
|
|
auto photoTop = (_st.photoPosition.y() < 0)
|
|
|
|
? (height() - _st.photoSize) / 2
|
|
|
|
: _st.photoPosition.y();
|
|
|
|
return { photoLeft, photoTop };
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage UserpicButton::prepareRippleMask() const {
|
|
|
|
return Ui::RippleAnimation::ellipseMask(QSize(
|
|
|
|
_st.photoSize,
|
|
|
|
_st.photoSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint UserpicButton::prepareRippleStartPosition() const {
|
|
|
|
return (_role == Role::ChangePhoto)
|
|
|
|
? mapFromGlobal(QCursor::pos()) - countPhotoPosition()
|
|
|
|
: DisabledRippleStartPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::processPeerPhoto() {
|
|
|
|
Expects(_peer != nullptr);
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
_userpicView = _peer->createUserpicView();
|
|
|
|
_waiting = _userpicView && !_userpicView->image();
|
2017-11-13 12:02:53 +00:00
|
|
|
if (_waiting) {
|
2019-04-12 11:52:39 +00:00
|
|
|
_peer->loadUserpic();
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
if (_role == Role::OpenPhoto) {
|
2017-12-05 06:41:43 +00:00
|
|
|
if (_peer->userpicPhotoUnknown()) {
|
2017-11-13 17:12:36 +00:00
|
|
|
_peer->updateFullForced();
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
2017-12-05 06:41:43 +00:00
|
|
|
_canOpenPhoto = (_peer->userpicPhotoId() != 0);
|
2017-11-13 17:12:36 +00:00
|
|
|
updateCursor();
|
2020-07-03 11:57:22 +00:00
|
|
|
updateVideo();
|
2017-11-13 17:12:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::updateCursor() {
|
|
|
|
Expects(_role == Role::OpenPhoto);
|
|
|
|
|
|
|
|
auto pointer = _canOpenPhoto
|
|
|
|
|| (_changeOverlayEnabled && _cursorInChangeOverlay);
|
|
|
|
setPointerCursor(pointer);
|
|
|
|
}
|
|
|
|
|
2020-07-03 11:57:22 +00:00
|
|
|
bool UserpicButton::createStreamingObjects(not_null<PhotoData*> photo) {
|
|
|
|
Expects(_peer != nullptr);
|
|
|
|
|
|
|
|
using namespace Media::Streaming;
|
|
|
|
|
|
|
|
const auto origin = _peer->isUser()
|
2021-04-01 21:04:10 +00:00
|
|
|
? Data::FileOriginUserPhoto(peerToUser(_peer->id), photo->id)
|
2020-07-03 11:57:22 +00:00
|
|
|
: Data::FileOrigin(Data::FileOriginPeerPhoto(_peer->id));
|
|
|
|
_streamed = std::make_unique<Instance>(
|
|
|
|
photo->owner().streaming().sharedDocument(photo, origin),
|
2020-07-03 17:44:21 +00:00
|
|
|
nullptr);
|
2020-07-03 18:57:30 +00:00
|
|
|
_streamed->lockPlayer();
|
2020-07-03 11:57:22 +00:00
|
|
|
_streamed->player().updates(
|
|
|
|
) | rpl::start_with_next_error([=](Update &&update) {
|
|
|
|
handleStreamingUpdate(std::move(update));
|
|
|
|
}, [=](Error &&error) {
|
|
|
|
handleStreamingError(std::move(error));
|
|
|
|
}, _streamed->lifetime());
|
|
|
|
if (_streamed->ready()) {
|
|
|
|
streamingReady(base::duplicate(_streamed->info()));
|
|
|
|
}
|
|
|
|
if (!_streamed->valid()) {
|
|
|
|
clearStreaming();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::clearStreaming() {
|
|
|
|
_streamed = nullptr;
|
|
|
|
_streamedPhoto = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::handleStreamingUpdate(Media::Streaming::Update &&update) {
|
|
|
|
using namespace Media::Streaming;
|
|
|
|
|
2020-08-31 08:14:53 +00:00
|
|
|
v::match(update.data, [&](Information &update) {
|
2020-07-03 11:57:22 +00:00
|
|
|
streamingReady(std::move(update));
|
|
|
|
}, [&](const PreloadedVideo &update) {
|
|
|
|
}, [&](const UpdateVideo &update) {
|
|
|
|
this->update();
|
|
|
|
}, [&](const PreloadedAudio &update) {
|
|
|
|
}, [&](const UpdateAudio &update) {
|
|
|
|
}, [&](const WaitingForData &update) {
|
|
|
|
}, [&](MutedByOther) {
|
|
|
|
}, [&](Finished) {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::handleStreamingError(Media::Streaming::Error &&error) {
|
|
|
|
Expects(_peer != nullptr);
|
|
|
|
|
|
|
|
_streamedPhoto->setVideoPlaybackFailed();
|
|
|
|
_streamedPhoto = nullptr;
|
|
|
|
_streamed = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::streamingReady(Media::Streaming::Information &&info) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::updateVideo() {
|
|
|
|
Expects(_role == Role::OpenPhoto);
|
|
|
|
|
|
|
|
const auto id = _peer->userpicPhotoId();
|
|
|
|
if (!id) {
|
|
|
|
clearStreaming();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto photo = _peer->owner().photo(id);
|
|
|
|
if (!photo->date || !photo->videoCanBePlayed()) {
|
|
|
|
clearStreaming();
|
|
|
|
return;
|
|
|
|
} else if (_streamed && _streamedPhoto == photo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!createStreamingObjects(photo)) {
|
|
|
|
photo->setVideoPlaybackFailed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_streamedPhoto = photo;
|
|
|
|
checkStreamedIsStarted();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::checkStreamedIsStarted() {
|
|
|
|
Expects(!_streamed || _streamedPhoto);
|
|
|
|
|
|
|
|
if (!_streamed) {
|
|
|
|
return;
|
|
|
|
} else if (_streamed->paused()) {
|
|
|
|
_streamed->resume();
|
|
|
|
}
|
|
|
|
if (_streamed && !_streamed->active() && !_streamed->failed()) {
|
|
|
|
const auto position = _streamedPhoto->videoStartPosition();
|
|
|
|
auto options = Media::Streaming::PlaybackOptions();
|
|
|
|
options.position = position;
|
|
|
|
options.mode = Media::Streaming::Mode::Video;
|
|
|
|
options.loop = true;
|
|
|
|
_streamed->play(options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:12:36 +00:00
|
|
|
void UserpicButton::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
RippleButton::mouseMoveEvent(e);
|
|
|
|
if (_role == Role::OpenPhoto) {
|
|
|
|
updateCursorInChangeOverlay(e->pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::updateCursorInChangeOverlay(QPoint localPos) {
|
|
|
|
auto photoPosition = countPhotoPosition();
|
|
|
|
auto overlayRect = QRect(
|
|
|
|
photoPosition.x(),
|
|
|
|
photoPosition.y() + _st.photoSize - _st.uploadHeight,
|
|
|
|
_st.photoSize,
|
|
|
|
_st.uploadHeight);
|
|
|
|
auto inOverlay = overlayRect.contains(localPos);
|
|
|
|
setCursorInChangeOverlay(inOverlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::leaveEventHook(QEvent *e) {
|
|
|
|
if (_role == Role::OpenPhoto) {
|
|
|
|
setCursorInChangeOverlay(false);
|
|
|
|
}
|
|
|
|
return RippleButton::leaveEventHook(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::setCursorInChangeOverlay(bool inOverlay) {
|
|
|
|
Expects(_role == Role::OpenPhoto);
|
|
|
|
|
|
|
|
if (_cursorInChangeOverlay != inOverlay) {
|
|
|
|
_cursorInChangeOverlay = inOverlay;
|
|
|
|
updateCursor();
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::processNewPeerPhoto() {
|
|
|
|
if (_userpicCustom) {
|
2017-03-07 09:17:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-13 12:02:53 +00:00
|
|
|
processPeerPhoto();
|
|
|
|
if (!_waiting) {
|
2017-11-13 13:19:14 +00:00
|
|
|
grabOldUserpic();
|
2017-11-13 12:02:53 +00:00
|
|
|
startNewPhotoShowing();
|
|
|
|
}
|
|
|
|
}
|
2017-03-07 09:17:37 +00:00
|
|
|
|
2017-11-13 13:19:14 +00:00
|
|
|
void UserpicButton::grabOldUserpic() {
|
|
|
|
auto photoRect = QRect(
|
|
|
|
countPhotoPosition(),
|
|
|
|
QSize(_st.photoSize, _st.photoSize)
|
|
|
|
);
|
2017-12-26 12:41:48 +00:00
|
|
|
_oldUserpic = GrabWidget(this, photoRect);
|
2017-11-13 13:19:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void UserpicButton::startNewPhotoShowing() {
|
2017-11-13 13:19:14 +00:00
|
|
|
auto oldUniqueKey = _userpicUniqueKey;
|
2017-11-13 12:02:53 +00:00
|
|
|
prepareUserpicPixmap();
|
2017-11-28 18:30:01 +00:00
|
|
|
update();
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
if (_notShownYet) {
|
|
|
|
return;
|
2017-03-07 09:17:37 +00:00
|
|
|
}
|
2017-11-13 13:19:14 +00:00
|
|
|
if (oldUniqueKey != _userpicUniqueKey
|
|
|
|
|| _a_appearance.animating()) {
|
|
|
|
startAnimation();
|
|
|
|
}
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::startAnimation() {
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_appearance.stop();
|
2017-11-13 12:02:53 +00:00
|
|
|
_a_appearance.start([this] { update(); }, 0, 1, _st.duration);
|
|
|
|
}
|
2017-03-07 09:17:37 +00:00
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void UserpicButton::switchChangePhotoOverlay(bool enabled) {
|
2017-11-13 17:12:36 +00:00
|
|
|
Expects(_role == Role::OpenPhoto);
|
2017-03-07 09:17:37 +00:00
|
|
|
|
2017-11-13 17:12:36 +00:00
|
|
|
if (_changeOverlayEnabled != enabled) {
|
|
|
|
_changeOverlayEnabled = enabled;
|
|
|
|
if (enabled) {
|
|
|
|
if (isOver()) {
|
|
|
|
startChangeOverlayAnimation();
|
|
|
|
}
|
|
|
|
updateCursorInChangeOverlay(
|
|
|
|
mapFromGlobal(QCursor::pos()));
|
|
|
|
} else {
|
2019-04-02 09:13:30 +00:00
|
|
|
_changeOverlayShown.stop();
|
2017-11-13 17:12:36 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 11:50:32 +00:00
|
|
|
void UserpicButton::showSavedMessagesOnSelf(bool enabled) {
|
|
|
|
if (_showSavedMessagesOnSelf != enabled) {
|
|
|
|
_showSavedMessagesOnSelf = enabled;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UserpicButton::showSavedMessages() const {
|
|
|
|
return _showSavedMessagesOnSelf && _peer && _peer->isSelf();
|
|
|
|
}
|
|
|
|
|
2020-09-11 15:33:26 +00:00
|
|
|
bool UserpicButton::showRepliesMessages() const {
|
|
|
|
return _showSavedMessagesOnSelf && _peer && _peer->isRepliesChat();
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:12:36 +00:00
|
|
|
void UserpicButton::startChangeOverlayAnimation() {
|
|
|
|
auto over = isOver() || isDown();
|
|
|
|
_changeOverlayShown.start(
|
|
|
|
[this] { update(); },
|
|
|
|
over ? 0. : 1.,
|
|
|
|
over ? 1. : 0.,
|
|
|
|
st::slideWrapDuration);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::onStateChanged(
|
|
|
|
State was,
|
|
|
|
StateChangeSource source) {
|
|
|
|
RippleButton::onStateChanged(was, source);
|
|
|
|
if (_changeOverlayEnabled) {
|
|
|
|
auto mask = (StateFlag::Over | StateFlag::Down);
|
|
|
|
auto wasOver = (was & mask) != 0;
|
|
|
|
auto nowOver = (state() & mask) != 0;
|
|
|
|
if (wasOver != nowOver) {
|
|
|
|
startChangeOverlayAnimation();
|
|
|
|
}
|
|
|
|
}
|
2017-03-07 09:17:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void UserpicButton::setImage(QImage &&image) {
|
2017-11-13 13:19:14 +00:00
|
|
|
grabOldUserpic();
|
2017-11-13 12:02:53 +00:00
|
|
|
|
|
|
|
auto size = QSize(_st.photoSize, _st.photoSize);
|
|
|
|
auto small = image.scaled(
|
|
|
|
size * cIntRetinaFactor(),
|
|
|
|
Qt::IgnoreAspectRatio,
|
|
|
|
Qt::SmoothTransformation);
|
2022-01-21 12:31:39 +00:00
|
|
|
_userpic = Ui::PixmapFromImage(Images::Circle(std::move(small)));
|
2017-11-13 12:02:53 +00:00
|
|
|
_userpic.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_userpicCustom = _userpicHasImage = true;
|
|
|
|
_result = std::move(image);
|
|
|
|
|
|
|
|
startNewPhotoShowing();
|
2017-03-07 09:17:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void UserpicButton::prepareUserpicPixmap() {
|
|
|
|
if (_userpicCustom) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto size = _st.photoSize;
|
|
|
|
auto paintButton = [&](Painter &p, const style::color &color) {
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setBrush(color);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawEllipse(0, 0, size, size);
|
|
|
|
};
|
|
|
|
_userpicHasImage = _peer
|
2020-05-28 14:32:10 +00:00
|
|
|
? (_peer->currentUserpic(_userpicView) || _role != Role::ChangePhoto)
|
2017-11-13 12:02:53 +00:00
|
|
|
: false;
|
|
|
|
_userpic = CreateSquarePixmap(size, [&](Painter &p) {
|
|
|
|
if (_userpicHasImage) {
|
2020-05-28 14:32:10 +00:00
|
|
|
_peer->paintUserpic(p, _userpicView, 0, 0, _st.photoSize);
|
2017-11-13 12:02:53 +00:00
|
|
|
} else {
|
|
|
|
paintButton(p, _st.changeButton.textBg);
|
|
|
|
}
|
|
|
|
});
|
2017-11-13 13:19:14 +00:00
|
|
|
_userpicUniqueKey = _userpicHasImage
|
2020-05-28 14:32:10 +00:00
|
|
|
? _peer->userpicUniqueKey(_userpicView)
|
2019-03-22 13:43:34 +00:00
|
|
|
: InMemoryKey();
|
2017-03-07 09:17:37 +00:00
|
|
|
}
|
2018-01-30 14:31:25 +00:00
|
|
|
|
2017-12-08 11:52:12 +00:00
|
|
|
SilentToggle::SilentToggle(QWidget *parent, not_null<ChannelData*> channel)
|
2021-02-01 06:33:32 +00:00
|
|
|
: RippleButton(parent, st::historySilentToggle.ripple)
|
|
|
|
, _st(st::historySilentToggle)
|
2017-12-08 11:52:12 +00:00
|
|
|
, _channel(channel)
|
2022-02-25 13:11:49 +00:00
|
|
|
, _checked(channel->owner().notifySilentPosts(_channel)) {
|
2019-07-24 11:13:51 +00:00
|
|
|
Expects(!channel->owner().notifySilentPostsUnknown(_channel));
|
2017-12-08 11:52:12 +00:00
|
|
|
|
2021-02-01 06:33:32 +00:00
|
|
|
resize(_st.width, _st.height);
|
|
|
|
|
|
|
|
paintRequest(
|
|
|
|
) | rpl::start_with_next([=](const QRect &clip) {
|
|
|
|
Painter p(this);
|
|
|
|
paintRipple(p, _st.rippleAreaPosition, nullptr);
|
|
|
|
|
2022-02-25 13:11:49 +00:00
|
|
|
//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());
|
2021-02-01 06:33:32 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2017-12-08 11:52:12 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SilentToggle::mouseMoveEvent(QMouseEvent *e) {
|
2021-02-01 06:33:32 +00:00
|
|
|
RippleButton::mouseMoveEvent(e);
|
2017-12-08 11:52:12 +00:00
|
|
|
if (rect().contains(e->pos())) {
|
|
|
|
Ui::Tooltip::Show(1000, this);
|
|
|
|
} else {
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SilentToggle::setChecked(bool checked) {
|
|
|
|
if (_checked != checked) {
|
|
|
|
_checked = checked;
|
2021-02-01 06:33:32 +00:00
|
|
|
_crossLineAnimation.start(
|
|
|
|
[=] { update(); },
|
|
|
|
_checked ? 0. : 1.,
|
|
|
|
_checked ? 1. : 0.,
|
|
|
|
kAnimationDuration);
|
2017-12-08 11:52:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SilentToggle::leaveEventHook(QEvent *e) {
|
2021-02-01 06:33:32 +00:00
|
|
|
RippleButton::leaveEventHook(e);
|
2017-12-08 11:52:12 +00:00
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SilentToggle::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
setChecked(!_checked);
|
2021-02-01 06:33:32 +00:00
|
|
|
RippleButton::mouseReleaseEvent(e);
|
2017-12-08 11:52:12 +00:00
|
|
|
Ui::Tooltip::Show(0, this);
|
2019-07-24 11:13:51 +00:00
|
|
|
_channel->owner().updateNotifySettings(
|
2017-12-08 11:52:12 +00:00
|
|
|
_channel,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::nullopt,
|
2018-04-09 17:48:29 +00:00
|
|
|
_checked);
|
2017-12-08 11:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString SilentToggle::tooltipText() const {
|
2019-06-19 15:09:03 +00:00
|
|
|
return _checked
|
|
|
|
? tr::lng_wont_be_notified(tr::now)
|
|
|
|
: tr::lng_will_be_notified(tr::now);
|
2017-12-08 11:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint SilentToggle::tooltipPos() const {
|
|
|
|
return QCursor::pos();
|
|
|
|
}
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
bool SilentToggle::tooltipWindowActive() const {
|
2019-12-31 13:48:44 +00:00
|
|
|
return Ui::AppInFocus() && InFocusChain(window());
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 06:33:32 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:18:23 +00:00
|
|
|
} // namespace Ui
|