Added container of controllers for photo editor.

This commit is contained in:
23rd 2021-02-23 13:34:12 +03:00
parent c312607ff8
commit 216ffad80e
11 changed files with 68 additions and 22 deletions

View file

@ -508,6 +508,7 @@ PRIVATE
dialogs/dialogs_widget.h dialogs/dialogs_widget.h
editor/color_picker.cpp editor/color_picker.cpp
editor/color_picker.h editor/color_picker.h
editor/controllers.h
editor/editor_crop.cpp editor/editor_crop.cpp
editor/editor_crop.h editor/editor_crop.h
editor/editor_paint.cpp editor/editor_paint.cpp

View file

@ -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> stickersPanelController,
std::unique_ptr<UndoController> undoController)
: stickersPanelController(std::move(stickersPanelController))
, undoController(std::move(undoController)) {
}
~Controllers() {
};
const std::unique_ptr<StickersPanelController> stickersPanelController;
const std::unique_ptr<UndoController> undoController;
};
} // namespace Editor

View file

@ -7,7 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "editor/editor_paint.h" #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 "base/event_filter.h"
#include <QGraphicsItemGroup> #include <QGraphicsItemGroup>
@ -42,7 +43,7 @@ Paint::Paint(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
PhotoModifications &modifications, PhotoModifications &modifications,
const QSize &imageSize, const QSize &imageSize,
std::shared_ptr<UndoController> undoController) std::shared_ptr<Controllers> controllers)
: RpWidget(parent) : RpWidget(parent)
, _scene(EnsureScene(modifications)) , _scene(EnsureScene(modifications))
, _view(base::make_unique_q<QGraphicsView>(_scene.get(), this)) , _view(base::make_unique_q<QGraphicsView>(_scene.get(), this))
@ -61,7 +62,7 @@ Paint::Paint(
initDrawing(); initDrawing();
// Undo / Redo. // Undo / Redo.
undoController->performRequestChanges( controllers->undoController->performRequestChanges(
) | rpl::start_with_next([=](const Undo &command) { ) | rpl::start_with_next([=](const Undo &command) {
const auto isUndo = (command == Undo::Undo); const auto isUndo = (command == Undo::Undo);
@ -81,7 +82,7 @@ Paint::Paint(
_hasRedo = hasRedo(); _hasRedo = hasRedo();
}, lifetime()); }, lifetime());
undoController->setCanPerformChanges(rpl::merge( controllers->undoController->setCanPerformChanges(rpl::merge(
_hasUndo.value() | rpl::map([](bool enable) { _hasUndo.value() | rpl::map([](bool enable) {
return UndoController::EnableRequest{ return UndoController::EnableRequest{
.command = Undo::Undo, .command = Undo::Undo,

View file

@ -16,7 +16,8 @@ class QGraphicsView;
namespace Editor { namespace Editor {
class UndoController; struct Controllers;
class ItemBase;
// Paint control. // Paint control.
class Paint final : public Ui::RpWidget { class Paint final : public Ui::RpWidget {
@ -25,7 +26,7 @@ public:
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
PhotoModifications &modifications, PhotoModifications &modifications,
const QSize &imageSize, const QSize &imageSize,
std::shared_ptr<UndoController> undoController); std::shared_ptr<Controllers> controllers);
[[nodiscard]] std::shared_ptr<QGraphicsScene> saveScene() const; [[nodiscard]] std::shared_ptr<QGraphicsScene> saveScene() const;

View file

@ -10,9 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "core/core_settings.h" #include "core/core_settings.h"
#include "editor/color_picker.h" #include "editor/color_picker.h"
#include "editor/controllers.h"
#include "editor/photo_editor_content.h" #include "editor/photo_editor_content.h"
#include "editor/photo_editor_controls.h" #include "editor/photo_editor_controls.h"
#include "editor/undo_controller.h" #include "window/window_controller.h"
#include "styles/style_editor.h" #include "styles/style_editor.h"
namespace Editor { namespace Editor {
@ -45,21 +46,28 @@ constexpr auto kPrecision = 100000;
PhotoEditor::PhotoEditor( PhotoEditor::PhotoEditor(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
not_null<Window::Controller*> controller,
std::shared_ptr<Image> photo, std::shared_ptr<Image> photo,
PhotoModifications modifications, PhotoModifications modifications,
EditorData data) EditorData data)
: RpWidget(parent) : RpWidget(parent)
, _modifications(std::move(modifications)) , _modifications(std::move(modifications))
, _undoController(std::make_shared<UndoController>()) , _controllers(std::make_shared<Controllers>(
controller->sessionController()
? std::make_unique<StickersPanelController>(
this,
controller->sessionController())
: nullptr,
std::make_unique<UndoController>()))
, _content(base::make_unique_q<PhotoEditorContent>( , _content(base::make_unique_q<PhotoEditorContent>(
this, this,
photo, photo,
_modifications, _modifications,
_undoController, _controllers,
std::move(data))) std::move(data)))
, _controls(base::make_unique_q<PhotoEditorControls>( , _controls(base::make_unique_q<PhotoEditorControls>(
this, this,
_undoController, _controllers,
_modifications)) _modifications))
, _colorPicker(std::make_unique<ColorPicker>( , _colorPicker(std::make_unique<ColorPicker>(
this, this,

View file

@ -13,17 +13,22 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "editor/photo_editor_common.h" #include "editor/photo_editor_common.h"
#include "ui/image/image.h" #include "ui/image/image.h"
namespace Window {
class Controller;
} // namespace Window
namespace Editor { namespace Editor {
class ColorPicker; class ColorPicker;
class PhotoEditorContent; class PhotoEditorContent;
class PhotoEditorControls; class PhotoEditorControls;
class UndoController; struct Controllers;
class PhotoEditor final : public Ui::RpWidget { class PhotoEditor final : public Ui::RpWidget {
public: public:
PhotoEditor( PhotoEditor(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
not_null<Window::Controller*> controller,
std::shared_ptr<Image> photo, std::shared_ptr<Image> photo,
PhotoModifications modifications, PhotoModifications modifications,
EditorData data = EditorData()); EditorData data = EditorData());
@ -36,7 +41,7 @@ private:
PhotoModifications _modifications; PhotoModifications _modifications;
const std::shared_ptr<UndoController> _undoController; const std::shared_ptr<Controllers> _controllers;
base::unique_qptr<PhotoEditorContent> _content; base::unique_qptr<PhotoEditorContent> _content;
base::unique_qptr<PhotoEditorControls> _controls; base::unique_qptr<PhotoEditorControls> _controls;

View file

@ -20,7 +20,7 @@ PhotoEditorContent::PhotoEditorContent(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
std::shared_ptr<Image> photo, std::shared_ptr<Image> photo,
PhotoModifications modifications, PhotoModifications modifications,
std::shared_ptr<UndoController> undoController, std::shared_ptr<Controllers> controllers,
EditorData data) EditorData data)
: RpWidget(parent) : RpWidget(parent)
, _photoSize(photo->size()) , _photoSize(photo->size())
@ -28,7 +28,7 @@ PhotoEditorContent::PhotoEditorContent(
this, this,
modifications, modifications,
_photoSize, _photoSize,
std::move(undoController))) std::move(controllers)))
, _crop(base::make_unique_q<Crop>( , _crop(base::make_unique_q<Crop>(
this, this,
modifications, modifications,

View file

@ -16,7 +16,7 @@ namespace Editor {
class Crop; class Crop;
class Paint; class Paint;
class UndoController; struct Controllers;
class PhotoEditorContent final : public Ui::RpWidget { class PhotoEditorContent final : public Ui::RpWidget {
public: public:
@ -24,7 +24,7 @@ public:
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
std::shared_ptr<Image> photo, std::shared_ptr<Image> photo,
PhotoModifications modifications, PhotoModifications modifications,
std::shared_ptr<UndoController> undoController, std::shared_ptr<Controllers> controllers,
EditorData data); EditorData data);
void applyModifications(PhotoModifications modifications); void applyModifications(PhotoModifications modifications);

View file

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "editor/photo_editor_controls.h" #include "editor/photo_editor_controls.h"
#include "editor/undo_controller.h" #include "editor/controllers.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/image/image_prepare.h" #include "ui/image/image_prepare.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
@ -134,7 +134,7 @@ void HorizontalContainer::updateChildrenPosition() {
PhotoEditorControls::PhotoEditorControls( PhotoEditorControls::PhotoEditorControls(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
std::shared_ptr<UndoController> undoController, std::shared_ptr<Controllers> controllers,
const PhotoModifications modifications, const PhotoModifications modifications,
bool doneControls) bool doneControls)
: RpWidget(parent) : RpWidget(parent)
@ -223,11 +223,11 @@ PhotoEditorControls::PhotoEditorControls(
}, lifetime()); }, lifetime());
undoController->setPerformRequestChanges(rpl::merge( controllers->undoController->setPerformRequestChanges(rpl::merge(
_undoButton->clicks() | rpl::map_to(Undo::Undo), _undoButton->clicks() | rpl::map_to(Undo::Undo),
_redoButton->clicks() | rpl::map_to(Undo::Redo))); _redoButton->clicks() | rpl::map_to(Undo::Redo)));
undoController->canPerformChanges( controllers->undoController->canPerformChanges(
) | rpl::start_with_next([=](const UndoController::EnableRequest &r) { ) | rpl::start_with_next([=](const UndoController::EnableRequest &r) {
const auto isUndo = (r.command == Undo::Undo); const auto isUndo = (r.command == Undo::Undo);
const auto &button = isUndo ? _undoButton : _redoButton; const auto &button = isUndo ? _undoButton : _redoButton;

View file

@ -19,13 +19,13 @@ namespace Editor {
class EdgeButton; class EdgeButton;
class HorizontalContainer; class HorizontalContainer;
class UndoController; struct Controllers;
class PhotoEditorControls final : public Ui::RpWidget { class PhotoEditorControls final : public Ui::RpWidget {
public: public:
PhotoEditorControls( PhotoEditorControls(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
std::shared_ptr<UndoController> undoController, std::shared_ptr<Controllers> controllers,
const PhotoModifications modifications, const PhotoModifications modifications,
bool doneControls = true); bool doneControls = true);

View file

@ -140,6 +140,7 @@ LayerWidget::LayerWidget(
: Ui::LayerWidget(parent) : Ui::LayerWidget(parent)
, _content(base::make_unique_q<PhotoEditor>( , _content(base::make_unique_q<PhotoEditor>(
this, this,
window,
photo, photo,
std::move(modifications), std::move(modifications),
std::move(data))) { std::move(data))) {