2017-04-19 20:25:48 +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.
|
2017-04-19 20:25:48 +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
|
2017-04-19 20:25:48 +00:00
|
|
|
*/
|
|
|
|
#include "calls/calls_panel.h"
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_photo.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2020-05-25 14:16:04 +00:00
|
|
|
#include "data/data_photo_media.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"
|
2017-04-25 16:45:41 +00:00
|
|
|
#include "calls/calls_emoji_fingerprint.h"
|
2020-08-06 16:55:58 +00:00
|
|
|
#include "calls/calls_signal_bars.h"
|
|
|
|
#include "calls/calls_userpic.h"
|
|
|
|
#include "calls/calls_video_bubble.h"
|
2017-04-19 20:25:48 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/shadow.h"
|
2017-05-05 10:14:40 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "ui/platform/ui_platform_utility.h"
|
2017-12-05 08:43:18 +00:00
|
|
|
#include "ui/empty_userpic.h"
|
2018-10-13 17:35:30 +00:00
|
|
|
#include "ui/emoji_config.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2017-05-12 15:27:19 +00:00
|
|
|
#include "mainwindow.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-04-19 20:25:48 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "platform/platform_specific.h"
|
2017-05-12 15:27:19 +00:00
|
|
|
#include "window/main_window.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "layout.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2020-07-31 14:36:35 +00:00
|
|
|
#include "webrtc/webrtc_video_track.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "styles/style_calls.h"
|
|
|
|
#include "styles/style_history.h"
|
2017-04-19 20:25:48 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtWidgets/QDesktopWidget>
|
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
namespace Calls {
|
2017-04-29 18:41:41 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kTooltipShowTimeoutMs = 1000;
|
|
|
|
|
|
|
|
} // namespace
|
2017-04-19 20:25:48 +00:00
|
|
|
|
|
|
|
class Panel::Button : public Ui::RippleButton {
|
|
|
|
public:
|
2017-05-05 10:14:40 +00:00
|
|
|
Button(QWidget *parent, const style::CallButton &stFrom, const style::CallButton *stTo = nullptr);
|
|
|
|
|
|
|
|
void setProgress(float64 progress);
|
2017-05-07 19:09:20 +00:00
|
|
|
void setOuterValue(float64 value);
|
2017-04-19 20:25:48 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
|
|
|
|
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
|
|
|
|
|
|
|
private:
|
2017-08-17 08:31:24 +00:00
|
|
|
QPoint iconPosition(not_null<const style::CallButton*> st) const;
|
2017-05-05 10:14:40 +00:00
|
|
|
void mixIconMasks();
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<const style::CallButton*> _stFrom;
|
2017-05-05 10:14:40 +00:00
|
|
|
const style::CallButton *_stTo = nullptr;
|
|
|
|
float64 _progress = 0.;
|
|
|
|
|
|
|
|
QImage _bgMask, _bg;
|
|
|
|
QPixmap _bgFrom, _bgTo;
|
|
|
|
QImage _iconMixedMask, _iconFrom, _iconTo, _iconMixed;
|
2017-04-19 20:25:48 +00:00
|
|
|
|
2017-05-07 19:09:20 +00:00
|
|
|
float64 _outerValue = 0.;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _outerAnimation;
|
2017-05-07 19:09:20 +00:00
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
};
|
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
Panel::Button::Button(QWidget *parent, const style::CallButton &stFrom, const style::CallButton *stTo) : Ui::RippleButton(parent, stFrom.button.ripple)
|
|
|
|
, _stFrom(&stFrom)
|
|
|
|
, _stTo(stTo) {
|
|
|
|
resize(_stFrom->button.width, _stFrom->button.height);
|
|
|
|
|
|
|
|
_bgMask = prepareRippleMask();
|
|
|
|
_bgFrom = App::pixmapFromImageInPlace(style::colorizeImage(_bgMask, _stFrom->bg));
|
|
|
|
if (_stTo) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_stFrom->button.width == _stTo->button.width);
|
|
|
|
Assert(_stFrom->button.height == _stTo->button.height);
|
|
|
|
Assert(_stFrom->button.rippleAreaPosition == _stTo->button.rippleAreaPosition);
|
|
|
|
Assert(_stFrom->button.rippleAreaSize == _stTo->button.rippleAreaSize);
|
2017-05-05 10:14:40 +00:00
|
|
|
|
|
|
|
_bg = QImage(_bgMask.size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
_bg.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_bgTo = App::pixmapFromImageInPlace(style::colorizeImage(_bgMask, _stTo->bg));
|
|
|
|
_iconMixedMask = QImage(_bgMask.size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
_iconMixedMask.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_iconFrom = QImage(_bgMask.size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
_iconFrom.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_iconFrom.fill(Qt::black);
|
|
|
|
{
|
|
|
|
Painter p(&_iconFrom);
|
|
|
|
p.drawImage((_stFrom->button.rippleAreaSize - _stFrom->button.icon.width()) / 2, (_stFrom->button.rippleAreaSize - _stFrom->button.icon.height()) / 2, _stFrom->button.icon.instance(Qt::white));
|
|
|
|
}
|
|
|
|
_iconTo = QImage(_bgMask.size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
_iconTo.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_iconTo.fill(Qt::black);
|
|
|
|
{
|
|
|
|
Painter p(&_iconTo);
|
|
|
|
p.drawImage((_stTo->button.rippleAreaSize - _stTo->button.icon.width()) / 2, (_stTo->button.rippleAreaSize - _stTo->button.icon.height()) / 2, _stTo->button.icon.instance(Qt::white));
|
|
|
|
}
|
|
|
|
_iconMixed = QImage(_bgMask.size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
_iconMixed.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-07 19:09:20 +00:00
|
|
|
void Panel::Button::setOuterValue(float64 value) {
|
|
|
|
if (_outerValue != value) {
|
|
|
|
_outerAnimation.start([this] {
|
|
|
|
if (_progress == 0. || _progress == 1.) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}, _outerValue, value, Call::kSoundSampleMs);
|
|
|
|
_outerValue = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
void Panel::Button::setProgress(float64 progress) {
|
|
|
|
_progress = progress;
|
|
|
|
update();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Button::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2017-05-07 19:09:20 +00:00
|
|
|
auto bgPosition = myrtlpoint(_stFrom->button.rippleAreaPosition);
|
2017-05-05 10:14:40 +00:00
|
|
|
auto paintFrom = (_progress == 0.) || !_stTo;
|
|
|
|
auto paintTo = !paintFrom && (_progress == 1.);
|
2017-05-07 19:09:20 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
auto outerValue = _outerAnimation.value(_outerValue);
|
2017-05-07 19:09:20 +00:00
|
|
|
if (outerValue > 0.) {
|
|
|
|
auto outerRadius = paintFrom ? _stFrom->outerRadius : paintTo ? _stTo->outerRadius : (_stFrom->outerRadius * (1. - _progress) + _stTo->outerRadius * _progress);
|
|
|
|
auto outerPixels = outerValue * outerRadius;
|
|
|
|
auto outerRect = QRectF(myrtlrect(bgPosition.x(), bgPosition.y(), _stFrom->button.rippleAreaSize, _stFrom->button.rippleAreaSize));
|
|
|
|
outerRect = outerRect.marginsAdded(QMarginsF(outerPixels, outerPixels, outerPixels, outerPixels));
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
if (paintFrom) {
|
|
|
|
p.setBrush(_stFrom->outerBg);
|
|
|
|
} else if (paintTo) {
|
|
|
|
p.setBrush(_stTo->outerBg);
|
|
|
|
} else {
|
|
|
|
p.setBrush(anim::brush(_stFrom->outerBg, _stTo->outerBg, _progress));
|
|
|
|
}
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawEllipse(outerRect);
|
|
|
|
}
|
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
if (paintFrom) {
|
|
|
|
p.drawPixmap(bgPosition, _bgFrom);
|
|
|
|
} else if (paintTo) {
|
|
|
|
p.drawPixmap(bgPosition, _bgTo);
|
|
|
|
} else {
|
|
|
|
style::colorizeImage(_bgMask, anim::color(_stFrom->bg, _stTo->bg, _progress), &_bg);
|
|
|
|
p.drawImage(bgPosition, _bg);
|
|
|
|
}
|
2017-04-19 20:25:48 +00:00
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
auto rippleColorInterpolated = QColor();
|
|
|
|
auto rippleColorOverride = &rippleColorInterpolated;
|
|
|
|
if (paintFrom) {
|
|
|
|
rippleColorOverride = nullptr;
|
|
|
|
} else if (paintTo) {
|
|
|
|
rippleColorOverride = &_stTo->button.ripple.color->c;
|
|
|
|
} else {
|
|
|
|
rippleColorInterpolated = anim::color(_stFrom->button.ripple.color, _stTo->button.ripple.color, _progress);
|
|
|
|
}
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, _stFrom->button.rippleAreaPosition.x(), _stFrom->button.rippleAreaPosition.y(), rippleColorOverride);
|
2017-04-19 20:25:48 +00:00
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
auto positionFrom = iconPosition(_stFrom);
|
|
|
|
if (paintFrom) {
|
|
|
|
_stFrom->button.icon.paint(p, positionFrom, width());
|
|
|
|
} else {
|
|
|
|
auto positionTo = iconPosition(_stTo);
|
|
|
|
if (paintTo) {
|
|
|
|
_stTo->button.icon.paint(p, positionTo, width());
|
|
|
|
} else {
|
|
|
|
mixIconMasks();
|
|
|
|
style::colorizeImage(_iconMixedMask, st::callIconFg->c, &_iconMixed);
|
|
|
|
p.drawImage(myrtlpoint(_stFrom->button.rippleAreaPosition), _iconMixed);
|
|
|
|
}
|
2017-04-29 18:00:27 +00:00
|
|
|
}
|
2017-05-05 10:14:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
QPoint Panel::Button::iconPosition(not_null<const style::CallButton*> st) const {
|
2017-05-05 10:14:40 +00:00
|
|
|
auto result = st->button.iconPosition;
|
|
|
|
if (result.x() < 0) {
|
|
|
|
result.setX((width() - st->button.icon.width()) / 2);
|
|
|
|
}
|
|
|
|
if (result.y() < 0) {
|
|
|
|
result.setY((height() - st->button.icon.height()) / 2);
|
2017-04-29 18:00:27 +00:00
|
|
|
}
|
2017-05-05 10:14:40 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Button::mixIconMasks() {
|
|
|
|
_iconMixedMask.fill(Qt::black);
|
|
|
|
|
|
|
|
Painter p(&_iconMixedMask);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
auto paintIconMask = [this, &p](const QImage &mask, float64 angle) {
|
|
|
|
auto skipFrom = _stFrom->button.rippleAreaSize / 2;
|
|
|
|
p.translate(skipFrom, skipFrom);
|
|
|
|
p.rotate(angle);
|
|
|
|
p.translate(-skipFrom, -skipFrom);
|
|
|
|
p.drawImage(0, 0, mask);
|
|
|
|
};
|
|
|
|
p.save();
|
|
|
|
paintIconMask(_iconFrom, (_stFrom->angle - _stTo->angle) * _progress);
|
|
|
|
p.restore();
|
|
|
|
p.setOpacity(_progress);
|
|
|
|
paintIconMask(_iconTo, (_stTo->angle - _stFrom->angle) * (1. - _progress));
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Button::onStateChanged(State was, StateChangeSource source) {
|
|
|
|
RippleButton::onStateChanged(was, source);
|
|
|
|
|
|
|
|
auto over = isOver();
|
|
|
|
auto wasOver = static_cast<bool>(was & StateFlag::Over);
|
|
|
|
if (over != wasOver) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Panel::Button::prepareRippleStartPosition() const {
|
2017-05-05 10:14:40 +00:00
|
|
|
return mapFromGlobal(QCursor::pos()) - _stFrom->button.rippleAreaPosition;
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QImage Panel::Button::prepareRippleMask() const {
|
2017-05-05 10:14:40 +00:00
|
|
|
return Ui::RippleAnimation::ellipseMask(QSize(_stFrom->button.rippleAreaSize, _stFrom->button.rippleAreaSize));
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Panel::Panel(not_null<Call*> call)
|
2020-05-27 05:50:07 +00:00
|
|
|
: RpWidget(Core::App().getModalParent())
|
2020-05-14 16:27:51 +00:00
|
|
|
, _call(call)
|
2017-04-19 20:25:48 +00:00
|
|
|
, _user(call->user())
|
2017-05-05 10:14:40 +00:00
|
|
|
, _answerHangupRedial(this, st::callAnswer, &st::callHangup)
|
2017-09-30 18:26:45 +00:00
|
|
|
, _decline(this, object_ptr<Button>(this, st::callHangup))
|
|
|
|
, _cancel(this, object_ptr<Button>(this, st::callCancel))
|
2020-07-16 16:23:55 +00:00
|
|
|
, _camera(this, st::callCameraToggle)
|
2017-04-19 20:25:48 +00:00
|
|
|
, _mute(this, st::callMuteToggle)
|
2017-04-25 16:45:41 +00:00
|
|
|
, _name(this, st::callName)
|
2020-08-06 16:55:58 +00:00
|
|
|
, _status(this, st::callStatus) {
|
2017-09-30 18:26:45 +00:00
|
|
|
_decline->setDuration(st::callPanelDuration);
|
|
|
|
_cancel->setDuration(st::callPanelDuration);
|
|
|
|
|
2017-04-29 18:41:41 +00:00
|
|
|
setMouseTracking(true);
|
2020-06-15 16:25:02 +00:00
|
|
|
setWindowIcon(Window::CreateIcon(&_user->session()));
|
2017-04-19 20:25:48 +00:00
|
|
|
initControls();
|
|
|
|
initLayout();
|
2017-04-25 20:36:04 +00:00
|
|
|
showAndActivate();
|
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
Panel::~Panel() = default;
|
|
|
|
|
2017-04-25 20:36:04 +00:00
|
|
|
void Panel::showAndActivate() {
|
2017-05-05 10:14:40 +00:00
|
|
|
toggleOpacityAnimation(true);
|
2017-04-25 20:36:04 +00:00
|
|
|
raise();
|
|
|
|
setWindowState(windowState() | Qt::WindowActive);
|
|
|
|
activateWindow();
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void Panel::replaceCall(not_null<Call*> call) {
|
2020-08-04 09:06:48 +00:00
|
|
|
reinitWithCall(call);
|
2017-05-04 12:29:32 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2017-11-21 13:23:56 +00:00
|
|
|
bool Panel::eventHook(QEvent *e) {
|
2017-04-25 20:36:04 +00:00
|
|
|
if (e->type() == QEvent::WindowDeactivate) {
|
2020-08-06 16:55:58 +00:00
|
|
|
checkForInactiveHide();
|
2017-04-25 20:36:04 +00:00
|
|
|
}
|
2017-11-21 13:23:56 +00:00
|
|
|
return RpWidget::eventHook(e);
|
2017-04-25 20:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::hideDeactivated() {
|
2017-05-05 10:14:40 +00:00
|
|
|
toggleOpacityAnimation(false);
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::initControls() {
|
2017-05-05 10:14:40 +00:00
|
|
|
_hangupShown = (_call->type() == Type::Outgoing);
|
2020-07-16 16:23:55 +00:00
|
|
|
_mute->setClickedCallback([=] {
|
2017-05-04 13:32:56 +00:00
|
|
|
if (_call) {
|
2020-07-16 16:23:55 +00:00
|
|
|
_call->setMuted(!_call->muted());
|
2017-05-04 13:32:56 +00:00
|
|
|
}
|
2017-04-25 16:45:41 +00:00
|
|
|
});
|
2020-07-16 16:23:55 +00:00
|
|
|
_camera->setClickedCallback([=] {
|
|
|
|
if (_call) {
|
2020-08-05 12:11:18 +00:00
|
|
|
_call->videoOutgoing()->setState(
|
|
|
|
(_call->videoOutgoing()->state() == webrtc::VideoState::Active)
|
|
|
|
? webrtc::VideoState::Inactive
|
|
|
|
: webrtc::VideoState::Active);
|
2020-07-16 16:23:55 +00:00
|
|
|
}
|
2017-04-25 16:45:41 +00:00
|
|
|
});
|
2020-06-12 12:12:34 +00:00
|
|
|
|
2017-04-25 16:45:41 +00:00
|
|
|
_updateDurationTimer.setCallback([this] {
|
|
|
|
if (_call) {
|
|
|
|
updateStatusText(_call->state());
|
|
|
|
}
|
|
|
|
});
|
2017-05-07 19:09:20 +00:00
|
|
|
_updateOuterRippleTimer.setCallback([this] {
|
|
|
|
if (_call) {
|
|
|
|
_answerHangupRedial->setOuterValue(_call->getWaitingSoundPeakValue());
|
|
|
|
} else {
|
|
|
|
_answerHangupRedial->setOuterValue(0.);
|
|
|
|
_updateOuterRippleTimer.cancel();
|
|
|
|
}
|
|
|
|
});
|
2017-05-05 10:14:40 +00:00
|
|
|
_answerHangupRedial->setClickedCallback([this] {
|
|
|
|
if (!_call || _hangupShownProgress.animating()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto state = _call->state();
|
|
|
|
if (state == State::Busy) {
|
|
|
|
_call->redial();
|
2017-05-08 09:26:43 +00:00
|
|
|
} else if (_call->isIncomingWaiting()) {
|
2017-05-05 10:14:40 +00:00
|
|
|
_call->answer();
|
|
|
|
} else {
|
|
|
|
_call->hangup();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
auto hangupCallback = [this] {
|
|
|
|
if (_call) {
|
|
|
|
_call->hangup();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
_decline->entity()->setClickedCallback(hangupCallback);
|
|
|
|
_cancel->entity()->setClickedCallback(hangupCallback);
|
2017-05-04 12:29:32 +00:00
|
|
|
|
2020-08-04 09:06:48 +00:00
|
|
|
reinitWithCall(_call);
|
2017-05-05 10:14:40 +00:00
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
_decline->finishAnimating();
|
|
|
|
_cancel->finishAnimating();
|
2020-08-04 09:06:48 +00:00
|
|
|
}
|
2020-05-19 06:33:57 +00:00
|
|
|
|
2020-08-04 09:06:48 +00:00
|
|
|
void Panel::setIncomingShown(bool shown) {
|
|
|
|
if (_incomingShown == shown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_incomingShown = shown;
|
|
|
|
if (_animationCache.isNull()) {
|
|
|
|
showControls();
|
|
|
|
}
|
2017-05-04 12:29:32 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 09:06:48 +00:00
|
|
|
void Panel::reinitWithCall(Call *call) {
|
|
|
|
_callLifetime.destroy();
|
|
|
|
_call = call;
|
|
|
|
if (!_call) {
|
2020-08-06 16:55:58 +00:00
|
|
|
_outgoingVideoBubble = nullptr;
|
2020-08-04 09:06:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_user = _call->user();
|
|
|
|
|
2020-08-06 16:55:58 +00:00
|
|
|
_signalBars.create(
|
|
|
|
this,
|
|
|
|
_call,
|
|
|
|
st::callPanelSignalBars,
|
|
|
|
[=] { rtlupdate(signalBarsRect()); });
|
|
|
|
|
|
|
|
auto remoteMuted = _call->remoteAudioStateValue(
|
|
|
|
) | rpl::map([=](Call::RemoteAudioState state) {
|
|
|
|
return (state == Call::RemoteAudioState::Muted);
|
|
|
|
});
|
|
|
|
_userpic = std::make_unique<Userpic>(this, _user, std::move(remoteMuted));
|
|
|
|
_outgoingVideoBubble = std::make_unique<VideoBubble>(
|
|
|
|
this,
|
|
|
|
_call->videoOutgoing());
|
|
|
|
_outgoingVideoBubble->setSizeConstraints(
|
|
|
|
st::callOutgoingPreviewSize);
|
|
|
|
|
2020-08-04 09:06:48 +00:00
|
|
|
_call->mutedValue(
|
|
|
|
) | rpl::start_with_next([=](bool mute) {
|
|
|
|
_mute->setIconOverride(mute ? &st::callUnmuteIcon : nullptr);
|
|
|
|
}, _callLifetime);
|
|
|
|
|
2020-08-05 12:11:18 +00:00
|
|
|
_call->videoOutgoing()->stateValue(
|
|
|
|
) | rpl::start_with_next([=](webrtc::VideoState state) {
|
|
|
|
_camera->setIconOverride((state == webrtc::VideoState::Active)
|
|
|
|
? nullptr
|
|
|
|
: &st::callNoCameraIcon);
|
2020-08-04 09:06:48 +00:00
|
|
|
}, _callLifetime);
|
2017-05-04 13:32:56 +00:00
|
|
|
|
2020-06-25 17:57:36 +00:00
|
|
|
_call->stateValue(
|
|
|
|
) | rpl::start_with_next([=](State state) {
|
|
|
|
stateChanged(state);
|
2020-08-04 09:06:48 +00:00
|
|
|
}, _callLifetime);
|
|
|
|
|
2020-08-06 16:55:58 +00:00
|
|
|
_call->videoIncoming()->renderNextFrame(
|
2020-08-04 09:06:48 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
setIncomingShown(!_call->videoIncoming()->frame({}).isNull());
|
|
|
|
update();
|
|
|
|
}, _callLifetime);
|
2017-05-04 12:29:32 +00:00
|
|
|
|
2020-08-06 16:55:58 +00:00
|
|
|
rpl::merge(
|
|
|
|
_call->videoIncoming()->stateChanges(),
|
|
|
|
_call->videoOutgoing()->stateChanges()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
checkForInactiveShow();
|
|
|
|
}, _callLifetime);
|
2018-05-27 08:24:47 +00:00
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
_name->setText(_user->name);
|
2017-05-04 12:29:32 +00:00
|
|
|
updateStatusText(_call->state());
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::initLayout() {
|
2020-08-06 16:55:58 +00:00
|
|
|
setWindowFlags(Qt::WindowFlags(Qt::FramelessWindowHint) | Qt::NoDropShadowWindowHint | Qt::Dialog);
|
2017-04-19 20:25:48 +00:00
|
|
|
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
|
2020-08-06 16:55:58 +00:00
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
2017-04-19 20:25:48 +00:00
|
|
|
|
|
|
|
initGeometry();
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
using UpdateFlag = Data::PeerUpdate::Flag;
|
|
|
|
_user->session().changes().peerUpdates(
|
2020-08-06 16:55:58 +00:00
|
|
|
UpdateFlag::Name
|
2020-06-12 12:12:34 +00:00
|
|
|
) | rpl::filter([=](const Data::PeerUpdate &update) {
|
|
|
|
// _user may change for the same Panel.
|
|
|
|
return (_call != nullptr) && (update.peer == _user);
|
|
|
|
}) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
2020-08-06 16:55:58 +00:00
|
|
|
_name->setText(_call->user()->name);
|
|
|
|
updateControlsGeometry();
|
2020-06-12 12:12:34 +00:00
|
|
|
}, lifetime());
|
2019-08-06 16:40:08 +00:00
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
createDefaultCacheImage();
|
2017-05-02 07:25:20 +00:00
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
Ui::Platform::InitOnTopPanel(this);
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 13:32:56 +00:00
|
|
|
void Panel::toggleOpacityAnimation(bool visible) {
|
2017-05-05 10:14:40 +00:00
|
|
|
if (!_call || _visible == visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_visible = visible;
|
2017-05-04 13:32:56 +00:00
|
|
|
if (_useTransparency) {
|
|
|
|
if (_animationCache.isNull()) {
|
2017-05-05 10:14:40 +00:00
|
|
|
showControls();
|
2017-12-26 12:41:48 +00:00
|
|
|
_animationCache = Ui::GrabWidget(this);
|
2017-05-04 13:32:56 +00:00
|
|
|
hideChildren();
|
|
|
|
}
|
2017-12-26 12:41:48 +00:00
|
|
|
_opacityAnimation.start(
|
|
|
|
[this] { update(); },
|
|
|
|
_visible ? 0. : 1.,
|
|
|
|
_visible ? 1. : 0.,
|
|
|
|
st::callPanelDuration,
|
|
|
|
_visible ? anim::easeOutCirc : anim::easeInCirc);
|
2020-05-10 17:01:01 +00:00
|
|
|
} else if (!isHidden() && !_visible) {
|
|
|
|
hide();
|
2017-05-05 10:14:40 +00:00
|
|
|
}
|
|
|
|
if (isHidden() && _visible) {
|
|
|
|
show();
|
2017-05-04 13:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
void Panel::finishAnimating() {
|
2017-05-04 13:32:56 +00:00
|
|
|
_animationCache = QPixmap();
|
|
|
|
if (_call) {
|
2017-05-05 10:14:40 +00:00
|
|
|
if (!_visible) {
|
|
|
|
hide();
|
|
|
|
} else {
|
|
|
|
showControls();
|
|
|
|
}
|
2017-05-04 13:32:56 +00:00
|
|
|
} else {
|
|
|
|
destroyDelayed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
void Panel::showControls() {
|
|
|
|
Expects(_call != nullptr);
|
2020-05-28 14:32:10 +00:00
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
showChildren();
|
2017-09-30 19:20:40 +00:00
|
|
|
_decline->setVisible(_decline->toggled());
|
|
|
|
_cancel->setVisible(_cancel->toggled());
|
2020-08-04 09:06:48 +00:00
|
|
|
_name->setVisible(!_incomingShown);
|
|
|
|
_status->setVisible(!_incomingShown);
|
2020-08-06 16:55:58 +00:00
|
|
|
_userpic->setVisible(!_incomingShown);
|
2017-05-05 10:14:40 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 13:32:56 +00:00
|
|
|
void Panel::destroyDelayed() {
|
|
|
|
hide();
|
2017-12-30 21:28:38 +00:00
|
|
|
crl::on_main(this, [=] {
|
|
|
|
delete this;
|
2017-05-04 13:32:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::hideAndDestroy() {
|
|
|
|
toggleOpacityAnimation(false);
|
2020-08-04 09:06:48 +00:00
|
|
|
reinitWithCall(nullptr);
|
2017-05-04 13:32:56 +00:00
|
|
|
if (_animationCache.isNull()) {
|
|
|
|
destroyDelayed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
void Panel::initGeometry() {
|
2020-05-14 16:27:51 +00:00
|
|
|
const auto center = Core::App().getPointForCallPanelCenter();
|
2019-09-16 11:14:06 +00:00
|
|
|
_useTransparency = Ui::Platform::TranslucentWindowsSupported(center);
|
2017-05-02 09:08:08 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !_useTransparency);
|
|
|
|
_padding = _useTransparency ? st::callShadow.extend : style::margins(st::lineWidth, st::lineWidth, st::lineWidth, st::lineWidth);
|
2020-08-04 09:06:48 +00:00
|
|
|
_controlsTop = _padding.top() + st::callControlsTop;
|
|
|
|
_contentTop = _padding.top() + 2 * st::callPhotoSize;
|
2020-05-14 16:27:51 +00:00
|
|
|
const auto rect = [&] {
|
|
|
|
const QRect initRect(0, 0, st::callWidth, st::callHeight);
|
|
|
|
return initRect.translated(center - initRect.center()).marginsAdded(_padding);
|
|
|
|
}();
|
|
|
|
setGeometry(rect);
|
|
|
|
setMinimumSize(rect.size());
|
|
|
|
setMaximumSize(rect.size());
|
2017-04-19 20:25:48 +00:00
|
|
|
createBottomImage();
|
2017-04-25 16:45:41 +00:00
|
|
|
updateControlsGeometry();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::createBottomImage() {
|
|
|
|
if (!_useTransparency) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto bottomWidth = width();
|
2020-08-04 09:06:48 +00:00
|
|
|
auto bottomHeight = height();
|
2017-04-19 20:25:48 +00:00
|
|
|
auto image = QImage(QSize(bottomWidth, bottomHeight) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
2020-08-04 09:06:48 +00:00
|
|
|
const auto inner = rect().marginsRemoved(_padding);
|
2017-04-19 20:25:48 +00:00
|
|
|
image.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
Painter p(&image);
|
2020-08-04 09:06:48 +00:00
|
|
|
Ui::Shadow::paint(p, inner, width(), st::callShadow);
|
2017-04-19 20:25:48 +00:00
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.setBrush(st::callBg);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2020-08-04 09:06:48 +00:00
|
|
|
p.drawRoundedRect(inner, st::callRadius, st::callRadius);
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
_bottomCache = App::pixmapFromImageInPlace(std::move(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::createDefaultCacheImage() {
|
|
|
|
if (!_useTransparency || !_cache.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-02 07:25:20 +00:00
|
|
|
auto cache = QImage(size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
cache.setDevicePixelRatio(cRetinaFactor());
|
2017-04-19 20:25:48 +00:00
|
|
|
cache.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
Painter p(&cache);
|
|
|
|
auto inner = rect().marginsRemoved(_padding);
|
|
|
|
Ui::Shadow::paint(p, inner, width(), st::callShadow);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.setBrush(st::callBg);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2018-03-31 01:45:40 +00:00
|
|
|
p.drawRoundedRect(myrtlrect(inner), st::callRadius, st::callRadius);
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
_cache = App::pixmapFromImageInPlace(std::move(cache));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::resizeEvent(QResizeEvent *e) {
|
2017-04-25 16:45:41 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::updateControlsGeometry() {
|
2020-08-06 16:55:58 +00:00
|
|
|
const auto size = st::callPhotoSize;
|
|
|
|
_userpic->setGeometry((width() - size) / 2, st::callPhotoSize, size);
|
2017-04-25 16:45:41 +00:00
|
|
|
_name->moveToLeft((width() - _name->width()) / 2, _contentTop + st::callNameTop);
|
|
|
|
updateStatusGeometry();
|
|
|
|
|
2020-08-06 16:55:58 +00:00
|
|
|
_outgoingVideoBubble->setBoundingRect({
|
|
|
|
(width() - st::callOutgoingPreviewSize.width()) / 2,
|
|
|
|
_contentTop + st::callStatusTop + _status->height(),
|
|
|
|
st::callOutgoingPreviewSize.width(),
|
|
|
|
st::callOutgoingPreviewSize.height()
|
|
|
|
});
|
|
|
|
|
2020-08-04 09:06:48 +00:00
|
|
|
auto controlsTop = _padding.top() + st::callControlsTop;
|
2017-05-05 10:14:40 +00:00
|
|
|
auto bothWidth = _answerHangupRedial->width() + st::callControlsSkip + st::callCancel.button.width;
|
|
|
|
_decline->moveToLeft((width() - bothWidth) / 2, controlsTop);
|
|
|
|
_cancel->moveToLeft((width() - bothWidth) / 2, controlsTop);
|
|
|
|
|
|
|
|
updateHangupGeometry();
|
|
|
|
|
2018-05-27 08:24:47 +00:00
|
|
|
const auto skip = st::callSignalMargin + st::callSignalPadding;
|
|
|
|
const auto delta = (_signalBars->width() - _signalBars->height());
|
|
|
|
_signalBars->moveToLeft(
|
|
|
|
_padding.left() + skip,
|
|
|
|
_padding.top() + skip + delta / 2);
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
void Panel::updateHangupGeometry() {
|
|
|
|
auto singleWidth = _answerHangupRedial->width();
|
|
|
|
auto bothWidth = singleWidth + st::callControlsSkip + st::callCancel.button.width;
|
|
|
|
auto rightFrom = (width() - bothWidth) / 2;
|
|
|
|
auto rightTo = (width() - singleWidth) / 2;
|
2019-04-02 09:13:30 +00:00
|
|
|
auto hangupProgress = _hangupShownProgress.value(_hangupShown ? 1. : 0.);
|
2017-05-05 10:14:40 +00:00
|
|
|
auto hangupRight = anim::interpolate(rightFrom, rightTo, hangupProgress);
|
2020-08-04 09:06:48 +00:00
|
|
|
auto controlsTop = _padding.top() + st::callControlsTop;
|
2017-05-05 10:14:40 +00:00
|
|
|
_answerHangupRedial->moveToRight(hangupRight, controlsTop);
|
|
|
|
_answerHangupRedial->setProgress(hangupProgress);
|
2020-08-04 09:06:48 +00:00
|
|
|
_mute->moveToRight(hangupRight - _mute->width(), controlsTop);
|
|
|
|
_camera->moveToLeft(hangupRight - _mute->width(), controlsTop);
|
2017-05-05 10:14:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 16:45:41 +00:00
|
|
|
void Panel::updateStatusGeometry() {
|
|
|
|
_status->moveToLeft((width() - _status->width()) / 2, _contentTop + st::callStatusTop);
|
|
|
|
}
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
void Panel::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2017-05-04 13:32:56 +00:00
|
|
|
if (!_animationCache.isNull()) {
|
2019-04-02 09:13:30 +00:00
|
|
|
auto opacity = _opacityAnimation.value(_call ? 1. : 0.);
|
2017-05-04 13:32:56 +00:00
|
|
|
if (!_opacityAnimation.animating()) {
|
2017-09-30 19:20:40 +00:00
|
|
|
finishAnimating();
|
2017-05-05 10:14:40 +00:00
|
|
|
if (!_call || isHidden()) return;
|
2017-05-04 13:32:56 +00:00
|
|
|
} else {
|
|
|
|
p.setOpacity(opacity);
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
auto marginRatio = (1. - opacity) / 5;
|
|
|
|
auto marginWidth = qRound(width() * marginRatio);
|
|
|
|
auto marginHeight = qRound(height() * marginRatio);
|
|
|
|
p.drawPixmap(rect().marginsRemoved(QMargins(marginWidth, marginHeight, marginWidth, marginHeight)), _animationCache, QRect(QPoint(0, 0), _animationCache.size()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
if (_useTransparency) {
|
|
|
|
p.drawPixmapLeft(0, 0, width(), _cache);
|
|
|
|
} else {
|
2017-05-02 09:08:08 +00:00
|
|
|
auto callBgOpaque = st::callBg->c;
|
|
|
|
callBgOpaque.setAlpha(255);
|
2020-08-04 09:06:48 +00:00
|
|
|
p.fillRect(rect(), QBrush(callBgOpaque));
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
2017-04-25 16:45:41 +00:00
|
|
|
|
2020-07-31 14:36:35 +00:00
|
|
|
const auto incomingFrame = _call
|
|
|
|
? _call->videoIncoming()->frame(webrtc::FrameRequest())
|
|
|
|
: QImage();
|
|
|
|
if (!incomingFrame.isNull()) {
|
2020-05-19 06:33:57 +00:00
|
|
|
const auto to = rect().marginsRemoved(_padding);
|
|
|
|
p.save();
|
|
|
|
p.setClipRect(to);
|
2020-08-04 09:06:48 +00:00
|
|
|
const auto big = incomingFrame.size().scaled(to.size(), Qt::KeepAspectRatio);
|
2020-07-31 14:36:35 +00:00
|
|
|
const auto pos = QPoint(
|
|
|
|
to.left() + (to.width() - big.width()) / 2,
|
|
|
|
to.top() + (to.height() - big.height()) / 2);
|
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
|
|
|
p.drawImage(QRect(pos, big), incomingFrame);
|
|
|
|
p.restore();
|
|
|
|
}
|
|
|
|
_call->videoIncoming()->markFrameShown();
|
|
|
|
|
2018-05-27 08:24:47 +00:00
|
|
|
if (_signalBars->isDisplayed()) {
|
|
|
|
paintSignalBarsBg(p);
|
|
|
|
}
|
|
|
|
|
2017-04-25 16:45:41 +00:00
|
|
|
if (!_fingerprint.empty()) {
|
2020-08-04 09:06:48 +00:00
|
|
|
App::roundRect(p, _fingerprintArea, st::callFingerprintBg, ImageRoundRadius::Large);
|
2017-04-29 18:41:41 +00:00
|
|
|
|
2018-10-13 17:35:30 +00:00
|
|
|
const auto realSize = Ui::Emoji::GetSizeLarge();
|
|
|
|
const auto size = realSize / cIntRetinaFactor();
|
2017-04-29 18:41:41 +00:00
|
|
|
auto left = _fingerprintArea.left() + st::callFingerprintPadding.left();
|
2018-10-13 17:35:30 +00:00
|
|
|
const auto top = _fingerprintArea.top() + st::callFingerprintPadding.top();
|
|
|
|
for (const auto emoji : _fingerprint) {
|
|
|
|
Ui::Emoji::Draw(p, emoji, realSize, left, top);
|
2017-04-25 16:45:41 +00:00
|
|
|
left += st::callFingerprintSkip + size;
|
|
|
|
}
|
|
|
|
}
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2018-05-27 08:24:47 +00:00
|
|
|
QRect Panel::signalBarsRect() const {
|
|
|
|
const auto size = 2 * st::callSignalPadding + _signalBars->width();
|
|
|
|
return QRect(
|
|
|
|
_padding.left() + st::callSignalMargin,
|
|
|
|
_padding.top() + st::callSignalMargin,
|
|
|
|
size,
|
|
|
|
size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::paintSignalBarsBg(Painter &p) {
|
|
|
|
App::roundRect(
|
|
|
|
p,
|
|
|
|
signalBarsRect(),
|
|
|
|
st::callFingerprintBg,
|
|
|
|
ImageRoundRadius::Small);
|
|
|
|
}
|
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
void Panel::closeEvent(QCloseEvent *e) {
|
2017-05-15 08:17:59 +00:00
|
|
|
if (_call) {
|
|
|
|
_call->hangup();
|
|
|
|
}
|
2017-05-12 15:27:19 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
void Panel::mousePressEvent(QMouseEvent *e) {
|
|
|
|
auto dragArea = myrtlrect(_padding.left(), _padding.top(), st::callWidth, st::callWidth);
|
2017-05-02 09:08:08 +00:00
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
if (dragArea.contains(e->pos())) {
|
|
|
|
_dragging = true;
|
|
|
|
_dragStartMousePosition = e->globalPos();
|
|
|
|
_dragStartMyPosition = QPoint(x(), y());
|
|
|
|
} else if (!rect().contains(e->pos())) {
|
|
|
|
if (_call && _call->state() == State::Established) {
|
|
|
|
hideDeactivated();
|
|
|
|
}
|
|
|
|
}
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
if (_dragging) {
|
2017-04-29 18:41:41 +00:00
|
|
|
Ui::Tooltip::Hide();
|
2017-04-19 20:25:48 +00:00
|
|
|
if (!(e->buttons() & Qt::LeftButton)) {
|
|
|
|
_dragging = false;
|
|
|
|
} else {
|
|
|
|
move(_dragStartMyPosition + (e->globalPos() - _dragStartMousePosition));
|
|
|
|
}
|
2017-04-29 18:41:41 +00:00
|
|
|
} else if (_fingerprintArea.contains(e->pos())) {
|
|
|
|
Ui::Tooltip::Show(kTooltipShowTimeoutMs, this);
|
|
|
|
} else {
|
|
|
|
Ui::Tooltip::Hide();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
_dragging = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-29 18:41:41 +00:00
|
|
|
void Panel::leaveEventHook(QEvent *e) {
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::leaveToChildEvent(QEvent *e, QWidget *child) {
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Panel::tooltipText() const {
|
2019-09-13 06:06:02 +00:00
|
|
|
return tr::lng_call_fingerprint_tooltip(tr::now, lt_user, _user->name);
|
2017-04-29 18:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Panel::tooltipPos() const {
|
|
|
|
return QCursor::pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Panel::tooltipWindowActive() const {
|
|
|
|
return !isHidden();
|
|
|
|
}
|
|
|
|
|
2017-04-25 16:45:41 +00:00
|
|
|
void Panel::stateChanged(State state) {
|
2020-08-06 16:55:58 +00:00
|
|
|
Expects(_call != nullptr);
|
|
|
|
|
2017-04-25 16:45:41 +00:00
|
|
|
updateStatusText(state);
|
2017-04-29 18:00:27 +00:00
|
|
|
|
2020-08-06 16:55:58 +00:00
|
|
|
if ((state != State::HangingUp)
|
|
|
|
&& (state != State::Ended)
|
|
|
|
&& (state != State::EndedByOtherDevice)
|
|
|
|
&& (state != State::FailedHangingUp)
|
|
|
|
&& (state != State::Failed)) {
|
|
|
|
auto toggleButton = [this](auto &&button, bool visible) {
|
|
|
|
button->toggle(
|
|
|
|
visible,
|
|
|
|
isHidden()
|
|
|
|
? anim::type::instant
|
|
|
|
: anim::type::normal);
|
|
|
|
};
|
|
|
|
auto incomingWaiting = _call->isIncomingWaiting();
|
|
|
|
if (incomingWaiting) {
|
|
|
|
_updateOuterRippleTimer.callEach(Call::kSoundSampleMs);
|
|
|
|
}
|
|
|
|
toggleButton(_decline, incomingWaiting);
|
|
|
|
toggleButton(_cancel, (state == State::Busy));
|
|
|
|
auto hangupShown = !_decline->toggled()
|
|
|
|
&& !_cancel->toggled();
|
|
|
|
if (_hangupShown != hangupShown) {
|
|
|
|
_hangupShown = hangupShown;
|
|
|
|
_hangupShownProgress.start([this] { updateHangupGeometry(); }, _hangupShown ? 0. : 1., _hangupShown ? 1. : 0., st::callPanelDuration, anim::sineInOut);
|
|
|
|
}
|
|
|
|
if (_fingerprint.empty() && _call->isKeyShaForFingerprintReady()) {
|
|
|
|
fillFingerprint();
|
2017-05-04 13:32:56 +00:00
|
|
|
}
|
2017-05-04 12:29:32 +00:00
|
|
|
}
|
2017-05-05 11:49:23 +00:00
|
|
|
if (windowHandle()) {
|
2020-08-06 16:55:58 +00:00
|
|
|
// First stateChanged() is called before
|
|
|
|
// the first Platform::InitOnTopPanel(this).
|
2017-05-05 11:49:23 +00:00
|
|
|
if ((state == State::Starting) || (state == State::WaitingIncoming)) {
|
2019-09-16 11:14:06 +00:00
|
|
|
Ui::Platform::ReInitOnTopPanel(this);
|
2017-05-05 11:49:23 +00:00
|
|
|
} else {
|
2019-09-16 11:14:06 +00:00
|
|
|
Ui::Platform::DeInitOnTopPanel(this);
|
2017-05-05 11:49:23 +00:00
|
|
|
}
|
2020-08-06 16:55:58 +00:00
|
|
|
checkForInactiveHide();
|
2017-05-02 09:08:08 +00:00
|
|
|
}
|
2020-08-06 16:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Panel::hasActiveVideo() const {
|
|
|
|
const auto inactive = webrtc::VideoState::Inactive;
|
|
|
|
return (_call->videoIncoming()->state() != inactive)
|
|
|
|
|| (_call->videoOutgoing()->state() != inactive);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::checkForInactiveHide() {
|
|
|
|
if (!_call
|
|
|
|
|| (_call->state() != State::Established)
|
|
|
|
|| isActiveWindow()
|
|
|
|
|| hasActiveVideo()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hideDeactivated();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::checkForInactiveShow() {
|
|
|
|
if (!_visible && hasActiveVideo()) {
|
|
|
|
toggleOpacityAnimation(true);
|
2017-04-25 20:36:04 +00:00
|
|
|
}
|
2017-04-25 16:45:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-29 18:41:41 +00:00
|
|
|
void Panel::fillFingerprint() {
|
2017-05-04 13:32:56 +00:00
|
|
|
Expects(_call != nullptr);
|
|
|
|
_fingerprint = ComputeEmojiFingerprint(_call);
|
2017-04-29 18:41:41 +00:00
|
|
|
|
2018-10-13 17:35:30 +00:00
|
|
|
auto realSize = Ui::Emoji::GetSizeLarge();
|
2017-04-29 18:41:41 +00:00
|
|
|
auto size = realSize / cIntRetinaFactor();
|
|
|
|
auto count = _fingerprint.size();
|
|
|
|
auto rectWidth = count * size + (count - 1) * st::callFingerprintSkip;
|
|
|
|
auto rectHeight = size;
|
|
|
|
auto left = (width() - rectWidth) / 2;
|
2020-08-04 09:06:48 +00:00
|
|
|
auto top = _padding.top() + st::callFingerprintBottom;
|
2017-04-29 18:41:41 +00:00
|
|
|
_fingerprintArea = QRect(left, top, rectWidth, rectHeight).marginsAdded(st::callFingerprintPadding);
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-04-25 16:45:41 +00:00
|
|
|
void Panel::updateStatusText(State state) {
|
|
|
|
auto statusText = [this, state]() -> QString {
|
|
|
|
switch (state) {
|
2017-04-25 20:36:04 +00:00
|
|
|
case State::Starting:
|
2017-04-25 16:45:41 +00:00
|
|
|
case State::WaitingInit:
|
2019-06-19 15:09:03 +00:00
|
|
|
case State::WaitingInitAck: return tr::lng_call_status_connecting(tr::now);
|
2017-04-25 16:45:41 +00:00
|
|
|
case State::Established: {
|
|
|
|
if (_call) {
|
|
|
|
auto durationMs = _call->getDurationMs();
|
|
|
|
auto durationSeconds = durationMs / 1000;
|
|
|
|
startDurationUpdateTimer(durationMs);
|
|
|
|
return formatDurationText(durationSeconds);
|
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_call_status_ended(tr::now);
|
2017-04-25 16:45:41 +00:00
|
|
|
} break;
|
2017-05-09 12:06:21 +00:00
|
|
|
case State::FailedHangingUp:
|
2019-06-19 15:09:03 +00:00
|
|
|
case State::Failed: return tr::lng_call_status_failed(tr::now);
|
|
|
|
case State::HangingUp: return tr::lng_call_status_hanging(tr::now);
|
2017-05-12 16:09:34 +00:00
|
|
|
case State::Ended:
|
2019-06-19 15:09:03 +00:00
|
|
|
case State::EndedByOtherDevice: return tr::lng_call_status_ended(tr::now);
|
|
|
|
case State::ExchangingKeys: return tr::lng_call_status_exchanging(tr::now);
|
|
|
|
case State::Waiting: return tr::lng_call_status_waiting(tr::now);
|
|
|
|
case State::Requesting: return tr::lng_call_status_requesting(tr::now);
|
|
|
|
case State::WaitingIncoming: return tr::lng_call_status_incoming(tr::now);
|
|
|
|
case State::Ringing: return tr::lng_call_status_ringing(tr::now);
|
|
|
|
case State::Busy: return tr::lng_call_status_busy(tr::now);
|
2017-04-25 16:45:41 +00:00
|
|
|
}
|
|
|
|
Unexpected("State in stateChanged()");
|
|
|
|
};
|
|
|
|
_status->setText(statusText());
|
|
|
|
updateStatusGeometry();
|
|
|
|
}
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void Panel::startDurationUpdateTimer(crl::time currentDuration) {
|
2017-04-25 16:45:41 +00:00
|
|
|
auto msTillNextSecond = 1000 - (currentDuration % 1000);
|
|
|
|
_updateDurationTimer.callOnce(msTillNextSecond + 5);
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Calls
|