From 8dd3f24285f7d8f50ee5aa93fc664106801e07d2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 13 Nov 2017 19:50:10 +0400 Subject: [PATCH] Replace Profile::UserpicButton with one from Ui:: --- Telegram/SourceFiles/info/info.style | 5 +++- .../info/profile/info_profile_cover.cpp | 17 ++++++++++--- .../info/profile/info_profile_cover.h | 16 +++++++----- .../profile/info_profile_inner_widget.cpp | 1 + Telegram/SourceFiles/settings/settings.style | 5 +++- .../SourceFiles/settings/settings_cover.cpp | 18 +++++++------ .../SourceFiles/settings/settings_cover.h | 6 ++--- .../settings/settings_inner_widget.cpp | 10 -------- .../settings/settings_inner_widget.h | 3 --- .../SourceFiles/settings/settings_widget.cpp | 4 --- .../SourceFiles/settings/settings_widget.h | 1 - Telegram/SourceFiles/window/layer_widget.cpp | 5 +--- Telegram/SourceFiles/window/window.style | 5 +++- .../SourceFiles/window/window_main_menu.cpp | 25 +++++++++---------- .../SourceFiles/window/window_main_menu.h | 14 +++++------ 15 files changed, 67 insertions(+), 68 deletions(-) diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index 6268268c2e..ec5cc41f77 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -251,7 +251,10 @@ infoTabs: SettingsSlider(defaultTabsSlider) { labelTop: 19px; } -infoProfilePhotoSize: 72px; +infoProfilePhoto: UserpicButton(defaultUserpicButton) { + size: size(72px, 72px); + photoSize: 72px; +} infoProfilePhotoLeft: 19px; infoProfilePhotoTop: 18px; infoProfilePhotoBottom: 18px; diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index cb61194c87..4d03403c21 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -24,15 +24,16 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include #include "data/data_photo.h" #include "info/profile/info_profile_values.h" +#include "info/info_controller.h" #include "lang/lang_keys.h" #include "styles/style_info.h" #include "ui/widgets/labels.h" #include "ui/effects/ripple_animation.h" +#include "ui/special_buttons.h" #include "observer_peer.h" #include "messenger.h" #include "auth_session.h" #include "apiwrap.h" -#include "profile/profile_userpic_button.h" namespace Info { namespace Profile { @@ -218,14 +219,22 @@ int SectionWithToggle::toggleSkip() const { + _toggle->checkRect().width(); } -Cover::Cover(QWidget *parent, not_null peer) +Cover::Cover( + QWidget *parent, + not_null controller, + not_null peer) : SectionWithToggle( parent, st::infoProfilePhotoTop - + st::infoProfilePhotoSize + + st::infoProfilePhoto.size.height() + st::infoProfilePhotoBottom) , _peer(peer) -, _userpic(this, _peer, st::infoProfilePhotoSize) +, _userpic( + this, + controller->window(), + _peer, + Ui::UserpicButton::Role::OpenPhoto, + st::infoProfilePhoto) , _name(this, st::infoProfileNameLabel) , _status(this, st::infoProfileStatusLabel) { _peer->updateFull(); diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.h b/Telegram/SourceFiles/info/profile/info_profile_cover.h index b157c5fe67..302fb83ffd 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.h +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.h @@ -27,16 +27,17 @@ namespace style { struct InfoToggle; } // namespace style -namespace Profile { -class UserpicButton; -} // namespace Profile - namespace Ui { +class UserpicButton; class FlatLabel; template class SlideWrap; } // namespace Ui +namespace Info { +class Controller; +} // namespace Info + namespace Info { namespace Profile { @@ -61,7 +62,10 @@ private: class Cover : public SectionWithToggle { public: - Cover(QWidget *parent, not_null peer); + Cover( + QWidget *parent, + not_null controller, + not_null peer); Cover *setOnlineCount(rpl::producer &&count); @@ -86,7 +90,7 @@ private: not_null _peer; int _onlineCount = 0; - object_ptr<::Profile::UserpicButton> _userpic; + object_ptr _userpic; object_ptr _name = { nullptr }; object_ptr _verifiedCheck = { nullptr }; object_ptr _status = { nullptr }; diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp index e3446e97b2..ad1d011ca0 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp @@ -89,6 +89,7 @@ object_ptr InnerWidget::setupContent( auto result = object_ptr(parent); _cover = result->add(object_ptr( result, + _controller, _peer)); _cover->setOnlineCount(rpl::single(0)); auto details = SetupDetails(_controller, parent, _peer); diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index c8a3addccc..38b35dab91 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -42,7 +42,10 @@ settingsFixedBarClose: IconButton(boxTitleClose) { } settingsMarginTop: 34px; -settingsPhotoSize: 112px; +settingsPhoto: UserpicButton(defaultUserpicButton) { + size: size(112px, 112px); + photoSize: 112px; +} settingsPhotoLeft: -8px; settingsPhotoDuration: 500; settingsNameLeft: 26px; diff --git a/Telegram/SourceFiles/settings/settings_cover.cpp b/Telegram/SourceFiles/settings/settings_cover.cpp index 97e1e63083..452b11ddb2 100644 --- a/Telegram/SourceFiles/settings/settings_cover.cpp +++ b/Telegram/SourceFiles/settings/settings_cover.cpp @@ -23,13 +23,13 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "data/data_photo.h" #include "ui/widgets/labels.h" #include "ui/widgets/buttons.h" +#include "ui/special_buttons.h" #include "observer_peer.h" #include "lang/lang_keys.h" #include "messenger.h" #include "mainwindow.h" #include "apiwrap.h" #include "auth_session.h" -#include "profile/profile_userpic_button.h" #include "profile/profile_cover_drop_area.h" #include "boxes/confirm_box.h" #include "boxes/photo_crop_box.h" @@ -40,9 +40,15 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Settings { -CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, QString()) +CoverWidget::CoverWidget(QWidget *parent, UserData *self) +: BlockWidget(parent, self, QString()) , _self(App::self()) -, _userpicButton(this, _self) +, _userpicButton( + this, + App::wnd()->controller(), + _self, + Ui::UserpicButton::Role::OpenPhoto, + st::settingsPhoto) , _name(this, st::settingsNameLabel) , _editNameInline(this, st::settingsEditButton) , _setPhoto(this, langFactory(lng_settings_upload), st::settingsPrimaryButton) @@ -123,7 +129,7 @@ int CoverWidget::resizeGetHeight(int newWidth) { refreshButtonsGeometry(newWidth); refreshNameGeometry(newWidth); - newHeight += st::settingsPhotoSize; + newHeight += st::settingsPhoto.size.height(); newHeight += st::settingsMarginBottom; _dividerTop = newHeight; @@ -175,10 +181,6 @@ void CoverWidget::refreshNameGeometry(int newWidth) { _editNameInline->setVisible(editNameInlineVisible); } -void CoverWidget::showFinished() { - _userpicButton->showFinished(); -} - void CoverWidget::paintContents(Painter &p) { p.setFont(st::settingsStatusFont); p.setPen(_statusTextIsOnline ? st::settingsStatusFgActive : st::settingsStatusFg); diff --git a/Telegram/SourceFiles/settings/settings_cover.h b/Telegram/SourceFiles/settings/settings_cover.h index cd4ff3d34a..9a3e8f8ec8 100644 --- a/Telegram/SourceFiles/settings/settings_cover.h +++ b/Telegram/SourceFiles/settings/settings_cover.h @@ -27,6 +27,7 @@ namespace Ui { class FlatLabel; class RoundButton; class IconButton; +class UserpicButton; } // namespace Ui namespace Notify { @@ -34,7 +35,6 @@ struct PeerUpdate; } // namespace Notify namespace Profile { -class UserpicButton; class CoverDropArea; } // namespace Profile @@ -46,8 +46,6 @@ class CoverWidget : public BlockWidget { public: CoverWidget(QWidget *parent, UserData *self); - void showFinished(); - private slots: void onPhotoShow(); void onPhotoUploadStatusChanged(PeerId peerId = 0); @@ -86,7 +84,7 @@ private: UserData *_self; - object_ptr _userpicButton; + object_ptr _userpicButton; object_ptr _dropArea = { nullptr }; object_ptr _name; diff --git a/Telegram/SourceFiles/settings/settings_inner_widget.cpp b/Telegram/SourceFiles/settings/settings_inner_widget.cpp index 7f427b044a..5b1f7e413f 100644 --- a/Telegram/SourceFiles/settings/settings_inner_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_inner_widget.cpp @@ -77,9 +77,6 @@ void InnerWidget::refreshBlocks() { if (_cover) { _cover->show(); - if (_showFinished) { - _cover->showFinished(); - } } _blocks->show(); _blocks->heightValue() @@ -88,13 +85,6 @@ void InnerWidget::refreshBlocks() { }, lifetime()); } -void InnerWidget::showFinished() { - _showFinished = true; - if (_cover) { - _cover->showFinished(); - } -} - int InnerWidget::resizeGetHeight(int newWidth) { if (_cover) { _cover->setContentLeft(_contentLeft); diff --git a/Telegram/SourceFiles/settings/settings_inner_widget.h b/Telegram/SourceFiles/settings/settings_inner_widget.h index 9a09142267..ae51ce6ff8 100644 --- a/Telegram/SourceFiles/settings/settings_inner_widget.h +++ b/Telegram/SourceFiles/settings/settings_inner_widget.h @@ -38,8 +38,6 @@ public: return TWidget::resizeToWidth(newWidth); } - void showFinished(); - protected: int resizeGetHeight(int newWidth) override; void visibleTopBottomUpdated( @@ -56,7 +54,6 @@ private: UserData *_self = nullptr; int _contentLeft = 0; - bool _showFinished = false; }; diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index 370500c02d..9242483bb7 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -209,10 +209,6 @@ void Widget::refreshLang() { update(); } -void Widget::showFinished() { - _inner->showFinished(); -} - void Widget::keyPressEvent(QKeyEvent *e) { codesFeedString(e->text()); return LayerWidget::keyPressEvent(e); diff --git a/Telegram/SourceFiles/settings/settings_widget.h b/Telegram/SourceFiles/settings/settings_widget.h index f99417cc05..079d7779a9 100644 --- a/Telegram/SourceFiles/settings/settings_widget.h +++ b/Telegram/SourceFiles/settings/settings_widget.h @@ -32,7 +32,6 @@ public: void refreshLang(); - void showFinished() override; void parentResized() override; protected: diff --git a/Telegram/SourceFiles/window/layer_widget.cpp b/Telegram/SourceFiles/window/layer_widget.cpp index 8f24560126..27abfd06bd 100644 --- a/Telegram/SourceFiles/window/layer_widget.cpp +++ b/Telegram/SourceFiles/window/layer_widget.cpp @@ -609,9 +609,6 @@ void LayerStackWidget::showFinished() { fixOrder(); sendFakeMouseEvent(); updateLayerBoxes(); - if (_mainMenu) { - _mainMenu->showFinished(); - } if (_specialLayer) { _specialLayer->showFinished(); } @@ -653,7 +650,7 @@ void LayerStackWidget::hideSpecialLayer(anim::type animated) { void LayerStackWidget::showMainMenu(anim::type animated) { startAnimation([this] { - _mainMenu.create(this); + _mainMenu.create(this, _controller); _mainMenu->setGeometryToLeft(0, 0, _mainMenu->width(), height()); _mainMenu->setParent(this); }, [this] { diff --git a/Telegram/SourceFiles/window/window.style b/Telegram/SourceFiles/window/window.style index 2ecf465f18..a6b898128d 100644 --- a/Telegram/SourceFiles/window/window.style +++ b/Telegram/SourceFiles/window/window.style @@ -104,7 +104,10 @@ mainMenuWidth: 274px; mainMenuCoverHeight: 134px; mainMenuUserpicLeft: 24px; mainMenuUserpicTop: 20px; -mainMenuUserpicSize: 48px; +mainMenuUserpic: UserpicButton(defaultUserpicButton) { + size: size(48px, 48px); + photoSize: 48px; +} mainMenuCloudButton: IconButton { width: 64px; height: 64px; diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 0e6a9e75a8..61dafc79d3 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -22,11 +22,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_window.h" #include "styles/style_dialogs.h" -#include "profile/profile_userpic_button.h" #include "window/themes/window_theme.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/widgets/menu.h" +#include "ui/special_buttons.h" #include "mainwindow.h" #include "storage/localstorage.h" #include "boxes/about_box.h" @@ -40,7 +40,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Window { -MainMenu::MainMenu(QWidget *parent) : TWidget(parent) +MainMenu::MainMenu( + QWidget *parent, + not_null controller) +: TWidget(parent) +, _controller(controller) , _menu(this, st::mainMenu) , _telegram(this, st::mainMenuTelegramLabel) , _version(this, st::mainMenuVersionLabel) { @@ -136,7 +140,12 @@ void MainMenu::checkSelf() { App::main()->choosePeer(self->id, ShowAtUnreadMsgId); } }; - _userpicButton.create(this, self, st::mainMenuUserpicSize); + _userpicButton.create( + this, + _controller, + self, + Ui::UserpicButton::Role::Custom, + st::mainMenuUserpic); _userpicButton->setClickedCallback(showSelfChat); _userpicButton->show(); _cloudButton.create(this, st::mainMenuCloudButton); @@ -144,22 +153,12 @@ void MainMenu::checkSelf() { _cloudButton->show(); update(); updateControlsGeometry(); - if (_showFinished) { - _userpicButton->showFinished(); - } } else { _userpicButton.destroy(); _cloudButton.destroy(); } } -void MainMenu::showFinished() { - _showFinished = true; - if (_userpicButton) { - _userpicButton->showFinished(); - } -} - void MainMenu::resizeEvent(QResizeEvent *e) { _menu->setForceWidth(width()); updateControlsGeometry(); diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index ed6f4f6e6a..1a076901ce 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -26,22 +26,20 @@ namespace Ui { class IconButton; class FlatLabel; class Menu; -} // namespace Ui - -namespace Profile { class UserpicButton; -} // namespace Profile +} // namespace Ui namespace Window { +class Controller; + class MainMenu : public TWidget, private base::Subscriber { public: - MainMenu(QWidget *parent); + MainMenu(QWidget *parent, not_null controller); void setInnerFocus() { setFocus(); } - void showFinished(); protected: void paintEvent(QPaintEvent *e) override; @@ -53,7 +51,8 @@ private: void updatePhone(); void refreshMenu(); - object_ptr _userpicButton = { nullptr }; + not_null _controller; + object_ptr _userpicButton = { nullptr }; object_ptr _cloudButton = { nullptr }; object_ptr _menu; object_ptr _telegram; @@ -61,7 +60,6 @@ private: std::shared_ptr> _nightThemeAction; base::Timer _nightThemeSwitch; - bool _showFinished = false; QString _phoneText; };