From 329db0d8e9b87bf2d359abaa05147bef5236f62b Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 20 Jun 2018 01:02:36 +0100 Subject: [PATCH] Export panel minimizes to a top bar, like a Call. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/data/data_session.cpp | 28 +++++ Telegram/SourceFiles/data/data_session.h | 16 +++ .../SourceFiles/export/export_api_wrap.cpp | 5 + Telegram/SourceFiles/export/view/export.style | 7 ++ .../export/view/export_view_content.cpp | 2 +- .../export/view/export_view_content.h | 12 +- .../view/export_view_panel_controller.cpp | 15 ++- .../view/export_view_panel_controller.h | 11 ++ .../export/view/export_view_top_bar.cpp | 91 +++++++++++++++ .../export/view/export_view_top_bar.h | 51 +++++++++ Telegram/SourceFiles/mainwidget.cpp | 106 ++++++++++++++++-- Telegram/SourceFiles/mainwidget.h | 24 +++- .../SourceFiles/settings/settings_widget.cpp | 9 +- .../SourceFiles/ui/widgets/separate_panel.cpp | 33 +++++- .../SourceFiles/ui/widgets/separate_panel.h | 4 + .../SourceFiles/window/player_wrap_widget.cpp | 31 ----- .../SourceFiles/window/player_wrap_widget.h | 36 ------ .../SourceFiles/window/window_controller.cpp | 20 ---- .../SourceFiles/window/window_controller.h | 12 -- .../SourceFiles/window/window_top_bar_wrap.h | 45 ++++++++ Telegram/gyp/telegram_sources.txt | 5 +- 22 files changed, 437 insertions(+), 127 deletions(-) create mode 100644 Telegram/SourceFiles/export/view/export_view_top_bar.cpp create mode 100644 Telegram/SourceFiles/export/view/export_view_top_bar.h delete mode 100644 Telegram/SourceFiles/window/player_wrap_widget.cpp delete mode 100644 Telegram/SourceFiles/window/player_wrap_widget.h create mode 100644 Telegram/SourceFiles/window/window_top_bar_wrap.h diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b4d0dd86f5..4ab96e951c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1654,6 +1654,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_passport_bad_name" = "Please use latin characters only."; "lng_export_title" = "Personal data export"; +"lng_export_progress_title" = "Exporting personal data"; "lng_export_option_info" = "Personal information"; "lng_export_option_contacts" = "Contacts list"; "lng_export_option_sessions" = "Sessions list"; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 55c47efaf3..47a5915173 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "observer_peer.h" #include "auth_session.h" #include "apiwrap.h" +#include "export/export_controller.h" +#include "export/view/export_view_panel_controller.h" #include "window/notifications_manager.h" #include "history/history.h" #include "history/history_item_components.h" @@ -68,6 +70,32 @@ Session::Session(not_null session) setupChannelLeavingViewer(); } +void Session::startExport() { + _export = std::make_unique(); + _exportPanel = std::make_unique( + _export.get()); + + _exportViewChanges.fire(_exportPanel.get()); + + _exportPanel->closed( + ) | rpl::start_with_next([=] { + clearExport(); + }, _export->lifetime()); +} + +rpl::producer Session::currentExportView( +) const { + return _exportViewChanges.events_starting_with(_exportPanel.get()); +} + +void Session::clearExport() { + if (_exportPanel) { + _exportPanel = nullptr; + _exportViewChanges.fire(nullptr); + } + _export = nullptr; +} + void Session::setupContactViewsViewer() { Notify::PeerUpdateViewer( Notify::PeerUpdate::Flag::UserIsContact diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index fbbf39b9d5..c1b254cb9a 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -27,6 +27,13 @@ class Reader; } // namespace Clip } // namespace Media +namespace Export { +class ControllerWrap; +namespace View { +class PanelController; +} // namespace View +} // namespace Export + namespace Data { class Feed; @@ -44,6 +51,9 @@ public: return *_session; } + void startExport(); + rpl::producer currentExportView() const; + [[nodiscard]] base::Variable &contactsLoaded() { return _contactsLoaded; } @@ -395,6 +405,8 @@ public: } private: + void clearExport(); + void setupContactViewsViewer(); void setupChannelLeavingViewer(); void photoApplyFields( @@ -489,6 +501,10 @@ private: not_null _session; + std::unique_ptr _export; + std::unique_ptr _exportPanel; + rpl::event_stream _exportViewChanges; + base::Variable _contactsLoaded = { false }; base::Variable _allChatsLoaded = { false }; base::Observable _moreChatsLoaded; diff --git a/Telegram/SourceFiles/export/export_api_wrap.cpp b/Telegram/SourceFiles/export/export_api_wrap.cpp index 35048b70fe..a6dad61321 100644 --- a/Telegram/SourceFiles/export/export_api_wrap.cpp +++ b/Telegram/SourceFiles/export/export_api_wrap.cpp @@ -699,6 +699,7 @@ void ApiWrap::requestMessages( void ApiWrap::requestDialogsSlice() { Expects(_dialogsProcess != nullptr); + LOG(("REQUEST %1 %2").arg(_dialogsProcess->offsetDate).arg(_dialogsProcess->offsetId)); mainRequest(MTPmessages_GetDialogs( MTP_flags(0), MTP_int(_dialogsProcess->offsetDate), @@ -722,6 +723,10 @@ void ApiWrap::requestDialogsSlice() { _dialogsProcess->offsetDate = last.topMessageDate; _dialogsProcess->offsetPeer = last.input; + for (const auto &item : info.list) { + LOG(("RESULT: %1 %2").arg(item.topMessageDate).arg(item.topMessageId)); + } + appendDialogsSlice(std::move(info)); const auto count = _dialogsProcess->info.list.size(); diff --git a/Telegram/SourceFiles/export/view/export.style b/Telegram/SourceFiles/export/view/export.style index 3981476278..fe393f4a1d 100644 --- a/Telegram/SourceFiles/export/view/export.style +++ b/Telegram/SourceFiles/export/view/export.style @@ -62,3 +62,10 @@ exportProgressInfoLabel: FlatLabel(boxLabel) { exportProgressWidth: 3px; exportProgressFg: mediaPlayerActiveFg; exportProgressBg: mediaPlayerInactiveFg; + +exportTopBarLabel: FlatLabel(defaultFlatLabel) { + maxHeight: 20px; + palette: TextPalette(defaultTextPalette) { + linkFg: windowSubTextFg; + } +} diff --git a/Telegram/SourceFiles/export/view/export_view_content.cpp b/Telegram/SourceFiles/export/view/export_view_content.cpp index 6c34e1d232..f517cf5453 100644 --- a/Telegram/SourceFiles/export/view/export_view_content.cpp +++ b/Telegram/SourceFiles/export/view/export_view_content.cpp @@ -70,7 +70,7 @@ Content ContentFromState(const ProcessingState &state) { pushMain(lang(lng_export_state_userpics)); pushBytes( "userpic" + QString::number(state.entityIndex), - "Photo_" + QString::number(state.entityIndex + 1) + ".jpg"); + state.bytesName); break; case Step::Contacts: pushMain(lang(lng_export_option_contacts)); diff --git a/Telegram/SourceFiles/export/view/export_view_content.h b/Telegram/SourceFiles/export/view/export_view_content.h index f0c5e230e4..0240f8b398 100644 --- a/Telegram/SourceFiles/export/view/export_view_content.h +++ b/Telegram/SourceFiles/export/view/export_view_content.h @@ -27,14 +27,16 @@ struct Content { Content ContentFromState(const ProcessingState &state); inline auto ContentFromState(rpl::producer state) { - return rpl::single(Content()) | rpl::then(std::move( + return std::move( state ) | rpl::filter([](const State &state) { - return state.template is(); + return state.is() || state.is(); }) | rpl::map([](const State &state) { - return ContentFromState( - state.template get_unchecked()); - })); + if (const auto process = base::get_if(&state)) { + return ContentFromState(*process); + } + return Content(); + }); } } // namespace View diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index 4da0b6fc30..aae8d4dd89 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -28,6 +28,10 @@ PanelController::PanelController(not_null process) }, _lifetime); } +void PanelController::activatePanel() { + _panel->showAndActivate(); +} + void PanelController::createPanel() { _panel = base::make_unique_q(); _panel->setTitle(Lang::Viewer(lng_export_title)); @@ -84,12 +88,17 @@ void PanelController::showError(const QString &text) { }, container->lifetime()); _panel->showInner(std::move(container)); + _panel->setHideOnDeactivate(false); } void PanelController::showProgress() { + _panel->setTitle(Lang::Viewer(lng_export_progress_title)); + auto progress = base::make_unique_q( _panel.get(), - ContentFromState(_process->state())); + rpl::single( + ContentFromState(ProcessingState()) + ) | rpl::then(progressState())); progress->cancelClicks( ) | rpl::start_with_next([=] { @@ -97,9 +106,12 @@ void PanelController::showProgress() { }, progress->lifetime()); _panel->showInner(std::move(progress)); + _panel->setHideOnDeactivate(true); } void PanelController::showDone(const QString &path) { + _panel->setTitle(Lang::Viewer(lng_export_title)); + auto done = base::make_unique_q(_panel.get()); done->showClicks( @@ -114,6 +126,7 @@ void PanelController::showDone(const QString &path) { }, done->lifetime()); _panel->showInner(std::move(done)); + _panel->setHideOnDeactivate(false); } rpl::producer<> PanelController::closed() const { diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.h b/Telegram/SourceFiles/export/view/export_view_panel_controller.h index 35f68afb75..a273aab3cd 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.h +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "export/export_controller.h" +#include "export/view/export_view_content.h" #include "base/unique_qptr.h" namespace Ui { @@ -23,8 +24,18 @@ class PanelController { public: PanelController(not_null process); + void activatePanel(); + rpl::producer<> closed() const; + rpl::lifetime &lifetime() { + return _lifetime; + } + + auto progressState() const { + return ContentFromState(_process->state()); + } + ~PanelController(); private: diff --git a/Telegram/SourceFiles/export/view/export_view_top_bar.cpp b/Telegram/SourceFiles/export/view/export_view_top_bar.cpp new file mode 100644 index 0000000000..b2cdef9b45 --- /dev/null +++ b/Telegram/SourceFiles/export/view/export_view_top_bar.cpp @@ -0,0 +1,91 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "export/view/export_view_top_bar.h" + +#include "export/view/export_view_content.h" +#include "ui/widgets/continuous_sliders.h" +#include "ui/widgets/labels.h" +#include "ui/widgets/buttons.h" +#include "ui/widgets/shadow.h" +#include "lang/lang_keys.h" +#include "styles/style_export.h" +#include "styles/style_media_player.h" + +namespace Export { +namespace View { + +TopBar::TopBar(QWidget *parent, Content &&content) +: RpWidget(parent) +, _info(this, st::exportTopBarLabel) +, _shadow(this) +, _progress(this, st::mediaPlayerPlayback) +, _button(this) { + resize(width(), st::mediaPlayerHeight + st::lineWidth); + _progress->setAttribute(Qt::WA_TransparentForMouseEvents); + updateData(std::move(content)); +} + +rpl::producer<> TopBar::clicks() const { + return _button->clicks(); +} + +void TopBar::updateData(Content &&content) { + if (content.rows.empty()) { + return; + } + const auto &row = content.rows[0]; + const auto clean = &TextUtilities::Clean; + _info->setRichText(textcmdStartSemibold() + + clean(lang(lng_export_progress_title)) + + textcmdStopSemibold() + + QString::fromUtf8(" \xe2\x80\x93 ") + + clean(row.label) + + ' ' + + textcmdLink(1, clean(row.info))); + _progress->setValue(row.progress); +} + +void TopBar::resizeEvent(QResizeEvent *e) { + _info->moveToLeft( + st::mediaPlayerPlayLeft + st::mediaPlayerPadding, + st::mediaPlayerNameTop - st::mediaPlayerName.style.font->ascent); + _button->setGeometry(0, 0, width(), height() - st::lineWidth); + _progress->setGeometry( + 0, + height() - st::mediaPlayerPlayback.fullWidth, + width(), + st::mediaPlayerPlayback.fullWidth); +} + +void TopBar::paintEvent(QPaintEvent *e) { + Painter p(this); + auto fill = e->rect().intersected( + QRect(0, 0, width(), st::mediaPlayerHeight)); + if (!fill.isEmpty()) { + p.fillRect(fill, st::mediaPlayerBg); + } +} + +void TopBar::setShadowGeometryToLeft(int x, int y, int w, int h) { + _shadow->setGeometryToLeft(x, y, w, h); +} + +void TopBar::showShadow() { + _shadow->show(); + _progress->show(); +} + +void TopBar::hideShadow() { + _shadow->hide(); + _progress->hide(); +} + +TopBar::~TopBar() = default; + +} // namespace View +} // namespace Export diff --git a/Telegram/SourceFiles/export/view/export_view_top_bar.h b/Telegram/SourceFiles/export/view/export_view_top_bar.h new file mode 100644 index 0000000000..07b54299e0 --- /dev/null +++ b/Telegram/SourceFiles/export/view/export_view_top_bar.h @@ -0,0 +1,51 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "ui/rp_widget.h" + +namespace Ui { +class FlatLabel; +class FilledSlider; +class AbstractButton; +class PlainShadow; +} // namespace Ui + +namespace Export { +namespace View { + +struct Content; + +class TopBar : public Ui::RpWidget { +public: + TopBar(QWidget *parent, Content &&content); + + rpl::producer<> clicks() const; + + void updateData(Content &&content); + + void setShadowGeometryToLeft(int x, int y, int w, int h); + void showShadow(); + void hideShadow(); + + ~TopBar(); + +protected: + void resizeEvent(QResizeEvent *e) override; + void paintEvent(QPaintEvent *e) override; + +private: + object_ptr _info; + object_ptr _shadow = { nullptr }; + object_ptr _progress; + object_ptr _button; + +}; + +} // namespace View +} // namespace Export diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index c4ddba6594..499d2b8119 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -69,7 +69,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_regex.h" #include "base/qthelp_url.h" #include "base/flat_set.h" -#include "window/player_wrap_widget.h" +#include "window/window_top_bar_wrap.h" #include "window/notifications_manager.h" #include "window/window_slide_animation.h" #include "window/window_controller.h" @@ -79,6 +79,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" #include "calls/calls_instance.h" #include "calls/calls_top_bar.h" +#include "export/view/export_view_top_bar.h" +#include "export/view/export_view_panel_controller.h" #include "auth_session.h" #include "storage/storage_facade.h" #include "storage/storage_shared_media.h" @@ -269,6 +271,12 @@ MainWidget::MainWidget( } }); subscribe(Auth().calls().currentCallChanged(), [this](Calls::Call *call) { setCurrentCall(call); }); + + Auth().data().currentExportView( + ) | rpl::start_with_next([=](Export::View::PanelController *view) { + setCurrentExportView(view); + }, lifetime()); + subscribe(_controller->dialogsListFocused(), [this](bool) { updateDialogsWidthAnimated(); }); @@ -1578,7 +1586,7 @@ void MainWidget::createPlayer() { return; } if (!_player) { - _player.create(this); + _player.create(this, object_ptr(this)); rpl::merge( _player->heightValue() | rpl::map([] { return true; }), _player->shownValue() @@ -1645,6 +1653,7 @@ void MainWidget::setCurrentCall(Calls::Call *call) { void MainWidget::createCallTopBar() { Expects(_currentCall != nullptr); + _callTopBar.create(this, object_ptr(this, _currentCall)); _callTopBar->heightValue( ) | rpl::start_with_next([this](int value) { @@ -1679,6 +1688,74 @@ void MainWidget::callTopBarHeightUpdated(int callTopBarHeight) { } } +void MainWidget::setCurrentExportView(Export::View::PanelController *view) { + _currentExportView = view; + if (_currentExportView) { + _currentExportView->progressState( + ) | rpl::start_with_next([=](Export::View::Content &&data) { + if (data.rows.empty()) { + destroyExportTopBar(); + } else if (!_exportTopBar) { + createExportTopBar(std::move(data)); + } else { + _exportTopBar->entity()->updateData(std::move(data)); + } + }, _currentExportView->lifetime()); + } else { + destroyExportTopBar(); + } +} + +void MainWidget::createExportTopBar(Export::View::Content &&data) { + _exportTopBar.create( + this, + object_ptr(this, std::move(data))); + rpl::merge( + _exportTopBar->heightValue() | rpl::map([] { return true; }), + _exportTopBar->shownValue() + ) | rpl::start_with_next([=] { + exportTopBarHeightUpdated(); + }, _exportTopBar->lifetime()); + _exportTopBar->entity()->clicks( + ) | rpl::start_with_next([=] { + if (_currentExportView) { + _currentExportView->activatePanel(); + } + }, _exportTopBar->lifetime()); + orderWidgets(); + if (_a_show.animating()) { + _exportTopBar->show(anim::type::instant); + _exportTopBar->setVisible(false); + } else { + _exportTopBar->hide(anim::type::instant); + _exportTopBar->show(anim::type::normal); + _exportTopBarHeight = _contentScrollAddToY = _exportTopBar->contentHeight(); + updateControlsGeometry(); + } +} + +void MainWidget::destroyExportTopBar() { + if (_exportTopBar) { + _exportTopBar->hide(anim::type::normal); + } +} + +void MainWidget::exportTopBarHeightUpdated() { + if (!_exportTopBar) { + // Player could be already "destroyDelayed", but still handle events. + return; + } + const auto exportTopBarHeight = _exportTopBar->contentHeight(); + if (exportTopBarHeight != _exportTopBarHeight) { + _contentScrollAddToY += exportTopBarHeight - _exportTopBarHeight; + _exportTopBarHeight = exportTopBarHeight; + updateControlsGeometry(); + } + if (!_exportTopBarHeight && _exportTopBar->isHidden()) { + _exportTopBar.destroyDelayed(); + } +} + void MainWidget::documentLoadProgress(FileLoader *loader) { if (auto documentId = loader ? loader->objId() : 0) { documentLoadProgress(Auth().data().document(documentId)); @@ -2560,12 +2637,15 @@ void MainWidget::showBackFromStack( void MainWidget::orderWidgets() { _dialogs->raise(); - if (_callTopBar) { - _callTopBar->raise(); - } if (_player) { _player->raise(); } + if (_exportTopBar) { + _exportTopBar->raise(); + } + if (_callTopBar) { + _callTopBar->raise(); + } if (_playerVolume) { _playerVolume->raise(); } @@ -2767,7 +2847,7 @@ void MainWidget::paintEvent(QPaintEvent *e) { } int MainWidget::getMainSectionTop() const { - return _callTopBarHeight + _playerHeight; + return _callTopBarHeight + _exportTopBarHeight + _playerHeight; } int MainWidget::getThirdSectionTop() const { @@ -2916,9 +2996,13 @@ void MainWidget::updateControlsGeometry() { _callTopBar->resizeToWidth(dialogsWidth); _callTopBar->moveToLeft(0, 0); } + if (_exportTopBar) { + _exportTopBar->resizeToWidth(dialogsWidth); + _exportTopBar->moveToLeft(0, _callTopBarHeight); + } if (_player) { _player->resizeToWidth(dialogsWidth); - _player->moveToLeft(0, _callTopBarHeight); + _player->moveToLeft(0, _callTopBarHeight + _exportTopBarHeight); } auto mainSectionGeometry = QRect( 0, @@ -2954,9 +3038,15 @@ void MainWidget::updateControlsGeometry() { _callTopBar->resizeToWidth(mainSectionWidth); _callTopBar->moveToLeft(dialogsWidth, 0); } + if (_exportTopBar) { + _exportTopBar->resizeToWidth(mainSectionWidth); + _exportTopBar->moveToLeft(dialogsWidth, _callTopBarHeight); + } if (_player) { _player->resizeToWidth(mainSectionWidth); - _player->moveToLeft(dialogsWidth, _callTopBarHeight); + _player->moveToLeft( + dialogsWidth, + _callTopBarHeight + _exportTopBarHeight); } _history->setGeometryToLeft(dialogsWidth, mainSectionTop, mainSectionWidth, height() - mainSectionTop); if (_hider) { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index fa7770d162..cc0be0aaac 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -40,6 +40,14 @@ class Float; } // namespace Player } // namespace Media +namespace Export { +namespace View { +class TopBar; +class PanelController; +struct Content; +} // namespace View +} // namespace Export + namespace Ui { class ResizeArea; class PlainShadow; @@ -50,7 +58,8 @@ class SlideWrap; namespace Window { class Controller; -class PlayerWrapWidget; +template +class TopBarWrapWidget; class SectionMemento; class SectionWidget; class AbstractSectionWidget; @@ -422,6 +431,11 @@ private: void destroyCallTopBar(); void callTopBarHeightUpdated(int callTopBarHeight); + void setCurrentExportView(Export::View::PanelController *view); + void createExportTopBar(Export::View::Content &&data); + void destroyExportTopBar(); + void exportTopBarHeightUpdated(); + void messagesAffected( not_null peer, const MTPmessages_AffectedMessages &result); @@ -545,7 +559,12 @@ private: base::weak_ptr _currentCall; object_ptr> _callTopBar = { nullptr }; - object_ptr _player = { nullptr }; + Export::View::PanelController *_currentExportView = nullptr; + object_ptr> _exportTopBar + = { nullptr }; + + object_ptr> _player + = { nullptr }; object_ptr _playerVolume = { nullptr }; object_ptr _playerPlaylist; object_ptr _playerPanel; @@ -558,6 +577,7 @@ private: int _playerHeight = 0; int _callTopBarHeight = 0; + int _exportTopBarHeight = 0; int _contentScrollAddToY = 0; int32 updDate = 0; diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index f666157ca5..730198b6a7 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -9,15 +9,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_inner_widget.h" #include "settings/settings_fixed_bar.h" -#include "styles/style_settings.h" -#include "styles/style_window.h" -#include "styles/style_boxes.h" #include "platform/platform_specific.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/buttons.h" #include "ui/toast/toast.h" #include "mainwindow.h" #include "mainwidget.h" +#include "data/data_session.h" #include "storage/localstorage.h" #include "boxes/confirm_box.h" #include "lang/lang_keys.h" @@ -32,6 +30,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/media_audio_track.h" #include "mainwindow.h" #include "window/window_controller.h" +#include "styles/style_settings.h" +#include "styles/style_window.h" +#include "styles/style_boxes.h" namespace Settings { namespace { @@ -128,7 +129,7 @@ void fillCodes() { Ui::Toast::Show("Forced custom scheme register."); }); Codes.insert(qsl("export"), [] { - App::wnd()->controller()->startDataExport(); + Auth().data().startExport(); }); auto audioFilters = qsl("Audio files (*.wav *.mp3);;") + FileDialog::AllFilesFilter(); diff --git a/Telegram/SourceFiles/ui/widgets/separate_panel.cpp b/Telegram/SourceFiles/ui/widgets/separate_panel.cpp index 1b1c59c684..07ddaffded 100644 --- a/Telegram/SourceFiles/ui/widgets/separate_panel.cpp +++ b/Telegram/SourceFiles/ui/widgets/separate_panel.cpp @@ -37,6 +37,8 @@ SeparatePanel::SeparatePanel() void SeparatePanel::setTitle(rpl::producer title) { _title.create(this, std::move(title), st::separatePanelTitle); _title->setAttribute(Qt::WA_TransparentForMouseEvents); + _title->show(); + updateTitleGeometry(width()); } void SeparatePanel::initControls() { @@ -45,10 +47,7 @@ void SeparatePanel::initControls() { _back->moveToLeft(_padding.left(), _padding.top()); _close->moveToRight(_padding.right(), _padding.top()); if (_title) { - _title->resizeToWidth(width - - _padding.left() - _back->width() - - _padding.right() - _close->width()); - updateTitlePosition(); + updateTitleGeometry(width); } }, lifetime()); @@ -64,6 +63,13 @@ void SeparatePanel::initControls() { _titleLeft.finish(); } +void SeparatePanel::updateTitleGeometry(int newWidth) { + _title->resizeToWidth(newWidth + - _padding.left() - _back->width() + - _padding.right() - _close->width()); + updateTitlePosition(); +} + void SeparatePanel::updateTitlePosition() { if (!_title) { return; @@ -100,6 +106,15 @@ void SeparatePanel::setBackAllowed(bool allowed) { } } +void SeparatePanel::setHideOnDeactivate(bool hideOnDeactivate) { + _hideOnDeactivate = hideOnDeactivate; + if (!_hideOnDeactivate) { + showAndActivate(); + } else if (!isActiveWindow()) { + hideGetDuration(); + } +} + void SeparatePanel::showAndActivate() { toggleOpacityAnimation(true); raise(); @@ -115,6 +130,13 @@ void SeparatePanel::keyPressEvent(QKeyEvent *e) { return RpWidget::keyPressEvent(e); } +bool SeparatePanel::eventHook(QEvent *e) { + if (e->type() == QEvent::WindowDeactivate && _hideOnDeactivate) { + hideGetDuration(); + } + return RpWidget::eventHook(e); +} + void SeparatePanel::initLayout() { setWindowFlags(Qt::WindowFlags(Qt::FramelessWindowHint) | Qt::WindowStaysOnTopHint @@ -506,7 +528,8 @@ void SeparatePanel::mousePressEvent(QMouseEvent *e) { _dragging = true; _dragStartMousePosition = e->globalPos(); _dragStartMyPosition = QPoint(x(), y()); - } else if (!rect().contains(e->pos())) { + } else if (!rect().contains(e->pos()) && _hideOnDeactivate) { + hideGetDuration(); } } } diff --git a/Telegram/SourceFiles/ui/widgets/separate_panel.h b/Telegram/SourceFiles/ui/widgets/separate_panel.h index a415b20b8e..4dc21963fb 100644 --- a/Telegram/SourceFiles/ui/widgets/separate_panel.h +++ b/Telegram/SourceFiles/ui/widgets/separate_panel.h @@ -30,6 +30,7 @@ public: void setTitle(rpl::producer title); void setInnerSize(QSize size); + void setHideOnDeactivate(bool hideOnDeactivate); void showAndActivate(); int hideGetDuration(); @@ -56,6 +57,7 @@ protected: void leaveEventHook(QEvent *e) override; void leaveToChildEvent(QEvent *e, QWidget *child) override; void keyPressEvent(QKeyEvent *e) override; + bool eventHook(QEvent *e) override; private: void initControls(); @@ -68,6 +70,7 @@ private: void opacityCallback(); void ensureLayerCreated(); + void updateTitleGeometry(int newWidth); void updateTitlePosition(); void paintShadowBorder(Painter &p) const; void paintOpaqueBorder(Painter &p) const; @@ -86,6 +89,7 @@ private: rpl::event_stream<> _userCloseRequests; rpl::event_stream<> _closeEvents; + bool _hideOnDeactivate = false; bool _useTransparency = true; style::margins _padding; diff --git a/Telegram/SourceFiles/window/player_wrap_widget.cpp b/Telegram/SourceFiles/window/player_wrap_widget.cpp deleted file mode 100644 index ad30fd7cd4..0000000000 --- a/Telegram/SourceFiles/window/player_wrap_widget.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "window/player_wrap_widget.h" - -#include "ui/widgets/shadow.h" - -namespace Window { - -PlayerWrapWidget::PlayerWrapWidget(QWidget *parent) -: Parent(parent, object_ptr(parent)) { - sizeValue( - ) | rpl::start_with_next([this](const QSize &size) { - updateShadowGeometry(size); - }, lifetime()); -} - -void PlayerWrapWidget::updateShadowGeometry(const QSize &size) { - auto skip = Adaptive::OneColumn() ? 0 : st::lineWidth; - entity()->setShadowGeometryToLeft( - skip, - size.height() - st::lineWidth, - size.width() - skip, - st::lineWidth); -} - -} // namespace Window diff --git a/Telegram/SourceFiles/window/player_wrap_widget.h b/Telegram/SourceFiles/window/player_wrap_widget.h deleted file mode 100644 index 85fba6e90c..0000000000 --- a/Telegram/SourceFiles/window/player_wrap_widget.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "ui/wrap/slide_wrap.h" -#include "media/player/media_player_widget.h" - -namespace Ui { -class PlainShadow; -} // namespace Ui - -namespace Window { - -class PlayerWrapWidget : public Ui::SlideWrap { - using Parent = Ui::SlideWrap; - -public: - PlayerWrapWidget(QWidget *parent); - - void updateAdaptiveLayout() { - updateShadowGeometry(size()); - } - void showShadow() { - entity()->showShadow(); - } - void hideShadow() { - entity()->hideShadow(); - } - int contentHeight() const { - return qMax(height() - st::lineWidth, 0); - } - -private: - void updateShadowGeometry(const QSize &size); - -}; - -} // namespace Window diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 5e17721342..44ef88b4cf 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -16,8 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_feed.h" #include "passport/passport_form_controller.h" -#include "export/export_controller.h" -#include "export/view/export_view_panel_controller.h" #include "boxes/calendar_box.h" #include "mainwidget.h" #include "mainwindow.h" @@ -418,24 +416,6 @@ void Controller::clearPassportForm() { _passportForm = nullptr; } -void Controller::startDataExport() { - using namespace Export; - - _export = std::make_unique(); - _exportPanel = std::make_unique( - _export.get()); - - _exportPanel->closed( - ) | rpl::start_with_next([=] { - clearDataExport(); - }, _export->lifetime()); -} - -void Controller::clearDataExport() { - _exportPanel = nullptr; - _export = nullptr; -} - void Controller::updateColumnLayout() { App::main()->updateColumnLayout(); } diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index c30456ec33..e286e33f44 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -26,13 +26,6 @@ struct FormRequest; class FormController; } // namespace Passport -namespace Export { -class ControllerWrap; -namespace View { -class PanelController; -} // namespace View -} // namespace Export - namespace Window { class LayerWidget; @@ -215,8 +208,6 @@ public: void showPassportForm(const Passport::FormRequest &request); void clearPassportForm(); - void startDataExport(); - base::Variable &dialogsListFocused() { return _dialogsListFocused; } @@ -260,13 +251,10 @@ private: int dialogsWidth, int thirdWidth, int bodyWidth) const; - void clearDataExport(); not_null _window; std::unique_ptr _passportForm; - std::unique_ptr _export; - std::unique_ptr _exportPanel; GifPauseReasons _gifPauseReasons = 0; base::Observable _gifPauseLevelChanged; diff --git a/Telegram/SourceFiles/window/window_top_bar_wrap.h b/Telegram/SourceFiles/window/window_top_bar_wrap.h new file mode 100644 index 0000000000..42dc30a23e --- /dev/null +++ b/Telegram/SourceFiles/window/window_top_bar_wrap.h @@ -0,0 +1,45 @@ +#pragma once + +#include "ui/wrap/slide_wrap.h" + +namespace Window { + +template +class TopBarWrapWidget : public Ui::SlideWrap { + using Parent = Ui::SlideWrap; + +public: + TopBarWrapWidget(QWidget *parent, object_ptr inner) + : Parent(parent, std::move(inner)) { + this->sizeValue( + ) | rpl::start_with_next([this](const QSize &size) { + updateShadowGeometry(size); + }, this->lifetime()); + } + + void updateAdaptiveLayout() { + updateShadowGeometry(this->size()); + } + void showShadow() { + this->entity()->showShadow(); + } + void hideShadow() { + this->entity()->hideShadow(); + } + int contentHeight() const { + return qMax(this->height() - st::lineWidth, 0); + } + +private: + void updateShadowGeometry(const QSize &size) { + auto skip = Adaptive::OneColumn() ? 0 : st::lineWidth; + this->entity()->setShadowGeometryToLeft( + skip, + size.height() - st::lineWidth, + size.width() - skip, + st::lineWidth); + } + +}; + +} // namespace Window diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index f286f15aa3..02a847dafa 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -235,6 +235,8 @@ <(src_loc)/export/view/export_view_progress.h <(src_loc)/export/view/export_view_settings.cpp <(src_loc)/export/view/export_view_settings.h +<(src_loc)/export/view/export_view_top_bar.cpp +<(src_loc)/export/view/export_view_top_bar.h <(src_loc)/history/admin_log/history_admin_log_filter.cpp <(src_loc)/history/admin_log/history_admin_log_filter.h <(src_loc)/history/admin_log/history_admin_log_inner.cpp @@ -735,8 +737,6 @@ <(src_loc)/window/notifications_manager_default.h <(src_loc)/window/notifications_utilities.cpp <(src_loc)/window/notifications_utilities.h -<(src_loc)/window/player_wrap_widget.cpp -<(src_loc)/window/player_wrap_widget.h <(src_loc)/window/section_memento.h <(src_loc)/window/section_widget.cpp <(src_loc)/window/section_widget.h @@ -753,6 +753,7 @@ <(src_loc)/window/window_slide_animation.cpp <(src_loc)/window/window_slide_animation.h <(src_loc)/window/window_title.h +<(src_loc)/window/window_top_bar_wrap.h <(src_loc)/window/themes/window_theme.cpp <(src_loc)/window/themes/window_theme.h <(src_loc)/window/themes/window_theme_editor.cpp