Add title to group call panel.

This commit is contained in:
John Preston 2020-11-26 16:04:11 +03:00
parent 858ee0e8c4
commit ec5aeb32f1
6 changed files with 95 additions and 14 deletions

View File

@ -1811,6 +1811,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_call_microphone_off" = "{user}'s microphone is off";
"lng_group_call_title" = "Voice Chat";
"lng_group_call_active" = "speaking";
"lng_group_call_inactive" = "listening";
"lng_group_call_settings" = "Settings";
"lng_group_call_unmute" = "Unmute";
"lng_group_call_you_are_live" = "You are Live";
"lng_group_call_connecting" = "Connecting...";
"lng_group_call_leave" = "Leave";
"lng_group_call_leave_title" = "Leave voice chat";
"lng_group_call_leave_sure" = "Are you sure you want to leave this voice chat?";
"lng_group_call_also_end" = "End voice chat";
"lng_group_call_settings_title" = "Settings";
"lng_group_call_speakers" = "Speakers";
"lng_group_call_microphone" = "Microphone";
"lng_group_call_share" = "Share Invite Link";
"lng_group_call_end" = "End Voice Chat";
"lng_group_call_join" = "Join";
"lng_no_mic_permission" = "Telegram needs access to your microphone so that you can make calls and record voice messages.";
"lng_player_message_today" = "Today at {time}";

View File

