From d08dbb835f747da38c897acfb4ffcf83f18ca610 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 3 Jul 2017 13:31:37 +0300 Subject: [PATCH] Paint admin stars with different color in profile. --- Telegram/Resources/colors.palette | 5 +++- Telegram/SourceFiles/profile/profile.style | 5 +++- .../profile/profile_block_group_members.cpp | 26 +++++++++++-------- .../profile/profile_block_peer_list.cpp | 9 ++++--- .../profile/profile_block_peer_list.h | 7 ++++- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Telegram/Resources/colors.palette b/Telegram/Resources/colors.palette index bdc7fe7156..ec28a02c4f 100644 --- a/Telegram/Resources/colors.palette +++ b/Telegram/Resources/colors.palette @@ -468,7 +468,10 @@ overviewPhotoSelectOverlay: #40ace333; // shared photos / videos / links fill fo profileStatusFgOver: #7c99b2; // group members list in group profile user last seen text with mouse over profileVerifiedCheckBg: windowBgActive; // profile verified check icon background profileVerifiedCheckFg: windowFgActive; // profile verified check icon tick -profileAdminStartFg: windowBgActive; // group members list admin star icon +profileAdminStartFg: windowBgActive; // group members list creator star icon +profileAdminStarFgOver: profileAdminStartFg; // group members list creator star icon with mouse over +profileOtherAdminStarFg: windowSubTextFg; // group members list admin star icon +profileOtherAdminStarFgOver: profileStatusFgOver; // group members list admin star icon with mouse over // settings notificationsBoxMonitorFg: windowFg; // custom notifications settings box monitor color diff --git a/Telegram/SourceFiles/profile/profile.style b/Telegram/SourceFiles/profile/profile.style index 6136624c0b..44c0bb89a5 100644 --- a/Telegram/SourceFiles/profile/profile.style +++ b/Telegram/SourceFiles/profile/profile.style @@ -132,7 +132,10 @@ profileMemberPhotoPosition: point(12px, 6px); profileMemberNamePosition: point(68px, 11px); profileMemberNameFg: windowBoldFg; profileMemberStatusPosition: point(68px, 31px); -profileMemberAdminIcon: icon {{ "profile_admin_star", profileAdminStartFg, point(4px, 3px) }}; +profileMemberCreatorIcon: icon {{ "profile_admin_star", profileAdminStartFg, point(4px, 3px) }}; +profileMemberCreatorIconOver: icon {{ "profile_admin_star", profileAdminStarFgOver, point(4px, 3px) }}; +profileMemberAdminIcon: icon {{ "profile_admin_star", profileOtherAdminStarFg, point(4px, 3px) }}; +profileMemberAdminIconOver: icon {{ "profile_admin_star", profileOtherAdminStarFgOver, point(4px, 3px) }}; profileLimitReachedLabel: FlatLabel(defaultFlatLabel) { width: 180px; margin: margins(profileMemberPaddingLeft, 9px, profileMemberPaddingLeft, 6px); diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index 5a224d9ca1..705e8dc279 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -209,7 +209,7 @@ Ui::PopupMenu *GroupMembersWidget::fillPeerMenu(PeerData *selectedPeer) { for_const (auto item, items()) { if (item->peer == selectedPeer) { auto canRemoveAdmin = [item, chat, channel] { - if (item->hasAdminStar && !item->peer->isSelf()) { + if ((item->adminState == Item::AdminState::Admin) && !item->peer->isSelf()) { if (chat) { // Adding of admins from context menu of chat participants // is not supported, so the removing is also disabled. @@ -222,7 +222,7 @@ Ui::PopupMenu *GroupMembersWidget::fillPeerMenu(PeerData *selectedPeer) { }; if (channel) { if (channel->canEditAdmin(user)) { - auto label = lang(item->hasAdminStar ? lng_context_edit_permissions : lng_context_promote_admin); + auto label = lang((item->adminState != Item::AdminState::None) ? lng_context_edit_permissions : lng_context_promote_admin); result->addAction(label, base::lambda_guarded(this, [this, user] { editAdmin(user); })); @@ -250,7 +250,7 @@ void GroupMembersWidget::updateItemStatusText(Item *item) { auto user = member->user(); if (member->statusText.isEmpty() || (member->onlineTextTill <= _now)) { if (user->botInfo) { - auto seesAllMessages = (user->botInfo->readsAllHistory || member->hasAdminStar); + auto seesAllMessages = (user->botInfo->readsAllHistory || (member->adminState != Item::AdminState::None)); member->statusText = lang(seesAllMessages ? lng_status_bot_reads_all : lng_status_bot_not_reads_all); member->onlineTextTill = _now + 86400; } else { @@ -390,15 +390,17 @@ void GroupMembersWidget::fillChatMembers(ChatData *chat) { } void GroupMembersWidget::setItemFlags(Item *item, ChatData *chat) { + using AdminState = Item::AdminState; auto user = getMember(item)->user(); auto isCreator = (peerFromUser(chat->creator) == item->peer->id); auto isAdmin = chat->admins.contains(user); - item->hasAdminStar = isCreator || isAdmin; + auto adminState = isCreator ? AdminState::Creator : isAdmin ? AdminState::Admin : AdminState::None; + item->adminState = adminState; if (item->peer->id == AuthSession::CurrentUserPeerId()) { item->hasRemoveLink = false; - } else if (chat->amCreator() || (chat->amAdmin() && !item->hasAdminStar)) { + } else if (chat->amCreator() || (chat->amAdmin() && (adminState == AdminState::None))) { item->hasRemoveLink = true; - } else if (chat->invitedByMe.contains(user) && !item->hasAdminStar) { + } else if (chat->invitedByMe.contains(user) && (adminState == AdminState::None)) { item->hasRemoveLink = true; } else { item->hasRemoveLink = false; @@ -462,14 +464,16 @@ bool GroupMembersWidget::addUsersToEnd(ChannelData *megagroup) { } void GroupMembersWidget::setItemFlags(Item *item, ChannelData *megagroup) { - auto amCreatorOrAdmin = item->peer->isSelf() && (megagroup->hasAdminRights() || megagroup->amCreator()); + using AdminState = Item::AdminState; + auto amCreator = item->peer->isSelf() && megagroup->amCreator(); + auto amAdmin = item->peer->isSelf() && megagroup->hasAdminRights(); auto adminIt = megagroup->mgInfo->lastAdmins.constFind(getMember(item)->user()); auto isAdmin = (adminIt != megagroup->mgInfo->lastAdmins.cend()); auto isCreator = megagroup->mgInfo->creator == item->peer; auto adminCanEdit = isAdmin && adminIt->canEdit; - auto hasAdminStar = amCreatorOrAdmin || isAdmin || isCreator; - if (item->hasAdminStar != hasAdminStar) { - item->hasAdminStar = hasAdminStar; + auto adminState = (amCreator || isCreator) ? AdminState::Creator : (amAdmin || isAdmin) ? AdminState::Admin : AdminState::None; + if (item->adminState != adminState) { + item->adminState = adminState; auto user = item->peer->asUser(); t_assert(user != nullptr); if (user->botInfo) { @@ -480,7 +484,7 @@ void GroupMembersWidget::setItemFlags(Item *item, ChannelData *megagroup) { } if (item->peer->isSelf()) { item->hasRemoveLink = false; - } else if (megagroup->amCreator() || (megagroup->canBanMembers() && (!item->hasAdminStar || adminCanEdit))) { + } else if (megagroup->amCreator() || megagroup->canBanMembers() && ((adminState == AdminState::None) || adminCanEdit)) { item->hasRemoveLink = true; } else { item->hasRemoveLink = false; diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index 1cde11dfe2..03416065d2 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -111,10 +111,13 @@ void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool select p.drawTextLeft(nameLeft + nameWidth - _removeWidth, nameTop, width(), _removeText, _removeWidth); nameWidth -= _removeWidth + skip; } - if (item->hasAdminStar) { + if (item->adminState != Item::AdminState::None) { nameWidth -= st::profileMemberAdminIcon.width(); - int iconLeft = nameLeft + qMin(nameWidth, item->name.maxWidth()); - st::profileMemberAdminIcon.paint(p, QPoint(iconLeft, nameTop), width()); + auto iconLeft = nameLeft + qMin(nameWidth, item->name.maxWidth()); + auto &icon = (item->adminState == Item::AdminState::Creator) + ? (selected ? st::profileMemberCreatorIconOver : st::profileMemberCreatorIcon) + : (selected ? st::profileMemberAdminIconOver : st::profileMemberAdminIcon); + icon.paint(p, QPoint(iconLeft, nameTop), width()); } p.setPen(st::profileMemberNameFg); item->name.drawLeftElided(p, nameLeft, nameTop, nameWidth, width()); diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.h b/Telegram/SourceFiles/profile/profile_block_peer_list.h index 73874de684..879c76be82 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.h +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.h @@ -48,7 +48,12 @@ public: Text name; QString statusText; bool statusHasOnlineColor = false; - bool hasAdminStar = false; + enum class AdminState { + None, + Admin, + Creator, + }; + AdminState adminState = AdminState::None; bool hasRemoveLink = false; std::unique_ptr ripple; };