From 0b77c0bce8af356d58e9dca2b8e8dea1c6e8c601 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 14 May 2017 22:44:50 +0300 Subject: [PATCH] Version 1.1: Show user name in call top bar. --- Telegram/Resources/langs/lang.strings | 1 - Telegram/Resources/langs/lang_de.strings | 1 - Telegram/Resources/langs/lang_es.strings | 1 - Telegram/Resources/langs/lang_it.strings | 1 - Telegram/Resources/langs/lang_ko.strings | 1 - Telegram/Resources/langs/lang_nl.strings | 1 - Telegram/Resources/langs/lang_pt_BR.strings | 1 - Telegram/SourceFiles/calls/calls.style | 8 ++++ Telegram/SourceFiles/calls/calls_top_bar.cpp | 49 +++++++++++++++++--- Telegram/SourceFiles/calls/calls_top_bar.h | 6 ++- 10 files changed, 55 insertions(+), 15 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7e88de1e6c..e3f455955f 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1143,7 +1143,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_call_error_outdated" = "{user}'s app does not support calls. They need to update their app before you can call them."; "lng_call_error_audio_io" = "There seems to be a problem with audio playback on your computer. Please make sure that your computer's speakers and microphone are working and try again."; -"lng_call_bar_info" = "Show call info"; "lng_call_bar_hangup" = "End call"; "lng_call_box_title" = "Calls"; diff --git a/Telegram/Resources/langs/lang_de.strings b/Telegram/Resources/langs/lang_de.strings index 69c2fe111f..93868775c2 100644 --- a/Telegram/Resources/langs/lang_de.strings +++ b/Telegram/Resources/langs/lang_de.strings @@ -1143,7 +1143,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_call_error_outdated" = "{user}s App unterstützt keine Anrufe. Dein Chatpartner muss seine App aktualisieren, bevor du anrufen kannst."; "lng_call_error_audio_io" = "Leider gibt es ein Problem mit der Audiowiedergabe auf deinem Computer. Bitte stelle sicher, dass Lautsprecher und Mikrofon funktionieren und probiere es erneut."; -"lng_call_bar_info" = "Anrufinfo anzeigen"; "lng_call_bar_hangup" = "Anruf beenden"; "lng_call_box_title" = "Anrufe"; diff --git a/Telegram/Resources/langs/lang_es.strings b/Telegram/Resources/langs/lang_es.strings index db1936d6d2..f23a32e0be 100644 --- a/Telegram/Resources/langs/lang_es.strings +++ b/Telegram/Resources/langs/lang_es.strings @@ -1143,7 +1143,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_call_error_outdated" = "La app de {user} no soporta llamadas. Debe actualizar su app para recibir tu llamada."; "lng_call_error_audio_io" = "Parece existir un problema con la reproducción de audio en tu PC. Por favor, verifica que tu altavoz y micrófono están funcionando y reinténtalo."; -"lng_call_bar_info" = "Información"; "lng_call_bar_hangup" = "Terminar llamada"; "lng_call_box_title" = "Llamadas"; diff --git a/Telegram/Resources/langs/lang_it.strings b/Telegram/Resources/langs/lang_it.strings index 26198aa0cd..e6f19c472f 100644 --- a/Telegram/Resources/langs/lang_it.strings +++ b/Telegram/Resources/langs/lang_it.strings @@ -1143,7 +1143,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_call_error_outdated" = "L'app di {user} non supporta le chiamate. Deve aggiornare la sua app prima che tu possa chiamarlo."; "lng_call_error_audio_io" = "Sembra esserci un problema con la riproduzione audio del tuo computer. Per favore assicurati che gli altoparlanti e il microfono del tuo computer stiano funzionando e riprova."; -"lng_call_bar_info" = "Info chiamata"; "lng_call_bar_hangup" = "Termina chiamata"; "lng_call_box_title" = "Chiamate"; diff --git a/Telegram/Resources/langs/lang_ko.strings b/Telegram/Resources/langs/lang_ko.strings index bc96fa52da..ee43e3a329 100644 --- a/Telegram/Resources/langs/lang_ko.strings +++ b/Telegram/Resources/langs/lang_ko.strings @@ -1143,7 +1143,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_call_error_outdated" = "{user}님의 앱이 전화를 지원하고 있지 않습니다. 상대방 앱을 업데이트 해야합니다."; "lng_call_error_audio_io" = "회원님 컴퓨터의 음성 재생에 문제가 있습니다. 스피커와 마이크가 작동을 하는지 확인 후 다시 시도해주세요."; -"lng_call_bar_info" = "전화 정보 보기"; "lng_call_bar_hangup" = "통화종료"; "lng_call_box_title" = "전화"; diff --git a/Telegram/Resources/langs/lang_nl.strings b/Telegram/Resources/langs/lang_nl.strings index 1a26d93f91..0c3462373b 100644 --- a/Telegram/Resources/langs/lang_nl.strings +++ b/Telegram/Resources/langs/lang_nl.strings @@ -1143,7 +1143,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_call_error_outdated" = "{user}'s app heeft nog geen ondersteuning voor spraakoproepen en zal eerst een update moeten uitvoeren."; "lng_call_error_audio_io" = "Er lijkt iets mis te gaan met het afspelen van audio op je computer. Zorg dat je microfoon en luidsprekers werken en probeer het opnieuw."; -"lng_call_bar_info" = "Oproepinformatie"; "lng_call_bar_hangup" = "Nu beëindigen"; "lng_call_box_title" = "Spraakoproepen"; diff --git a/Telegram/Resources/langs/lang_pt_BR.strings b/Telegram/Resources/langs/lang_pt_BR.strings index b2edec2490..e372ab07db 100644 --- a/Telegram/Resources/langs/lang_pt_BR.strings +++ b/Telegram/Resources/langs/lang_pt_BR.strings @@ -1143,7 +1143,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_call_error_outdated" = "O aplicativo de {user} não suporta chamadas. O aplicativo desse usuário precisa ser atualizado para que você possa chamá-lo."; "lng_call_error_audio_io" = "Parece haver um problema com a reprodução de áudio em seu computador. Verifique se os auto-falantes e microfone estão funcionando e tente novamente."; -"lng_call_bar_info" = "Informações da Chamada"; "lng_call_bar_hangup" = "Encerrar chamada"; "lng_call_box_title" = "Chamadas"; diff --git a/Telegram/SourceFiles/calls/calls.style b/Telegram/SourceFiles/calls/calls.style index 0f402e2ba9..533cbbaf77 100644 --- a/Telegram/SourceFiles/calls/calls.style +++ b/Telegram/SourceFiles/calls/calls.style @@ -147,6 +147,14 @@ callBarLabel: LabelSimple(defaultLabelSimple) { font: semiboldFont; textFg: callBarFg; } +callBarInfoLabel: FlatLabel(defaultFlatLabel) { + maxHeight: 28px; + align: align(top); + textFg: callBarFg; + style: TextStyle(defaultTextStyle) { + font: semiboldFont; + } +} callBarLabelTop: 10px; callArrowPosition: point(-2px, 1px); diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 4c6e12881e..a70464bf10 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -27,6 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "calls/calls_call.h" #include "calls/calls_instance.h" #include "styles/style_boxes.h" +#include "observer_peer.h" #include "boxes/abstract_box.h" #include "base/timer.h" @@ -76,7 +77,8 @@ void DebugInfoBox::updateText() { TopBar::TopBar(QWidget *parent, const base::weak_unique_ptr &call) : TWidget(parent) , _call(call) , _durationLabel(this, st::callBarLabel) -, _infoLabel(this, st::callBarLabel, lang(lng_call_bar_info).toUpper()) +, _fullInfoLabel(this, st::callBarInfoLabel) +, _shortInfoLabel(this, st::callBarInfoLabel) , _hangupLabel(this, st::callBarLabel, lang(lng_call_bar_hangup).toUpper()) , _mute(this, st::callBarMuteToggle) , _info(this) @@ -96,6 +98,14 @@ void TopBar::initControls() { setMuted(mute); update(); }); + 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(); _info->setClickedCallback([this] { if (auto call = _call.get()) { if (cDebug() && (_info->clickModifiers() & Qt::ControlModifier)) { @@ -114,6 +124,21 @@ void TopBar::initControls() { updateDurationText(); } +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()); + } +} + void TopBar::setMuted(bool mute) { _mute->setIconOverride(mute ? &st::callBarUnmuteIcon : nullptr); _mute->setRippleColorOverride(mute ? &st::callBarUnmuteRipple : nullptr); @@ -155,13 +180,23 @@ void TopBar::updateControlsGeometry() { _hangup->setGeometryToRight(0, 0, right, height()); _info->setGeometryToLeft(_mute->width(), 0, width() - _mute->width() - _hangup->width(), height()); - auto minPadding = qMax(left, right); + auto fullWidth = _fullInfoLabel->naturalWidth(); + auto showFull = (left + fullWidth + right <= width()); + _fullInfoLabel->setVisible(showFull); + _shortInfoLabel->setVisible(!showFull); - auto infoLeft = (width() - _infoLabel->width()) / 2; - if (infoLeft < minPadding) { - infoLeft = left + (width() - left - right - _infoLabel->width()) / 2; - } - _infoLabel->moveToLeft(infoLeft, st::callBarLabelTop); + 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); } void TopBar::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/calls/calls_top_bar.h b/Telegram/SourceFiles/calls/calls_top_bar.h index 6d5f2b64be..67d3e395b9 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.h +++ b/Telegram/SourceFiles/calls/calls_top_bar.h @@ -27,6 +27,7 @@ namespace Ui { class IconButton; class AbstractButton; class LabelSimple; +class FlatLabel; } // namespace Ui namespace Calls { @@ -45,6 +46,8 @@ protected: private: void initControls(); + void updateInfoLabels(); + void setInfoLabels(); void updateDurationText(); void updateControlsGeometry(); void startDurationUpdateTimer(TimeMs currentDuration); @@ -54,7 +57,8 @@ private: bool _muted = false; object_ptr _durationLabel; - object_ptr _infoLabel; + object_ptr _fullInfoLabel; + object_ptr _shortInfoLabel; object_ptr _hangupLabel; object_ptr _mute; object_ptr _info;