@ -455,6 +455,7 @@ groupCallHeaderLabel: FlatLabel(defaultFlatLabel) {
}
}
groupCallAddButtonPosition: point(10px, 7px);
groupCallMembersWidthMax: 360px;
groupCallInactiveButton: IconButton {
width: 36px;

View File

@ -142,10 +142,10 @@ void Row::refreshStatus() {
setCustomStatus([&] {
switch (_state) {
case State::Inactive:
case State::Muted: return "listening";
case State::Active: return "speaking";
case State::Muted: return tr::lng_group_call_inactive(tr::now);
case State::Active: return tr::lng_group_call_active(tr::now);
}
return "";
Unexpected("State in Row::refreshStatus.");
}());
}
@ -510,11 +510,11 @@ std::vector<not_null<PeerData*>> GroupMembers::peerListCollectSelectedRows() {
}
void GroupMembers::peerListAddSelectedPeerInBunch(not_null<PeerData*> peer) {
Unexpected("Item selection in Info::Profile::Members.");
Unexpected("Item selection in Calls::GroupMembers.");
}
void GroupMembers::peerListAddSelectedRowInBunch(not_null<PeerListRow*> row) {
Unexpected("Item selection in Info::Profile::Members.");
Unexpected("Item selection in Calls::GroupMembers.");
}
void GroupMembers::peerListFinishSelectedRowsBunch() {

View File

@ -249,8 +249,10 @@ void GroupPanel::initWindow() {
_window->setAttribute(Qt::WA_NoSystemBackground);
_window->setWindowIcon(
QIcon(QPixmap::fromImage(Image::Empty()->original(), Qt::ColorOnly)));
_window->setTitle(u" "_q);
_window->setTitleStyle(st::callTitle);
_window->setTitle(computeTitleRect()
? u" "_q
: tr::lng_group_call_title(tr::now));
base::install_event_filter(_window.get(), [=](not_null<QEvent*> e) {
if (e->type() == QEvent::Close && handleClose()) {
@ -366,22 +368,43 @@ void GroupPanel::initGeometry() {
updateControlsGeometry();
}
int GroupPanel::computeMembersListTop() const {
#ifdef Q_OS_WIN
return st::callTitleButton.height + st::groupCallMembersMargin.top() / 2;
#elif defined Q_OS_MAC // Q_OS_WIN
return st::groupCallMembersMargin.top() * 2;
#else // Q_OS_WIN || Q_OS_MAC
return st::groupCallMembersMargin.top();
#endif // Q_OS_WIN || Q_OS_MAC
}
std::optional<QRect> GroupPanel::computeTitleRect() const {
#ifdef Q_OS_WIN
const auto controls = _controls->geometry();
return QRect(0, 0, controls.x(), controls.height());
#else // Q_OS_WIN
return std::nullopt;
#endif // Q_OS_WIN
}
void GroupPanel::updateControlsGeometry() {
if (widget()->size().isEmpty()) {
return;
}
const auto desiredHeight = _members->desiredHeight();
const auto membersWidth = widget()->width()
const auto membersWidthAvailable = widget()->width()
- st::groupCallMembersMargin.left()
- st::groupCallMembersMargin.right();
const auto membersWidthMin = st::groupCallWidth
- st::groupCallMembersMargin.left()
- st::groupCallMembersMargin.right();
const auto membersWidth = std::clamp(
membersWidthAvailable,
membersWidthMin,
st::groupCallMembersWidthMax);
const auto muteTop = widget()->height() - 2 * _mute->height();
const auto buttonsTop = muteTop;
#ifdef Q_OS_WIN
const auto membersTop = st::callTitleButton.height
+ st::groupCallMembersMargin.top() / 2;
#else // Q_OS_WIN
const auto membersTop = st::groupCallMembersMargin.top();
#endif // Q_OS_WIN
const auto membersTop = computeMembersListTop();
const auto availableHeight = buttonsTop
- membersTop
- st::groupCallMembersMargin.bottom();
@ -393,6 +416,39 @@ void GroupPanel::updateControlsGeometry() {
_mute->move((widget()->width() - _mute->width()) / 2, muteTop);
_settings->moveToLeft(_settings->width(), buttonsTop);
_hangup->moveToRight(_settings->width(), buttonsTop);
refreshTitle();
}
void GroupPanel::refreshTitle() {
if (const auto titleRect = computeTitleRect()) {
if (!_title) {
_title.create(
widget(),
tr::lng_group_call_title(),
st::groupCallHeaderLabel);
_window->setTitle(u" "_q);
}
const auto best = _title->naturalWidth();
const auto from = (widget()->width() - best) / 2;
const auto top = (computeMembersListTop() - _title->height()) / 2;
const auto left = titleRect->x();
if (from >= left && from + best <= left + titleRect->width()) {
_title->resizeToWidth(best);
_title->moveToLeft(from, top);
} else if (titleRect->width() < best) {
_title->resizeToWidth(titleRect->width());
_title->moveToLeft(left, top);
} else if (from < left) {
_title->resizeToWidth(best);
_title->moveToLeft(left, top);
} else {
_title->resizeToWidth(best);
_title->moveToLeft(left + titleRect->width() - best, top);
}
} else if (_title) {
_title.destroy();
_window->setTitle(tr::lng_group_call_title(tr::now));
}
}
void GroupPanel::paint(QRect clip) {

View File

@ -76,6 +76,10 @@ private:
void stateChanged(State state);
void showControls();
[[nodiscard]] int computeMembersListTop() const;
[[nodiscard]] std::optional<QRect> computeTitleRect() const;
void refreshTitle();
GroupCall *_call = nullptr;
not_null<ChannelData*> _channel;
@ -87,6 +91,7 @@ private:
rpl::lifetime _callLifetime;
object_ptr<Ui::FlatLabel> _title = { nullptr };
object_ptr<GroupMembers> _members;
object_ptr<Button> _settings;

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/message_bar.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/buttons.h"
#include "lang/lang_keys.h"
#include "styles/style_chat.h"
#include "styles/palette.h"
@ -102,7 +103,7 @@ void GroupCallBar::paint(Painter &p) {
p.fillRect(_inner->rect(), st::historyComposeAreaBg);
p.setPen(st::defaultMessageBar.textFg);
p.setFont(st::defaultMessageBar.text.font);
p.drawText(_inner->rect(), "Voice Chat", style::al_center);
p.drawText(_inner->rect(), tr::lng_group_call_title(tr::now), style::al_center);
}
void GroupCallBar::updateControlsGeometry(QRect wrapGeometry) {