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"
|
2021-02-03 10:43:31 +00:00
|
|
|
#include "ui/platform/ui_platform_window_title.h"
|
2020-11-28 12:00:06 +00:00
|
|
|
#include "ui/widgets/call_button.h"
|
2017-04-19 20:25:48 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/shadow.h"
|
2020-08-12 13:35:31 +00:00
|
|
|
#include "ui/widgets/window.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2020-09-30 11:32:02 +00:00
|
|
|
#include "ui/text/format_values.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2020-08-14 08:32:05 +00:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "ui/platform/ui_platform_utility.h"
|
2020-08-21 12:34:37 +00:00
|
|
|
#include "ui/toast/toast.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"
|
2020-08-13 10:32:11 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2017-05-12 15:27:19 +00:00
|
|
|
#include "window/main_window.h"
|
2021-01-27 17:19:04 +00:00
|
|
|
#include "media/view/media_view_pip.h" // Utilities for frame rotation.
|
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"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2017-04-19 20:25:48 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtWidgets/QDesktopWidget>
|
|
|
|
#include <QtWidgets/QApplication>
|
2020-08-12 16:58:24 +00:00
|
|
|
#include <QtGui/QWindow>
|
2019-09-04 07:19:15 +00:00
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
namespace Calls {
|
2020-08-17 09:49:45 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
#if defined Q_OS_MAC && !defined OS_MAC_OLD
|
|
|
|
#define USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
#endif // Q_OS_MAC && !OS_MAC_OLD
|
|
|
|
|
|
|
|
#ifdef USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
using IncomingParent = Ui::RpWidgetWrap<QOpenGLWidget>;
|
|
|
|
#else // USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
using IncomingParent = Ui::RpWidget;
|
|
|
|
#endif // USE_OPENGL_OVERLAY_WIDGET
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class Panel::Incoming final : public IncomingParent {
|
|
|
|
public:
|
|
|
|
Incoming(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<Webrtc::VideoTrack*> track);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
void initBottomShadow();
|
|
|
|
void fillTopShadow(QPainter &p);
|
|
|
|
void fillBottomShadow(QPainter &p);
|
|
|
|
|
|
|
|
const not_null<Webrtc::VideoTrack*> _track;
|
|
|
|
QPixmap _bottomShadow;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Panel::Incoming::Incoming(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<Webrtc::VideoTrack*> track)
|
|
|
|
: IncomingParent(parent)
|
|
|
|
, _track(track) {
|
|
|
|
initBottomShadow();
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Incoming::paintEvent(QPaintEvent *e) {
|
|
|
|
QPainter p(this);
|
|
|
|
|
2021-01-27 17:19:04 +00:00
|
|
|
const auto [image, rotation] = _track->frameOriginalWithRotation();
|
|
|
|
if (image.isNull()) {
|
2020-08-17 09:49:45 +00:00
|
|
|
p.fillRect(e->rect(), Qt::black);
|
|
|
|
} else {
|
2021-01-27 17:19:04 +00:00
|
|
|
using namespace Media::View;
|
2020-08-17 09:49:45 +00:00
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
2021-01-27 17:19:04 +00:00
|
|
|
if (UsePainterRotation(rotation)) {
|
|
|
|
if (rotation) {
|
|
|
|
p.save();
|
|
|
|
p.rotate(rotation);
|
|
|
|
}
|
|
|
|
p.drawImage(RotatedRect(rect(), rotation), image);
|
|
|
|
if (rotation) {
|
|
|
|
p.restore();
|
|
|
|
}
|
|
|
|
} else if (rotation) {
|
|
|
|
p.drawImage(rect(), RotateFrameImage(image, rotation));
|
|
|
|
} else {
|
|
|
|
p.drawImage(rect(), image);
|
|
|
|
}
|
2020-08-21 08:04:19 +00:00
|
|
|
fillBottomShadow(p);
|
|
|
|
fillTopShadow(p);
|
2020-08-17 09:49:45 +00:00
|
|
|
}
|
|
|
|
_track->markFrameShown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Incoming::initBottomShadow() {
|
|
|
|
auto image = QImage(
|
|
|
|
QSize(1, st::callBottomShadowSize) * cIntRetinaFactor(),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
const auto colorFrom = uint32(0);
|
|
|
|
const auto colorTill = uint32(74);
|
|
|
|
const auto rows = image.height();
|
|
|
|
const auto step = (uint64(colorTill - colorFrom) << 32) / rows;
|
|
|
|
auto accumulated = uint64();
|
|
|
|
auto bytes = image.bits();
|
|
|
|
for (auto y = 0; y != rows; ++y) {
|
|
|
|
accumulated += step;
|
|
|
|
const auto color = (colorFrom + uint32(accumulated >> 32)) << 24;
|
|
|
|
for (auto x = 0; x != image.width(); ++x) {
|
|
|
|
*(reinterpret_cast<uint32*>(bytes) + x) = color;
|
|
|
|
}
|
|
|
|
bytes += image.bytesPerLine();
|
|
|
|
}
|
|
|
|
_bottomShadow = Images::PixmapFast(std::move(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Incoming::fillTopShadow(QPainter &p) {
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
const auto width = parentWidget()->width();
|
|
|
|
const auto position = QPoint(width - st::callTitleShadow.width(), 0);
|
|
|
|
const auto shadowArea = QRect(
|
|
|
|
position,
|
|
|
|
st::callTitleShadow.size());
|
2020-08-21 08:04:19 +00:00
|
|
|
const auto fill = shadowArea.intersected(geometry()).translated(-pos());
|
2020-08-17 09:49:45 +00:00
|
|
|
if (fill.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p.save();
|
|
|
|
p.setClipRect(fill);
|
2020-08-21 08:04:19 +00:00
|
|
|
st::callTitleShadow.paint(p, position - pos(), width);
|
2020-08-17 09:49:45 +00:00
|
|
|
p.restore();
|
|
|
|
#endif // Q_OS_WIN
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::Incoming::fillBottomShadow(QPainter &p) {
|
|
|
|
const auto shadowArea = QRect(
|
|
|
|
0,
|
|
|
|
parentWidget()->height() - st::callBottomShadowSize,
|
|
|
|
parentWidget()->width(),
|
|
|
|
st::callBottomShadowSize);
|
2020-08-21 08:04:19 +00:00
|
|
|
const auto fill = shadowArea.intersected(geometry()).translated(-pos());
|
2020-08-17 09:49:45 +00:00
|
|
|
if (fill.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto factor = cIntRetinaFactor();
|
|
|
|
p.drawPixmap(
|
|
|
|
fill,
|
|
|
|
_bottomShadow,
|
|
|
|
QRect(
|
|
|
|
0,
|
2020-08-21 08:04:19 +00:00
|
|
|
factor * (fill.y() - shadowArea.translated(-pos()).y()),
|
2020-08-17 09:49:45 +00:00
|
|
|
factor,
|
|
|
|
factor * fill.height()));
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Panel::Panel(not_null<Call*> call)
|
2020-08-12 13:35:31 +00:00
|
|
|
: _call(call)
|
2017-04-19 20:25:48 +00:00
|
|
|
, _user(call->user())
|
2020-08-12 13:35:31 +00:00
|
|
|
, _window(std::make_unique<Ui::Window>(Core::App().getModalParent()))
|
2021-02-03 10:43:31 +00:00
|
|
|
#ifndef Q_OS_MAC
|
2020-08-13 10:32:11 +00:00
|
|
|
, _controls(std::make_unique<Ui::Platform::TitleControls>(
|
2021-02-03 10:43:31 +00:00
|
|
|
_window->body(),
|
2020-08-13 13:58:54 +00:00
|
|
|
st::callTitle,
|
2020-08-13 10:32:11 +00:00
|
|
|
[=](bool maximized) { toggleFullScreen(maximized); }))
|
2021-02-03 10:43:31 +00:00
|
|
|
#endif // !Q_OS_MAC
|
2020-08-07 13:28:41 +00:00
|
|
|
, _bodySt(&st::callBodyLayout)
|
2020-08-12 13:35:31 +00:00
|
|
|
, _answerHangupRedial(widget(), st::callAnswer, &st::callHangup)
|
2020-11-28 12:00:06 +00:00
|
|
|
, _decline(widget(), object_ptr<Ui::CallButton>(widget(), st::callHangup))
|
|
|
|
, _cancel(widget(), object_ptr<Ui::CallButton>(widget(), st::callCancel))
|
2020-08-13 14:45:40 +00:00
|
|
|
, _camera(widget(), st::callCameraMute, &st::callCameraUnmute)
|
|
|
|
, _mute(widget(), st::callMicrophoneMute, &st::callMicrophoneUnmute)
|
2020-08-12 13:35:31 +00:00
|
|
|
, _name(widget(), st::callName)
|
|
|
|
, _status(widget(), st::callStatus) {
|
2017-09-30 18:26:45 +00:00
|
|
|
_decline->setDuration(st::callPanelDuration);
|
2020-08-14 10:54:15 +00:00
|
|
|
_decline->entity()->setText(tr::lng_call_decline());
|
2017-09-30 18:26:45 +00:00
|
|
|
_cancel->setDuration(st::callPanelDuration);
|
2020-08-14 10:54:15 +00:00
|
|
|
_cancel->entity()->setText(tr::lng_call_cancel());
|
2017-09-30 18:26:45 +00:00
|
|
|
|
2020-08-12 13:35:31 +00:00
|
|
|
initWindow();
|
|
|
|
initWidget();
|
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;
|
|
|
|
|
2020-12-08 17:06:56 +00:00
|
|
|
bool Panel::isActive() const {
|
|
|
|
return _window->isActiveWindow()
|
|
|
|
&& _window->isVisible()
|
|
|
|
&& !(_window->windowState() & Qt::WindowMinimized);
|
|
|
|
}
|
|
|
|
|
2017-04-25 20:36:04 +00:00
|
|
|
void Panel::showAndActivate() {
|
2020-12-11 07:58:00 +00:00
|
|
|
if (_window->isHidden()) {
|
|
|
|
_window->show();
|
|
|
|
}
|
|
|
|
const auto state = _window->windowState();
|
|
|
|
if (state & Qt::WindowMinimized) {
|
|
|
|
_window->setWindowState(state & ~Qt::WindowMinimized);
|
|
|
|
}
|
2020-08-12 13:35:31 +00:00
|
|
|
_window->raise();
|
|
|
|
_window->activateWindow();
|
|
|
|
_window->setFocus();
|
2017-04-25 20:36:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 16:09:32 +00:00
|
|
|
void Panel::minimize() {
|
|
|
|
_window->setWindowState(_window->windowState() | Qt::WindowMinimized);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-08-12 13:35:31 +00:00
|
|
|
void Panel::initWindow() {
|
2020-08-17 09:49:45 +00:00
|
|
|
_window->setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
_window->setAttribute(Qt::WA_NoSystemBackground);
|
2020-08-12 13:35:31 +00:00
|
|
|
_window->setWindowIcon(
|
|
|
|
QIcon(QPixmap::fromImage(Image::Empty()->original(), Qt::ColorOnly)));
|
|
|
|
_window->setTitle(u" "_q);
|
2020-08-12 16:58:24 +00:00
|
|
|
_window->setTitleStyle(st::callTitle);
|
2020-08-12 13:35:31 +00:00
|
|
|
|
|
|
|
_window->events(
|
|
|
|
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
|
|
|
if (e->type() == QEvent::Close) {
|
|
|
|
handleClose();
|
2020-08-12 16:58:24 +00:00
|
|
|
} else if (e->type() == QEvent::KeyPress) {
|
|
|
|
if ((static_cast<QKeyEvent*>(e.get())->key() == Qt::Key_Escape)
|
|
|
|
&& _window->isFullScreen()) {
|
|
|
|
_window->showNormal();
|
|
|
|
}
|
2020-08-12 13:35:31 +00:00
|
|
|
}
|
|
|
|
}, _window->lifetime());
|
|
|
|
|
|
|
|
_window->setBodyTitleArea([=](QPoint widgetPoint) {
|
2020-08-13 09:02:15 +00:00
|
|
|
using Flag = Ui::WindowTitleHitTestFlag;
|
|
|
|
if (!widget()->rect().contains(widgetPoint)) {
|
|
|
|
return Flag::None | Flag(0);
|
|
|
|
}
|
2021-02-03 10:43:31 +00:00
|
|
|
#ifndef Q_OS_MAC
|
2020-08-13 10:32:11 +00:00
|
|
|
if (_controls->geometry().contains(widgetPoint)) {
|
|
|
|
return Flag::None | Flag(0);
|
|
|
|
}
|
2021-02-03 10:43:31 +00:00
|
|
|
#endif // !Q_OS_MAC
|
2020-08-12 13:35:31 +00:00
|
|
|
const auto buttonWidth = st::callCancel.button.width;
|
|
|
|
const auto buttonsWidth = buttonWidth * 4;
|
2020-08-14 12:51:47 +00:00
|
|
|
const auto inControls = (_fingerprint
|
|
|
|
&& _fingerprint->geometry().contains(widgetPoint))
|
2020-08-12 16:58:24 +00:00
|
|
|
|| QRect(
|
2020-08-12 13:35:31 +00:00
|
|
|
(widget()->width() - buttonsWidth) / 2,
|
|
|
|
_answerHangupRedial->y(),
|
|
|
|
buttonsWidth,
|
|
|
|
_answerHangupRedial->height()).contains(widgetPoint)
|
2020-08-12 16:58:24 +00:00
|
|
|
|| (!_outgoingPreviewInBody
|
|
|
|
&& _outgoingVideoBubble->geometry().contains(widgetPoint));
|
|
|
|
return inControls
|
|
|
|
? Flag::None
|
|
|
|
: (Flag::Move | Flag::FullScreen);
|
2020-08-12 13:35:31 +00:00
|
|
|
});
|
2020-08-12 16:58:24 +00:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// On Windows we replace snap-to-top maximizing with fullscreen.
|
|
|
|
//
|
|
|
|
// We have to switch first to showNormal, so that showFullScreen
|
|
|
|
// will remember correct normal window geometry and next showNormal
|
|
|
|
// will show it instead of a moving maximized window.
|
|
|
|
//
|
|
|
|
// We have to do it in InvokeQueued, otherwise it still captures
|
|
|
|
// the maximized window geometry and saves it.
|
|
|
|
//
|
|
|
|
// I couldn't find a less glitchy way to do that *sigh*.
|
|
|
|
const auto object = _window->windowHandle();
|
|
|
|
const auto signal = &QWindow::windowStateChanged;
|
|
|
|
QObject::connect(object, signal, [=](Qt::WindowState state) {
|
|
|
|
if (state == Qt::WindowMaximized) {
|
|
|
|
InvokeQueued(object, [=] {
|
|
|
|
_window->showNormal();
|
|
|
|
_window->showFullScreen();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
#endif // Q_OS_WIN
|
2017-04-25 20:36:04 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 13:35:31 +00:00
|
|
|
void Panel::initWidget() {
|
|
|
|
widget()->setMouseTracking(true);
|
|
|
|
|
|
|
|
widget()->paintRequest(
|
|
|
|
) | rpl::start_with_next([=](QRect clip) {
|
|
|
|
paint(clip);
|
|
|
|
}, widget()->lifetime());
|
|
|
|
|
2020-08-14 12:51:47 +00:00
|
|
|
widget()->sizeValue(
|
|
|
|
) | rpl::skip(1) | rpl::start_with_next([=] {
|
|
|
|
updateControlsGeometry();
|
2020-08-12 13:35:31 +00:00
|
|
|
}, widget()->lifetime());
|
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-11-30 20:56:43 +00:00
|
|
|
_call->switchVideoOutgoing();
|
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-13 11:32:25 +00:00
|
|
|
void Panel::setIncomingSize(QSize size) {
|
|
|
|
if (_incomingFrameSize == size) {
|
2020-08-04 09:06:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-13 11:32:25 +00:00
|
|
|
_incomingFrameSize = size;
|
2020-08-17 09:49:45 +00:00
|
|
|
refreshIncomingGeometry();
|
2020-08-12 13:35:31 +00:00
|
|
|
showControls();
|
2017-05-04 12:29:32 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 09:49:45 +00:00
|
|
|
void Panel::refreshIncomingGeometry() {
|
|
|
|
Expects(_call != nullptr);
|
|
|
|
Expects(_incoming != nullptr);
|
|
|
|
|
|
|
|
if (_incomingFrameSize.isEmpty()) {
|
|
|
|
_incoming->hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto to = widget()->size();
|
|
|
|
const auto small = _incomingFrameSize.scaled(to, Qt::KeepAspectRatio);
|
|
|
|
const auto big = _incomingFrameSize.scaled(
|
|
|
|
to,
|
|
|
|
Qt::KeepAspectRatioByExpanding);
|
|
|
|
|
|
|
|
// If we cut out no more than 0.33 of the original, let's use expanding.
|
|
|
|
const auto use = ((big.width() * 3 <= to.width() * 4)
|
|
|
|
&& (big.height() * 3 <= to.height() * 4))
|
|
|
|
? big
|
|
|
|
: small;
|
|
|
|
const auto pos = QPoint(
|
|
|
|
(to.width() - use.width()) / 2,
|
|
|
|
(to.height() - use.height()) / 2);
|
|
|
|
_incoming->setGeometry(QRect(pos, use));
|
|
|
|
_incoming->show();
|
|
|
|
}
|
|
|
|
|
2020-08-04 09:06:48 +00:00
|
|
|
void Panel::reinitWithCall(Call *call) {
|
|
|
|
_callLifetime.destroy();
|
|
|
|
_call = call;
|
|
|
|
if (!_call) {
|
2020-08-17 09:49:45 +00:00
|
|
|
_incoming = nullptr;
|
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
|
|
|
auto remoteMuted = _call->remoteAudioStateValue(
|
|
|
|
) | rpl::map([=](Call::RemoteAudioState state) {
|
|
|
|
return (state == Call::RemoteAudioState::Muted);
|
|
|
|
});
|
2020-08-14 08:32:05 +00:00
|
|
|
rpl::duplicate(
|
|
|
|
remoteMuted
|
|
|
|
) | rpl::start_with_next([=](bool muted) {
|
|
|
|
if (muted) {
|
|
|
|
createRemoteAudioMute();
|
|
|
|
} else {
|
|
|
|
_remoteAudioMute.destroy();
|
|
|
|
}
|
|
|
|
}, _callLifetime);
|
2020-08-12 13:35:31 +00:00
|
|
|
_userpic = std::make_unique<Userpic>(
|
|
|
|
widget(),
|
|
|
|
_user,
|
|
|
|
std::move(remoteMuted));
|
2020-08-06 16:55:58 +00:00
|
|
|
_outgoingVideoBubble = std::make_unique<VideoBubble>(
|
2020-08-12 13:35:31 +00:00
|
|
|
widget(),
|
2020-08-06 16:55:58 +00:00
|
|
|
_call->videoOutgoing());
|
2020-08-17 09:49:45 +00:00
|
|
|
_incoming = std::make_unique<Incoming>(
|
|
|
|
widget(),
|
|
|
|
_call->videoIncoming());
|
|
|
|
_incoming->hide();
|
2020-08-06 16:55:58 +00:00
|
|
|
|
2020-08-04 09:06:48 +00:00
|
|
|
_call->mutedValue(
|
|
|
|
) | rpl::start_with_next([=](bool mute) {
|
2020-08-13 14:45:40 +00:00
|
|
|
_mute->setProgress(mute ? 1. : 0.);
|
2020-08-14 10:54:15 +00:00
|
|
|
_mute->setText(mute
|
|
|
|
? tr::lng_call_unmute_audio()
|
|
|
|
: tr::lng_call_mute_audio());
|
2020-08-04 09:06:48 +00:00
|
|
|
}, _callLifetime);
|
|
|
|
|
2020-08-05 12:11:18 +00:00
|
|
|
_call->videoOutgoing()->stateValue(
|
2020-08-11 09:59:48 +00:00
|
|
|
) | rpl::start_with_next([=](Webrtc::VideoState state) {
|
2020-08-14 10:54:15 +00:00
|
|
|
const auto active = (state == Webrtc::VideoState::Active);
|
|
|
|
_camera->setProgress(active ? 0. : 1.);
|
|
|
|
_camera->setText(active
|
|
|
|
? tr::lng_call_stop_video()
|
|
|
|
: tr::lng_call_start_video());
|
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-13 11:32:25 +00:00
|
|
|
_call->videoIncoming()->renderNextFrame(
|
2020-08-04 09:06:48 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2021-01-27 17:19:04 +00:00
|
|
|
const auto track = _call->videoIncoming();
|
|
|
|
const auto [frame, rotation] = track->frameOriginalWithRotation();
|
|
|
|
setIncomingSize((rotation == 90 || rotation == 270)
|
|
|
|
? QSize(frame.height(), frame.width())
|
|
|
|
: frame.size());
|
2020-08-17 09:49:45 +00:00
|
|
|
if (_incoming->isHidden()) {
|
2020-08-13 11:32:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto incoming = incomingFrameGeometry();
|
|
|
|
const auto outgoing = outgoingFrameGeometry();
|
2020-08-17 09:49:45 +00:00
|
|
|
_incoming->update();
|
2020-08-13 11:32:25 +00:00
|
|
|
if (incoming.intersects(outgoing)) {
|
2020-08-17 09:49:45 +00:00
|
|
|
widget()->update(outgoing);
|
2020-08-13 11:32:25 +00:00
|
|
|
}
|
|
|
|
}, _callLifetime);
|
|
|
|
|
|
|
|
_call->videoOutgoing()->renderNextFrame(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto incoming = incomingFrameGeometry();
|
|
|
|
const auto outgoing = outgoingFrameGeometry();
|
2020-08-17 09:49:45 +00:00
|
|
|
widget()->update(outgoing);
|
2020-08-13 11:32:25 +00:00
|
|
|
if (incoming.intersects(outgoing)) {
|
2020-08-17 09:49:45 +00:00
|
|
|
_incoming->update();
|
2020-08-13 11:32:25 +00:00
|
|
|
}
|
2020-08-06 16:55:58 +00:00
|
|
|
}, _callLifetime);
|
2018-05-27 08:24:47 +00:00
|
|
|
|
2020-08-07 13:28:41 +00:00
|
|
|
rpl::combine(
|
|
|
|
_call->stateValue(),
|
|
|
|
_call->videoOutgoing()->renderNextFrame()
|
|
|
|
) | rpl::start_with_next([=](State state, auto) {
|
|
|
|
if (state != State::Ended
|
|
|
|
&& state != State::EndedByOtherDevice
|
|
|
|
&& state != State::Failed
|
|
|
|
&& state != State::FailedHangingUp
|
|
|
|
&& state != State::HangingUp) {
|
|
|
|
refreshOutgoingPreviewInBody(state);
|
|
|
|
}
|
|
|
|
}, _callLifetime);
|
|
|
|
|
2020-08-21 12:34:37 +00:00
|
|
|
_call->errors(
|
|
|
|
) | rpl::start_with_next([=](Error error) {
|
|
|
|
const auto text = [=] {
|
|
|
|
switch (error.type) {
|
|
|
|
case ErrorType::NoCamera:
|
|
|
|
return tr::lng_call_error_no_camera(tr::now);
|
|
|
|
case ErrorType::NotVideoCall:
|
|
|
|
return tr::lng_call_error_camera_outdated(tr::now, lt_user, _user->name);
|
|
|
|
case ErrorType::NotStartedCall:
|
|
|
|
return tr::lng_call_error_camera_not_started(tr::now);
|
|
|
|
//case ErrorType::NoMicrophone:
|
|
|
|
// return tr::lng_call_error_no_camera(tr::now);
|
|
|
|
case ErrorType::Unknown:
|
|
|
|
return Lang::Hard::CallErrorIncompatible();
|
|
|
|
}
|
|
|
|
Unexpected("Error type in _call->errors().");
|
|
|
|
}();
|
|
|
|
Ui::Toast::Show(widget(), Ui::Toast::Config{
|
|
|
|
.text = { text },
|
|
|
|
.st = &st::callErrorToast,
|
|
|
|
.multiline = true,
|
|
|
|
});
|
|
|
|
}, _callLifetime);
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
_name->setText(_user->name);
|
2017-05-04 12:29:32 +00:00
|
|
|
updateStatusText(_call->state());
|
2020-08-17 09:49:45 +00:00
|
|
|
|
|
|
|
_incoming->lower();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2020-08-14 08:32:05 +00:00
|
|
|
void Panel::createRemoteAudioMute() {
|
|
|
|
_remoteAudioMute.create(
|
|
|
|
widget(),
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
widget(),
|
|
|
|
tr::lng_call_microphone_off(
|
|
|
|
lt_user,
|
|
|
|
rpl::single(_user->shortName())),
|
|
|
|
st::callRemoteAudioMute),
|
|
|
|
st::callTooltipPadding);
|
2020-08-14 12:51:47 +00:00
|
|
|
_remoteAudioMute->setAttribute(Qt::WA_TransparentForMouseEvents);
|
2020-08-14 08:32:05 +00:00
|
|
|
|
|
|
|
_remoteAudioMute->paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto p = QPainter(_remoteAudioMute);
|
|
|
|
const auto height = _remoteAudioMute->height();
|
|
|
|
|
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
2020-08-14 10:54:15 +00:00
|
|
|
p.setBrush(st::videoPlayIconBg);
|
2020-08-14 08:32:05 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawRoundedRect(_remoteAudioMute->rect(), height / 2, height / 2);
|
|
|
|
|
|
|
|
st::callTooltipMutedIcon.paint(
|
|
|
|
p,
|
|
|
|
st::callTooltipMutedIconPosition,
|
|
|
|
_remoteAudioMute->width());
|
|
|
|
}, _remoteAudioMute->lifetime());
|
|
|
|
|
|
|
|
showControls();
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
void Panel::initLayout() {
|
|
|
|
initGeometry();
|
|
|
|
|
2020-08-13 13:58:54 +00:00
|
|
|
_name->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
_status->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
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-08-12 13:35:31 +00:00
|
|
|
}, widget()->lifetime());
|
2020-08-13 10:32:11 +00:00
|
|
|
|
2021-02-03 10:43:31 +00:00
|
|
|
#ifndef Q_OS_MAC
|
2020-08-13 10:32:11 +00:00
|
|
|
_controls->raise();
|
2021-02-03 10:43:31 +00:00
|
|
|
#endif // !Q_OS_MAC
|
2017-05-04 13:32:56 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
void Panel::showControls() {
|
|
|
|
Expects(_call != nullptr);
|
2020-05-28 14:32:10 +00:00
|
|
|
|
2020-08-12 13:35:31 +00:00
|
|
|
widget()->showChildren();
|
2017-09-30 19:20:40 +00:00
|
|
|
_decline->setVisible(_decline->toggled());
|
|
|
|
_cancel->setVisible(_cancel->toggled());
|
2020-08-13 11:32:25 +00:00
|
|
|
|
|
|
|
const auto shown = !_incomingFrameSize.isEmpty();
|
2020-08-17 09:49:45 +00:00
|
|
|
_incoming->setVisible(shown);
|
2020-08-13 11:32:25 +00:00
|
|
|
_name->setVisible(!shown);
|
|
|
|
_status->setVisible(!shown);
|
|
|
|
_userpic->setVisible(!shown);
|
2020-08-14 08:32:05 +00:00
|
|
|
if (_remoteAudioMute) {
|
|
|
|
_remoteAudioMute->setVisible(shown);
|
|
|
|
}
|
2017-05-05 10:14:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-14 15:59:24 +00:00
|
|
|
void Panel::closeBeforeDestroy() {
|
|
|
|
_window->close();
|
2020-08-04 09:06:48 +00:00
|
|
|
reinitWithCall(nullptr);
|
2017-05-04 13:32:56 +00:00
|
|
|
}
|
|
|
|
|
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();
|
2020-08-12 13:35:31 +00:00
|
|
|
const auto initRect = QRect(0, 0, st::callWidth, st::callHeight);
|
|
|
|
_window->setGeometry(initRect.translated(center - initRect.center()));
|
|
|
|
_window->setMinimumSize({ st::callWidthMin, st::callHeightMin });
|
|
|
|
_window->show();
|
2017-04-25 16:45:41 +00:00
|
|
|
updateControlsGeometry();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 13:28:41 +00:00
|
|
|
void Panel::refreshOutgoingPreviewInBody(State state) {
|
|
|
|
const auto inBody = (state != State::Established)
|
2020-08-11 09:59:48 +00:00
|
|
|
&& (_call->videoOutgoing()->state() != Webrtc::VideoState::Inactive)
|
2020-08-07 13:28:41 +00:00
|
|
|
&& !_call->videoOutgoing()->frameSize().isEmpty();
|
|
|
|
if (_outgoingPreviewInBody == inBody) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_outgoingPreviewInBody = inBody;
|
|
|
|
_bodySt = inBody ? &st::callBodyWithPreview : &st::callBodyLayout;
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2020-08-13 10:32:11 +00:00
|
|
|
void Panel::toggleFullScreen(bool fullscreen) {
|
|
|
|
if (fullscreen) {
|
|
|
|
_window->showFullScreen();
|
|
|
|
} else {
|
|
|
|
_window->showNormal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 11:32:25 +00:00
|
|
|
QRect Panel::incomingFrameGeometry() const {
|
2020-08-17 09:49:45 +00:00
|
|
|
return (!_incoming || _incoming->isHidden())
|
|
|
|
? QRect()
|
|
|
|
: _incoming->geometry();
|
2020-08-13 11:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect Panel::outgoingFrameGeometry() const {
|
|
|
|
return _outgoingVideoBubble->geometry();
|
|
|
|
}
|
|
|
|
|
2020-08-12 13:35:31 +00:00
|
|
|
void Panel::updateControlsGeometry() {
|
2020-08-13 11:16:39 +00:00
|
|
|
if (widget()->size().isEmpty()) {
|
2017-04-19 20:25:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-17 09:49:45 +00:00
|
|
|
if (_incoming) {
|
|
|
|
refreshIncomingGeometry();
|
|
|
|
}
|
2020-08-14 12:51:47 +00:00
|
|
|
if (_fingerprint) {
|
2021-02-03 10:43:31 +00:00
|
|
|
#ifndef Q_OS_MAC
|
2020-08-14 12:51:47 +00:00
|
|
|
const auto minRight = _controls->geometry().width()
|
|
|
|
+ st::callFingerprintTop;
|
2021-02-03 10:43:31 +00:00
|
|
|
#else // !Q_OS_MAC
|
2020-08-14 12:51:47 +00:00
|
|
|
const auto minRight = 0;
|
|
|
|
#endif // _controls
|
|
|
|
const auto desired = (widget()->width() - _fingerprint->width()) / 2;
|
|
|
|
_fingerprint->moveToRight(
|
|
|
|
std::max(desired, minRight),
|
|
|
|
st::callFingerprintTop);
|
|
|
|
}
|
2020-08-13 11:16:39 +00:00
|
|
|
const auto innerHeight = std::max(widget()->height(), st::callHeightMin);
|
|
|
|
const auto innerWidth = widget()->width() - 2 * st::callInnerPadding;
|
2020-08-14 12:51:47 +00:00
|
|
|
const auto availableTop = st::callFingerprintTop
|
|
|
|
+ (_fingerprint ? _fingerprint->height() : 0)
|
|
|
|
+ st::callFingerprintBottom;
|
2020-08-12 13:35:31 +00:00
|
|
|
const auto available = widget()->height()
|
|
|
|
- st::callBottomControlsHeight
|
2020-08-07 13:28:41 +00:00
|
|
|
- availableTop;
|
|
|
|
const auto bodyPreviewSizeMax = st::callOutgoingPreviewMin
|
|
|
|
+ ((st::callOutgoingPreview
|
|
|
|
- st::callOutgoingPreviewMin)
|
|
|
|
* (innerHeight - st::callHeightMin)
|
|
|
|
/ (st::callHeight - st::callHeightMin));
|
|
|
|
const auto bodyPreviewSize = QSize(
|
2020-08-13 11:16:39 +00:00
|
|
|
std::min(
|
|
|
|
bodyPreviewSizeMax.width(),
|
|
|
|
std::min(innerWidth, st::callOutgoingPreviewMax.width())),
|
|
|
|
std::min(
|
|
|
|
bodyPreviewSizeMax.height(),
|
|
|
|
st::callOutgoingPreviewMax.height()));
|
2020-08-07 13:28:41 +00:00
|
|
|
const auto contentHeight = _bodySt->height
|
|
|
|
+ (_outgoingPreviewInBody ? bodyPreviewSize.height() : 0);
|
|
|
|
const auto remainingHeight = available - contentHeight;
|
|
|
|
const auto skipHeight = remainingHeight
|
|
|
|
/ (_outgoingPreviewInBody ? 3 : 2);
|
|
|
|
|
|
|
|
_bodyTop = availableTop + skipHeight;
|
|
|
|
_buttonsTop = availableTop + available;
|
|
|
|
const auto previewTop = _bodyTop + _bodySt->height + skipHeight;
|
|
|
|
|
|
|
|
_userpic->setGeometry(
|
2020-08-12 13:35:31 +00:00
|
|
|
(widget()->width() - _bodySt->photoSize) / 2,
|
2020-08-07 13:28:41 +00:00
|
|
|
_bodyTop + _bodySt->photoTop,
|
|
|
|
_bodySt->photoSize);
|
2020-08-13 15:48:20 +00:00
|
|
|
_userpic->setMuteLayout(
|
|
|
|
_bodySt->mutePosition,
|
|
|
|
_bodySt->muteSize,
|
|
|
|
_bodySt->muteStroke);
|
2020-08-07 13:28:41 +00:00
|
|
|
|
|
|
|
_name->moveToLeft(
|
2020-08-12 13:35:31 +00:00
|
|
|
(widget()->width() - _name->width()) / 2,
|
2020-08-07 13:28:41 +00:00
|
|
|
_bodyTop + _bodySt->nameTop);
|
2017-04-25 16:45:41 +00:00
|
|
|
updateStatusGeometry();
|
|
|
|
|
2020-08-14 08:32:05 +00:00
|
|
|
if (_remoteAudioMute) {
|
|
|
|
_remoteAudioMute->moveToLeft(
|
|
|
|
(widget()->width() - _remoteAudioMute->width()) / 2,
|
|
|
|
(_buttonsTop
|
|
|
|
- st::callRemoteAudioMuteSkip
|
|
|
|
- _remoteAudioMute->height()));
|
|
|
|
}
|
|
|
|
|
2020-08-07 13:28:41 +00:00
|
|
|
if (_outgoingPreviewInBody) {
|
|
|
|
_outgoingVideoBubble->updateGeometry(
|
|
|
|
VideoBubble::DragMode::None,
|
|
|
|
QRect(
|
2020-08-12 13:35:31 +00:00
|
|
|
(widget()->width() - bodyPreviewSize.width()) / 2,
|
2020-08-07 13:28:41 +00:00
|
|
|
previewTop,
|
|
|
|
bodyPreviewSize.width(),
|
|
|
|
bodyPreviewSize.height()));
|
|
|
|
} else {
|
|
|
|
updateOutgoingVideoBubbleGeometry();
|
|
|
|
}
|
2020-08-06 16:55:58 +00:00
|
|
|
|
2020-08-07 13:28:41 +00:00
|
|
|
auto bothWidth = _answerHangupRedial->width() + st::callCancel.button.width;
|
2020-08-12 13:35:31 +00:00
|
|
|
_decline->moveToLeft((widget()->width() - bothWidth) / 2, _buttonsTop);
|
|
|
|
_cancel->moveToLeft((widget()->width() - bothWidth) / 2, _buttonsTop);
|
2017-05-05 10:14:40 +00:00
|
|
|
|
|
|
|
updateHangupGeometry();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 13:28:41 +00:00
|
|
|
void Panel::updateOutgoingVideoBubbleGeometry() {
|
|
|
|
Expects(!_outgoingPreviewInBody);
|
|
|
|
|
2020-08-13 11:16:39 +00:00
|
|
|
const auto margins = QMargins{
|
|
|
|
st::callInnerPadding,
|
|
|
|
st::callInnerPadding,
|
|
|
|
st::callInnerPadding,
|
|
|
|
st::callInnerPadding,
|
|
|
|
};
|
2020-08-07 13:28:41 +00:00
|
|
|
const auto size = st::callOutgoingDefaultSize;
|
|
|
|
_outgoingVideoBubble->updateGeometry(
|
|
|
|
VideoBubble::DragMode::SnapToCorners,
|
2020-08-13 11:16:39 +00:00
|
|
|
widget()->rect().marginsRemoved(margins),
|
2020-08-07 13:28:41 +00:00
|
|
|
size);
|
|
|
|
}
|
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
void Panel::updateHangupGeometry() {
|
|
|
|
auto singleWidth = _answerHangupRedial->width();
|
2020-08-07 13:28:41 +00:00
|
|
|
auto bothWidth = singleWidth + st::callCancel.button.width;
|
2020-08-12 13:35:31 +00:00
|
|
|
auto rightFrom = (widget()->width() - bothWidth) / 2;
|
|
|
|
auto rightTo = (widget()->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-07 13:28:41 +00:00
|
|
|
_answerHangupRedial->moveToRight(hangupRight, _buttonsTop);
|
2017-05-05 10:14:40 +00:00
|
|
|
_answerHangupRedial->setProgress(hangupProgress);
|
2020-08-07 13:28:41 +00:00
|
|
|
_mute->moveToRight(hangupRight - _mute->width(), _buttonsTop);
|
|
|
|
_camera->moveToLeft(hangupRight - _mute->width(), _buttonsTop);
|
2017-05-05 10:14:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 16:45:41 +00:00
|
|
|
void Panel::updateStatusGeometry() {
|
2020-08-12 13:35:31 +00:00
|
|
|
_status->moveToLeft(
|
|
|
|
(widget()->width() - _status->width()) / 2,
|
|
|
|
_bodyTop + _bodySt->statusTop);
|
2017-04-25 16:45:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 13:35:31 +00:00
|
|
|
void Panel::paint(QRect clip) {
|
|
|
|
Painter p(widget());
|
2017-05-04 13:32:56 +00:00
|
|
|
|
2020-08-17 09:49:45 +00:00
|
|
|
auto region = QRegion(clip);
|
|
|
|
if (!_incoming->isHidden()) {
|
|
|
|
region = region.subtracted(QRegion(_incoming->geometry()));
|
|
|
|
}
|
2020-11-04 15:50:17 +00:00
|
|
|
for (const auto rect : region) {
|
2020-08-17 09:49:45 +00:00
|
|
|
p.fillRect(rect, st::callBgOpaque);
|
|
|
|
}
|
|
|
|
if (_incoming && _incoming->isHidden()) {
|
|
|
|
_call->videoIncoming()->markFrameShown();
|
2020-07-31 14:36:35 +00:00
|
|
|
}
|
2018-05-27 08:24:47 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 13:35:31 +00:00
|
|
|
void Panel::handleClose() {
|
2017-05-15 08:17:59 +00:00
|
|
|
if (_call) {
|
|
|
|
_call->hangup();
|
|
|
|
}
|
2017-05-12 15:27:19 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 13:35:31 +00:00
|
|
|
not_null<Ui::RpWidget*> Panel::widget() const {
|
|
|
|
return _window->body();
|
2017-04-29 18:41:41 +00:00
|
|
|
}
|
|
|
|
|
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)) {
|
2020-08-14 12:51:47 +00:00
|
|
|
auto toggleButton = [&](auto &&button, bool visible) {
|
2020-08-06 16:55:58 +00:00
|
|
|
button->toggle(
|
|
|
|
visible,
|
2020-08-12 13:35:31 +00:00
|
|
|
_window->isHidden()
|
2020-08-06 16:55:58 +00:00
|
|
|
? 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);
|
|
|
|
}
|
2020-08-14 10:54:15 +00:00
|
|
|
const auto answerHangupRedialState = incomingWaiting
|
|
|
|
? AnswerHangupRedialState::Answer
|
|
|
|
: (state == State::Busy)
|
|
|
|
? AnswerHangupRedialState::Redial
|
|
|
|
: AnswerHangupRedialState::Hangup;
|
|
|
|
if (_answerHangupRedialState != answerHangupRedialState) {
|
|
|
|
_answerHangupRedialState = answerHangupRedialState;
|
|
|
|
refreshAnswerHangupRedialLabel();
|
|
|
|
}
|
2020-08-14 12:51:47 +00:00
|
|
|
if (!_call->isKeyShaForFingerprintReady()) {
|
|
|
|
_fingerprint.destroy();
|
|
|
|
} else if (!_fingerprint) {
|
|
|
|
_fingerprint = CreateFingerprintAndSignalBars(widget(), _call);
|
|
|
|
updateControlsGeometry();
|
2017-05-04 13:32:56 +00:00
|
|
|
}
|
2017-05-04 12:29:32 +00:00
|
|
|
}
|
2017-04-25 16:45:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-14 10:54:15 +00:00
|
|
|
void Panel::refreshAnswerHangupRedialLabel() {
|
|
|
|
Expects(_answerHangupRedialState.has_value());
|
|
|
|
|
|
|
|
_answerHangupRedial->setText([&] {
|
|
|
|
switch (*_answerHangupRedialState) {
|
|
|
|
case AnswerHangupRedialState::Answer: return tr::lng_call_accept();
|
|
|
|
case AnswerHangupRedialState::Hangup: return tr::lng_call_end_call();
|
|
|
|
case AnswerHangupRedialState::Redial: return tr::lng_call_redial();
|
|
|
|
}
|
|
|
|
Unexpected("AnswerHangupRedialState value.");
|
|
|
|
}());
|
|
|
|
}
|
|
|
|
|
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);
|
2020-09-30 11:32:02 +00:00
|
|
|
return Ui::FormatDurationText(durationSeconds);
|
2017-04-25 16:45:41 +00:00
|
|
|
}
|
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
|