From cb78bd1a10f0d4a5080ae3287fee97dfdaa309e0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 4 Mar 2016 18:47:48 +0200 Subject: [PATCH] public links display / edit done in megagroups --- Telegram/Resources/lang.strings | 4 ++ Telegram/SourceFiles/boxes/addcontactbox.cpp | 62 +++++++++++++------- Telegram/SourceFiles/boxes/addcontactbox.h | 2 + Telegram/SourceFiles/profilewidget.cpp | 6 +- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/Telegram/Resources/lang.strings b/Telegram/Resources/lang.strings index 39574f5a6..95efa2589 100644 --- a/Telegram/Resources/lang.strings +++ b/Telegram/Resources/lang.strings @@ -477,6 +477,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org "lng_create_public_channel_about" = "Anyone can find the channel in search and join"; "lng_create_private_channel_title" = "Private Channel"; "lng_create_private_channel_about" = "Only people with a special invite link may join"; +"lng_create_public_group_title" = "Public Group"; +"lng_create_public_group_about" = "Anyone can find the group in search and join, all chat history is available to everybody"; +"lng_create_private_group_title" = "Private Group"; +"lng_create_private_group_about" = "Only invited people may join and see the chat history"; "lng_create_channel_comments" = "Enable Comments"; "lng_create_channel_comments_about" = "If you enable comments, members will be able to discuss your posts in the channel"; "lng_create_group_skip" = "Skip"; diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index c695c1949..7ba83729d 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -605,12 +605,12 @@ void GroupInfoBox::onPhotoReady(const QImage &img) { SetupChannelBox::SetupChannelBox(ChannelData *channel, bool existing) : AbstractBox() , _channel(channel) , _existing(existing) -, _public(this, qsl("channel_privacy"), 0, lang(lng_create_public_channel_title), true) -, _private(this, qsl("channel_privacy"), 1, lang(lng_create_private_channel_title)) +, _public(this, qsl("channel_privacy"), 0, lang(channel->isMegagroup() ? lng_create_public_group_title : lng_create_public_channel_title), true) +, _private(this, qsl("channel_privacy"), 1, lang(channel->isMegagroup() ? lng_create_private_group_title : lng_create_private_channel_title)) , _comments(this, lang(lng_create_channel_comments), false) , _aboutPublicWidth(width() - st::boxPadding.left() - st::boxButtonPadding.right() - st::newGroupPadding.left() - st::defaultRadiobutton.textPosition.x()) -, _aboutPublic(st::normalFont, lang(lng_create_public_channel_about), _defaultOptions, _aboutPublicWidth) -, _aboutPrivate(st::normalFont, lang(lng_create_private_channel_about), _defaultOptions, _aboutPublicWidth) +, _aboutPublic(st::normalFont, lang(channel->isMegagroup() ? lng_create_public_group_about : lng_create_public_channel_about), _defaultOptions, _aboutPublicWidth) +, _aboutPrivate(st::normalFont, lang(channel->isMegagroup() ? lng_create_private_group_about : lng_create_private_channel_about), _defaultOptions, _aboutPublicWidth) , _aboutComments(st::normalFont, lang(lng_create_channel_comments_about), _defaultOptions, _aboutPublicWidth) , _link(this, st::defaultInputField, QString(), channel->username, true) , _linkOver(false) @@ -626,7 +626,7 @@ SetupChannelBox::SetupChannelBox(ChannelData *channel, bool existing) : Abstract _checkRequestId = MTP::send(MTPchannels_CheckUsername(_channel->inputChannel, MTP_string("preston")), RPCDoneHandlerPtr(), rpcFail(&SetupChannelBox::onFirstCheckFail)); _aboutPublicHeight = _aboutPublic.countHeight(_aboutPublicWidth); - setMaxHeight(st::boxPadding.top() + st::newGroupPadding.top() + _public.height() + _aboutPublicHeight + st::newGroupSkip + _private.height() + _aboutPrivate.countHeight(_aboutPublicWidth)/* + st::newGroupSkip + _comments.height() + _aboutComments.countHeight(_aboutPublicWidth)*/ + st::newGroupSkip + st::newGroupPadding.bottom() + st::newGroupLinkPadding.top() + _link.height() + st::newGroupLinkPadding.bottom() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom()); + updateMaxHeight(); connect(&_save, SIGNAL(clicked()), this, SLOT(onSave())); connect(&_skip, SIGNAL(clicked()), this, SLOT(onClose())); @@ -669,6 +669,14 @@ void SetupChannelBox::showDone() { _link.setFocus(); } +void SetupChannelBox::updateMaxHeight() { + if (!_channel->isMegagroup() || _public.checked()) { + setMaxHeight(st::boxPadding.top() + st::newGroupPadding.top() + _public.height() + _aboutPublicHeight + st::newGroupSkip + _private.height() + _aboutPrivate.countHeight(_aboutPublicWidth)/* + st::newGroupSkip + _comments.height() + _aboutComments.countHeight(_aboutPublicWidth)*/ + st::newGroupSkip + st::newGroupPadding.bottom() + st::newGroupLinkPadding.top() + _link.height() + st::newGroupLinkPadding.bottom() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom()); + } else { + setMaxHeight(st::boxPadding.top() + st::newGroupPadding.top() + _public.height() + _aboutPublicHeight + st::newGroupSkip + _private.height() + _aboutPrivate.countHeight(_aboutPublicWidth)/* + st::newGroupSkip + _comments.height() + _aboutComments.countHeight(_aboutPublicWidth)*/ + st::newGroupSkip + st::newGroupPadding.bottom() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom()); + } +} + void SetupChannelBox::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { if (_link.hasFocus()) { @@ -699,22 +707,26 @@ void SetupChannelBox::paintEvent(QPaintEvent *e) { //QRect aboutComments(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _comments.y() + _comments.height(), _aboutPublicWidth, _aboutPublicHeight); //_aboutComments.drawLeft(p, aboutComments.x(), aboutComments.y(), aboutComments.width(), width()); - p.setPen(st::black); - p.setFont(st::newGroupLinkFont); - p.drawTextLeft(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultInputField.textMargins.left(), _link.y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop, width(), lang(_link.isHidden() ? lng_create_group_invite_link : lng_create_group_link)); + if (!_channel->isMegagroup() || !_link.isHidden()) { + p.setPen(st::black); + p.setFont(st::newGroupLinkFont); + p.drawTextLeft(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultInputField.textMargins.left(), _link.y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop, width(), lang(_link.isHidden() ? lng_create_group_invite_link : lng_create_group_link)); + } if (_link.isHidden()) { - QTextOption option(style::al_left); - option.setWrapMode(QTextOption::WrapAnywhere); - p.setFont(_linkOver ? st::boxTextFont->underline() : st::boxTextFont); - p.setPen(st::btnDefLink.color); - p.drawText(_invitationLink, _channel->invitationUrl, option); - if (!_goodTextLink.isEmpty() && a_goodOpacity.current() > 0) { - p.setOpacity(a_goodOpacity.current()); - p.setPen(st::setGoodColor); - p.setFont(st::boxTextFont); - p.drawTextRight(st::boxPadding.right(), _link.y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop + st::newGroupLinkFont->ascent - st::boxTextFont->ascent, width(), _goodTextLink); - p.setOpacity(1); + if (!_channel->isMegagroup()) { + QTextOption option(style::al_left); + option.setWrapMode(QTextOption::WrapAnywhere); + p.setFont(_linkOver ? st::boxTextFont->underline() : st::boxTextFont); + p.setPen(st::btnDefLink.color); + p.drawText(_invitationLink, _channel->invitationUrl, option); + if (!_goodTextLink.isEmpty() && a_goodOpacity.current() > 0) { + p.setOpacity(a_goodOpacity.current()); + p.setPen(st::setGoodColor); + p.setFont(st::boxTextFont); + p.drawTextRight(st::boxPadding.right(), _link.y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop + st::newGroupLinkFont->ascent - st::boxTextFont->ascent, width(), _goodTextLink); + p.setOpacity(1); + } } } else { if (!_errorText.isEmpty()) { @@ -879,6 +891,9 @@ void SetupChannelBox::onPrivacyChange() { _link.hide(); setFocus(); } + if (_channel->isMegagroup()) { + updateMaxHeight(); + } update(); } @@ -1198,11 +1213,10 @@ void EditChannelBox::showAll() { _description.show(); _save.show(); _cancel.show(); + _publicLink.show(); if (_channel->isMegagroup()) { - _publicLink.hide(); _sign.hide(); } else { - _publicLink.show(); _sign.show(); } } @@ -1259,7 +1273,11 @@ void EditChannelBox::resizeEvent(QResizeEvent *e) { _sign.moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description.y() + _description.height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top()); - _publicLink.moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _sign.y() + _sign.height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top()); + if (_channel->isMegagroup()) { + _publicLink.moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description.y() + _description.height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top()); + } else { + _publicLink.moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _sign.y() + _sign.height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top()); + } _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); diff --git a/Telegram/SourceFiles/boxes/addcontactbox.h b/Telegram/SourceFiles/boxes/addcontactbox.h index 55e89f3e6..90e55311c 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.h +++ b/Telegram/SourceFiles/boxes/addcontactbox.h @@ -211,6 +211,8 @@ private: bool onCheckFail(const RPCError &error); bool onFirstCheckFail(const RPCError &error); + void updateMaxHeight(); + ChannelData *_channel; bool _existing; diff --git a/Telegram/SourceFiles/profilewidget.cpp b/Telegram/SourceFiles/profilewidget.cpp index ccc1f4a52..859dd7441 100644 --- a/Telegram/SourceFiles/profilewidget.cpp +++ b/Telegram/SourceFiles/profilewidget.cpp @@ -841,7 +841,7 @@ void ProfileInner::paintEvent(QPaintEvent *e) { addbyname = st::profileStatusTop + st::linkFont->ascent - (st::profileNameTop + st::profileNameFont->ascent); p.setPen(st::black->p); p.drawText(_left + st::profilePhotoSize + st::profileStatusLeft, top + st::profileStatusTop + st::linkFont->ascent, '@' + _peerUser->username); - } else if (_peerChannel && !_peerChannel->isMegagroup() && (_peerChannel->isPublic() || _amCreator )) { + } else if (_peerChannel && (_peerChannel->isPublic() || _amCreator)) { addbyname = st::profileStatusTop + st::linkFont->ascent - (st::profileNameTop + st::profileNameFont->ascent); } if (!_peerChannel || !_peerChannel->canViewParticipants() || _peerChannel->isMegagroup()) { @@ -1337,7 +1337,7 @@ void ProfileInner::resizeEvent(QResizeEvent *e) { // profile top += st::profilePadding.top(); int32 addbyname = 0; - if (_peerChannel && !_peerChannel->isMegagroup() && (_amCreator || _peerChannel->isPublic())) { + if (_peerChannel && (_amCreator || _peerChannel->isPublic())) { _username.move(_left + st::profilePhotoSize + st::profileStatusLeft, top + st::profileStatusTop); addbyname = st::profileStatusTop + st::linkFont->ascent - (st::profileNameTop + st::profileNameFont->ascent); } @@ -1711,7 +1711,7 @@ void ProfileInner::showAll() { } else { _deleteChannel.hide(); } - if (!_peerChannel->isMegagroup() && (_peerChannel->isPublic() || _amCreator)) { + if (_peerChannel->isPublic() || _amCreator) { _username.show(); } else { _username.hide();