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
editor/color_picker.cpp
editor/color_picker.h
editor/controllers.h
editor/editor_crop.cpp
editor/editor_crop.h
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/undo_controller.h"
#include "editor/scene_item_base.h"
#include "editor/controllers.h"
#include "base/event_filter.h"
#include <QGraphicsItemGroup>
@ -42,7 +43,7 @@ Paint::Paint(
not_null<Ui::RpWidget*> parent,
PhotoModifications &modifications,
const QSize &imageSize,
std::shared_ptr<UndoController> undoController)
std::shared_ptr<Controllers> controllers)
: RpWidget(parent)
, _scene(EnsureScene(modifications))
, _view(base::make_unique_q<QGraphicsView>(_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,

View file

@ -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<Ui::RpWidget*> parent,
PhotoModifications &modifications,
const QSize &imageSize,
std::shared_ptr<UndoController> undoController);
std::shared_ptr<Controllers> controllers);
[[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/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<Ui::RpWidget*> parent,
not_null<Window::Controller*> controller,
std::shared_ptr<Image> photo,
PhotoModifications modifications,
EditorData data)
: RpWidget(parent)
, _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>(
this,
photo,
_modifications,
_undoController,
_controllers,
std::move(data)))
, _controls(base::make_unique_q<PhotoEditorControls>(
this,
_undoController,
_controllers,
_modifications))
, _colorPicker(std::make_unique<ColorPicker>(
this,

View file

@ -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<Ui::RpWidget*> parent,
not_null<Window::Controller*> controller,
std::shared_ptr<Image> photo,
PhotoModifications modifications,
EditorData data = EditorData());
@ -36,7 +41,7 @@ private:
PhotoModifications _modifications;
const std::shared_ptr<UndoController> _undoController;
const std::shared_ptr<Controllers> _controllers;
base::unique_qptr<PhotoEditorContent> _content;
base::unique_qptr<PhotoEditorControls> _controls;

View file

@ -20,7 +20,7 @@ PhotoEditorContent::PhotoEditorContent(
not_null<Ui::RpWidget*> parent,
std::shared_ptr<Image> photo,
PhotoModifications modifications,
std::shared_ptr<UndoController> undoController,
std::shared_ptr<Controllers> 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<Crop>(
this,
modifications,

View file

@ -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<Ui::RpWidget*> parent,
std::shared_ptr<Image> photo,
PhotoModifications modifications,
std::shared_ptr<UndoController> undoController,
std::shared_ptr<Controllers> controllers,
EditorData data);
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/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<Ui::RpWidget*> parent,
std::shared_ptr<UndoController> undoController,
std::shared_ptr<Controllers> 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;

View file

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

View file

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