CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, QString()) , _self(App::self()) , _userpicButton(this, _self) , _name(this, st::settingsNameLabel) , _editNameInline(this, QString(), st::settingsEditButton) , _setPhoto(this, lang(lng_settings_upload), st::settingsPrimaryButton) , _editName(this, lang(lng_settings_edit), st::settingsSecondaryButton) { setAcceptDrops(true); _name->setSelectable(true); _name->setContextCopyText(lang(lng_profile_copy_fullname)); _setPhoto->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_setPhoto, SIGNAL(clicked()), this, SLOT(onSetPhoto())); _editName->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_editName, SIGNAL(clicked()), this, SLOT(onEditName())); connect(_editNameInline, SIGNAL(clicked()), this, SLOT(onEditName())); auto observeEvents = Notify::PeerUpdate::Flag::NameChanged; Notify::registerPeerObserver(observeEvents, this, &CoverWidget::notifyPeerUpdated); FileDialog::registerObserver(this, &CoverWidget::notifyFileQueryUpdated); connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId))); connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId))); connect(_userpicButton, SIGNAL(clicked()), this, SLOT(onPhotoShow())); validatePhoto(); refreshNameText(); refreshStatusText(); }
void CoverWidget::showSetPhotoBox(const QImage &img) { if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) { Ui::show(Box<InformBox>(lang(lng_bad_photo))); return; } auto peer = _self; auto box = Ui::show(Box<PhotoCropBox>(img, peer)); box->ready( ) | rpl::start_with_next([=](QImage &&image) { Messenger::Instance().uploadProfilePhoto( std::move(image), peer->id); }, box->lifetime()); subscribe(box->boxClosing, [this] { onPhotoUploadStatusChanged(); }); }