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
|
|
|
|
2017-03-07 09:17:37 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-05-19 17:18:23 +00:00
|
|
|
#include "styles/style_history.h"
|
2016-06-03 12:45:33 +00:00
|
|
|
#include "dialogs/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"
|
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"
|
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"
|
2017-11-13 12:02:53 +00:00
|
|
|
#include "boxes/photo_crop_box.h"
|
|
|
|
#include "boxes/confirm_box.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"
|
|
|
|
#include "auth_session.h"
|
2018-09-06 11:13:54 +00:00
|
|
|
#include "apiwrap.h"
|
2017-12-08 11:52:12 +00:00
|
|
|
#include "mainwidget.h"
|
2017-11-13 12:02:53 +00:00
|
|
|
#include "observer_peer.h"
|
2016-05-19 17:18:23 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
2016-12-26 22:46:36 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr int kWideScale = 5;
|
|
|
|
|
2018-12-23 17:23:36 +00:00
|
|
|
QString CropTitle(not_null<PeerData*> peer) {
|
|
|
|
if (peer->isChat() || peer->isMegagroup()) {
|
|
|
|
return lang(lng_create_group_crop);
|
|
|
|
} else if (peer->isChannel()) {
|
|
|
|
return lang(lng_create_channel_crop);
|
|
|
|
} else {
|
|
|
|
return lang(lng_settings_crop_profile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
return App::pixmapFromImageInPlace(std::move(image));
|
|
|
|
};
|
|
|
|
|
2017-11-13 17:12:36 +00:00
|
|
|
template <typename Callback>
|
|
|
|
void SuggestPhoto(
|
|
|
|
const QImage &image,
|
2018-12-23 17:23:36 +00:00
|
|
|
const QString &title,
|
2017-11-13 17:12:36 +00:00
|
|
|
Callback &&callback) {
|
|
|
|
auto badAspect = [](int a, int b) {
|
|
|
|
return (a >= 10 * b);
|
|
|
|
};
|
|
|
|
if (image.isNull()
|
|
|
|
|| badAspect(image.width(), image.height())
|
|
|
|
|| badAspect(image.height(), image.width())) {
|
|
|
|
Ui::show(
|
|
|
|
Box<InformBox>(lang(lng_bad_photo)),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-23 17:23:36 +00:00
|
|
|
const auto box = Ui::show(
|
|
|
|
Box<PhotoCropBox>(image, title),
|
2017-11-13 17:12:36 +00:00
|
|
|
LayerOption::KeepOther);
|
2017-12-22 07:05:20 +00:00
|
|
|
box->ready(
|
|
|
|
) | rpl::start_with_next(
|
|
|
|
std::forward<Callback>(callback),
|
|
|
|
box->lifetime());
|
2017-11-13 17:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Callback>
|
|
|
|
void SuggestPhotoFile(
|
|
|
|
const FileDialog::OpenResult &result,
|
2018-12-23 17:23:36 +00:00
|
|
|
const QString &title,
|
2017-11-13 17:12:36 +00:00
|
|
|
Callback &&callback) {
|
|
|
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto image = [&] {
|
|
|
|
if (!result.remoteContent.isEmpty()) {
|
|
|
|
return App::readImage(result.remoteContent);
|
|
|
|
} else if (!result.paths.isEmpty()) {
|
|
|
|
return App::readImage(result.paths.front());
|
|
|
|
}
|
|
|
|
return QImage();
|
|
|
|
}();
|
|
|
|
SuggestPhoto(
|
|
|
|
image,
|
2018-12-23 17:23:36 +00:00
|
|
|
title,
|
2017-11-13 17:12:36 +00:00
|
|
|
std::forward<Callback>(callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Callback>
|
2018-04-17 15:19:34 +00:00
|
|
|
void ShowChoosePhotoBox(
|
2018-04-09 17:48:29 +00:00
|
|
|
QPointer<QWidget> parent,
|
2018-12-23 17:23:36 +00:00
|
|
|
const QString &title,
|
2018-04-17 15:19:34 +00:00
|
|
|
Callback &&callback) {
|
2017-11-13 17:12:36 +00:00
|
|
|
auto imgExtensions = cImgExtensions();
|
|
|
|
auto filter = qsl("Image files (*")
|
|
|
|
+ imgExtensions.join(qsl(" *"))
|
|
|
|
+ qsl(");;")
|
|
|
|
+ FileDialog::AllFilesFilter();
|
|
|
|
auto handleChosenPhoto = [
|
2018-12-23 17:23:36 +00:00
|
|
|
title,
|
2017-11-13 17:12:36 +00:00
|
|
|
callback = std::forward<Callback>(callback)
|
|
|
|
](auto &&result) mutable {
|
2018-12-23 17:23:36 +00:00
|
|
|
SuggestPhotoFile(result, title, std::move(callback));
|
2017-11-13 17:12:36 +00:00
|
|
|
};
|
|
|
|
FileDialog::GetOpenPath(
|
2018-04-17 15:19:34 +00:00
|
|
|
parent,
|
2017-11-13 17:12:36 +00:00
|
|
|
lang(lng_choose_image),
|
|
|
|
filter,
|
|
|
|
std::move(handleChosenPhoto));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
Dialogs::Layout::UnreadBadgeStyle st;
|
|
|
|
st.align = style::al_center;
|
|
|
|
st.font = st::historyToDownBadgeFont;
|
|
|
|
st.size = st::historyToDownBadgeSize;
|
|
|
|
st.sizeId = Dialogs::Layout::UnreadBadgeInHistoryToDown;
|
2019-05-22 08:57:25 +00:00
|
|
|
Dialogs::Layout::paintUnreadCount(p, unreadString, width(), 0, st, nullptr, 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-21 10:27:37 +00:00
|
|
|
EmojiButton::EmojiButton(QWidget *parent, const style::IconButton &st)
|
|
|
|
: RippleButton(parent, st.ripple)
|
2018-05-04 16:57:50 +00:00
|
|
|
, _st(st) {
|
2016-10-26 16:43:13 +00:00
|
|
|
resize(_st.width, _st.height);
|
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(e->rect(), st::historyComposeAreaBg);
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), _rippleOverride ? &(*_rippleOverride)->c : nullptr);
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2018-09-20 16:39:59 +00:00
|
|
|
const auto over = isOver();
|
2018-05-04 16:57:50 +00:00
|
|
|
const auto loadingState = _loading
|
|
|
|
? _loading->computeState()
|
2019-01-02 12:11:13 +00:00
|
|
|
: Ui::RadialState{ 0., 0, FullArcLength };
|
2018-09-20 16:39:59 +00:00
|
|
|
if (loadingState.shown < 1.) {
|
|
|
|
p.setOpacity(1. - loadingState.shown);
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2018-11-22 12:48:50 +00:00
|
|
|
const auto icon = _iconOverride ? _iconOverride : &(over ? _st.iconOver : _st.icon);
|
|
|
|
auto position = _st.iconPosition;
|
|
|
|
if (position.x() < 0) {
|
|
|
|
position.setX((width() - icon->width()) / 2);
|
|
|
|
}
|
|
|
|
if (position.y() < 0) {
|
|
|
|
position.setY((height() - icon->height()) / 2);
|
|
|
|
}
|
|
|
|
icon->paint(p, position, width());
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2018-09-20 16:39:59 +00:00
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2018-11-22 12:48:50 +00:00
|
|
|
QRect inner(QPoint((width() - st::historyEmojiCircle.width()) / 2, (height() - st::historyEmojiCircle.height()) / 2), st::historyEmojiCircle);
|
2018-09-20 16:39:59 +00:00
|
|
|
const auto color = (_colorOverride
|
|
|
|
? *_colorOverride
|
|
|
|
: (over
|
|
|
|
? st::historyEmojiCircleFgOver
|
|
|
|
: st::historyEmojiCircleFg));
|
2018-09-27 20:41:49 +00:00
|
|
|
if (anim::Disabled() && _loading && _loading->animating()) {
|
2018-09-20 16:39:59 +00:00
|
|
|
anim::DrawStaticLoading(
|
|
|
|
p,
|
|
|
|
inner,
|
|
|
|
st::historyEmojiCircleLine,
|
|
|
|
color);
|
2016-10-26 16:43:13 +00:00
|
|
|
} else {
|
2018-09-20 16:39:59 +00:00
|
|
|
auto pen = color->p;
|
|
|
|
pen.setWidth(st::historyEmojiCircleLine);
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
p.setPen(pen);
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
if (loadingState.arcLength < FullArcLength) {
|
|
|
|
p.drawArc(inner, loadingState.arcFrom, loadingState.arcLength);
|
|
|
|
} else {
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
void EmojiButton::loadingAnimationCallback() {
|
|
|
|
if (!anim::Disabled()) {
|
2018-09-20 16:39:59 +00:00
|
|
|
update();
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiButton::setLoading(bool loading) {
|
2018-05-04 16:57:50 +00:00
|
|
|
if (loading && !_loading) {
|
|
|
|
_loading = std::make_unique<Ui::InfiniteRadialAnimation>(
|
2019-04-01 17:44:54 +00:00
|
|
|
[=] { loadingAnimationCallback(); },
|
2018-05-04 16:57:50 +00:00
|
|
|
st::defaultInfiniteRadialAnimation);
|
|
|
|
}
|
|
|
|
if (loading) {
|
|
|
|
_loading->start();
|
2018-09-20 16:39:59 +00:00
|
|
|
update();
|
2018-05-08 18:06:56 +00:00
|
|
|
} else if (_loading) {
|
2018-05-04 16:57:50 +00:00
|
|
|
_loading->stop();
|
2018-09-20 16:39:59 +00:00
|
|
|
update();
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 09:40:03 +00:00
|
|
|
void EmojiButton::setColorOverrides(const style::icon *iconOverride, const style::color *colorOverride, const style::color *rippleOverride) {
|
|
|
|
_iconOverride = iconOverride;
|
|
|
|
_colorOverride = colorOverride;
|
|
|
|
_rippleOverride = rippleOverride;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void EmojiButton::onStateChanged(State was, StateChangeSource source) {
|
|
|
|
RippleButton::onStateChanged(was, source);
|
|
|
|
auto wasOver = static_cast<bool>(was & StateFlag::Over);
|
|
|
|
if (isOver() != wasOver) {
|
2016-11-01 12:46:34 +00:00
|
|
|
update();
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
QPoint EmojiButton::prepareRippleStartPosition() const {
|
2018-11-22 12:48:50 +00:00
|
|
|
if (!_st.rippleAreaSize) {
|
|
|
|
return DisabledRippleStartPosition();
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
return mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage EmojiButton::prepareRippleMask() const {
|
|
|
|
return RippleAnimation::ellipseMask(QSize(_st.rippleAreaSize, _st.rippleAreaSize));
|
|
|
|
}
|
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
SendButton::SendButton(QWidget *parent) : RippleButton(parent, st::historyReplyCancel.ripple) {
|
|
|
|
resize(st::historySendSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::setType(Type type) {
|
|
|
|
if (_type != type) {
|
|
|
|
_contentFrom = grabContent();
|
|
|
|
_type = type;
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_typeChanged.stop();
|
2016-12-26 22:46:36 +00:00
|
|
|
_contentTo = grabContent();
|
|
|
|
_a_typeChanged.start([this] { update(); }, 0., 1., st::historyRecordVoiceDuration);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
if (_type != Type::Record) {
|
|
|
|
_recordActive = false;
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_recordActive.stop();
|
2016-12-26 22:46:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::setRecordActive(bool recordActive) {
|
|
|
|
if (_recordActive != recordActive) {
|
|
|
|
_recordActive = recordActive;
|
|
|
|
_a_recordActive.start([this] { recordAnimationCallback(); }, _recordActive ? 0. : 1., _recordActive ? 1. : 0, st::historyRecordVoiceDuration);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
void SendButton::finishAnimating() {
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_typeChanged.stop();
|
|
|
|
_a_recordActive.stop();
|
2016-12-26 22:46:36 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
AbstractButton::mouseMoveEvent(e);
|
|
|
|
if (_recording) {
|
|
|
|
if (_recordUpdateCallback) {
|
|
|
|
_recordUpdateCallback(e->globalPos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
auto over = (isDown() || isOver());
|
2019-04-02 09:13:30 +00:00
|
|
|
auto changed = _a_typeChanged.value(1.);
|
2016-12-26 22:46:36 +00:00
|
|
|
if (changed < 1.) {
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setOpacity(1. - changed);
|
|
|
|
auto targetRect = QRect((1 - kWideScale) / 2 * width(), (1 - kWideScale) / 2 * height(), kWideScale * width(), kWideScale * height());
|
|
|
|
auto hiddenWidth = anim::interpolate(0, (1 - kWideScale) / 2 * width(), changed);
|
|
|
|
auto hiddenHeight = anim::interpolate(0, (1 - kWideScale) / 2 * height(), changed);
|
|
|
|
p.drawPixmap(targetRect.marginsAdded(QMargins(hiddenWidth, hiddenHeight, hiddenWidth, hiddenHeight)), _contentFrom);
|
|
|
|
p.setOpacity(changed);
|
|
|
|
auto shownWidth = anim::interpolate((1 - kWideScale) / 2 * width(), 0, changed);
|
|
|
|
auto shownHeight = anim::interpolate((1 - kWideScale) / 2 * height(), 0, changed);
|
|
|
|
p.drawPixmap(targetRect.marginsAdded(QMargins(shownWidth, shownHeight, shownWidth, shownHeight)), _contentTo);
|
|
|
|
} else if (_type == Type::Record) {
|
|
|
|
auto recordActive = recordActiveRatio();
|
|
|
|
auto rippleColor = anim::color(st::historyAttachEmoji.ripple.color, st::historyRecordVoiceRippleBgActive, recordActive);
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), &rippleColor);
|
2016-12-26 22:46:36 +00:00
|
|
|
|
2018-04-07 08:47:08 +00:00
|
|
|
auto fastIcon = [&] {
|
2016-12-26 22:46:36 +00:00
|
|
|
if (recordActive == 1.) {
|
|
|
|
return &st::historyRecordVoiceActive;
|
|
|
|
} else if (over) {
|
|
|
|
return &st::historyRecordVoiceOver;
|
|
|
|
}
|
|
|
|
return &st::historyRecordVoice;
|
|
|
|
};
|
|
|
|
fastIcon()->paintInCenter(p, rect());
|
|
|
|
if (recordActive > 0. && recordActive < 1.) {
|
|
|
|
p.setOpacity(recordActive);
|
|
|
|
st::historyRecordVoiceActive.paintInCenter(p, rect());
|
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
|
|
|
} else if (_type == Type::Save) {
|
|
|
|
auto &saveIcon = over ? st::historyEditSaveIconOver : st::historyEditSaveIcon;
|
|
|
|
saveIcon.paint(p, st::historySendIconPosition, width());
|
|
|
|
} else if (_type == Type::Cancel) {
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y());
|
2016-12-26 22:46:36 +00:00
|
|
|
|
|
|
|
auto &cancelIcon = over ? st::historyReplyCancelIconOver : st::historyReplyCancelIcon;
|
|
|
|
cancelIcon.paintInCenter(p, rect());
|
|
|
|
} else {
|
|
|
|
auto &sendIcon = over ? st::historySendIconOver : st::historySendIcon;
|
|
|
|
sendIcon.paint(p, st::historySendIconPosition, width());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::onStateChanged(State was, StateChangeSource source) {
|
|
|
|
RippleButton::onStateChanged(was, source);
|
|
|
|
|
|
|
|
auto down = (state() & StateFlag::Down);
|
|
|
|
if ((was & StateFlag::Down) != down) {
|
|
|
|
if (down) {
|
|
|
|
if (_type == Type::Record) {
|
|
|
|
_recording = true;
|
|
|
|
if (_recordStartCallback) {
|
|
|
|
_recordStartCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (_recording) {
|
|
|
|
_recording = false;
|
|
|
|
if (_recordStopCallback) {
|
|
|
|
_recordStopCallback(_recordActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap SendButton::grabContent() {
|
|
|
|
auto result = QImage(kWideScale * size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
result.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
Painter p(&result);
|
2017-12-26 12:41:48 +00:00
|
|
|
p.drawPixmap(
|
|
|
|
(kWideScale - 1) / 2 * width(),
|
|
|
|
(kWideScale - 1) / 2 * height(),
|
|
|
|
GrabWidget(this));
|
2016-12-26 22:46:36 +00:00
|
|
|
}
|
2017-02-21 13:45:56 +00:00
|
|
|
return App::pixmapFromImageInPlace(std::move(result));
|
2016-12-26 22:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QImage SendButton::prepareRippleMask() const {
|
|
|
|
auto size = (_type == Type::Record) ? st::historyAttachEmoji.rippleAreaSize : st::historyReplyCancel.rippleAreaSize;
|
|
|
|
return Ui::RippleAnimation::ellipseMask(QSize(size, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint SendButton::prepareRippleStartPosition() const {
|
|
|
|
auto real = mapFromGlobal(QCursor::pos());
|
|
|
|
auto size = (_type == Type::Record) ? st::historyAttachEmoji.rippleAreaSize : st::historyReplyCancel.rippleAreaSize;
|
|
|
|
auto y = (_type == Type::Record) ? st::historyAttachEmoji.rippleAreaPosition.y() : (height() - st::historyReplyCancel.rippleAreaSize) / 2;
|
|
|
|
return real - QPoint((width() - size) / 2, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::recordAnimationCallback() {
|
|
|
|
update();
|
|
|
|
if (_recordAnimationCallback) {
|
|
|
|
_recordAnimationCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
UserpicButton::UserpicButton(
|
|
|
|
QWidget *parent,
|
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)
|
2018-12-23 17:23:36 +00:00
|
|
|
, _cropTitle(cropTitle)
|
2017-11-13 12:02:53 +00:00
|
|
|
, _role(role) {
|
|
|
|
Expects(_role == Role::ChangePhoto);
|
|
|
|
|
|
|
|
_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)
|
|
|
|
, _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) {
|
2018-04-06 16:23:09 +00:00
|
|
|
Expects(_role != Role::OpenProfile);
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
_waiting = false;
|
|
|
|
prepare();
|
|
|
|
}
|
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void UserpicButton::prepare() {
|
|
|
|
resize(_st.size);
|
|
|
|
_notShownYet = _waiting;
|
|
|
|
if (!_waiting) {
|
|
|
|
prepareUserpicPixmap();
|
|
|
|
}
|
|
|
|
setClickHandlerByRole();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::setClickHandlerByRole() {
|
|
|
|
switch (_role) {
|
|
|
|
case Role::ChangePhoto:
|
|
|
|
addClickHandler(App::LambdaDelayed(
|
|
|
|
_st.changeButton.ripple.hideDuration,
|
|
|
|
this,
|
|
|
|
[this] { changePhotoLazy(); }));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Role::OpenPhoto:
|
|
|
|
addClickHandler([this] {
|
|
|
|
openPeerPhoto();
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Role::OpenProfile:
|
|
|
|
addClickHandler([this] {
|
|
|
|
Expects(_controller != nullptr);
|
|
|
|
|
|
|
|
_controller->showPeerInfo(_peer);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::changePhotoLazy() {
|
2018-06-04 15:35:11 +00:00
|
|
|
auto callback = crl::guard(
|
2017-11-13 12:02:53 +00:00
|
|
|
this,
|
2017-11-13 17:12:36 +00:00
|
|
|
[this](QImage &&image) { setImage(std::move(image)); });
|
2018-12-23 17:23:36 +00:00
|
|
|
ShowChoosePhotoBox(this, _cropTitle, std::move(callback));
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 17:12:36 +00:00
|
|
|
void UserpicButton::uploadNewPeerPhoto() {
|
2018-09-06 11:13:54 +00:00
|
|
|
auto callback = crl::guard(this, [=](QImage &&image) {
|
|
|
|
Auth().api().uploadPeerPhoto(_peer, std::move(image));
|
|
|
|
});
|
2018-12-23 17:23:36 +00:00
|
|
|
ShowChoosePhotoBox(this, _cropTitle, std::move(callback));
|
2017-03-07 09:17:37 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
uploadNewPeerPhoto();
|
|
|
|
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;
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto photo = Auth().data().photo(id);
|
2017-11-13 12:02:53 +00:00
|
|
|
if (photo->date) {
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().showPhoto(photo, _peer);
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::setupPeerViewers() {
|
|
|
|
Notify::PeerUpdateViewer(
|
|
|
|
_peer,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::PhotoChanged
|
|
|
|
) | rpl::start_with_next([this] {
|
|
|
|
processNewPeerPhoto();
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
|
|
|
base::ObservableViewer(
|
|
|
|
Auth().downloaderTaskFinished()
|
|
|
|
) | rpl::start_with_next([this] {
|
|
|
|
if (_waiting && _peer->userpicLoaded()) {
|
|
|
|
_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);
|
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);
|
|
|
|
} 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
|
|
|
}
|
|
|
|
p.drawPixmapLeft(photoPosition, width(), _userpic);
|
2017-11-13 12:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_role == Role::ChangePhoto) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
_waiting = !_peer->userpicLoaded();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserpicButton::updateCursor() {
|
|
|
|
Expects(_role == Role::OpenPhoto);
|
|
|
|
|
|
|
|
auto pointer = _canOpenPhoto
|
|
|
|
|| (_changeOverlayEnabled && _cursorInChangeOverlay);
|
|
|
|
setPointerCursor(pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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);
|
2017-03-07 09:17:37 +00:00
|
|
|
Images::prepareCircle(small);
|
2017-11-13 12:02:53 +00:00
|
|
|
_userpic = App::pixmapFromImageInPlace(std::move(small));
|
|
|
|
_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
|
|
|
|
? (_peer->currentUserpic() || _role != Role::ChangePhoto)
|
|
|
|
: false;
|
|
|
|
_userpic = CreateSquarePixmap(size, [&](Painter &p) {
|
|
|
|
if (_userpicHasImage) {
|
|
|
|
_peer->paintUserpic(p, 0, 0, _st.photoSize);
|
|
|
|
} else {
|
|
|
|
paintButton(p, _st.changeButton.textBg);
|
|
|
|
}
|
|
|
|
});
|
2017-11-13 13:19:14 +00:00
|
|
|
_userpicUniqueKey = _userpicHasImage
|
|
|
|
? _peer->userpicUniqueKey()
|
2019-03-22 13:43:34 +00:00
|
|
|
: InMemoryKey();
|
2017-03-07 09:17:37 +00:00
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
// // #feed
|
|
|
|
//FeedUserpicButton::FeedUserpicButton(
|
|
|
|
// QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
// not_null<Window::SessionController*> controller,
|
2019-04-15 11:54:03 +00:00
|
|
|
// not_null<Data::Feed*> feed,
|
|
|
|
// const style::FeedUserpicButton &st)
|
|
|
|
//: AbstractButton(parent)
|
|
|
|
//, _st(st)
|
|
|
|
//, _controller(controller)
|
|
|
|
//, _feed(feed) {
|
|
|
|
// prepare();
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void FeedUserpicButton::prepare() {
|
|
|
|
// resize(_st.size);
|
|
|
|
//
|
|
|
|
// Auth().data().feedUpdated(
|
|
|
|
// ) | rpl::filter([=](const Data::FeedUpdate &update) {
|
|
|
|
// return (update.feed == _feed)
|
|
|
|
// && (update.flag == Data::FeedUpdateFlag::Channels);
|
|
|
|
// }) | rpl::start_with_next([=] {
|
|
|
|
// crl::on_main(this, [=] { checkParts(); });
|
|
|
|
// }, lifetime());
|
|
|
|
//
|
|
|
|
// refreshParts();
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void FeedUserpicButton::checkParts() {
|
|
|
|
// if (!partsAreValid()) {
|
|
|
|
// refreshParts();
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//bool FeedUserpicButton::partsAreValid() const {
|
|
|
|
// const auto &channels = _feed->channels();
|
|
|
|
// const auto count = std::min(int(channels.size()), 4);
|
|
|
|
// if (count != _parts.size()) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// for (auto i = 0; i != count; ++i) {
|
|
|
|
// if (channels[i]->peer != _parts[i].channel) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void FeedUserpicButton::refreshParts() {
|
|
|
|
// const auto &channels = _feed->channels();
|
|
|
|
// const auto count = std::min(int(channels.size()), 4);
|
|
|
|
//
|
|
|
|
// const auto createButton = [&](not_null<ChannelData*> channel) {
|
|
|
|
// auto result = base::make_unique_q<Ui::UserpicButton>(
|
|
|
|
// this,
|
|
|
|
// _controller,
|
|
|
|
// channel,
|
|
|
|
// Ui::UserpicButton::Role::Custom,
|
|
|
|
// _st.innerPart);
|
|
|
|
// result->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
// result->show();
|
|
|
|
// return result;
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// const auto position = countInnerPosition();
|
|
|
|
// auto x = position.x();
|
|
|
|
// auto y = position.y();
|
|
|
|
// const auto delta = _st.innerSize - _st.innerPart.photoSize;
|
|
|
|
// _parts.clear();
|
|
|
|
// for (auto i = 0; i != count; ++i) {
|
|
|
|
// const auto channel = channels[i]->peer->asChannel();
|
|
|
|
// _parts.push_back({ channel, createButton(channel) });
|
|
|
|
// _parts.back().button->moveToLeft(x, y);
|
|
|
|
// switch (i) {
|
|
|
|
// case 0:
|
|
|
|
// case 2: x += delta; break;
|
|
|
|
// case 1: x -= delta; y += delta; break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//QPoint FeedUserpicButton::countInnerPosition() const {
|
|
|
|
// auto innerLeft = (_st.innerPosition.x() < 0)
|
|
|
|
// ? (width() - _st.innerSize) / 2
|
|
|
|
// : _st.innerPosition.x();
|
|
|
|
// auto innerTop = (_st.innerPosition.y() < 0)
|
|
|
|
// ? (height() - _st.innerSize) / 2
|
|
|
|
// : _st.innerPosition.y();
|
|
|
|
// return { innerLeft, innerTop };
|
|
|
|
//}
|
2018-01-30 14:31:25 +00:00
|
|
|
|
2017-12-08 11:52:12 +00:00
|
|
|
SilentToggle::SilentToggle(QWidget *parent, not_null<ChannelData*> channel)
|
|
|
|
: IconButton(parent, st::historySilentToggle)
|
|
|
|
, _channel(channel)
|
2018-04-09 17:48:29 +00:00
|
|
|
, _checked(Auth().data().notifySilentPosts(_channel)) {
|
|
|
|
Expects(!Auth().data().notifySilentPostsUnknown(_channel));
|
2017-12-08 11:52:12 +00:00
|
|
|
|
|
|
|
if (_checked) {
|
|
|
|
refreshIconOverrides();
|
|
|
|
}
|
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SilentToggle::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
IconButton::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;
|
|
|
|
refreshIconOverrides();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
IconButton::leaveEventHook(e);
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SilentToggle::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
setChecked(!_checked);
|
|
|
|
IconButton::mouseReleaseEvent(e);
|
|
|
|
Ui::Tooltip::Show(0, this);
|
2018-04-09 17:48:29 +00:00
|
|
|
Auth().data().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 {
|
|
|
|
return lang(_checked ? lng_wont_be_notified : lng_will_be_notified);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint SilentToggle::tooltipPos() const {
|
|
|
|
return QCursor::pos();
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:18:23 +00:00
|
|
|
} // namespace Ui
|