From b79ddb7a1c1c66f41130eff39e4d5d3a5f27155b Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 10 Jul 2017 15:43:30 +0300 Subject: [PATCH] Handle click on userpic in edit admin/banned box. In admins/banned/restricted lists on row click the edit box is shown. Now click on the userpic in this box allows to get to user profile. --- Telegram/SourceFiles/boxes/boxes.style | 5 ++++- Telegram/SourceFiles/boxes/edit_participant_box.cpp | 11 +++++++---- Telegram/SourceFiles/ui/special_buttons.h | 4 ++-- Telegram/SourceFiles/ui/widgets/widgets.style | 5 +++++ Telegram/SourceFiles/window/window.style | 4 ---- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 5b86a78b8..162f3fd50 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -662,7 +662,10 @@ rightsDividerHeight: 11px; rightsHeaderMargin: margins(23px, 20px, 23px, 8px); rightsToggleMargin: margins(23px, 8px, 23px, 8px); rightsAboutMargin: margins(23px, 8px, 23px, 8px); -rightsPhotoSize: 60px; +rightsPhotoButton: PeerAvatarButton { + size: 60px; + photoSize: 60px; +} rightsPhotoMargin: margins(20px, 0px, 15px, 18px); rightsNameStyle: TextStyle(semiboldTextStyle) { font: font(15px semibold); diff --git a/Telegram/SourceFiles/boxes/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/edit_participant_box.cpp index 0e369d6c6..6666f9e64 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_participant_box.cpp @@ -26,6 +26,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/buttons.h" #include "styles/style_boxes.h" #include "styles/style_profile.h" +#include "ui/special_buttons.h" #include "boxes/calendar_box.h" namespace { @@ -118,6 +119,7 @@ private: gsl::not_null _channel; gsl::not_null _user; + object_ptr _userPhoto; Text _userName; bool _hasAdminRights = false; struct Control { @@ -131,8 +133,10 @@ private: EditParticipantBox::Inner::Inner(QWidget *parent, gsl::not_null channel, gsl::not_null user, bool hasAdminRights) : TWidget(parent) , _channel(channel) , _user(user) +, _userPhoto(this, _user, st::rightsPhotoButton) , _hasAdminRights(hasAdminRights) { _userName.setText(st::rightsNameStyle, App::peerName(_user), _textNameOptions); + _userPhoto->setClickedCallback([this] { Ui::showPeerProfile(_user); }); } void EditParticipantBox::Inner::removeControl(QPointer widget) { @@ -151,7 +155,8 @@ void EditParticipantBox::Inner::doAddControl(object_ptr widget, QMargin } int EditParticipantBox::Inner::resizeGetHeight(int newWidth) { - auto newHeight = st::rightsPhotoMargin.top() + st::rightsPhotoSize + st::rightsPhotoMargin.bottom(); + _userPhoto->moveToLeft(st::rightsPhotoMargin.left(), st::rightsPhotoMargin.top()); + auto newHeight = st::rightsPhotoMargin.top() + st::rightsPhotoButton.size + st::rightsPhotoMargin.bottom(); for (auto &&row : _rows) { auto rowWidth = newWidth - row.margin.left() - row.margin.right(); newHeight += row.margin.top(); @@ -167,10 +172,8 @@ void EditParticipantBox::Inner::paintEvent(QPaintEvent *e) { p.fillRect(e->rect(), st::boxBg); - _user->paintUserpicLeft(p, st::rightsPhotoMargin.left(), st::rightsPhotoMargin.top(), width(), st::rightsPhotoSize); - p.setPen(st::contactsNameFg); - auto namex = st::rightsPhotoMargin.left() + st::rightsPhotoSize + st::rightsPhotoMargin.right(); + auto namex = st::rightsPhotoMargin.left() + st::rightsPhotoButton.size + st::rightsPhotoMargin.right(); auto namew = width() - namex - st::rightsPhotoMargin.right(); _userName.drawLeftElided(p, namex, st::rightsPhotoMargin.top() + st::rightsNameTop, namew, width()); auto statusText = [this] { diff --git a/Telegram/SourceFiles/ui/special_buttons.h b/Telegram/SourceFiles/ui/special_buttons.h index 972a1c5e7..5f9d6c7b6 100644 --- a/Telegram/SourceFiles/ui/special_buttons.h +++ b/Telegram/SourceFiles/ui/special_buttons.h @@ -146,7 +146,7 @@ private: class PeerAvatarButton : public AbstractButton { public: - PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st); + PeerAvatarButton(QWidget *parent,PeerData *peer, const style::PeerAvatarButton &st); void setPeer(PeerData *peer) { _peer = peer; @@ -157,7 +157,7 @@ protected: void paintEvent(QPaintEvent *e) override; private: - PeerData *_peer; + PeerData *_peer = nullptr; const style::PeerAvatarButton &_st; }; diff --git a/Telegram/SourceFiles/ui/widgets/widgets.style b/Telegram/SourceFiles/ui/widgets/widgets.style index 14bc207d6..ccea3b47d 100644 --- a/Telegram/SourceFiles/ui/widgets/widgets.style +++ b/Telegram/SourceFiles/ui/widgets/widgets.style @@ -492,6 +492,11 @@ ImportantTooltip { duration: int; } +PeerAvatarButton { + size: pixels; + photoSize: pixels; +} + defaultLabelSimple: LabelSimple { font: normalFont; maxWidth: 0px; diff --git a/Telegram/SourceFiles/window/window.style b/Telegram/SourceFiles/window/window.style index c412ea71e..c3a553961 100644 --- a/Telegram/SourceFiles/window/window.style +++ b/Telegram/SourceFiles/window/window.style @@ -283,10 +283,6 @@ topBarMenuToggle: IconButton(topBarSearch) { } topBarActionSkip: 10px; -PeerAvatarButton { - size: pixels; - photoSize: pixels; -} topBarInfoButton: PeerAvatarButton { size: topBarHeight; photoSize: 42px;