2017-04-25 20:36:04 +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-25 20:36:04 +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-25 20:36:04 +00:00
|
|
|
*/
|
|
|
|
#include "calls/calls_top_bar.h"
|
|
|
|
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2017-09-20 19:44:22 +00:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-04-25 20:36:04 +00:00
|
|
|
#include "calls/calls_call.h"
|
|
|
|
#include "calls/calls_instance.h"
|
2018-05-27 08:24:47 +00:00
|
|
|
#include "calls/calls_panel.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2017-05-14 19:44:50 +00:00
|
|
|
#include "observer_peer.h"
|
2017-05-04 12:28:37 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
|
|
|
#include "base/timer.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "layout.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "styles/style_calls.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2017-04-25 20:36:04 +00:00
|
|
|
|
|
|
|
namespace Calls {
|
2017-05-04 12:28:37 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
constexpr auto kUpdateDebugTimeoutMs = crl::time(500);
|
2017-05-04 12:28:37 +00:00
|
|
|
|
|
|
|
class DebugInfoBox : public BoxContent {
|
|
|
|
public:
|
2017-11-30 17:33:27 +00:00
|
|
|
DebugInfoBox(QWidget*, base::weak_ptr<Call> call);
|
2017-05-04 12:28:37 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateText();
|
|
|
|
|
2017-11-30 17:33:27 +00:00
|
|
|
base::weak_ptr<Call> _call;
|
2017-05-04 12:28:37 +00:00
|
|
|
QPointer<Ui::FlatLabel> _text;
|
|
|
|
base::Timer _updateTextTimer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-11-30 17:33:27 +00:00
|
|
|
DebugInfoBox::DebugInfoBox(QWidget*, base::weak_ptr<Call> call)
|
|
|
|
: _call(call) {
|
2017-05-04 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugInfoBox::prepare() {
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle([] { return QString("Call Debug"); });
|
|
|
|
|
|
|
|
addButton(langFactory(lng_close), [this] { closeBox(); });
|
2017-09-20 19:44:22 +00:00
|
|
|
_text = setInnerWidget(
|
|
|
|
object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::FlatLabel>(this, st::callDebugLabel),
|
|
|
|
st::callDebugPadding))->entity();
|
2017-05-04 12:28:37 +00:00
|
|
|
_text->setSelectable(true);
|
|
|
|
updateText();
|
|
|
|
_updateTextTimer.setCallback([this] { updateText(); });
|
|
|
|
_updateTextTimer.callEach(kUpdateDebugTimeoutMs);
|
|
|
|
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugInfoBox::updateText() {
|
|
|
|
if (auto call = _call.get()) {
|
|
|
|
_text->setText(call->getDebugLog());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2017-04-25 20:36:04 +00:00
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
TopBar::TopBar(
|
|
|
|
QWidget *parent,
|
2017-11-30 17:33:27 +00:00
|
|
|
const base::weak_ptr<Call> &call)
|
2017-09-13 16:57:44 +00:00
|
|
|
: RpWidget(parent)
|
2017-04-25 20:36:04 +00:00
|
|
|
, _call(call)
|
|
|
|
, _durationLabel(this, st::callBarLabel)
|
2018-05-27 08:24:47 +00:00
|
|
|
, _signalBars(this, _call.get(), st::callBarSignalBars)
|
2017-05-14 19:44:50 +00:00
|
|
|
, _fullInfoLabel(this, st::callBarInfoLabel)
|
|
|
|
, _shortInfoLabel(this, st::callBarInfoLabel)
|
2017-04-25 20:36:04 +00:00
|
|
|
, _hangupLabel(this, st::callBarLabel, lang(lng_call_bar_hangup).toUpper())
|
|
|
|
, _mute(this, st::callBarMuteToggle)
|
|
|
|
, _info(this)
|
|
|
|
, _hangup(this, st::callBarHangup) {
|
|
|
|
initControls();
|
|
|
|
resize(width(), st::callBarHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::initControls() {
|
|
|
|
_mute->setClickedCallback([this] {
|
2017-05-05 16:27:05 +00:00
|
|
|
if (auto call = _call.get()) {
|
|
|
|
call->setMute(!call->isMute());
|
|
|
|
}
|
2017-04-25 20:36:04 +00:00
|
|
|
});
|
2017-05-02 07:25:20 +00:00
|
|
|
setMuted(_call->isMute());
|
2017-04-25 20:36:04 +00:00
|
|
|
subscribe(_call->muteChanged(), [this](bool mute) {
|
2017-05-02 07:25:20 +00:00
|
|
|
setMuted(mute);
|
2017-04-25 20:36:04 +00:00
|
|
|
update();
|
|
|
|
});
|
2017-05-14 19:44:50 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::NameChanged, [this](const Notify::PeerUpdate &update) {
|
|
|
|
if (auto call = _call.get()) {
|
|
|
|
if (update.peer == call->user()) {
|
|
|
|
updateInfoLabels();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
setInfoLabels();
|
2017-04-25 20:36:04 +00:00
|
|
|
_info->setClickedCallback([this] {
|
|
|
|
if (auto call = _call.get()) {
|
2018-06-05 13:32:26 +00:00
|
|
|
if (Logs::DebugEnabled()
|
|
|
|
&& (_info->clickModifiers() & Qt::ControlModifier)) {
|
2017-05-04 12:28:37 +00:00
|
|
|
Ui::show(Box<DebugInfoBox>(_call));
|
|
|
|
} else {
|
|
|
|
Current().showInfoPanel(call);
|
|
|
|
}
|
2017-04-25 20:36:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
_hangup->setClickedCallback([this] {
|
2017-05-05 16:27:05 +00:00
|
|
|
if (auto call = _call.get()) {
|
|
|
|
call->hangup();
|
2017-04-25 20:36:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
_updateDurationTimer.setCallback([this] { updateDurationText(); });
|
|
|
|
updateDurationText();
|
|
|
|
}
|
|
|
|
|
2017-05-14 19:44:50 +00:00
|
|
|
void TopBar::updateInfoLabels() {
|
|
|
|
setInfoLabels();
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::setInfoLabels() {
|
|
|
|
if (auto call = _call.get()) {
|
|
|
|
auto user = call->user();
|
|
|
|
auto fullName = App::peerName(user);
|
|
|
|
auto shortName = user->firstName;
|
|
|
|
_fullInfoLabel->setText(fullName.toUpper());
|
|
|
|
_shortInfoLabel->setText(shortName.toUpper());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-02 07:25:20 +00:00
|
|
|
void TopBar::setMuted(bool mute) {
|
|
|
|
_mute->setIconOverride(mute ? &st::callBarUnmuteIcon : nullptr);
|
|
|
|
_mute->setRippleColorOverride(mute ? &st::callBarUnmuteRipple : nullptr);
|
|
|
|
_hangup->setRippleColorOverride(mute ? &st::callBarUnmuteRipple : nullptr);
|
|
|
|
_muted = mute;
|
|
|
|
}
|
|
|
|
|
2017-04-25 20:36:04 +00:00
|
|
|
void TopBar::updateDurationText() {
|
|
|
|
if (!_call) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto wasWidth = _durationLabel->width();
|
|
|
|
auto durationMs = _call->getDurationMs();
|
|
|
|
auto durationSeconds = durationMs / 1000;
|
|
|
|
startDurationUpdateTimer(durationMs);
|
|
|
|
_durationLabel->setText(formatDurationText(durationSeconds));
|
|
|
|
if (_durationLabel->width() != wasWidth) {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void TopBar::startDurationUpdateTimer(crl::time currentDuration) {
|
2017-04-25 20:36:04 +00:00
|
|
|
auto msTillNextSecond = 1000 - (currentDuration % 1000);
|
|
|
|
_updateDurationTimer.callOnce(msTillNextSecond + 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::resizeEvent(QResizeEvent *e) {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::updateControlsGeometry() {
|
|
|
|
auto left = 0;
|
2018-05-27 08:24:47 +00:00
|
|
|
_mute->moveToLeft(left, 0);
|
|
|
|
left += _mute->width();
|
|
|
|
_durationLabel->moveToLeft(left, st::callBarLabelTop);
|
|
|
|
left += _durationLabel->width() + st::callBarSkip;
|
|
|
|
_signalBars->moveToLeft(left, (height() - _signalBars->height()) / 2);
|
|
|
|
left += _signalBars->width() + st::callBarSkip;
|
2017-04-25 20:36:04 +00:00
|
|
|
|
|
|
|
auto right = st::callBarRightSkip;
|
2018-05-27 08:24:47 +00:00
|
|
|
_hangupLabel->moveToRight(right, st::callBarLabelTop);
|
|
|
|
right += _hangupLabel->width();
|
2017-04-25 20:36:04 +00:00
|
|
|
right += st::callBarHangup.width;
|
|
|
|
_hangup->setGeometryToRight(0, 0, right, height());
|
2018-05-27 08:24:47 +00:00
|
|
|
_info->setGeometryToLeft(
|
|
|
|
_mute->width(),
|
|
|
|
0,
|
|
|
|
width() - _mute->width() - _hangup->width(),
|
|
|
|
height());
|
2017-04-25 20:36:04 +00:00
|
|
|
|
2017-05-14 19:44:50 +00:00
|
|
|
auto fullWidth = _fullInfoLabel->naturalWidth();
|
|
|
|
auto showFull = (left + fullWidth + right <= width());
|
|
|
|
_fullInfoLabel->setVisible(showFull);
|
|
|
|
_shortInfoLabel->setVisible(!showFull);
|
|
|
|
|
|
|
|
auto setInfoLabelGeometry = [this, left, right](auto &&infoLabel) {
|
|
|
|
auto minPadding = qMax(left, right);
|
|
|
|
auto infoWidth = infoLabel->naturalWidth();
|
|
|
|
auto infoLeft = (width() - infoWidth) / 2;
|
|
|
|
if (infoLeft < minPadding) {
|
|
|
|
infoLeft = left;
|
|
|
|
infoWidth = width() - left - right;
|
|
|
|
}
|
|
|
|
infoLabel->setGeometryToLeft(infoLeft, st::callBarLabelTop, infoWidth, st::callBarInfoLabel.style.font->height);
|
|
|
|
};
|
|
|
|
setInfoLabelGeometry(_fullInfoLabel);
|
|
|
|
setInfoLabelGeometry(_shortInfoLabel);
|
2017-04-25 20:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
p.fillRect(e->rect(), _muted ? st::callBarBgMuted : st::callBarBg);
|
|
|
|
}
|
|
|
|
|
|
|
|
TopBar::~TopBar() = default;
|
|
|
|
|
|
|
|
} // namespace Calls
|