From 90678d411f707e5fa636765c64afac4905d0165e Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 17 Aug 2016 18:14:08 +0300 Subject: [PATCH] Started a special LayerWidget: Settings::Widget. Also added some missing calls to parent event handlers in boxes. --- Telegram/Resources/icons/settings_close.png | Bin 0 -> 187 bytes .../Resources/icons/settings_close@2x.png | Bin 0 -> 296 bytes Telegram/SourceFiles/app.cpp | 7 -- Telegram/SourceFiles/app.h | 1 - Telegram/SourceFiles/boxes/aboutbox.cpp | 1 + Telegram/SourceFiles/boxes/abstractbox.cpp | 1 + Telegram/SourceFiles/boxes/addcontactbox.cpp | 7 ++ Telegram/SourceFiles/boxes/backgroundbox.cpp | 4 +- Telegram/SourceFiles/boxes/backgroundbox.h | 7 ++ Telegram/SourceFiles/boxes/confirmbox.cpp | 6 + Telegram/SourceFiles/boxes/connectionbox.cpp | 4 + Telegram/SourceFiles/boxes/contactsbox.cpp | 3 +- .../SourceFiles/boxes/downloadpathbox.cpp | 21 ++++ Telegram/SourceFiles/boxes/downloadpathbox.h | 16 +++ Telegram/SourceFiles/boxes/photocropbox.cpp | 1 + Telegram/SourceFiles/boxes/photosendbox.cpp | 2 + Telegram/SourceFiles/boxes/report_box.cpp | 1 + Telegram/SourceFiles/core/basic_types.h | 3 +- Telegram/SourceFiles/core/observer.h | 8 +- Telegram/SourceFiles/facades.cpp | 6 +- Telegram/SourceFiles/facades.h | 1 + Telegram/SourceFiles/historywidget.cpp | 2 +- Telegram/SourceFiles/historywidget.h | 2 +- Telegram/SourceFiles/layerwidget.cpp | 10 ++ Telegram/SourceFiles/layerwidget.h | 8 +- Telegram/SourceFiles/mainwidget.cpp | 15 +-- Telegram/SourceFiles/mainwindow.cpp | 110 +++++------------- Telegram/SourceFiles/mainwindow.h | 12 +- Telegram/SourceFiles/observer_peer.cpp | 1 + .../platform/mac/main_window_mac.mm | 1 - .../platform/win/windows_toasts.cpp | 1 - .../profile/profile_inner_widget.cpp | 2 +- .../SourceFiles/profile/profile_widget.cpp | 3 +- Telegram/SourceFiles/settings/settings.style | 29 +++++ .../settings/settings_fixed_bar.cpp | 54 +++++++++ .../SourceFiles/settings/settings_fixed_bar.h | 44 +++++++ .../settings/settings_inner_widget.cpp | 60 ++++++++++ .../settings/settings_inner_widget.h | 50 ++++++++ .../SourceFiles/settings/settings_widget.cpp | 86 ++++++++++++++ .../SourceFiles/settings/settings_widget.h | 25 ++++ Telegram/SourceFiles/settingswidget.cpp | 39 ++++--- Telegram/SourceFiles/settingswidget.h | 3 +- Telegram/SourceFiles/title.cpp | 28 +---- Telegram/SourceFiles/title.h | 1 - Telegram/SourceFiles/ui/button.cpp | 3 + Telegram/SourceFiles/ui/button.h | 22 ++-- Telegram/SourceFiles/ui/filedialog.cpp | 2 +- Telegram/gyp/Telegram.gyp | 4 + 48 files changed, 540 insertions(+), 177 deletions(-) create mode 100644 Telegram/Resources/icons/settings_close.png create mode 100644 Telegram/Resources/icons/settings_close@2x.png create mode 100644 Telegram/SourceFiles/settings/settings_fixed_bar.cpp create mode 100644 Telegram/SourceFiles/settings/settings_fixed_bar.h create mode 100644 Telegram/SourceFiles/settings/settings_inner_widget.cpp create mode 100644 Telegram/SourceFiles/settings/settings_inner_widget.h diff --git a/Telegram/Resources/icons/settings_close.png b/Telegram/Resources/icons/settings_close.png new file mode 100644 index 0000000000000000000000000000000000000000..7fa112a33b2e9cef41f273abc62eb07b4a1839b4 GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a)4CQlc~5RHkYlP+?y8gj5qzuvy= zzucZ6AMIlK<9me-ofKa1om^E^uEb>Qe5vA0Psf3~7fWLqQl4?ll$^=w;G$5T{@&Ip zbk5B4+>>T3X#T+%w}OlB5&w$|j%WN;8NNysPd-?ce|Proi?)9k#;vHATWGZ-Z-cX7 m-C&U>J17(8A5T-G@yGywp}X-3=t literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/settings_close@2x.png b/Telegram/Resources/icons/settings_close@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..40d3def3d2c56edb57dc818be15c1add75a32652 GIT binary patch literal 296 zcmV+@0oVSCP)CU0sydW8>EyV#t0+joP&9uVc+-f zo-niILPYsU&C5CWy6=MV< us`fKmy!Tx`KwVn9@0000settingsWidget(); - } - return nullptr; - } - bool passcoded() { if (auto w = wnd()) { return w->passcodeWidget(); diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index cc34e5fdab..5919f3d00d 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -46,7 +46,6 @@ namespace App { AppClass *app(); MainWindow *wnd(); MainWidget *main(); - SettingsWidget *settings(); bool passcoded(); FileUploader *uploader(); ApiWrap *api(); diff --git a/Telegram/SourceFiles/boxes/aboutbox.cpp b/Telegram/SourceFiles/boxes/aboutbox.cpp index 4b2e16d0d4..184df91d44 100644 --- a/Telegram/SourceFiles/boxes/aboutbox.cpp +++ b/Telegram/SourceFiles/boxes/aboutbox.cpp @@ -62,6 +62,7 @@ void AboutBox::resizeEvent(QResizeEvent *e) { _text2.moveToLeft(st::boxPadding.left(), _text1.y() + _text1.height() + st::aboutSkip); _text3.moveToLeft(st::boxPadding.left(), _text2.y() + _text2.height() + st::aboutSkip); _done.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done.height()); + AbstractBox::resizeEvent(e); } void AboutBox::onVersion() { diff --git a/Telegram/SourceFiles/boxes/abstractbox.cpp b/Telegram/SourceFiles/boxes/abstractbox.cpp index 0b80a12aaa..f08c6fa442 100644 --- a/Telegram/SourceFiles/boxes/abstractbox.cpp +++ b/Telegram/SourceFiles/boxes/abstractbox.cpp @@ -103,6 +103,7 @@ void AbstractBox::resizeEvent(QResizeEvent *e) { _blueShadow->moveToLeft(0, st::boxTitleHeight); _blueShadow->resize(width(), st::boxBlueShadow.pxHeight()); } + LayerWidget::resizeEvent(e); } void AbstractBox::parentResized() { diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index e7c19922dc..ee742defd1 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -135,6 +135,7 @@ void AddContactBox::resizeEvent(QResizeEvent *e) { _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); _retry.moveToRight(st::boxButtonPadding.right(), _save.y()); _cancel.moveToRight(st::boxButtonPadding.right() + (_retry.isHidden() ? _save.width() : _retry.width()) + st::boxButtonPadding.left(), _save.y()); + AbstractBox::resizeEvent(e); } void AddContactBox::onSubmit() { @@ -308,6 +309,7 @@ void NewGroupBox::resizeEvent(QResizeEvent *e) { _next.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _next.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _next.width() + st::boxButtonPadding.left(), _next.y()); + AbstractBox::resizeEvent(e); } void NewGroupBox::onNext() { @@ -400,6 +402,7 @@ void GroupInfoBox::resizeEvent(QResizeEvent *e) { _next.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _next.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _next.width() + st::boxButtonPadding.left(), _next.y()); + AbstractBox::resizeEvent(e); } void GroupInfoBox::mouseMoveEvent(QMouseEvent *e) { @@ -707,6 +710,7 @@ void SetupChannelBox::resizeEvent(QResizeEvent *e) { _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); _skip.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); + AbstractBox::resizeEvent(e); } void SetupChannelBox::mouseMoveEvent(QMouseEvent *e) { @@ -1045,6 +1049,7 @@ void EditNameTitleBox::resizeEvent(QResizeEvent *e) { _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); + AbstractBox::resizeEvent(e); } void EditNameTitleBox::onSave() { @@ -1238,6 +1243,7 @@ void EditChannelBox::resizeEvent(QResizeEvent *e) { _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); + AbstractBox::resizeEvent(e); } void EditChannelBox::onSave() { @@ -1427,6 +1433,7 @@ void RevokePublicLinkBox::paintEvent(QPaintEvent *e) { void RevokePublicLinkBox::resizeEvent(QResizeEvent *e) { _aboutRevoke->moveToLeft(st::boxPadding.left(), st::boxPadding.top()); _cancel->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _cancel->height()); + AbstractBox::resizeEvent(e); } void RevokePublicLinkBox::paintChat(Painter &p, const ChatRow &row, bool selected, bool pressed) const { diff --git a/Telegram/SourceFiles/boxes/backgroundbox.cpp b/Telegram/SourceFiles/boxes/backgroundbox.cpp index a4b8ff28d6..c8e3b93ed8 100644 --- a/Telegram/SourceFiles/boxes/backgroundbox.cpp +++ b/Telegram/SourceFiles/boxes/backgroundbox.cpp @@ -196,7 +196,9 @@ void BackgroundBox::onBackgroundChosen(int index) { if (index >= 0 && index < App::cServerBackgrounds().size()) { const App::WallPaper &paper(App::cServerBackgrounds().at(index)); if (App::main()) App::main()->setChatBackground(paper); - if (App::settings()) App::settings()->needBackgroundUpdate(!paper.id); + if (_updateCallback) { + _updateCallback(!paper.id); + } } onClose(); } diff --git a/Telegram/SourceFiles/boxes/backgroundbox.h b/Telegram/SourceFiles/boxes/backgroundbox.h index 2c6455a545..466e32d664 100644 --- a/Telegram/SourceFiles/boxes/backgroundbox.h +++ b/Telegram/SourceFiles/boxes/backgroundbox.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #pragma once #include "abstractbox.h" +#include "core/lambda_wrap.h" class BackgroundInner : public QWidget, public RPCSender { Q_OBJECT @@ -53,6 +54,11 @@ class BackgroundBox : public ItemListBox { public: BackgroundBox(); + // When background is chosen this callback is called with "bool isTiled" arg. + void setUpdateCallback(base::lambda_unique &&updateCallback) { + _updateCallback = std::move(updateCallback); + } + public slots: void onBackgroundChosen(int index); @@ -61,5 +67,6 @@ protected: private: BackgroundInner _inner; + base::lambda_unique _updateCallback; }; diff --git a/Telegram/SourceFiles/boxes/confirmbox.cpp b/Telegram/SourceFiles/boxes/confirmbox.cpp index 543a292da3..71a97e945d 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.cpp +++ b/Telegram/SourceFiles/boxes/confirmbox.cpp @@ -172,6 +172,7 @@ void ConfirmBox::paintEvent(QPaintEvent *e) { void ConfirmBox::resizeEvent(QResizeEvent *e) { _confirm.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _confirm.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _confirm.width() + st::boxButtonPadding.left(), _confirm.y()); + AbstractBox::resizeEvent(e); } SharePhoneConfirmBox::SharePhoneConfirmBox(PeerData *recipient) @@ -281,6 +282,7 @@ void MaxInviteBox::paintEvent(QPaintEvent *e) { void MaxInviteBox::resizeEvent(QResizeEvent *e) { _close.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close.height()); _invitationLink = myrtlrect(st::boxPadding.left(), st::boxPadding.top() + _textHeight + st::boxTextFont->height, width() - st::boxPadding.left() - st::boxPadding.right(), 2 * st::boxTextFont->height); + AbstractBox::resizeEvent(e); } ConvertToSupergroupBox::ConvertToSupergroupBox(ChatData *chat) : AbstractBox(st::boxWideWidth) @@ -374,6 +376,7 @@ void ConvertToSupergroupBox::paintEvent(QPaintEvent *e) { void ConvertToSupergroupBox::resizeEvent(QResizeEvent *e) { _convert.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _convert.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _convert.width() + st::boxButtonPadding.left(), _convert.y()); + AbstractBox::resizeEvent(e); } PinMessageBox::PinMessageBox(ChannelData *channel, MsgId msgId) : AbstractBox(st::boxWidth) @@ -395,6 +398,7 @@ void PinMessageBox::resizeEvent(QResizeEvent *e) { _notify.moveToLeft(st::boxPadding.left(), _text.y() + _text.height() + st::boxMediumSkip); _pin.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _pin.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _pin.width() + st::boxButtonPadding.left(), _pin.y()); + AbstractBox::resizeEvent(e); } void PinMessageBox::onPin() { @@ -453,6 +457,7 @@ void RichDeleteMessageBox::resizeEvent(QResizeEvent *e) { _deleteAll.moveToLeft(st::boxPadding.left(), _reportSpam.y() + _reportSpam.height() + st::boxLittleSkip); _delete.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _delete.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _delete.width() + st::boxButtonPadding.left(), _delete.y()); + AbstractBox::resizeEvent(e); } void RichDeleteMessageBox::onDelete() { @@ -562,6 +567,7 @@ void ConfirmInviteBox::resizeEvent(QResizeEvent *e) { _status->move((width() - _status->width()) / 2, st::confirmInviteStatusTop); _join->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _join->height()); _cancel->moveToRight(st::boxButtonPadding.right() + _join->width() + st::boxButtonPadding.left(), _join->y()); + AbstractBox::resizeEvent(e); } void ConfirmInviteBox::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/boxes/connectionbox.cpp b/Telegram/SourceFiles/boxes/connectionbox.cpp index 659b3ddbfc..aab70ac035 100644 --- a/Telegram/SourceFiles/boxes/connectionbox.cpp +++ b/Telegram/SourceFiles/boxes/connectionbox.cpp @@ -121,6 +121,8 @@ void ConnectionBox::resizeEvent(QResizeEvent *e) { _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); + + AbstractBox::resizeEvent(e); } void ConnectionBox::onChange() { @@ -264,6 +266,8 @@ void AutoDownloadBox::resizeEvent(QResizeEvent *e) { _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); + + AbstractBox::resizeEvent(e); } void AutoDownloadBox::onSave() { diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index c3de232337..291ccc73ae 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -709,9 +709,8 @@ void ContactsInner::chooseParticipant() { connect(box, SIGNAL(confirmed()), this, SLOT(onAddBot())); Ui::showLayer(box, KeepOtherLayers); } else { - App::wnd()->hideSettings(true); + Ui::hideSettingsAndLayer(true); App::main()->choosePeer(peer->id, ShowAtUnreadMsgId); - Ui::hideLayer(); } } } diff --git a/Telegram/SourceFiles/boxes/downloadpathbox.cpp b/Telegram/SourceFiles/boxes/downloadpathbox.cpp index 9aa2ca3e8b..b5131ff4d0 100644 --- a/Telegram/SourceFiles/boxes/downloadpathbox.cpp +++ b/Telegram/SourceFiles/boxes/downloadpathbox.cpp @@ -27,6 +27,25 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/filedialog.h" #include "pspecific.h" +namespace internal { +namespace { + +void StartCallback() { +} + +void FinishCallback() { +} + +Notify::SimpleObservedEventRegistrator creator(StartCallback, FinishCallback); + +} // namespace + +Notify::ConnectionId plainRegisterObserver(DownloadPathUpdateHandler &&handler) { + return creator.registerObserver(std_::forward(handler)); +} + +} // namespace interanl + DownloadPathBox::DownloadPathBox() : AbstractBox() , _path(cDownloadPath()) , _pathBookmark(cDownloadPathBookmark()) @@ -90,6 +109,7 @@ void DownloadPathBox::resizeEvent(QResizeEvent *e) { _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); + AbstractBox::resizeEvent(e); } void DownloadPathBox::onChange() { @@ -132,6 +152,7 @@ void DownloadPathBox::onSave() { cSetDownloadPath(_default.checked() ? QString() : (_temp.checked() ? qsl("tmp") : _path)); cSetDownloadPathBookmark((_default.checked() || _temp.checked()) ? QByteArray() : _pathBookmark); Local::writeUserSettings(); + internal::creator.notify(DownloadPathUpdate()); onClose(); } diff --git a/Telegram/SourceFiles/boxes/downloadpathbox.h b/Telegram/SourceFiles/boxes/downloadpathbox.h index 55fc27a824..f6077d7090 100644 --- a/Telegram/SourceFiles/boxes/downloadpathbox.h +++ b/Telegram/SourceFiles/boxes/downloadpathbox.h @@ -21,6 +21,22 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #pragma once #include "abstractbox.h" +#include "core/observer.h" + +// Just a notification that cDownloadPath() has changed. +struct DownloadPathUpdate { +}; + +namespace internal { +using DownloadPathUpdateHandler = Function; +Notify::ConnectionId plainRegisterObserver(DownloadPathUpdateHandler &&handler); +} // namespace internal + +template +void registerDownloadPathObserver(ObserverType *observer, void (ObserverType::*handler)(const DownloadPathUpdate &)) { + auto connection = internal::plainRegisterObserver(func(observer, handler)); + Notify::observerRegistered(observer, connection); +} class DownloadPathBox : public AbstractBox { Q_OBJECT diff --git a/Telegram/SourceFiles/boxes/photocropbox.cpp b/Telegram/SourceFiles/boxes/photocropbox.cpp index 47a7c2cc96..5d9c09a4c0 100644 --- a/Telegram/SourceFiles/boxes/photocropbox.cpp +++ b/Telegram/SourceFiles/boxes/photocropbox.cpp @@ -258,6 +258,7 @@ void PhotoCropBox::paintEvent(QPaintEvent *e) { void PhotoCropBox::resizeEvent(QResizeEvent *e) { _done.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done.height()); _cancel.moveToRight(st::boxButtonPadding.right() + _done.width() + st::boxButtonPadding.left(), _done.y()); + AbstractBox::resizeEvent(e); } void PhotoCropBox::onSend() { diff --git a/Telegram/SourceFiles/boxes/photosendbox.cpp b/Telegram/SourceFiles/boxes/photosendbox.cpp index a7e9965684..9bc20e7ba3 100644 --- a/Telegram/SourceFiles/boxes/photosendbox.cpp +++ b/Telegram/SourceFiles/boxes/photosendbox.cpp @@ -292,6 +292,7 @@ void PhotoSendBox::resizeEvent(QResizeEvent *e) { _caption.resize(st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(), _caption.height()); _caption.moveToLeft(st::boxPhotoPadding.left(), _send.y() - st::boxButtonPadding.top() - _caption.height()); _compressed.moveToLeft(st::boxPhotoPadding.left(), st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxPhotoCompressedPadding.top()); + AbstractBox::resizeEvent(e); } void PhotoSendBox::closePressed() { @@ -617,6 +618,7 @@ void EditCaptionBox::resizeEvent(QResizeEvent *e) { _cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); _field->resize(st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(), _field->height()); _field->moveToLeft(st::boxPhotoPadding.left(), _save.y() - st::boxButtonPadding.top() - st::normalFont->height - _field->height()); + AbstractBox::resizeEvent(e); } void EditCaptionBox::showAll() { diff --git a/Telegram/SourceFiles/boxes/report_box.cpp b/Telegram/SourceFiles/boxes/report_box.cpp index 0076f548b3..d8ec67ce79 100644 --- a/Telegram/SourceFiles/boxes/report_box.cpp +++ b/Telegram/SourceFiles/boxes/report_box.cpp @@ -66,6 +66,7 @@ void ReportBox::resizeEvent(QResizeEvent *e) { _report->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _report->height()); _cancel->moveToRight(st::boxButtonPadding.right() + _report->width() + st::boxButtonPadding.left(), _report->y()); + AbstractBox::resizeEvent(e); } void ReportBox::onChange() { diff --git a/Telegram/SourceFiles/core/basic_types.h b/Telegram/SourceFiles/core/basic_types.h index 678170c164..9437729032 100644 --- a/Telegram/SourceFiles/core/basic_types.h +++ b/Telegram/SourceFiles/core/basic_types.h @@ -885,7 +885,8 @@ enum ShowLayerOption { AnimatedShowLayer = 0x00, ForceFastShowLayer = 0x04, }; -typedef QFlags ShowLayerOptions; +Q_DECLARE_FLAGS(ShowLayerOptions, ShowLayerOption); +Q_DECLARE_OPERATORS_FOR_FLAGS(ShowLayerOptions); static int32 FullArcLength = 360 * 16; static int32 QuarterArcLength = (FullArcLength / 4); diff --git a/Telegram/SourceFiles/core/observer.h b/Telegram/SourceFiles/core/observer.h index 1530328f85..7b0df81a24 100644 --- a/Telegram/SourceFiles/core/observer.h +++ b/Telegram/SourceFiles/core/observer.h @@ -81,7 +81,7 @@ template class ObservedEventRegistrator : public internal::BaseObservedEventRegistrator { public: ObservedEventRegistrator(StartObservedEventCallback startCallback, - FinishObservedEventCallback finishCallback) : internal::BaseObservedEventRegistrator(reinterpret_cast(this), + FinishObservedEventCallback finishCallback) : internal::BaseObservedEventRegistrator(static_cast(this), ObservedEventRegistrator::start, ObservedEventRegistrator::finish, ObservedEventRegistrator::unregister) @@ -113,21 +113,21 @@ public: private: using Self = ObservedEventRegistrator; static void start(void *vthat) { - Self *that = reinterpret_cast(vthat); + Self *that = static_cast(vthat); t_assert(!that->started()); if (that->_startCallback) that->_startCallback(); that->_list = new internal::ObserversList(); } static void finish(void *vthat) { - Self *that = reinterpret_cast(vthat); + Self *that = static_cast(vthat); if (that->_finishCallback) that->_finishCallback(); delete that->_list; that->_list = nullptr; } static void unregister(void *vthat, int connectionIndex) { - Self *that = reinterpret_cast(vthat); + Self *that = static_cast(vthat); t_assert(that->started()); diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index cd3ae92a72..4cfdfd51c8 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -208,7 +208,11 @@ void showLayer(LayerWidget *box, ShowLayerOptions options) { } void hideLayer(bool fast) { - if (auto w = App::wnd()) w->ui_showLayer(0, ShowLayerOptions(CloseOtherLayers) | (fast ? ForceFastShowLayer : AnimatedShowLayer)); + if (auto w = App::wnd()) w->ui_showLayer(0, CloseOtherLayers | (fast ? ForceFastShowLayer : AnimatedShowLayer)); +} + +void hideSettingsAndLayer(bool fast) { + if (auto w = App::wnd()) w->ui_hideSettingsAndLayer(fast ? ForceFastShowLayer : AnimatedShowLayer); } bool isLayerShown() { diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index ec63e60fd4..c0b0a46138 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -58,6 +58,7 @@ void hideMediaPreview(); void showLayer(LayerWidget *box, ShowLayerOptions options = CloseOtherLayers); void hideLayer(bool fast = false); +void hideSettingsAndLayer(bool fast = false); bool isLayerShown(); bool isMediaViewShown(); bool isInlineItemBeingChosen(); diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 02847906b8..2d838b4678 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -6318,7 +6318,7 @@ void HistoryWidget::topBarClick() { } } -void HistoryWidget::updateOnlineDisplay(int32 x, int32 w) { +void HistoryWidget::updateOnlineDisplay() { if (!_history) return; QString text; diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index 7353db769a..3bf3e59a74 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -589,7 +589,7 @@ public: void cancelShareContact(); void updateControlsVisibility(); - void updateOnlineDisplay(int32 x, int32 w); + void updateOnlineDisplay(); void updateOnlineDisplayTimer(); void onShareContact(const PeerId &peer, UserData *contact); diff --git a/Telegram/SourceFiles/layerwidget.cpp b/Telegram/SourceFiles/layerwidget.cpp index c2fe4f63c6..b315056b0a 100644 --- a/Telegram/SourceFiles/layerwidget.cpp +++ b/Telegram/SourceFiles/layerwidget.cpp @@ -107,6 +107,16 @@ void LayerStackWidget::mousePressEvent(QMouseEvent *e) { onClose(); } +void LayerStackWidget::onCloseLayers() { + if (_specialLayer) { + clearLayers(); + fixOrder(); + if (App::wnd()) App::wnd()->setInnerFocus(); + } else { + onClose(); + } +} + void LayerStackWidget::onClose() { startHide(); } diff --git a/Telegram/SourceFiles/layerwidget.h b/Telegram/SourceFiles/layerwidget.h index 6bc69cd73a..9dc5090f8e 100644 --- a/Telegram/SourceFiles/layerwidget.h +++ b/Telegram/SourceFiles/layerwidget.h @@ -31,16 +31,15 @@ public: } void setInnerFocus(); - void mousePressEvent(QMouseEvent *e) { - e->accept(); - } - bool overlaps(const QRect &globalRect) { if (isHidden() || !testAttribute(Qt::WA_OpaquePaintEvent)) return false; return rect().contains(QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size())); } protected: + void mousePressEvent(QMouseEvent *e) override { + e->accept(); + } void resizeEvent(QResizeEvent *e) override { emit resized(); } @@ -74,6 +73,7 @@ public: bool contentOverlapped(const QRect &globalRect); + void onCloseLayers(); void onClose(); ~LayerStackWidget(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 5b449de6b9..7fe3997b23 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1510,11 +1510,7 @@ void MainWidget::loadFailed(mtpFileLoader *loader, bool started, const char *ret void MainWidget::onDownloadPathSettings() { cSetDownloadPath(QString()); cSetDownloadPathBookmark(QByteArray()); - DownloadPathBox *box = new DownloadPathBox(); - if (App::wnd() && App::wnd()->settingsWidget()) { - connect(box, SIGNAL(closed(LayerWidget*)), App::wnd()->settingsWidget(), SLOT(onDownloadPathEdited())); - } - Ui::showLayer(box); + Ui::showLayer(new DownloadPathBox()); } void MainWidget::onSharePhoneWithBot(PeerData *recipient) { @@ -1686,8 +1682,7 @@ void MainWidget::onParentResize(const QSize &newSize) { void MainWidget::updateOnlineDisplay() { if (this != App::main()) return; - _history->updateOnlineDisplay(_history->x(), width() - _history->x() - st::sysBtnDelta * 2 - st::sysCls.img.pxWidth() - st::sysRes.img.pxWidth() - st::sysMin.img.pxWidth()); - if (App::wnd()->settingsWidget()) App::wnd()->settingsWidget()->updateOnlineDisplay(); + _history->updateOnlineDisplay(); } void MainWidget::onSendFileConfirm(const FileLoadResultPtr &file, bool ctrlShiftEnter) { @@ -2046,7 +2041,7 @@ void MainWidget::ui_showPeerHistory(quint64 peerId, qint32 showAtMsgId, Ui::Show PeerData *wasActivePeer = activePeer(); - Ui::hideLayer(); + Ui::hideSettingsAndLayer(); if (_hider) { _hider->startHide(); _hider = nullptr; @@ -2195,7 +2190,7 @@ void MainWidget::showMediaOverview(PeerData *peer, MediaOverviewType type, bool peer = peer->migrateTo(); } - App::wnd()->hideSettings(); + Ui::hideSettingsAndLayer(); if (_overview && _overview->peer() == peer) { if (_overview->type() != type) { _overview->switchType(type); @@ -2248,7 +2243,7 @@ void MainWidget::showMediaOverview(PeerData *peer, MediaOverviewType type, bool } void MainWidget::showWideSection(const Window::SectionMemento &memento) { - App::wnd()->hideSettings(); + Ui::hideSettingsAndLayer(); if (_wideSection && _wideSection->showInternal(&memento)) { return; } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index e95be4cbb8..e907b9fddf 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -41,6 +41,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mediaview.h" #include "localstorage.h" #include "apiwrap.h" +#include "settings/settings_widget.h" ConnectingWidget::ConnectingWidget(QWidget *parent, const QString &text, const QString &reconnect) : QWidget(parent), _shadow(st::boxShadow), _reconnect(this, QString()) { set(text, reconnect); @@ -299,7 +300,6 @@ void NotifyWindow::mousePressEvent(QMouseEvent *e) { App::wnd()->setInnerFocus(); App::wnd()->notifyClear(); } else { - App::wnd()->hideSettings(); Ui::showPeerHistory(peer, msgId); } e->ignore(); @@ -486,13 +486,6 @@ void MainWindow::clearWidgets() { _passcode->deleteLater(); _passcode = 0; } - if (settings) { - settings->stop_show(); - settings->hide(); - settings->deleteLater(); - settings->rpcClear(); - settings = 0; - } if (main) { delete main; main = nullptr; @@ -537,8 +530,6 @@ void MainWindow::clearPasscode() { _passcode = 0; if (intro) { intro->animShow(bg, true); - } else if (settings) { - settings->animShow(bg, true); } else { main->animShow(bg, true); } @@ -558,7 +549,9 @@ void MainWindow::setupPasscode(bool anim) { _passcode = new PasscodeWidget(this); _passcode->move(0, st::titleHeight); if (main) main->hide(); - if (settings) settings->hide(); + if (settings) { + settings->deleteLater(); + } if (intro) intro->hide(); if (anim) { _passcode->animShow(bg); @@ -684,63 +677,29 @@ void MainWindow::showSettings() { if (isHidden()) showFromTray(); - Ui::hideLayer(); if (settings) { - return hideSettings(); + Ui::hideSettingsAndLayer(); + return; } - QPixmap bg = grabInner(); - if (intro) { - intro->stop_show(); - intro->hide(); - } else if (main) { - main->animStop_show(); - main->hide(); + if (!layerBg) { + layerBg = new LayerStackWidget(this); } - settings = new SettingsWidget(this); - settings->animShow(bg); - title->updateBackButton(); - - fixOrder(); + settings = new Settings::Widget(); + connect(settings, SIGNAL(destroyed(QObject*)), this, SLOT(onSettingsDestroyed(QObject*))); + layerBg->showSpecialLayer(settings); } -void MainWindow::hideSettings(bool fast) { - if (!settings || _passcode) return; - - if (fast) { - settings->stop_show(); - settings->hide(); - settings->deleteLater(); - settings->rpcClear(); - settings = 0; - if (intro) { - intro->show(); - } else { - main->show(); - } - } else { - QPixmap bg = grabInner(); - - settings->stop_show(); - settings->hide(); - settings->deleteLater(); - settings->rpcClear(); - settings = 0; - if (intro) { - intro->animShow(bg, true); - } else { - main->animShow(bg, true); - } +void MainWindow::ui_hideSettingsAndLayer(ShowLayerOptions options) { + if (layerBg) { + layerBg->onClose(); } - title->updateBackButton(); - - fixOrder(); } void MainWindow::mtpStateChanged(int32 dc, int32 state) { if (dc == MTP::maindc()) { updateTitleStatus(); - if (settings) settings->updateConnectionType(); +// if (settings) settings->updateConnectionType(); TODO } } @@ -766,10 +725,6 @@ MainWidget *MainWindow::mainWidget() { return main; } -SettingsWidget *MainWindow::settingsWidget() { - return settings; -} - PasscodeWidget *MainWindow::passcodeWidget() { return _passcode; } @@ -818,11 +773,15 @@ void MainWindow::ui_showLayer(LayerWidget *box, ShowLayerOptions options) { } } else { if (layerBg) { - layerBg->onClose(); - if (options.testFlag(ForceFastShowLayer)) { - layerBg->hide(); - layerBg->deleteLater(); - layerBg = nullptr; + if (settings) { + layerBg->onCloseLayers(); + } else { + layerBg->onClose(); + if (options.testFlag(ForceFastShowLayer)) { + layerBg->hide(); + layerBg->deleteLater(); + layerBg = nullptr; + } } } hideMediaview(); @@ -1218,9 +1177,9 @@ void MainWindow::noIntro(IntroWidget *was) { } } -void MainWindow::noSettings(SettingsWidget *was) { +void MainWindow::onSettingsDestroyed(QObject *was) { if (was == settings) { - settings = 0; + settings = nullptr; } checkHistoryActivation(); } @@ -1281,7 +1240,7 @@ void MainWindow::toggleDisplayNotifyFromTray() { } cSetDesktopNotify(!cDesktopNotify()); if (settings) { - settings->updateDisplayNotify(); +// settings->updateDisplayNotify(); TODO } else { if (!cDesktopNotify()) { notifyClear(); @@ -1330,15 +1289,10 @@ void MainWindow::resizeEvent(QResizeEvent *e) { void MainWindow::updateAdaptiveLayout() { title->updateAdaptiveLayout(); if (main) main->updateAdaptiveLayout(); - if (settings) settings->updateAdaptiveLayout(); if (intro) intro->updateAdaptiveLayout(); if (layerBg) layerBg->updateAdaptiveLayout(); } -bool MainWindow::needBackButton() { - return !!settings; -} - MainWindow::TempDirState MainWindow::tempDirState() { if (_clearManager && _clearManager->hasTask(Local::ClearManagerDownloads)) { return TempDirRemoving; @@ -1883,13 +1837,9 @@ QImage MainWindow::iconWithCounter(int size, int count, style::color bg, bool sm void MainWindow::sendPaths() { if (App::passcoded()) return; hideMediaview(); - if (settings) { - hideSettings(); - } else { - Ui::hideLayer(); - if (main) { - main->activate(); - } + Ui::hideSettingsAndLayer(); + if (main) { + main->activate(); } } diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 96372e3c68..413268c20b 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -30,12 +30,14 @@ class TitleWidget; class PasscodeWidget; class IntroWidget; class MainWidget; -class SettingsWidget; class LayerStackWidget; class LayerWidget; namespace Local { class ClearManager; } // namespace Local +namespace Settings { +class Widget; +} // namespace Settings class ConnectingWidget : public QWidget { Q_OBJECT @@ -150,7 +152,6 @@ public: void resizeEvent(QResizeEvent *e); void updateAdaptiveLayout(); - bool needBackButton(); void setupPasscode(bool anim); void clearPasscode(); @@ -173,7 +174,6 @@ public: IntroWidget *introWidget(); MainWidget *mainWidget(); - SettingsWidget *settingsWidget(); PasscodeWidget *passcodeWidget(); void showConnecting(const QString &text, const QString &reconnect = QString()); @@ -190,7 +190,6 @@ public: void activate(); void noIntro(IntroWidget *was); - void noSettings(SettingsWidget *was); void noMain(MainWidget *was); void noLayerStack(LayerStackWidget *was); void layerFinishedHide(LayerStackWidget *was); @@ -241,6 +240,7 @@ public: } void ui_showLayer(LayerWidget *box, ShowLayerOptions options); + void ui_hideSettingsAndLayer(ShowLayerOptions options); bool ui_isLayerShown(); bool ui_isMediaViewShown(); void ui_showMediaPreview(DocumentData *document); @@ -256,7 +256,6 @@ public slots: void checkAutoLock(); void showSettings(); - void hideSettings(bool fast = false); void layerHidden(); void setInnerFocus(); void updateTitleStatus(); @@ -298,6 +297,7 @@ signals: private slots: void onStateChanged(Qt::WindowState state); + void onSettingsDestroyed(QObject *was); private: @@ -316,7 +316,7 @@ private: PasscodeWidget *_passcode = nullptr; IntroWidget *intro = nullptr; MainWidget *main = nullptr; - SettingsWidget *settings = nullptr; + ChildWidget settings = { nullptr }; ChildWidget layerBg = { nullptr }; std_::unique_ptr _mediaPreview; diff --git a/Telegram/SourceFiles/observer_peer.cpp b/Telegram/SourceFiles/observer_peer.cpp index 12e84f5568..13bfe074a4 100644 --- a/Telegram/SourceFiles/observer_peer.cpp +++ b/Telegram/SourceFiles/observer_peer.cpp @@ -53,6 +53,7 @@ ObservedEventRegistrator creator(StartCall namespace internal { ConnectionId plainRegisterPeerObserver(PeerUpdate::Flags events, PeerUpdateHandler &&handler) { + constexpr auto tmp = sizeof(PeerUpdate); return creator.registerObserver(events, std_::forward(handler)); } diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 602816914b..c849827fc5 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -53,7 +53,6 @@ void MacPrivate::notifyClicked(unsigned long long peer, int msgid) { App::wnd()->setInnerFocus(); App::wnd()->notifyClear(); } else { - App::wnd()->hideSettings(); bool tomsg = !history->peer->isUser() && (msgid > 0); if (tomsg) { HistoryItem *item = App::histItemById(peerToChannel(PeerId(peer)), MsgId(msgid)); diff --git a/Telegram/SourceFiles/platform/win/windows_toasts.cpp b/Telegram/SourceFiles/platform/win/windows_toasts.cpp index 63550d549d..32ad7aa7e2 100644 --- a/Telegram/SourceFiles/platform/win/windows_toasts.cpp +++ b/Telegram/SourceFiles/platform/win/windows_toasts.cpp @@ -331,7 +331,6 @@ public: App::wnd()->setInnerFocus(); App::wnd()->notifyClear(); } else { - App::wnd()->hideSettings(); bool tomsg = !history->peer->isUser() && (_msgId > 0); if (tomsg) { HistoryItem *item = App::histItemById(peerToChannel(_peerId), _msgId); diff --git a/Telegram/SourceFiles/profile/profile_inner_widget.cpp b/Telegram/SourceFiles/profile/profile_inner_widget.cpp index 90e7cafd44..480bda60e9 100644 --- a/Telegram/SourceFiles/profile/profile_inner_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_inner_widget.cpp @@ -84,7 +84,7 @@ void InnerWidget::setVisibleTopBottom(int visibleTop, int visibleBottom) { decreaseAdditionalHeight(notDisplayedAtBottom); } - for_const (auto blockData, _blocks) { + for_const (auto &blockData, _blocks) { int blockY = blockData.block->y(); blockData.block->setVisibleTopBottom(visibleTop - blockY, visibleBottom - blockY); } diff --git a/Telegram/SourceFiles/profile/profile_widget.cpp b/Telegram/SourceFiles/profile/profile_widget.cpp index 336725c1e9..8c25e3bd44 100644 --- a/Telegram/SourceFiles/profile/profile_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_widget.cpp @@ -105,8 +105,7 @@ void Widget::resizeEvent(QResizeEvent *e) { QSize scrollSize(width(), height() - _fixedBar->height()); if (_scroll->size() != scrollSize) { _scroll->resize(scrollSize); -// _inner->resizeToWidth(scrollSize.width(), _scroll->height()); - _inner->resizeToWidth(scrollSize.width(), _scroll->height() * 2); // testing + _inner->resizeToWidth(scrollSize.width(), _scroll->height()); } _fixedBar->setHideShareContactButton(_inner->shareContactButtonShown()); diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index e9fb441c94..8a4875336d 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -21,3 +21,32 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org using "basic.style"; using "basic_types.style"; +settingsMaxWidth: 520px; +settingsMaxPadding: 48px; +settingsMinPadding: 32px; +settingsMargin: 48px; + +settingsFixedBarHeight: 52px; +settingsFixedBarFont: font(14px semibold); +settingsFixedBarFg: windowTextFg; +settingsFixedBarTextLeft: 20px; +settingsFixedBarTextTop: 16px; +settingsFixedBarClose: IconButton { + width: settingsFixedBarHeight; + height: settingsFixedBarHeight; + + opacity: 0.31; + overOpacity: 0.5; + + icon: icon { + { "settings_close", #000000, point(0px, 0px) }, + }; + iconPosition: point(20px, 20px); + downIconPosition: point(20px, 20px); + + duration: 200; +} +settingsFixedBarShadowBg1: #00000021; +settingsFixedBarShadowBg2: #0000000b; + +settingsPhotoLeft: -8px; \ No newline at end of file diff --git a/Telegram/SourceFiles/settings/settings_fixed_bar.cpp b/Telegram/SourceFiles/settings/settings_fixed_bar.cpp new file mode 100644 index 0000000000..7adeb6691a --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_fixed_bar.cpp @@ -0,0 +1,54 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +#include "stdafx.h" +#include "settings/settings_fixed_bar.h" + +#include "styles/style_settings.h" +#include "ui/buttons/icon_button.h" +#include "mainwindow.h" +#include "lang.h" + +namespace Settings { + +FixedBar::FixedBar(QWidget *parent) : TWidget(parent) +, _close(this, st::settingsFixedBarClose) { + _close->setClickedCallback([]() { + Ui::hideSettingsAndLayer(); + }); +} + +void FixedBar::resizeToWidth(int newWidth) { + resize(newWidth, st::settingsFixedBarHeight); +} + +void FixedBar::resizeEvent(QResizeEvent *e) { + _close->moveToRight(0, 0); +} + +void FixedBar::paintEvent(QPaintEvent *e) { + Painter p(this); + + p.setFont(st::settingsFixedBarFont); + p.setPen(st::windowTextFg); + p.drawTextLeft(st::settingsFixedBarTextLeft, st::settingsFixedBarTextTop, width(), lang(lng_menu_settings)); +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_fixed_bar.h b/Telegram/SourceFiles/settings/settings_fixed_bar.h new file mode 100644 index 0000000000..1e661586c2 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_fixed_bar.h @@ -0,0 +1,44 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +#pragma once + +namespace Ui { +class IconButton; +} // namespace Ui + +namespace Settings { + +class FixedBar : public TWidget { +public: + FixedBar(QWidget *parent); + + void resizeToWidth(int newWidth); + +protected: + void resizeEvent(QResizeEvent *e) override; + void paintEvent(QPaintEvent *e) override; + +private: + ChildWidget _close; + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_inner_widget.cpp b/Telegram/SourceFiles/settings/settings_inner_widget.cpp new file mode 100644 index 0000000000..d85c5eabe1 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_inner_widget.cpp @@ -0,0 +1,60 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +#include "stdafx.h" +#include "settings/settings_inner_widget.h" + +namespace Settings { + +InnerWidget::InnerWidget(QWidget *parent) : TWidget(parent) +{ +} + +void InnerWidget::resizeToWidth(int newWidth, int contentLeft) { + int newHeight = resizeGetHeight(newWidth, contentLeft); + resize(newWidth, newHeight); +} + +int InnerWidget::resizeGetHeight(int newWidth, int contentLeft) { + int result = 0; + //if (_cover) { + // result += _cover->height(); + //} + //for_const (auto blockData, _blocks) { + // if (blockData->isHidden()) { + // continue; + // } + + // result += blockData->height(); + //} + return result; +} + +void InnerWidget::setVisibleTopBottom(int visibleTop, int visibleBottom) { + _visibleTop = visibleTop; + _visibleBottom = visibleBottom; + + //for_const (auto blockData, _blocks) { + // int blockY = blockData->y(); + // blockData->setVisibleTopBottom(visibleTop - blockY, visibleBottom - blockY); + //} +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_inner_widget.h b/Telegram/SourceFiles/settings/settings_inner_widget.h new file mode 100644 index 0000000000..cb21d3112a --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_inner_widget.h @@ -0,0 +1,50 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +#pragma once + +namespace Settings { + +class CoverWidget; +class BlockWidget; + +class InnerWidget : public TWidget { +public: + InnerWidget(QWidget *parent); + + // Count new height for width=newWidth and resize to it. + void resizeToWidth(int newWidth, int contentLeft); + + // Updates the area that is visible inside the scroll container. + void setVisibleTopBottom(int visibleTop, int visibleBottom); + +private: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth, int contentLeft); + + ChildWidget _cover = { nullptr }; + QList _blocks; + + int _visibleTop = 0; + int _visibleBottom = 0; + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index 281a673d4b..a1cfc4a6a9 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -21,6 +21,92 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "stdafx.h" #include "settings/settings_widget.h" +#include "settings/settings_inner_widget.h" +#include "settings/settings_fixed_bar.h" +#include "styles/style_settings.h" +#include "ui/scrollarea.h" +#include "mainwindow.h" + namespace Settings { +Widget::Widget() : LayerWidget() +, _scroll(this, st::setScroll) +, _inner(this) +, _fixedBar(this) +, _fixedBarShadow1(this, st::settingsFixedBarShadowBg1) +, _fixedBarShadow2(this, st::settingsFixedBarShadowBg2) { + _scroll->setOwnedWidget(_inner); + setAttribute(Qt::WA_OpaquePaintEvent); + + _fixedBar->move(0, 0); + _fixedBarShadow1->move(0, _fixedBar->y() + st::settingsFixedBarHeight); + _fixedBarShadow2->move(0, _fixedBarShadow1->y() + st::lineWidth); +} + +void Widget::parentResized() { + int windowWidth = App::wnd()->width(); + int newWidth = st::settingsMaxWidth; + int newContentLeft = st::settingsMaxPadding; + if (windowWidth <= st::settingsMaxWidth) { + newWidth = windowWidth; + newContentLeft = st::settingsMinPadding; + if (windowWidth > st::wndMinWidth) { + // Width changes from st::wndMinWidth to st::settingsMaxWidth. + // Padding changes from st::settingsMinPadding to st::settingsMaxPadding. + newContentLeft += ((newWidth - st::wndMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::wndMinWidth); + } + } else if (windowWidth < st::settingsMaxWidth + 2 * st::settingsMargin) { + newWidth = windowWidth - 2 * st::settingsMargin; + newContentLeft = st::settingsMinPadding; + if (windowWidth > st::wndMinWidth) { + // Width changes from st::wndMinWidth to st::settingsMaxWidth. + // Padding changes from st::settingsMinPadding to st::settingsMaxPadding. + newContentLeft += ((newWidth - st::wndMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::wndMinWidth); + } + } + + // Widget height depends on InnerWidget height, so we + // resize it here, not in the resizeEvent() handler. + _inner->resizeToWidth(newWidth, newContentLeft); + + int windowHeight = App::wnd()->height(); + int maxHeight = st::settingsFixedBarHeight + _inner->height(); + int newHeight = maxHeight; + if (newHeight > windowHeight || newWidth >= windowWidth) { + newHeight = windowHeight; + } + + if (_contentLeft != newContentLeft) { + _contentLeft = newContentLeft; + } + + setGeometry((App::wnd()->width() - newWidth) / 2, (App::wnd()->height() - newHeight) / 2, newWidth, newHeight); + update(); +} + +void Widget::paintEvent(QPaintEvent *e) { + Painter p(this); + p.fillRect(rect(), st::windowBg); +} + +void Widget::resizeEvent(QResizeEvent *e) { + if (!width() || !height()) { + return; + } + + _fixedBar->resizeToWidth(width()); + _fixedBarShadow1->resize(width(), st::lineWidth); + _fixedBarShadow2->resize(width(), st::lineWidth); + + QSize scrollSize(width(), height() - _fixedBar->height()); + if (_scroll->size() != scrollSize) { + _scroll->resize(scrollSize); + } + + if (!_scroll->isHidden()) { + int scrollTop = _scroll->scrollTop(); + _inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height()); + } +} + } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_widget.h b/Telegram/SourceFiles/settings/settings_widget.h index aa345c8605..d729fbab01 100644 --- a/Telegram/SourceFiles/settings/settings_widget.h +++ b/Telegram/SourceFiles/settings/settings_widget.h @@ -20,6 +20,31 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once +#include "layerwidget.h" + namespace Settings { +class InnerWidget; +class FixedBar; + +class Widget : public LayerWidget { +public: + Widget(); + + void parentResized() override; + +protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + +private: + ChildWidget _scroll; + ChildWidget _inner; + ChildWidget _fixedBar; + ChildWidget _fixedBarShadow1, _fixedBarShadow2; + + int _contentLeft = 0; + +}; + } // namespace Settings diff --git a/Telegram/SourceFiles/settingswidget.cpp b/Telegram/SourceFiles/settingswidget.cpp index 954273a35c..2aeac5548c 100644 --- a/Telegram/SourceFiles/settingswidget.cpp +++ b/Telegram/SourceFiles/settingswidget.cpp @@ -208,6 +208,7 @@ SettingsInner::SettingsInner(SettingsWidget *parent) : TWidget(parent) , _logOut(this, lang(lng_settings_logout), st::btnRedLink) , _supportGetRequest(0) { Notify::registerPeerObserver(Notify::PeerUpdate::Flag::UsernameChanged, this, &SettingsInner::notifyPeerUpdated); + registerDownloadPathObserver(this, &SettingsInner::notifyDownloadPathUpdated); App::clearMousedItems(); @@ -367,6 +368,19 @@ void SettingsInner::notifyPeerUpdated(const Notify::PeerUpdate &update) { } } +void SettingsInner::notifyDownloadPathUpdated(const DownloadPathUpdate &update) { + QString path; + if (cDownloadPath().isEmpty()) { + path = lang(lng_download_path_default); + } else if (cDownloadPath() == qsl("tmp")) { + path = lang(lng_download_path_temp); + } else { + path = st::linkFont->elided(QDir::toNativeSeparators(cDownloadPath()), st::setWidth - st::setVersionLeft - _downloadPathWidth); + } + _downloadPathEdit.setText(path); + showAll(); +} + void SettingsInner::peerUpdated(PeerData *data) { if (self() && data == self()) { if (self()->photoId && self()->photoId != UnknownPeerPhotoId) { @@ -1208,10 +1222,9 @@ void SettingsInner::supportGot(const MTPhelp_Support &support) { if (!App::main()) return; if (support.type() == mtpc_help_support) { - const auto &d(support.c_help_support()); + auto &d = support.c_help_support(); UserData *u = App::feedUsers(MTP_vector(1, d.vuser)); Ui::showPeerHistory(u, ShowAtUnreadMsgId); - App::wnd()->hideSettings(); } } @@ -1637,6 +1650,10 @@ void SettingsInner::onCtrlEnterSend() { void SettingsInner::onBackFromGallery() { BackgroundBox *box = new BackgroundBox(); + box->setUpdateCallback([this, weak_this = weakThis()](bool tile) { + if (!weak_this) return; + needBackgroundUpdate(tile); + }); Ui::showLayer(box); } @@ -1774,22 +1791,7 @@ void SettingsInner::onDontAskDownloadPath() { } void SettingsInner::onDownloadPathEdit() { - DownloadPathBox *box = new DownloadPathBox(); - connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(onDownloadPathEdited())); - Ui::showLayer(box); -} - -void SettingsInner::onDownloadPathEdited() { - QString path; - if (cDownloadPath().isEmpty()) { - path = lang(lng_download_path_default); - } else if (cDownloadPath() == qsl("tmp")) { - path = lang(lng_download_path_temp); - } else { - path = st::linkFont->elided(QDir::toNativeSeparators(cDownloadPath()), st::setWidth - st::setVersionLeft - _downloadPathWidth); - } - _downloadPathEdit.setText(path); - showAll(); + Ui::showLayer(new DownloadPathBox()); } void SettingsInner::onDownloadPathClear() { @@ -2063,5 +2065,4 @@ void SettingsWidget::needBackgroundUpdate(bool tile) { } SettingsWidget::~SettingsWidget() { - if (App::wnd()) App::wnd()->noSettings(this); } diff --git a/Telegram/SourceFiles/settingswidget.h b/Telegram/SourceFiles/settingswidget.h index 8dffd1ed19..da7fcd4920 100644 --- a/Telegram/SourceFiles/settingswidget.h +++ b/Telegram/SourceFiles/settingswidget.h @@ -24,6 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/flatcheckbox.h" #include "sysbuttons.h" #include "core/observer.h" +#include "boxes/downloadpathbox.h" class MainWindow; @@ -151,7 +152,6 @@ public slots: void onDontAskDownloadPath(); void onDownloadPathEdit(); - void onDownloadPathEdited(); void onDownloadPathClear(); void onDownloadPathClearSure(); void onTempDirCleared(int task); @@ -194,6 +194,7 @@ private slots: private: void notifyPeerUpdated(const Notify::PeerUpdate &update); + void notifyDownloadPathUpdated(const DownloadPathUpdate &update); void saveError(const QString &str = QString()); diff --git a/Telegram/SourceFiles/title.cpp b/Telegram/SourceFiles/title.cpp index b969cd7bd0..e3cbdf91f1 100644 --- a/Telegram/SourceFiles/title.cpp +++ b/Telegram/SourceFiles/title.cpp @@ -52,7 +52,6 @@ TitleWidget::TitleWidget(MainWindow *window) : TWidget(window) , wnd(window) , hideLevel(0) , hider(0) -, _back(this, st::titleBackButton, lang(lng_menu_back)) , _cancel(this, lang(lng_cancel), st::titleTextButton) , _settings(this, lang(lng_menu_settings), st::titleTextButton) , _contacts(this, lang(lng_menu_contacts), st::titleTextButton) @@ -64,14 +63,12 @@ TitleWidget::TitleWidget(MainWindow *window) : TWidget(window) , _restore(this, window) , _close(this, window) , _a_update(animation(this, &TitleWidget::step_update)) -, lastMaximized(!(window->windowState() & Qt::WindowMaximized)) -{ +, lastMaximized(!(window->windowState() & Qt::WindowMaximized)) { setGeometry(0, 0, wnd->width(), st::titleHeight); setAttribute(Qt::WA_OpaquePaintEvent); _lock.hide(); _update.hide(); _cancel.hide(); - _back.hide(); if ( #ifndef TDESKTOP_DISABLE_AUTOUPDATE Sandbox::updatingState() == Application::UpdatingReady || @@ -82,7 +79,6 @@ TitleWidget::TitleWidget(MainWindow *window) : TWidget(window) } onWindowStateChanged(); - connect(&_back, SIGNAL(clicked()), window, SLOT(hideSettings())); connect(&_cancel, SIGNAL(clicked()), this, SIGNAL(hiderClicked())); connect(&_settings, SIGNAL(clicked()), window, SLOT(showSettings())); connect(&_contacts, SIGNAL(clicked()), this, SLOT(onContacts())); @@ -193,9 +189,7 @@ void TitleWidget::resizeEvent(QResizeEvent *e) { } _settings.move(st::titleMenuOffset, 0); - _back.move(st::titleMenuOffset, 0); - _back.resize((_minimize.isHidden() ? (_update.isHidden() ? width() : _update.x()) : _minimize.x()) - st::titleMenuOffset, _back.height()); - if (MTP::authedId() && _back.isHidden() && _cancel.isHidden() && !App::passcoded()) { + if (MTP::authedId() && _cancel.isHidden() && !App::passcoded()) { if (_contacts.isHidden()) _contacts.show(); _contacts.move(_settings.x() + _settings.width(), 0); _about.move(_contacts.x() + _contacts.width(), 0); @@ -210,7 +204,6 @@ void TitleWidget::resizeEvent(QResizeEvent *e) { void TitleWidget::updateBackButton() { if (App::passcoded()) { if (!_cancel.isHidden()) _cancel.hide(); - if (!_back.isHidden()) _back.hide(); if (!_settings.isHidden()) _settings.hide(); if (!_contacts.isHidden()) _contacts.hide(); if (!_about.isHidden()) _about.hide(); @@ -219,7 +212,6 @@ void TitleWidget::updateBackButton() { _lock.setSysBtnStyle(st::sysLock); if (Adaptive::OneColumn() && App::main() && App::main()->selectingPeer()) { _cancel.show(); - if (!_back.isHidden()) _back.hide(); if (!_settings.isHidden()) _settings.hide(); if (!_contacts.isHidden()) _contacts.hide(); if (!_about.isHidden()) _about.hide(); @@ -227,19 +219,10 @@ void TitleWidget::updateBackButton() { if (!_cancel.isHidden()) _cancel.hide(); bool authed = (MTP::authedId() > 0); if (Adaptive::OneColumn()) { - if (App::wnd()->needBackButton()) { - if (_back.isHidden()) _back.show(); - if (!_settings.isHidden()) _settings.hide(); - if (!_contacts.isHidden()) _contacts.hide(); - if (!_about.isHidden()) _about.hide(); - } else { - if (!_back.isHidden()) _back.hide(); - if (_settings.isHidden()) _settings.show(); - if (authed && _contacts.isHidden()) _contacts.show(); - if (_about.isHidden()) _about.show(); - } + if (_settings.isHidden()) _settings.show(); + if (authed && _contacts.isHidden()) _contacts.show(); + if (_about.isHidden()) _about.show(); } else { - if (!_back.isHidden()) _back.hide(); if (_settings.isHidden()) _settings.show(); if (authed && _contacts.isHidden()) _contacts.show(); if (_about.isHidden()) _about.show(); @@ -393,7 +376,6 @@ HitTestType TitleWidget::hitTest(const QPoint &p) { return HitTestSysButton; } else if (x >= 0 && x < w && y >= 0 && y < h) { if (false - || (!_back.isHidden() && _back.geometry().contains(x, y)) || (!_cancel.isHidden() && _cancel.geometry().contains(x, y)) || (!_settings.isHidden() && _settings.geometry().contains(x, y)) || (!_contacts.isHidden() && _contacts.geometry().contains(x, y)) diff --git a/Telegram/SourceFiles/title.h b/Telegram/SourceFiles/title.h index e6ef17cc57..a8ad2bfbe4 100644 --- a/Telegram/SourceFiles/title.h +++ b/Telegram/SourceFiles/title.h @@ -87,7 +87,6 @@ private: float64 _lastUpdateMs; - MaskedButton _back; FlatButton _cancel, _settings, _contacts, _about; LockBtn _lock; diff --git a/Telegram/SourceFiles/ui/button.cpp b/Telegram/SourceFiles/ui/button.cpp index 8cdd88889a..ff58f77d2a 100644 --- a/Telegram/SourceFiles/ui/button.cpp +++ b/Telegram/SourceFiles/ui/button.cpp @@ -74,6 +74,9 @@ void Button::mouseReleaseEvent(QMouseEvent *e) { onStateChanged(oldState, ButtonByPress); if (oldState & StateOver) { _modifiers = e->modifiers(); + if (_clickedCallback) { + _clickedCallback(); + } emit clicked(); } else { leaveEvent(e); diff --git a/Telegram/SourceFiles/ui/button.h b/Telegram/SourceFiles/ui/button.h index 13afd8f84a..298bc7e8c2 100644 --- a/Telegram/SourceFiles/ui/button.h +++ b/Telegram/SourceFiles/ui/button.h @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include #include "ui/twidget.h" +#include "core/lambda_wrap.h" typedef enum { ButtonByUser = 0x00, // by clearState() call @@ -42,17 +43,10 @@ public: StateDisabled = 0x04, }; - void mousePressEvent(QMouseEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - Qt::KeyboardModifiers clickModifiers() const { return _modifiers; } - void enterEvent(QEvent *e); - void leaveEvent(QEvent *e); - void clearState(); int getState() const; @@ -64,8 +58,18 @@ public: void setAcceptBoth(bool acceptBoth = true); -signals: + void setClickedCallback(base::lambda_unique &&callback) { + _clickedCallback = std_::move(callback); + } +protected: + void enterEvent(QEvent *e) override; + void leaveEvent(QEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + +signals: void clicked(); void stateChanged(int oldState, ButtonStateChangeSource source); @@ -77,4 +81,6 @@ protected: int _state; bool _acceptBoth; + base::lambda_unique _clickedCallback; + }; diff --git a/Telegram/SourceFiles/ui/filedialog.cpp b/Telegram/SourceFiles/ui/filedialog.cpp index f9559a193a..45a947ceb8 100644 --- a/Telegram/SourceFiles/ui/filedialog.cpp +++ b/Telegram/SourceFiles/ui/filedialog.cpp @@ -373,7 +373,7 @@ bool processQuery() { } break; } - // No one know what happened during filedialogGet*() call in the event loop. + // No one knows what happened during filedialogGet*() call in the event loop. if (!creator.started() || !Global::started()) return false; creator.notify(update); diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index 67aade2a6f..0532b50242 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -331,6 +331,10 @@ '<(src_loc)/serialize/serialize_common.h', '<(src_loc)/serialize/serialize_document.cpp', '<(src_loc)/serialize/serialize_document.h', + '<(src_loc)/settings/settings_fixed_bar.cpp', + '<(src_loc)/settings/settings_fixed_bar.h', + '<(src_loc)/settings/settings_inner_widget.cpp', + '<(src_loc)/settings/settings_inner_widget.h', '<(src_loc)/settings/settings_widget.cpp', '<(src_loc)/settings/settings_widget.h', '<(src_loc)/ui/buttons/history_down_button.cpp',