Fix crop photo box title.

This commit is contained in:
John Preston 2018-12-23 21:23:36 +04:00
parent aa94ca6619
commit 8bd3051224
7 changed files with 38 additions and 43 deletions

View File

@ -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(

View File

@ -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<PeerData*> 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() {

View File

@ -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<PeerData*> 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;

View File

@ -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))

View File

@ -74,7 +74,8 @@ void SetupPhoto(
return;
}
auto box = Ui::show(Box<PhotoCropBox>(image, self));
const auto box = Ui::show(
Box<PhotoCropBox>(image, lang(lng_settings_crop_profile)));
box->ready(
) | rpl::start_with_next([=](QImage &&image) {
Auth().api().uploadPeerPhoto(self, std::move(image));

View File

@ -34,6 +34,16 @@ namespace {
constexpr int kWideScale = 5;
QString CropTitle(not_null<PeerData*> 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 <typename Callback>
QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) {
auto size = QSize(width, width) * cIntRetinaFactor();
@ -50,7 +60,7 @@ QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) {
template <typename Callback>
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<PhotoCropBox>(image, peerForCrop),
const auto box = Ui::show(
Box<PhotoCropBox>(image, title),
LayerOption::KeepOther);
box->ready(
) | rpl::start_with_next(
@ -76,7 +86,7 @@ void SuggestPhoto(
template <typename Callback>
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>(callback));
}
template <typename Callback>
void ShowChoosePhotoBox(
QPointer<QWidget> 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>(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() {

View File

@ -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;