From 216ffad80e8cfdd7e7e7932819d2034551b660a1 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 23 Feb 2021 13:34:12 +0300 Subject: [PATCH] Added container of controllers for photo editor. --- Telegram/CMakeLists.txt | 1 + Telegram/SourceFiles/editor/controllers.h | 29 +++++++++++++++++++ Telegram/SourceFiles/editor/editor_paint.cpp | 9 +++--- Telegram/SourceFiles/editor/editor_paint.h | 5 ++-- Telegram/SourceFiles/editor/photo_editor.cpp | 16 +++++++--- Telegram/SourceFiles/editor/photo_editor.h | 9 ++++-- .../editor/photo_editor_content.cpp | 4 +-- .../SourceFiles/editor/photo_editor_content.h | 4 +-- .../editor/photo_editor_controls.cpp | 8 ++--- .../editor/photo_editor_controls.h | 4 +-- .../editor/photo_editor_layer_widget.cpp | 1 + 11 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 Telegram/SourceFiles/editor/controllers.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 40d753436..bf13c6159 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -508,6 +508,7 @@ PRIVATE dialogs/dialogs_widget.h editor/color_picker.cpp editor/color_picker.h + editor/controllers.h editor/editor_crop.cpp editor/editor_crop.h editor/editor_paint.cpp diff --git a/Telegram/SourceFiles/editor/controllers.h b/Telegram/SourceFiles/editor/controllers.h new file mode 100644 index 000000000..53445cb7f --- /dev/null +++ b/Telegram/SourceFiles/editor/controllers.h @@ -0,0 +1,29 @@ +/* +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 "editor/stickers_panel_controller.h" +#include "editor/undo_controller.h" + +namespace Editor { + +struct Controllers final { + Controllers( + std::unique_ptr stickersPanelController, + std::unique_ptr undoController) + : stickersPanelController(std::move(stickersPanelController)) + , undoController(std::move(undoController)) { + } + ~Controllers() { + }; + + const std::unique_ptr stickersPanelController; + const std::unique_ptr undoController; +}; + +} // namespace Editor diff --git a/Telegram/SourceFiles/editor/editor_paint.cpp b/Telegram/SourceFiles/editor/editor_paint.cpp index 48cea69b1..6ba8e8db8 100644 --- a/Telegram/SourceFiles/editor/editor_paint.cpp +++ b/Telegram/SourceFiles/editor/editor_paint.cpp @@ -7,7 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "editor/editor_paint.h" -#include "editor/undo_controller.h" +#include "editor/scene_item_base.h" +#include "editor/controllers.h" #include "base/event_filter.h" #include @@ -42,7 +43,7 @@ Paint::Paint( not_null parent, PhotoModifications &modifications, const QSize &imageSize, - std::shared_ptr undoController) + std::shared_ptr controllers) : RpWidget(parent) , _scene(EnsureScene(modifications)) , _view(base::make_unique_q(_scene.get(), this)) @@ -61,7 +62,7 @@ Paint::Paint( initDrawing(); // Undo / Redo. - undoController->performRequestChanges( + controllers->undoController->performRequestChanges( ) | rpl::start_with_next([=](const Undo &command) { const auto isUndo = (command == Undo::Undo); @@ -81,7 +82,7 @@ Paint::Paint( _hasRedo = hasRedo(); }, lifetime()); - undoController->setCanPerformChanges(rpl::merge( + controllers->undoController->setCanPerformChanges(rpl::merge( _hasUndo.value() | rpl::map([](bool enable) { return UndoController::EnableRequest{ .command = Undo::Undo, diff --git a/Telegram/SourceFiles/editor/editor_paint.h b/Telegram/SourceFiles/editor/editor_paint.h index d0294b3fc..9001e93dd 100644 --- a/Telegram/SourceFiles/editor/editor_paint.h +++ b/Telegram/SourceFiles/editor/editor_paint.h @@ -16,7 +16,8 @@ class QGraphicsView; namespace Editor { -class UndoController; +struct Controllers; +class ItemBase; // Paint control. class Paint final : public Ui::RpWidget { @@ -25,7 +26,7 @@ public: not_null parent, PhotoModifications &modifications, const QSize &imageSize, - std::shared_ptr undoController); + std::shared_ptr controllers); [[nodiscard]] std::shared_ptr saveScene() const; diff --git a/Telegram/SourceFiles/editor/photo_editor.cpp b/Telegram/SourceFiles/editor/photo_editor.cpp index f7210ce96..b2d1ed3d5 100644 --- a/Telegram/SourceFiles/editor/photo_editor.cpp +++ b/Telegram/SourceFiles/editor/photo_editor.cpp @@ -10,9 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/core_settings.h" #include "editor/color_picker.h" +#include "editor/controllers.h" #include "editor/photo_editor_content.h" #include "editor/photo_editor_controls.h" -#include "editor/undo_controller.h" +#include "window/window_controller.h" #include "styles/style_editor.h" namespace Editor { @@ -45,21 +46,28 @@ constexpr auto kPrecision = 100000; PhotoEditor::PhotoEditor( not_null parent, + not_null controller, std::shared_ptr photo, PhotoModifications modifications, EditorData data) : RpWidget(parent) , _modifications(std::move(modifications)) -, _undoController(std::make_shared()) +, _controllers(std::make_shared( + controller->sessionController() + ? std::make_unique( + this, + controller->sessionController()) + : nullptr, + std::make_unique())) , _content(base::make_unique_q( this, photo, _modifications, - _undoController, + _controllers, std::move(data))) , _controls(base::make_unique_q( this, - _undoController, + _controllers, _modifications)) , _colorPicker(std::make_unique( this, diff --git a/Telegram/SourceFiles/editor/photo_editor.h b/Telegram/SourceFiles/editor/photo_editor.h index 275ffe59e..dc05d80f5 100644 --- a/Telegram/SourceFiles/editor/photo_editor.h +++ b/Telegram/SourceFiles/editor/photo_editor.h @@ -13,17 +13,22 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "editor/photo_editor_common.h" #include "ui/image/image.h" +namespace Window { +class Controller; +} // namespace Window + namespace Editor { class ColorPicker; class PhotoEditorContent; class PhotoEditorControls; -class UndoController; +struct Controllers; class PhotoEditor final : public Ui::RpWidget { public: PhotoEditor( not_null parent, + not_null controller, std::shared_ptr photo, PhotoModifications modifications, EditorData data = EditorData()); @@ -36,7 +41,7 @@ private: PhotoModifications _modifications; - const std::shared_ptr _undoController; + const std::shared_ptr _controllers; base::unique_qptr _content; base::unique_qptr _controls; diff --git a/Telegram/SourceFiles/editor/photo_editor_content.cpp b/Telegram/SourceFiles/editor/photo_editor_content.cpp index 6311af681..3be425a74 100644 --- a/Telegram/SourceFiles/editor/photo_editor_content.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_content.cpp @@ -20,7 +20,7 @@ PhotoEditorContent::PhotoEditorContent( not_null parent, std::shared_ptr photo, PhotoModifications modifications, - std::shared_ptr undoController, + std::shared_ptr controllers, EditorData data) : RpWidget(parent) , _photoSize(photo->size()) @@ -28,7 +28,7 @@ PhotoEditorContent::PhotoEditorContent( this, modifications, _photoSize, - std::move(undoController))) + std::move(controllers))) , _crop(base::make_unique_q( this, modifications, diff --git a/Telegram/SourceFiles/editor/photo_editor_content.h b/Telegram/SourceFiles/editor/photo_editor_content.h index 9290f8b3f..310f99dff 100644 --- a/Telegram/SourceFiles/editor/photo_editor_content.h +++ b/Telegram/SourceFiles/editor/photo_editor_content.h @@ -16,7 +16,7 @@ namespace Editor { class Crop; class Paint; -class UndoController; +struct Controllers; class PhotoEditorContent final : public Ui::RpWidget { public: @@ -24,7 +24,7 @@ public: not_null parent, std::shared_ptr photo, PhotoModifications modifications, - std::shared_ptr undoController, + std::shared_ptr controllers, EditorData data); void applyModifications(PhotoModifications modifications); diff --git a/Telegram/SourceFiles/editor/photo_editor_controls.cpp b/Telegram/SourceFiles/editor/photo_editor_controls.cpp index 6f377aa94..dbc5a6404 100644 --- a/Telegram/SourceFiles/editor/photo_editor_controls.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_controls.cpp @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "editor/photo_editor_controls.h" -#include "editor/undo_controller.h" +#include "editor/controllers.h" #include "lang/lang_keys.h" #include "ui/image/image_prepare.h" #include "ui/widgets/buttons.h" @@ -134,7 +134,7 @@ void HorizontalContainer::updateChildrenPosition() { PhotoEditorControls::PhotoEditorControls( not_null parent, - std::shared_ptr undoController, + std::shared_ptr controllers, const PhotoModifications modifications, bool doneControls) : RpWidget(parent) @@ -223,11 +223,11 @@ PhotoEditorControls::PhotoEditorControls( }, lifetime()); - undoController->setPerformRequestChanges(rpl::merge( + controllers->undoController->setPerformRequestChanges(rpl::merge( _undoButton->clicks() | rpl::map_to(Undo::Undo), _redoButton->clicks() | rpl::map_to(Undo::Redo))); - undoController->canPerformChanges( + controllers->undoController->canPerformChanges( ) | rpl::start_with_next([=](const UndoController::EnableRequest &r) { const auto isUndo = (r.command == Undo::Undo); const auto &button = isUndo ? _undoButton : _redoButton; diff --git a/Telegram/SourceFiles/editor/photo_editor_controls.h b/Telegram/SourceFiles/editor/photo_editor_controls.h index 903028419..6b16de0f7 100644 --- a/Telegram/SourceFiles/editor/photo_editor_controls.h +++ b/Telegram/SourceFiles/editor/photo_editor_controls.h @@ -19,13 +19,13 @@ namespace Editor { class EdgeButton; class HorizontalContainer; -class UndoController; +struct Controllers; class PhotoEditorControls final : public Ui::RpWidget { public: PhotoEditorControls( not_null parent, - std::shared_ptr undoController, + std::shared_ptr controllers, const PhotoModifications modifications, bool doneControls = true); diff --git a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp index 4507da66f..a0a883392 100644 --- a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp @@ -140,6 +140,7 @@ LayerWidget::LayerWidget( : Ui::LayerWidget(parent) , _content(base::make_unique_q( this, + window, photo, std::move(modifications), std::move(data))) {