mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-11 09:19:35 +00:00
Replace PeerAvatarButton with UserpicButton.
This commit is contained in:
parent
3d37ac9235
commit
830c6a4894
@ -663,8 +663,8 @@ rightsDividerHeight: 10px;
|
||||
rightsHeaderMargin: margins(23px, 20px, 23px, 8px);
|
||||
rightsToggleMargin: margins(23px, 8px, 23px, 8px);
|
||||
rightsAboutMargin: margins(23px, 8px, 23px, 8px);
|
||||
rightsPhotoButton: PeerAvatarButton {
|
||||
size: 60px;
|
||||
rightsPhotoButton: UserpicButton(defaultUserpicButton) {
|
||||
size: size(60px, 60px);
|
||||
photoSize: 60px;
|
||||
}
|
||||
rightsPhotoMargin: margins(20px, 0px, 15px, 18px);
|
||||
@ -685,8 +685,8 @@ rightsHeaderLabel: FlatLabel(boxLabel) {
|
||||
}
|
||||
rightsUntilMargin: margins(0px, 8px, 0px, 0px);
|
||||
|
||||
mutePhotoButton: PeerAvatarButton {
|
||||
size: 40px;
|
||||
mutePhotoButton: UserpicButton(defaultUserpicButton) {
|
||||
size: size(40px, 40px);
|
||||
photoSize: 40px;
|
||||
}
|
||||
muteChatTitle: FlatLabel(boxLabel) {
|
||||
|
@ -75,7 +75,12 @@ void ApplyDependencies(CheckboxesMap &checkboxes, DependenciesMap &dependencies,
|
||||
|
||||
class EditParticipantBox::Inner : public TWidget {
|
||||
public:
|
||||
Inner(QWidget *parent, not_null<ChannelData*> channel, not_null<UserData*> user, bool hasAdminRights);
|
||||
Inner(
|
||||
QWidget *parent,
|
||||
not_null<Window::Controller*> controller,
|
||||
not_null<ChannelData*> channel,
|
||||
not_null<UserData*> user,
|
||||
bool hasAdminRights);
|
||||
|
||||
template <typename Widget>
|
||||
QPointer<Widget> addControl(object_ptr<Widget> widget, QMargins margin) {
|
||||
@ -94,7 +99,7 @@ private:
|
||||
|
||||
not_null<ChannelData*> _channel;
|
||||
not_null<UserData*> _user;
|
||||
object_ptr<Ui::PeerAvatarButton> _userPhoto;
|
||||
object_ptr<Ui::UserpicButton> _userPhoto;
|
||||
Text _userName;
|
||||
bool _hasAdminRights = false;
|
||||
struct Control {
|
||||
@ -105,13 +110,24 @@ private:
|
||||
|
||||
};
|
||||
|
||||
EditParticipantBox::Inner::Inner(QWidget *parent, not_null<ChannelData*> channel, not_null<UserData*> user, bool hasAdminRights) : TWidget(parent)
|
||||
EditParticipantBox::Inner::Inner(
|
||||
QWidget *parent,
|
||||
not_null<Window::Controller*> controller,
|
||||
not_null<ChannelData*> channel,
|
||||
not_null<UserData*> user,
|
||||
bool hasAdminRights)
|
||||
: TWidget(parent)
|
||||
, _channel(channel)
|
||||
, _user(user)
|
||||
, _userPhoto(this, _user, st::rightsPhotoButton)
|
||||
, _userPhoto(
|
||||
this,
|
||||
controller,
|
||||
_user,
|
||||
Ui::UserpicButton::Role::Custom,
|
||||
st::rightsPhotoButton)
|
||||
, _hasAdminRights(hasAdminRights) {
|
||||
_userPhoto->setPointerCursor(false);
|
||||
_userName.setText(st::rightsNameStyle, App::peerName(_user), _textNameOptions);
|
||||
_userPhoto->setClickedCallback([this] { Ui::showPeerProfile(_user); });
|
||||
}
|
||||
|
||||
void EditParticipantBox::Inner::removeControl(QPointer<TWidget> widget) {
|
||||
@ -131,7 +147,9 @@ void EditParticipantBox::Inner::doAddControl(object_ptr<TWidget> widget, QMargin
|
||||
|
||||
int EditParticipantBox::Inner::resizeGetHeight(int newWidth) {
|
||||
_userPhoto->moveToLeft(st::rightsPhotoMargin.left(), st::rightsPhotoMargin.top());
|
||||
auto newHeight = st::rightsPhotoMargin.top() + st::rightsPhotoButton.size + st::rightsPhotoMargin.bottom();
|
||||
auto newHeight = st::rightsPhotoMargin.top()
|
||||
+ st::rightsPhotoButton.size.height()
|
||||
+ st::rightsPhotoMargin.bottom();
|
||||
for (auto &&row : _rows) {
|
||||
auto rowWidth = newWidth - row.margin.left() - row.margin.right();
|
||||
newHeight += row.margin.top();
|
||||
@ -148,7 +166,9 @@ void EditParticipantBox::Inner::paintEvent(QPaintEvent *e) {
|
||||
p.fillRect(e->rect(), st::boxBg);
|
||||
|
||||
p.setPen(st::contactsNameFg);
|
||||
auto namex = st::rightsPhotoMargin.left() + st::rightsPhotoButton.size + st::rightsPhotoMargin.right();
|
||||
auto namex = st::rightsPhotoMargin.left()
|
||||
+ st::rightsPhotoButton.size .width()
|
||||
+ st::rightsPhotoMargin.right();
|
||||
auto namew = width() - namex - st::rightsPhotoMargin.right();
|
||||
_userName.drawLeftElided(p, namex, st::rightsPhotoMargin.top() + st::rightsNameTop, namew, width());
|
||||
auto statusText = [this] {
|
||||
@ -170,7 +190,12 @@ EditParticipantBox::EditParticipantBox(QWidget*, not_null<ChannelData*> channel,
|
||||
}
|
||||
|
||||
void EditParticipantBox::prepare() {
|
||||
_inner = setInnerWidget(object_ptr<Inner>(this, _channel, _user, hasAdminRights()));
|
||||
_inner = setInnerWidget(object_ptr<Inner>(
|
||||
this,
|
||||
controller(),
|
||||
_channel,
|
||||
_user,
|
||||
hasAdminRights()));
|
||||
}
|
||||
|
||||
template <typename Widget>
|
||||
|
@ -23,7 +23,12 @@ void MuteSettingsBox::prepare() {
|
||||
info->moveToLeft(st::boxPadding.left(), y);
|
||||
y += info->height() + st::boxLittleSkip;
|
||||
|
||||
object_ptr<Ui::PeerAvatarButton> icon(this, _peer, st::mutePhotoButton);
|
||||
auto icon = object_ptr<Ui::UserpicButton>(
|
||||
this,
|
||||
controller(),
|
||||
_peer,
|
||||
Ui::UserpicButton::Role::Custom,
|
||||
st::mutePhotoButton);
|
||||
icon->setPointerCursor(false);
|
||||
icon->moveToLeft(st::boxPadding.left(), y);
|
||||
|
||||
|
@ -51,7 +51,6 @@ HistoryTopBarWidget::HistoryTopBarWidget(
|
||||
, _clearSelection(this, langFactory(lng_selected_clear), st::topBarClearButton)
|
||||
, _forward(this, langFactory(lng_selected_forward), st::defaultActiveButton)
|
||||
, _delete(this, langFactory(lng_selected_delete), st::defaultActiveButton)
|
||||
, _info(this, nullptr, st::topBarInfoButton)
|
||||
, _call(this, st::topBarCall)
|
||||
, _search(this, st::topBarSearch)
|
||||
, _infoToggle(this, st::topBarInfo)
|
||||
@ -64,7 +63,6 @@ HistoryTopBarWidget::HistoryTopBarWidget(
|
||||
_delete->setClickedCallback([this] { onDeleteSelection(); });
|
||||
_delete->setWidthChangedCallback([this] { updateControlsGeometry(); });
|
||||
_clearSelection->setClickedCallback([this] { onClearSelection(); });
|
||||
_info->setClickedCallback([this] { onInfoClicked(); });
|
||||
_call->setClickedCallback([this] { onCall(); });
|
||||
_search->setClickedCallback([this] { onSearch(); });
|
||||
_menuToggle->setClickedCallback([this] { showMenu(); });
|
||||
@ -256,7 +254,7 @@ void HistoryTopBarWidget::paintEvent(QPaintEvent *e) {
|
||||
|
||||
p.save();
|
||||
auto decreaseWidth = 0;
|
||||
if (!_info->isHidden()) {
|
||||
if (_info && !_info->isHidden()) {
|
||||
decreaseWidth += _info->width();
|
||||
}
|
||||
if (!_menuToggle->isHidden()) {
|
||||
@ -370,6 +368,25 @@ void HistoryTopBarWidget::clicked() {
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryTopBarWidget::setHistoryPeer(
|
||||
not_null<PeerData*> historyPeer) {
|
||||
if (_historyPeer != historyPeer) {
|
||||
_historyPeer = historyPeer;
|
||||
if (_historyPeer) {
|
||||
_info.create(
|
||||
this,
|
||||
_controller,
|
||||
_historyPeer,
|
||||
Ui::UserpicButton::Role::OpenProfile,
|
||||
st::topBarInfoButton);
|
||||
} else {
|
||||
_info.destroy();
|
||||
}
|
||||
updateOnlineDisplay();
|
||||
updateControlsVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryTopBarWidget::resizeEvent(QResizeEvent *e) {
|
||||
updateControlsGeometry();
|
||||
}
|
||||
@ -401,9 +418,11 @@ void HistoryTopBarWidget::updateControlsGeometry() {
|
||||
_clearSelection->moveToRight(st::topBarActionSkip, selectedButtonsTop);
|
||||
|
||||
auto right = 0;
|
||||
_info->moveToRight(right, otherButtonsTop);
|
||||
if (_info) {
|
||||
_info->moveToRight(right, otherButtonsTop);
|
||||
}
|
||||
_menuToggle->moveToRight(right, otherButtonsTop);
|
||||
if (_info->isHidden()) {
|
||||
if (!_info || _info->isHidden()) {
|
||||
right += _menuToggle->width() + st::topBarSkip;
|
||||
} else {
|
||||
right += _info->width();
|
||||
@ -427,32 +446,28 @@ void HistoryTopBarWidget::updateControlsVisibility() {
|
||||
_delete->setVisible(_canDelete);
|
||||
_forward->setVisible(_canForward);
|
||||
|
||||
if (_historyPeer) {
|
||||
if (Adaptive::OneColumn() || !App::main()->stackIsEmpty()) {
|
||||
_info->setPeer(_historyPeer);
|
||||
if (Adaptive::OneColumn()
|
||||
|| (App::main() && !App::main()->stackIsEmpty())) {
|
||||
if (_info) {
|
||||
_info->show();
|
||||
_menuToggle->hide();
|
||||
_menu.destroy();
|
||||
} else {
|
||||
_info->hide();
|
||||
_menuToggle->show();
|
||||
}
|
||||
_search->show();
|
||||
_infoToggle->setVisible(!Adaptive::OneColumn()
|
||||
&& _controller->canShowThirdSection());
|
||||
auto callsEnabled = false;
|
||||
if (auto user = _historyPeer->asUser()) {
|
||||
callsEnabled = Global::PhoneCallsEnabled() && user->hasCalls();
|
||||
}
|
||||
_call->setVisible(callsEnabled);
|
||||
} else {
|
||||
_search->hide();
|
||||
_call->hide();
|
||||
_info->hide();
|
||||
_menuToggle->hide();
|
||||
_infoToggle->hide();
|
||||
_menu.destroy();
|
||||
} else {
|
||||
if (_info) {
|
||||
_info->hide();
|
||||
}
|
||||
_menuToggle->show();
|
||||
}
|
||||
_search->show();
|
||||
_infoToggle->setVisible(!Adaptive::OneColumn()
|
||||
&& _controller->canShowThirdSection());
|
||||
auto callsEnabled = false;
|
||||
if (auto user = _historyPeer ? _historyPeer->asUser() : nullptr) {
|
||||
callsEnabled = Global::PhoneCallsEnabled() && user->hasCalls();
|
||||
}
|
||||
_call->setVisible(callsEnabled);
|
||||
|
||||
if (_membersShowArea) {
|
||||
_membersShowArea->show();
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "base/timer.h"
|
||||
|
||||
namespace Ui {
|
||||
class PeerAvatarButton;
|
||||
class UserpicButton;
|
||||
class RoundButton;
|
||||
class IconButton;
|
||||
class DropdownMenu;
|
||||
@ -54,9 +54,7 @@ public:
|
||||
return _membersShowAreaActive.events();
|
||||
}
|
||||
|
||||
void setHistoryPeer(not_null<PeerData*> historyPeer) {
|
||||
_historyPeer = historyPeer;
|
||||
}
|
||||
void setHistoryPeer(not_null<PeerData*> historyPeer);
|
||||
|
||||
void clicked();
|
||||
static void paintUnreadCounter(
|
||||
@ -107,7 +105,7 @@ private:
|
||||
object_ptr<Ui::RoundButton> _clearSelection;
|
||||
object_ptr<Ui::RoundButton> _forward, _delete;
|
||||
|
||||
object_ptr<Ui::PeerAvatarButton> _info;
|
||||
object_ptr<Ui::UserpicButton> _info = { nullptr };
|
||||
|
||||
object_ptr<Ui::IconButton> _call;
|
||||
object_ptr<Ui::IconButton> _search;
|
||||
|
@ -320,19 +320,6 @@ void SendButton::recordAnimationCallback() {
|
||||
}
|
||||
}
|
||||
|
||||
PeerAvatarButton::PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st) : AbstractButton(parent)
|
||||
, _peer(peer)
|
||||
, _st(st) {
|
||||
resize(_st.size, _st.size);
|
||||
}
|
||||
|
||||
void PeerAvatarButton::paintEvent(QPaintEvent *e) {
|
||||
if (_peer) {
|
||||
Painter p(this);
|
||||
_peer->paintUserpic(p, (_st.size - _st.photoSize) / 2, (_st.size - _st.photoSize) / 2, _st.photoSize);
|
||||
}
|
||||
}
|
||||
|
||||
UserpicButton::UserpicButton(
|
||||
QWidget *parent,
|
||||
PeerId peerForCrop,
|
||||
@ -587,17 +574,29 @@ void UserpicButton::processNewPeerPhoto() {
|
||||
}
|
||||
processPeerPhoto();
|
||||
if (!_waiting) {
|
||||
_oldUserpic = myGrab(this);
|
||||
grabOldUserpic();
|
||||
startNewPhotoShowing();
|
||||
}
|
||||
}
|
||||
|
||||
void UserpicButton::grabOldUserpic() {
|
||||
auto photoRect = QRect(
|
||||
countPhotoPosition(),
|
||||
QSize(_st.photoSize, _st.photoSize)
|
||||
);
|
||||
_oldUserpic = myGrab(this, photoRect);
|
||||
}
|
||||
|
||||
void UserpicButton::startNewPhotoShowing() {
|
||||
auto oldUniqueKey = _userpicUniqueKey;
|
||||
prepareUserpicPixmap();
|
||||
if (_notShownYet) {
|
||||
return;
|
||||
}
|
||||
startAnimation();
|
||||
if (oldUniqueKey != _userpicUniqueKey
|
||||
|| _a_appearance.animating()) {
|
||||
startAnimation();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
@ -611,7 +610,7 @@ void UserpicButton::switchChangePhotoOverlay(bool enabled) {
|
||||
}
|
||||
|
||||
void UserpicButton::setImage(QImage &&image) {
|
||||
_oldUserpic = myGrab(this);
|
||||
grabOldUserpic();
|
||||
|
||||
auto size = QSize(_st.photoSize, _st.photoSize);
|
||||
auto small = image.scaled(
|
||||
@ -648,6 +647,9 @@ void UserpicButton::prepareUserpicPixmap() {
|
||||
paintButton(p, _st.changeButton.textBg);
|
||||
}
|
||||
});
|
||||
_userpicUniqueKey = _userpicHasImage
|
||||
? _peer->userpicUniqueKey()
|
||||
: StorageKey();
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
@ -152,24 +152,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class PeerAvatarButton : public AbstractButton {
|
||||
public:
|
||||
PeerAvatarButton(QWidget *parent,PeerData *peer, const style::PeerAvatarButton &st);
|
||||
|
||||
void setPeer(PeerData *peer) {
|
||||
_peer = peer;
|
||||
update();
|
||||
}
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
private:
|
||||
PeerData *_peer = nullptr;
|
||||
const style::PeerAvatarButton &_st;
|
||||
|
||||
};
|
||||
|
||||
class UserpicButton : public RippleButton {
|
||||
public:
|
||||
enum class Role {
|
||||
@ -214,6 +196,7 @@ private:
|
||||
void prepareUserpicPixmap();
|
||||
QPoint countPhotoPosition() const;
|
||||
|
||||
void grabOldUserpic();
|
||||
void setClickHandlerByRole();
|
||||
void openPeerPhoto();
|
||||
void changePhotoLazy();
|
||||
@ -231,6 +214,7 @@ private:
|
||||
QPixmap _userpic, _oldUserpic;
|
||||
bool _userpicHasImage = false;
|
||||
bool _userpicCustom = false;
|
||||
StorageKey _userpicUniqueKey;
|
||||
Animation _a_appearance;
|
||||
QImage _result;
|
||||
|
||||
|
@ -492,11 +492,6 @@ ImportantTooltip {
|
||||
duration: int;
|
||||
}
|
||||
|
||||
PeerAvatarButton {
|
||||
size: pixels;
|
||||
photoSize: pixels;
|
||||
}
|
||||
|
||||
UserpicButton {
|
||||
size: size;
|
||||
photoSize: pixels;
|
||||
@ -985,12 +980,13 @@ defaultImportantTooltipLabel: FlatLabel(defaultFlatLabel) {
|
||||
}
|
||||
}
|
||||
|
||||
defaultChangeUserpicIcon: icon {{ "new_chat_photo", activeButtonFg }};
|
||||
defaultUserpicButton: UserpicButton {
|
||||
size: size(76px, 76px);
|
||||
photoSize: 76px;
|
||||
photoPosition: point(-1px, -1px);
|
||||
changeButton: defaultActiveButton;
|
||||
changeIcon: icon {{ "new_chat_photo", activeButtonFg }};
|
||||
changeIcon: defaultChangeUserpicIcon;
|
||||
changeIconPosition: point(23px, 25px);
|
||||
duration: 500;
|
||||
}
|
||||
|
@ -296,8 +296,8 @@ topBarMenuToggle: IconButton(topBarSearch) {
|
||||
}
|
||||
topBarActionSkip: 10px;
|
||||
|
||||
topBarInfoButton: PeerAvatarButton {
|
||||
size: topBarHeight;
|
||||
topBarInfoButton: UserpicButton(defaultUserpicButton) {
|
||||
size: size(topBarHeight, topBarHeight);
|
||||
photoSize: 42px;
|
||||
}
|
||||
topBarSlideDuration: 200;
|
||||
|
Loading…
Reference in New Issue
Block a user