2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

0.8.25.dev version with ipv6, bots profiles, keyboard and command autocomplete + elided text align fixed

This commit is contained in:
John Preston
2015-06-15 20:19:24 +03:00
parent 83744e77d1
commit 84c2a33c18
42 changed files with 1667 additions and 354 deletions

View File

@@ -39,9 +39,16 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, const Pee
_addParticipant(this, lang(lng_profile_add_participant), st::btnShareContact),
_sendMessage(this, lang(lng_profile_send_message), st::btnShareContact),
_shareContact(this, lang(lng_profile_share_contact), st::btnShareContact),
_inviteToGroup(this, lang(lng_profile_invite_to_group), st::btnShareContact),
_cancelPhoto(this, lang(lng_cancel)),
_createInvitationLink(this, lang(lng_group_invite_create)),
_invitationLink(this, qsl("telegram.me/joinchat/")),
_botSettings(this, lang(lng_profile_bot_settings)),
_botHelp(this, lang(lng_profile_bot_help)),
// about
_about(st::wndMinWidth - st::profilePadding.left() - st::profilePadding.right()),
_aboutTop(0), _aboutHeight(0),
a_photo(0),
_photoOver(false),
@@ -66,7 +73,7 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, const Pee
_menu(0) {
connect(App::api(), SIGNAL(fullPeerLoaded(PeerData*)), this, SLOT(onFullPeerLoaded(PeerData*)));
connect(App::api(), SIGNAL(fullPeerUpdated(PeerData*)), this, SLOT(onFullPeerUpdated(PeerData*)));
if (_peerUser) {
_phoneText = _peerUser->phone.isEmpty() ? QString() : App::formatPhone(_peerUser->phone);
@@ -87,12 +94,16 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, const Pee
connect(&_addParticipant, SIGNAL(clicked()), this, SLOT(onAddParticipant()));
connect(&_sendMessage, SIGNAL(clicked()), this, SLOT(onSendMessage()));
connect(&_shareContact, SIGNAL(clicked()), this, SLOT(onShareContact()));
connect(&_inviteToGroup, SIGNAL(clicked()), this, SLOT(onInviteToGroup()));
connect(&_cancelPhoto, SIGNAL(clicked()), this, SLOT(onUpdatePhotoCancel()));
connect(&_createInvitationLink, SIGNAL(clicked()), this, SLOT(onCreateInvitationLink()));
connect(&_invitationLink, SIGNAL(clicked()), this, SLOT(onInvitationLink()));
_invitationLink.setAcceptBoth(true);
updateInvitationLink();
connect(&_botSettings, SIGNAL(clicked()), this, SLOT(onBotSettings()));
connect(&_botHelp, SIGNAL(clicked()), this, SLOT(onBotHelp()));
connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUpdateDone(PeerId)));
connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUpdateFail(PeerId)));
@@ -100,6 +111,17 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, const Pee
connect(App::main(), SIGNAL(peerUpdated(PeerData *)), this, SLOT(peerUpdated(PeerData *)));
connect(App::main(), SIGNAL(peerNameChanged(PeerData *, const PeerData::Names &, const PeerData::NameFirstChars &)), this, SLOT(peerUpdated(PeerData *)));
// about
if (_peerUser && _peerUser->botInfo) {
if (!_peerUser->botInfo->shareText.isEmpty()) {
_about.setText(st::linkFont, _peerUser->botInfo->shareText, _historyBotOptions);
}
updateBotLinksVisibility();
} else {
_botSettings.hide();
_botHelp.hide();
}
// settings
connect(&_enableNotifications, SIGNAL(clicked()), this, SLOT(onEnableNotifications()));
connect(&_clearHistory, SIGNAL(clicked()), this, SLOT(onClearHistory()));
@@ -126,6 +148,10 @@ void ProfileInner::onShareContact() {
App::main()->shareContactLayer(_peerUser);
}
void ProfileInner::onInviteToGroup() {
App::wnd()->showLayer(new ContactsBox(_peerUser));
}
void ProfileInner::onSendMessage() {
App::main()->showPeer(_peer->id);
}
@@ -279,7 +305,7 @@ void ProfileInner::chatInviteDone(const MTPExportedChatInvite &result) {
App::wnd()->hideLayer();
}
void ProfileInner::onFullPeerLoaded(PeerData *peer) {
void ProfileInner::onFullPeerUpdated(PeerData *peer) {
if (peer != _peer) return;
if (_peerUser) {
PhotoData *userPhoto = _peerUser->photoId ? App::photo(_peerUser->photoId) : 0;
@@ -288,6 +314,15 @@ void ProfileInner::onFullPeerLoaded(PeerData *peer) {
} else {
_photoLink = TextLinkPtr();
}
if (_peerUser->botInfo) {
if (_peerUser->botInfo->shareText.isEmpty()) {
_about = Text(st::wndMinWidth - st::profilePadding.left() - st::profilePadding.right());
} else {
_about.setText(st::linkFont, _peerUser->botInfo->shareText, _historyBotOptions);
}
updateBotLinksVisibility();
resizeEvent(0);
}
} else if (_peerChat) {
updateInvitationLink();
showAll();
@@ -295,6 +330,30 @@ void ProfileInner::onFullPeerLoaded(PeerData *peer) {
}
}
void ProfileInner::onBotSettings() {
for (int32 i = 0, l = _peerUser->botInfo->commands.size(); i != l; ++i) {
QString cmd = _peerUser->botInfo->commands.at(i).command;
if (!cmd.compare(qsl("settings"), Qt::CaseInsensitive)) {
App::main()->showPeer(_peer->id);
App::main()->sendBotCommand('/' + cmd, 0);
return;
}
}
updateBotLinksVisibility();
}
void ProfileInner::onBotHelp() {
for (int32 i = 0, l = _peerUser->botInfo->commands.size(); i != l; ++i) {
QString cmd = _peerUser->botInfo->commands.at(i).command;
if (!cmd.compare(qsl("help"), Qt::CaseInsensitive)) {
App::main()->showPeer(_peer->id);
App::main()->sendBotCommand('/' + cmd, 0);
return;
}
}
updateBotLinksVisibility();
}
void ProfileInner::peerUpdated(PeerData *data) {
if (data == _peer) {
PhotoData *photo = 0;
@@ -446,7 +505,7 @@ void ProfileInner::paintEvent(QPaintEvent *e) {
if (!_errorText.isEmpty()) {
p.setFont(st::setErrFont->f);
p.setPen(st::setErrColor->p);
p.drawText(_left + st::profilePhotoSize + st::profilePhoneLeft, top + addbyname + st::profilePhoneTop + st::profilePhoneFont->ascent, _errorText);
p.drawText(_left + st::profilePhotoSize + st::profilePhoneLeft, _cancelPhoto.y() + addbyname + st::profilePhoneFont->ascent, _errorText);
}
if (!_phoneText.isEmpty()) {
p.setPen(st::black->p);
@@ -464,6 +523,17 @@ void ProfileInner::paintEvent(QPaintEvent *e) {
}
top += _shareContact.height();
// about
if (!_about.isEmpty()) {
p.setFont(st::profileHeaderFont->f);
p.setPen(st::profileHeaderColor->p);
p.drawText(_left + st::profileHeaderLeft, top + st::profileHeaderTop + st::profileHeaderFont->ascent, lang(lng_profile_about_section));
top += st::profileHeaderSkip;
_about.draw(p, _left, top, _width);
top += _aboutHeight;
}
// settings
p.setFont(st::profileHeaderFont->f);
p.setPen(st::profileHeaderColor->p);
@@ -537,7 +607,15 @@ void ProfileInner::paintEvent(QPaintEvent *e) {
if (!data) {
data = _participantsData[cnt] = new ParticipantData();
data->name.setText(st::profileListNameFont, user->name, _textNameOptions);
data->online = App::onlineText(user, l_time);
if (user->botInfo) {
if (user->botInfo->readsAllHistory) {
data->online = lang(lng_status_bot_reads_all);
} else {
data->online = lang(lng_status_bot_not_reads_all);
}
} else {
data->online = App::onlineText(user, l_time);
}
data->cankick = (user != App::self()) && (_chatAdmin || (_peerChat->cankick.constFind(user) != _peerChat->cankick.cend()));
}
p.setPen(st::profileListNameColor->p);
@@ -579,9 +657,9 @@ void ProfileInner::mouseMoveEvent(QMouseEvent *e) {
}
}
if (!_photoLink && (!_peerChat || _peerChat->forbidden)) {
setCursor((_kickOver || _kickDown) ? style::cur_pointer : style::cur_default);
setCursor((_kickOver || _kickDown || textlnkOver()) ? style::cur_pointer : style::cur_default);
} else {
setCursor((_kickOver || _kickDown || _photoOver) ? style::cur_pointer : style::cur_default);
setCursor((_kickOver || _kickDown || _photoOver || textlnkOver()) ? style::cur_pointer : style::cur_default);
}
}
@@ -590,6 +668,16 @@ void ProfileInner::updateSelected() {
QPoint lp = mapFromGlobal(_lastPos);
TextLinkPtr lnk;
bool inText = false;
if (!_about.isEmpty() && lp.y() >= _aboutTop && lp.y() < _aboutTop + _aboutHeight && lp.x() >= _left && lp.x() < _left + _width) {
_about.getState(lnk, inText, lp.x() - _left, lp.y() - _aboutTop, _width);
}
if (textlnkOver() != lnk) {
textlnkOver(lnk);
update(QRect(_left, _aboutTop, _width, _aboutHeight));
}
int32 partfrom = _mediaAudios.y() + _mediaAudios.height() + st::profileHeaderSkip;
int32 newSelected = (lp.x() >= _left - st::profileListPadding.width() && lp.x() < _left + _width + st::profileListPadding.width() && lp.y() >= partfrom) ? (lp.y() - partfrom) / _pHeight : -1;
@@ -631,18 +719,31 @@ void ProfileInner::mousePressEvent(QMouseEvent *e) {
onUpdatePhoto();
}
}
textlnkDown(textlnkOver());
}
}
void ProfileInner::mouseReleaseEvent(QMouseEvent *e) {
_lastPos = e->globalPos();
updateSelected();
if (_kickDown && _kickDown == _kickOver) {
_kickConfirm = _kickOver;
ConfirmBox *box = new ConfirmBox(lng_profile_sure_kick(lt_user, _kickOver->firstName));
connect(box, SIGNAL(confirmed()), this, SLOT(onKickConfirm()));
App::wnd()->showLayer(box);
}
if (textlnkDown()) {
TextLinkPtr lnk = textlnkDown();
textlnkDown(TextLinkPtr());
if (lnk == textlnkOver()) {
if (reBotCommand().match(lnk->encoded()).hasMatch()) {
App::main()->showPeer(_peer->id);
}
lnk->onClick(e->button());
}
}
_kickDown = 0;
setCursor(_kickOver ? style::cur_pointer : style::cur_default);
setCursor((_kickOver || textlnkOver()) ? style::cur_pointer : style::cur_default);
update();
}
@@ -697,6 +798,8 @@ void ProfileInner::resizeEvent(QResizeEvent *e) {
_cancelPhoto.move(_left + _width - _cancelPhoto.width(), top + st::profilePhotoSize - st::linkFont->height);
} else {
_cancelPhoto.move(_left + _width - _cancelPhoto.width(), top + st::profilePhoneTop);
_botSettings.move(_left + st::profilePhotoSize + st::profilePhoneLeft, top + st::profileStatusTop + st::linkFont->ascent - (st::profileNameTop + st::profileNameFont->ascent) + st::profilePhoneTop);
_botHelp.move(_botSettings.x() + (_botSettings.isHidden() ? 0 : _botSettings.width() + st::profilePhoneLeft), _botSettings.y());
}
top += st::profilePhotoSize;
@@ -705,8 +808,17 @@ void ProfileInner::resizeEvent(QResizeEvent *e) {
_sendMessage.setGeometry(_left, top, btnWidth, _sendMessage.height());
_addParticipant.setGeometry(_left + _width - btnWidth, top, btnWidth, _addParticipant.height());
_shareContact.setGeometry(_left + _width - btnWidth, top, btnWidth, _shareContact.height());
_inviteToGroup.setGeometry(_left + _width - btnWidth, top, btnWidth, _inviteToGroup.height());
top += _shareContact.height();
// about
if (!_about.isEmpty()) {
top += st::profileHeaderSkip;
_aboutTop = top; _aboutHeight = _about.countHeight(_width); top += _aboutHeight;
} else {
_aboutTop = _aboutHeight = 0;
}
// settings
top += st::profileHeaderSkip;
_enableNotifications.move(_left, top); top += _enableNotifications.height();
@@ -829,6 +941,7 @@ void ProfileInner::showAll() {
if (_peerChat) {
_sendMessage.hide();
_shareContact.hide();
_inviteToGroup.hide();
if (_peerChat->forbidden) {
_uploadPhoto.hide();
_cancelPhoto.hide();
@@ -871,8 +984,14 @@ void ProfileInner::showAll() {
_sendMessage.show();
if (_peerUser->phone.isEmpty()) {
_shareContact.hide();
if (_peerUser->botInfo && !_peerUser->botInfo->cantJoinGroups) {
_inviteToGroup.show();
} else {
_inviteToGroup.hide();
}
} else {
_shareContact.show();
_inviteToGroup.hide();
}
_enableNotifications.show();
_clearHistory.show();
@@ -944,6 +1063,23 @@ void ProfileInner::updateInvitationLink() {
}
}
void ProfileInner::updateBotLinksVisibility() {
if (!_peerUser || !_peerUser->botInfo || _peerUser->botInfo->commands.isEmpty()) {
_botSettings.hide();
_botHelp.hide();
return;
}
bool hasSettings = false, hasHelp = false;
for (int32 i = 0, l = _peerUser->botInfo->commands.size(); i != l; ++i) {
QString cmd = _peerUser->botInfo->commands.at(i).command;
hasSettings |= !cmd.compare(qsl("settings"), Qt::CaseInsensitive);
hasHelp |= !cmd.compare(qsl("help"), Qt::CaseInsensitive);
if (hasSettings && hasHelp) break;
}
_botSettings.setVisible(hasSettings);
_botHelp.setVisible(hasHelp);
}
QString ProfileInner::overviewLinkText(int32 type, int32 count) {
switch (type) {
case OverviewPhotos: return lng_profile_photos(lt_count, count);