From 1aaf7df54a49f620a473468a5ee7841a11e6b436 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 14 Aug 2020 14:54:15 +0400 Subject: [PATCH] Add labels to call buttons. --- Telegram/Resources/icons/call_cancel.png | Bin 0 -> 214 bytes Telegram/Resources/icons/call_cancel@2x.png | Bin 0 -> 426 bytes Telegram/Resources/icons/call_cancel@3x.png | Bin 0 -> 912 bytes Telegram/SourceFiles/calls/calls.style | 24 +++++-- Telegram/SourceFiles/calls/calls_panel.cpp | 67 +++++++++++++++--- Telegram/SourceFiles/calls/calls_panel.h | 7 ++ .../SourceFiles/mtproto/session_private.cpp | 17 ++++- Telegram/ThirdParty/tgcalls | 2 +- 8 files changed, 96 insertions(+), 21 deletions(-) create mode 100644 Telegram/Resources/icons/call_cancel.png create mode 100644 Telegram/Resources/icons/call_cancel@2x.png create mode 100644 Telegram/Resources/icons/call_cancel@3x.png diff --git a/Telegram/Resources/icons/call_cancel.png b/Telegram/Resources/icons/call_cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..607033d0fc9da3bd689b030e4b5215622bf61094 GIT binary patch literal 214 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbB=6bp~hD5Z!o$koxtjOcCd~e(L z_$q#Vq4f{dcL!bg`7xR!Rjz|u{fC3{4<>^N9p!409xvF0k~}&T728@Q5*J2kpXqsK z^Z2H$Tgr@^1vT@o-aV<~wj*KZL+6>c3vV7{Px;omkCpGFjqtB2Rw~Aqw%Y!Cb|NVD zRY>mt*X@QiE2Fbt>|H#?=bP0 Hl+XkK3eZ&{ literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/call_cancel@2x.png b/Telegram/Resources/icons/call_cancel@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..611f89d36ca23e5e6585f8c2332b26aee7dda4f2 GIT binary patch literal 426 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@Zgyv2U@Y`>aSW-L^Y-?^u0sYQZV%7o ze2!6kFTLw+_SAPqF^(ERpSNFK7XDnOK)EQ{zUM}Ry<&^hi_HBOwlI6JOyE!ubWmz= zVd!KKVpL(mE3k{XSL~^QH#vI=gA+-c{*#Nj;@9$FqDdhZLV{zwWJhH!Z^K za@zdA{|?{eo)YwG(_#g=n$8;{!LZ8V)zIq&DB zyoWbFzu!^*J7a;E-)qzVkJ=xJ$+Ua?E10AB^GIRK6Y=Ammv(a7$nAW0G*hwm=)~8b zF8tFtCw1w%%&q$q+Y&2IPun1Awp!Tl>Hj39yf9Z{{0+a*( zAJ~4`{#tdPlk=n4;v?RR{O>8Rxc{h|-)`+qiqT^ySN!=ZAUkoKh??tNB?{ zqVl6Ze`+$A+26cSkweuP(iF|9<(+n>Qz4zYy`%W1(fu zG5urP#g|1yM@wtIeefVbCsS(iM$LKi<|UPunz~0;as{tQ%!=tceE2ZG=jDx3lOKKj zXeia|wr4x_9_xbPoEsQaU)Jg1m`t<3JojX0dcI?>k!kz1B zfZnag$2o&_bajt@{aPC2!POhe_bAz&D_BQQuTS;ut5>V+r~TTo@etc3l?7VUr%&Iw zVS~f8qhiY@G-#bSkqusb^~ENp{jLg1zXG4`c+d3f=F-b^{5uV z{OC2#*tE}tRmkk!(ffgy-o1NQ^RZlL)3MmNpKal9K2N{;w(R&M(+(}}84FA|)~J7% zTz&Ta(%xH243VYhijzXW6;}xRsRgDUpR#>ts?a?TE@87*yz94TrJE_%OE9Ue`O(xb z{a4p_t7*GT_2jp!UFsL`0|mFXT*@)~e|n{-Y1G=VZ>ul;vp;9>N0*7pX%vy}Cu(#( aQt#E4+I&yTc@i+EF?hQAxvX text); protected: void paintEvent(QPaintEvent *e) override; @@ -83,7 +85,7 @@ private: const style::CallButton *_stTo = nullptr; float64 _progress = 0.; - const style::icon *_iconOverride = nullptr; + object_ptr _label = { nullptr }; QImage _bgMask, _bg; QPixmap _bgFrom, _bgTo; @@ -94,7 +96,10 @@ private: }; -Panel::Button::Button(QWidget *parent, const style::CallButton &stFrom, const style::CallButton *stTo) +Panel::Button::Button( + QWidget *parent, + const style::CallButton &stFrom, + const style::CallButton *stTo) : Ui::RippleButton(parent, stFrom.button.ripple) , _stFrom(&stFrom) , _stTo(stTo) { @@ -143,9 +148,18 @@ void Panel::Button::setOuterValue(float64 value) { } } -void Panel::Button::setIconOverride(const style::icon *iconOverride) { - _iconOverride = iconOverride; - update(); +void Panel::Button::setText(rpl::producer text) { + _label.create(this, std::move(text), _stFrom->label); + _label->show(); + rpl::combine( + sizeValue(), + _label->sizeValue() + ) | rpl::start_with_next([=](QSize my, QSize label) { + _label->moveToLeft( + (my.width() - label.width()) / 2, + my.height() - label.height(), + my.width()); + }, _label->lifetime()); } void Panel::Button::setProgress(float64 progress) { @@ -201,7 +215,7 @@ void Panel::Button::paintEvent(QPaintEvent *e) { auto positionFrom = iconPosition(_stFrom); if (paintFrom) { - const auto icon = _iconOverride ? _iconOverride : &_stFrom->button.icon; + const auto icon = &_stFrom->button.icon; icon->paint(p, positionFrom, width()); } else { auto positionTo = iconPosition(_stTo); @@ -282,7 +296,9 @@ Panel::Panel(not_null call) , _name(widget(), st::callName) , _status(widget(), st::callStatus) { _decline->setDuration(st::callPanelDuration); + _decline->entity()->setText(tr::lng_call_decline()); _cancel->setDuration(st::callPanelDuration); + _cancel->entity()->setText(tr::lng_call_cancel()); initWindow(); initWidget(); @@ -497,11 +513,18 @@ void Panel::reinitWithCall(Call *call) { _call->mutedValue( ) | rpl::start_with_next([=](bool mute) { _mute->setProgress(mute ? 1. : 0.); + _mute->setText(mute + ? tr::lng_call_unmute_audio() + : tr::lng_call_mute_audio()); }, _callLifetime); _call->videoOutgoing()->stateValue( ) | rpl::start_with_next([=](Webrtc::VideoState state) { - _camera->setProgress((state == Webrtc::VideoState::Active) ? 0. : 1.); + 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()); }, _callLifetime); _call->stateValue( @@ -569,7 +592,7 @@ void Panel::createRemoteAudioMute() { const auto height = _remoteAudioMute->height(); auto hq = PainterHighQualityEnabler(p); - p.setBrush(st::toastBg); + p.setBrush(st::videoPlayIconBg); p.setPen(Qt::NoPen); p.drawRoundedRect(_remoteAudioMute->rect(), height / 2, height / 2); @@ -986,12 +1009,34 @@ void Panel::stateChanged(State state) { _hangupShown = hangupShown; _hangupShownProgress.start([this] { updateHangupGeometry(); }, _hangupShown ? 0. : 1., _hangupShown ? 1. : 0., st::callPanelDuration, anim::sineInOut); } + const auto answerHangupRedialState = incomingWaiting + ? AnswerHangupRedialState::Answer + : (state == State::Busy) + ? AnswerHangupRedialState::Redial + : AnswerHangupRedialState::Hangup; + if (_answerHangupRedialState != answerHangupRedialState) { + _answerHangupRedialState = answerHangupRedialState; + refreshAnswerHangupRedialLabel(); + } if (_fingerprint.empty() && _call->isKeyShaForFingerprintReady()) { fillFingerprint(); } } } +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."); + }()); +} + void Panel::fillFingerprint() { Expects(_call != nullptr); diff --git a/Telegram/SourceFiles/calls/calls_panel.h b/Telegram/SourceFiles/calls/calls_panel.h index c57ca6070..ccdff5791 100644 --- a/Telegram/SourceFiles/calls/calls_panel.h +++ b/Telegram/SourceFiles/calls/calls_panel.h @@ -60,6 +60,11 @@ private: class Button; using State = Call::State; using Type = Call::Type; + enum class AnswerHangupRedialState : uchar { + Answer, + Hangup, + Redial, + }; [[nodiscard]] not_null widget() const; @@ -101,6 +106,7 @@ private: void refreshOutgoingPreviewInBody(State state); void toggleFullScreen(bool fullscreen); void createRemoteAudioMute(); + void refreshAnswerHangupRedialLabel(); [[nodiscard]] QRect incomingFrameGeometry() const; [[nodiscard]] QRect outgoingFrameGeometry() const; @@ -124,6 +130,7 @@ private: object_ptr> _cancel; bool _hangupShown = false; bool _outgoingPreviewInBody = false; + std::optional _answerHangupRedialState; Ui::Animations::Simple _hangupShownProgress; object_ptr