From 8bd30512243024894db7781532aed79c80ef7ca7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 23 Dec 2018 21:23:36 +0400 Subject: [PATCH] Fix crop photo box title. --- .../SourceFiles/boxes/add_contact_box.cpp | 6 +-- Telegram/SourceFiles/boxes/photo_crop_box.cpp | 24 +++--------- Telegram/SourceFiles/boxes/photo_crop_box.h | 4 +- Telegram/SourceFiles/intro/introsignup.cpp | 2 +- .../settings/settings_information.cpp | 3 +- Telegram/SourceFiles/ui/special_buttons.cpp | 38 ++++++++++++------- Telegram/SourceFiles/ui/special_buttons.h | 4 +- 7 files changed, 38 insertions(+), 43 deletions(-) diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 569a910b32..b5ddda9ddb 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -329,9 +329,9 @@ void GroupInfoBox::prepare() { _photo.create( this, - (_creating == CreatingGroupChannel) - ? peerFromChannel(0) - : peerFromChat(0), + lang((_creating == CreatingGroupChannel) + ? lng_create_channel_crop + : lng_create_group_crop), Ui::UserpicButton::Role::ChangePhoto, st::defaultUserpicButton); _title.create( diff --git a/Telegram/SourceFiles/boxes/photo_crop_box.cpp b/Telegram/SourceFiles/boxes/photo_crop_box.cpp index 3047221fbb..434f7496b5 100644 --- a/Telegram/SourceFiles/boxes/photo_crop_box.cpp +++ b/Telegram/SourceFiles/boxes/photo_crop_box.cpp @@ -11,26 +11,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "styles/style_boxes.h" -PhotoCropBox::PhotoCropBox(QWidget*, const QImage &img, const PeerId &peer) +PhotoCropBox::PhotoCropBox( + QWidget*, + const QImage &img, + const QString &title) : _img(img) -, _peerId(peer) { - init(img, nullptr); -} - -PhotoCropBox::PhotoCropBox(QWidget*, const QImage &img, not_null peer) -: _img(img) -, _peerId(peer->id) { - init(img, peer); -} - -void PhotoCropBox::init(const QImage &img, PeerData *peer) { - if (peerIsChat(_peerId) || (peer && peer->isMegagroup())) { - _title = lang(lng_create_group_crop); - } else if (peerIsChannel(_peerId)) { - _title = lang(lng_create_channel_crop); - } else { - _title = lang(lng_settings_crop_profile); - } +, _title(title) { } void PhotoCropBox::prepare() { diff --git a/Telegram/SourceFiles/boxes/photo_crop_box.h b/Telegram/SourceFiles/boxes/photo_crop_box.h index 19e9f83f3d..251cf4f00a 100644 --- a/Telegram/SourceFiles/boxes/photo_crop_box.h +++ b/Telegram/SourceFiles/boxes/photo_crop_box.h @@ -11,8 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class PhotoCropBox : public BoxContent { public: - PhotoCropBox(QWidget*, const QImage &img, const PeerId &peer); - PhotoCropBox(QWidget*, const QImage &img, not_null peer); + PhotoCropBox(QWidget*, const QImage &img, const QString &title); int32 mouseState(QPoint p); @@ -28,7 +27,6 @@ protected: void mouseMoveEvent(QMouseEvent *e) override; private: - void init(const QImage &img, PeerData *peer); void sendPhoto(); QString _title; diff --git a/Telegram/SourceFiles/intro/introsignup.cpp b/Telegram/SourceFiles/intro/introsignup.cpp index 16492d0ae4..0b5ba98494 100644 --- a/Telegram/SourceFiles/intro/introsignup.cpp +++ b/Telegram/SourceFiles/intro/introsignup.cpp @@ -24,7 +24,7 @@ namespace Intro { SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, data) , _photo( this, - peerFromUser(0), + lang(lng_settings_crop_profile), Ui::UserpicButton::Role::ChangePhoto, st::defaultUserpicButton) , _first(this, st::introName, langFactory(lng_signup_firstname)) diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index b3ec4d46bf..b8212a34b9 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -74,7 +74,8 @@ void SetupPhoto( return; } - auto box = Ui::show(Box(image, self)); + const auto box = Ui::show( + Box(image, lang(lng_settings_crop_profile))); box->ready( ) | rpl::start_with_next([=](QImage &&image) { Auth().api().uploadPeerPhoto(self, std::move(image)); diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index 888840ee9d..a25116ad33 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -34,6 +34,16 @@ namespace { constexpr int kWideScale = 5; +QString CropTitle(not_null peer) { + if (peer->isChat() || peer->isMegagroup()) { + return lang(lng_create_group_crop); + } else if (peer->isChannel()) { + return lang(lng_create_channel_crop); + } else { + return lang(lng_settings_crop_profile); + } +} + template QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) { auto size = QSize(width, width) * cIntRetinaFactor(); @@ -50,7 +60,7 @@ QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) { template void SuggestPhoto( const QImage &image, - PeerId peerForCrop, + const QString &title, Callback &&callback) { auto badAspect = [](int a, int b) { return (a >= 10 * b); @@ -64,8 +74,8 @@ void SuggestPhoto( return; } - auto box = Ui::show( - Box(image, peerForCrop), + const auto box = Ui::show( + Box(image, title), LayerOption::KeepOther); box->ready( ) | rpl::start_with_next( @@ -76,7 +86,7 @@ void SuggestPhoto( template void SuggestPhotoFile( const FileDialog::OpenResult &result, - PeerId peerForCrop, + const QString &title, Callback &&callback) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { return; @@ -92,14 +102,14 @@ void SuggestPhotoFile( }(); SuggestPhoto( image, - peerForCrop, + title, std::forward(callback)); } template void ShowChoosePhotoBox( QPointer parent, - PeerId peerForCrop, + const QString &title, Callback &&callback) { auto imgExtensions = cImgExtensions(); auto filter = qsl("Image files (*") @@ -107,10 +117,10 @@ void ShowChoosePhotoBox( + qsl(");;") + FileDialog::AllFilesFilter(); auto handleChosenPhoto = [ - peerForCrop, + title, callback = std::forward(callback) ](auto &&result) mutable { - SuggestPhotoFile(result, peerForCrop, std::move(callback)); + SuggestPhotoFile(result, title, std::move(callback)); }; FileDialog::GetOpenPath( parent, @@ -426,12 +436,12 @@ void SendButton::recordAnimationCallback() { UserpicButton::UserpicButton( QWidget *parent, - PeerId peerForCrop, + const QString &cropTitle, Role role, const style::UserpicButton &st) : RippleButton(parent, st.changeButton.ripple) , _st(st) -, _peerForCrop(peerForCrop) +, _cropTitle(cropTitle) , _role(role) { Expects(_role == Role::ChangePhoto); @@ -449,7 +459,7 @@ UserpicButton::UserpicButton( , _st(st) , _controller(controller) , _peer(peer) -, _peerForCrop(_peer->id) +, _cropTitle(CropTitle(_peer)) , _role(role) { processPeerPhoto(); prepare(); @@ -464,7 +474,7 @@ UserpicButton::UserpicButton( : RippleButton(parent, st.changeButton.ripple) , _st(st) , _peer(peer) -, _peerForCrop(_peer->id) +, _cropTitle(CropTitle(_peer)) , _role(role) { Expects(_role != Role::OpenProfile); @@ -510,14 +520,14 @@ void UserpicButton::changePhotoLazy() { auto callback = crl::guard( this, [this](QImage &&image) { setImage(std::move(image)); }); - ShowChoosePhotoBox(this, _peerForCrop, std::move(callback)); + ShowChoosePhotoBox(this, _cropTitle, std::move(callback)); } void UserpicButton::uploadNewPeerPhoto() { auto callback = crl::guard(this, [=](QImage &&image) { Auth().api().uploadPeerPhoto(_peer, std::move(image)); }); - ShowChoosePhotoBox(this, _peerForCrop, std::move(callback)); + ShowChoosePhotoBox(this, _cropTitle, std::move(callback)); } void UserpicButton::openPeerPhoto() { diff --git a/Telegram/SourceFiles/ui/special_buttons.h b/Telegram/SourceFiles/ui/special_buttons.h index 0a4b3c3e69..342e6a9ddb 100644 --- a/Telegram/SourceFiles/ui/special_buttons.h +++ b/Telegram/SourceFiles/ui/special_buttons.h @@ -149,7 +149,7 @@ public: UserpicButton( QWidget *parent, - PeerId peerForCrop, + const QString &cropTitle, Role role, const style::UserpicButton &st); UserpicButton( @@ -206,7 +206,7 @@ private: const style::UserpicButton &_st; Window::Controller *_controller = nullptr; PeerData *_peer = nullptr; - PeerId _peerForCrop = 0; + QString _cropTitle; Role _role = Role::ChangePhoto; bool _notShownYet = true; bool _waiting = false;