mirror of
https://github.com/vale981/tdesktop
synced 2025-03-05 17:51:41 -05:00
Fix crop photo box title.
This commit is contained in:
parent
aa94ca6619
commit
8bd3051224
7 changed files with 38 additions and 43 deletions
|
@ -329,9 +329,9 @@ void GroupInfoBox::prepare() {
|
||||||
|
|
||||||
_photo.create(
|
_photo.create(
|
||||||
this,
|
this,
|
||||||
(_creating == CreatingGroupChannel)
|
lang((_creating == CreatingGroupChannel)
|
||||||
? peerFromChannel(0)
|
? lng_create_channel_crop
|
||||||
: peerFromChat(0),
|
: lng_create_group_crop),
|
||||||
Ui::UserpicButton::Role::ChangePhoto,
|
Ui::UserpicButton::Role::ChangePhoto,
|
||||||
st::defaultUserpicButton);
|
st::defaultUserpicButton);
|
||||||
_title.create(
|
_title.create(
|
||||||
|
|
|
@ -11,26 +11,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "styles/style_boxes.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)
|
: _img(img)
|
||||||
, _peerId(peer) {
|
, _title(title) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhotoCropBox::prepare() {
|
void PhotoCropBox::prepare() {
|
||||||
|
|
|
@ -11,8 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
class PhotoCropBox : public BoxContent {
|
class PhotoCropBox : public BoxContent {
|
||||||
public:
|
public:
|
||||||
PhotoCropBox(QWidget*, const QImage &img, const PeerId &peer);
|
PhotoCropBox(QWidget*, const QImage &img, const QString &title);
|
||||||
PhotoCropBox(QWidget*, const QImage &img, not_null<PeerData*> peer);
|
|
||||||
|
|
||||||
int32 mouseState(QPoint p);
|
int32 mouseState(QPoint p);
|
||||||
|
|
||||||
|
@ -28,7 +27,6 @@ protected:
|
||||||
void mouseMoveEvent(QMouseEvent *e) override;
|
void mouseMoveEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(const QImage &img, PeerData *peer);
|
|
||||||
void sendPhoto();
|
void sendPhoto();
|
||||||
|
|
||||||
QString _title;
|
QString _title;
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Intro {
|
||||||
SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, data)
|
SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, data)
|
||||||
, _photo(
|
, _photo(
|
||||||
this,
|
this,
|
||||||
peerFromUser(0),
|
lang(lng_settings_crop_profile),
|
||||||
Ui::UserpicButton::Role::ChangePhoto,
|
Ui::UserpicButton::Role::ChangePhoto,
|
||||||
st::defaultUserpicButton)
|
st::defaultUserpicButton)
|
||||||
, _first(this, st::introName, langFactory(lng_signup_firstname))
|
, _first(this, st::introName, langFactory(lng_signup_firstname))
|
||||||
|
|
|
@ -74,7 +74,8 @@ void SetupPhoto(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto box = Ui::show(Box<PhotoCropBox>(image, self));
|
const auto box = Ui::show(
|
||||||
|
Box<PhotoCropBox>(image, lang(lng_settings_crop_profile)));
|
||||||
box->ready(
|
box->ready(
|
||||||
) | rpl::start_with_next([=](QImage &&image) {
|
) | rpl::start_with_next([=](QImage &&image) {
|
||||||
Auth().api().uploadPeerPhoto(self, std::move(image));
|
Auth().api().uploadPeerPhoto(self, std::move(image));
|
||||||
|
|
|
@ -34,6 +34,16 @@ namespace {
|
||||||
|
|
||||||
constexpr int kWideScale = 5;
|
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>
|
template <typename Callback>
|
||||||
QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) {
|
QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) {
|
||||||
auto size = QSize(width, width) * cIntRetinaFactor();
|
auto size = QSize(width, width) * cIntRetinaFactor();
|
||||||
|
@ -50,7 +60,7 @@ QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) {
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
void SuggestPhoto(
|
void SuggestPhoto(
|
||||||
const QImage &image,
|
const QImage &image,
|
||||||
PeerId peerForCrop,
|
const QString &title,
|
||||||
Callback &&callback) {
|
Callback &&callback) {
|
||||||
auto badAspect = [](int a, int b) {
|
auto badAspect = [](int a, int b) {
|
||||||
return (a >= 10 * b);
|
return (a >= 10 * b);
|
||||||
|
@ -64,8 +74,8 @@ void SuggestPhoto(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto box = Ui::show(
|
const auto box = Ui::show(
|
||||||
Box<PhotoCropBox>(image, peerForCrop),
|
Box<PhotoCropBox>(image, title),
|
||||||
LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
box->ready(
|
box->ready(
|
||||||
) | rpl::start_with_next(
|
) | rpl::start_with_next(
|
||||||
|
@ -76,7 +86,7 @@ void SuggestPhoto(
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
void SuggestPhotoFile(
|
void SuggestPhotoFile(
|
||||||
const FileDialog::OpenResult &result,
|
const FileDialog::OpenResult &result,
|
||||||
PeerId peerForCrop,
|
const QString &title,
|
||||||
Callback &&callback) {
|
Callback &&callback) {
|
||||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -92,14 +102,14 @@ void SuggestPhotoFile(
|
||||||
}();
|
}();
|
||||||
SuggestPhoto(
|
SuggestPhoto(
|
||||||
image,
|
image,
|
||||||
peerForCrop,
|
title,
|
||||||
std::forward<Callback>(callback));
|
std::forward<Callback>(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
void ShowChoosePhotoBox(
|
void ShowChoosePhotoBox(
|
||||||
QPointer<QWidget> parent,
|
QPointer<QWidget> parent,
|
||||||
PeerId peerForCrop,
|
const QString &title,
|
||||||
Callback &&callback) {
|
Callback &&callback) {
|
||||||
auto imgExtensions = cImgExtensions();
|
auto imgExtensions = cImgExtensions();
|
||||||
auto filter = qsl("Image files (*")
|
auto filter = qsl("Image files (*")
|
||||||
|
@ -107,10 +117,10 @@ void ShowChoosePhotoBox(
|
||||||
+ qsl(");;")
|
+ qsl(");;")
|
||||||
+ FileDialog::AllFilesFilter();
|
+ FileDialog::AllFilesFilter();
|
||||||
auto handleChosenPhoto = [
|
auto handleChosenPhoto = [
|
||||||
peerForCrop,
|
title,
|
||||||
callback = std::forward<Callback>(callback)
|
callback = std::forward<Callback>(callback)
|
||||||
](auto &&result) mutable {
|
](auto &&result) mutable {
|
||||||
SuggestPhotoFile(result, peerForCrop, std::move(callback));
|
SuggestPhotoFile(result, title, std::move(callback));
|
||||||
};
|
};
|
||||||
FileDialog::GetOpenPath(
|
FileDialog::GetOpenPath(
|
||||||
parent,
|
parent,
|
||||||
|
@ -426,12 +436,12 @@ void SendButton::recordAnimationCallback() {
|
||||||
|
|
||||||
UserpicButton::UserpicButton(
|
UserpicButton::UserpicButton(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
PeerId peerForCrop,
|
const QString &cropTitle,
|
||||||
Role role,
|
Role role,
|
||||||
const style::UserpicButton &st)
|
const style::UserpicButton &st)
|
||||||
: RippleButton(parent, st.changeButton.ripple)
|
: RippleButton(parent, st.changeButton.ripple)
|
||||||
, _st(st)
|
, _st(st)
|
||||||
, _peerForCrop(peerForCrop)
|
, _cropTitle(cropTitle)
|
||||||
, _role(role) {
|
, _role(role) {
|
||||||
Expects(_role == Role::ChangePhoto);
|
Expects(_role == Role::ChangePhoto);
|
||||||
|
|
||||||
|
@ -449,7 +459,7 @@ UserpicButton::UserpicButton(
|
||||||
, _st(st)
|
, _st(st)
|
||||||
, _controller(controller)
|
, _controller(controller)
|
||||||
, _peer(peer)
|
, _peer(peer)
|
||||||
, _peerForCrop(_peer->id)
|
, _cropTitle(CropTitle(_peer))
|
||||||
, _role(role) {
|
, _role(role) {
|
||||||
processPeerPhoto();
|
processPeerPhoto();
|
||||||
prepare();
|
prepare();
|
||||||
|
@ -464,7 +474,7 @@ UserpicButton::UserpicButton(
|
||||||
: RippleButton(parent, st.changeButton.ripple)
|
: RippleButton(parent, st.changeButton.ripple)
|
||||||
, _st(st)
|
, _st(st)
|
||||||
, _peer(peer)
|
, _peer(peer)
|
||||||
, _peerForCrop(_peer->id)
|
, _cropTitle(CropTitle(_peer))
|
||||||
, _role(role) {
|
, _role(role) {
|
||||||
Expects(_role != Role::OpenProfile);
|
Expects(_role != Role::OpenProfile);
|
||||||
|
|
||||||
|
@ -510,14 +520,14 @@ void UserpicButton::changePhotoLazy() {
|
||||||
auto callback = crl::guard(
|
auto callback = crl::guard(
|
||||||
this,
|
this,
|
||||||
[this](QImage &&image) { setImage(std::move(image)); });
|
[this](QImage &&image) { setImage(std::move(image)); });
|
||||||
ShowChoosePhotoBox(this, _peerForCrop, std::move(callback));
|
ShowChoosePhotoBox(this, _cropTitle, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserpicButton::uploadNewPeerPhoto() {
|
void UserpicButton::uploadNewPeerPhoto() {
|
||||||
auto callback = crl::guard(this, [=](QImage &&image) {
|
auto callback = crl::guard(this, [=](QImage &&image) {
|
||||||
Auth().api().uploadPeerPhoto(_peer, std::move(image));
|
Auth().api().uploadPeerPhoto(_peer, std::move(image));
|
||||||
});
|
});
|
||||||
ShowChoosePhotoBox(this, _peerForCrop, std::move(callback));
|
ShowChoosePhotoBox(this, _cropTitle, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserpicButton::openPeerPhoto() {
|
void UserpicButton::openPeerPhoto() {
|
||||||
|
|
|
@ -149,7 +149,7 @@ public:
|
||||||
|
|
||||||
UserpicButton(
|
UserpicButton(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
PeerId peerForCrop,
|
const QString &cropTitle,
|
||||||
Role role,
|
Role role,
|
||||||
const style::UserpicButton &st);
|
const style::UserpicButton &st);
|
||||||
UserpicButton(
|
UserpicButton(
|
||||||
|
@ -206,7 +206,7 @@ private:
|
||||||
const style::UserpicButton &_st;
|
const style::UserpicButton &_st;
|
||||||
Window::Controller *_controller = nullptr;
|
Window::Controller *_controller = nullptr;
|
||||||
PeerData *_peer = nullptr;
|
PeerData *_peer = nullptr;
|
||||||
PeerId _peerForCrop = 0;
|
QString _cropTitle;
|
||||||
Role _role = Role::ChangePhoto;
|
Role _role = Role::ChangePhoto;
|
||||||
bool _notShownYet = true;
|
bool _notShownYet = true;
|
||||||
bool _waiting = false;
|
bool _waiting = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue