ZaStoGram_desktop/Telegram/SourceFiles/editor/photo_editor.h

125 lines
3.4 KiB
C++

/*
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"
#include "ui/image/image.h"
#include "base/unique_qptr.h"
#include "editor/photo_editor_common.h"
#include "editor/photo_editor_inner_common.h"
#include <array>
namespace Ui {
class LayerManager;
class LayerWidget;
class RoundVideoRecorder;
class Show;
template <typename Widget>
class FadeWrap;
} // namespace Ui
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Window {
class Controller;
} // namespace Window
namespace Editor {
class CaptionBar;
class ColorPicker;
class PhotoEditorContent;
class PhotoEditorControls;
struct Controllers;
class PhotoEditor final : public Ui::RpWidget {
public:
PhotoEditor(
not_null<QWidget*> parent,
not_null<Window::Controller*> controller,
std::shared_ptr<Image> photo,
PhotoModifications modifications,
EditorData data = EditorData());
PhotoEditor(
not_null<QWidget*> parent,
std::shared_ptr<Ui::Show> show,
std::shared_ptr<ChatHelpers::Show> sessionShow,
std::shared_ptr<Image> photo,
PhotoModifications modifications,
EditorData data = EditorData());
~PhotoEditor();
void save();
[[nodiscard]] rpl::producer<PhotoModifications> doneRequests() const;
[[nodiscard]] rpl::producer<> cancelRequests() const;
[[nodiscard]] rpl::producer<PhotoModifications> saveRequests() const;
void setSaveEnabled(bool enabled);
[[nodiscard]] TextWithTags caption() const;
[[nodiscard]] int period() const;
[[nodiscard]] bool edited() const;
[[nodiscard]] PhotoModifications collect();
private:
void keyPressEvent(QKeyEvent *e) override;
void keyReleaseEvent(QKeyEvent *e) override;
void updateColorPickerVisibility(anim::type animated);
void done();
void toggleRoundRecording();
void startRoundRecording();
void stopRoundRecording(bool save);
void layoutContent();
[[nodiscard]] QMargins contentMargins() const;
PhotoModifications _modifications;
const int _initialAngle = 0;
const bool _initialFlipped = false;
const std::unique_ptr<Ui::LayerManager> _layers;
const std::shared_ptr<Controllers> _controllers;
base::unique_qptr<PhotoEditorContent> _content;
base::unique_qptr<PhotoEditorControls> _controls;
base::unique_qptr<Ui::FadeWrap<CaptionBar>> _captionBar;
std::unique_ptr<Ui::RoundVideoRecorder> _roundRecorder;
rpl::lifetime _roundLifetime;
bool _roundRecording = false;
std::array<Brush, 5> _brushes;
Brush::Tool _brushTool = Brush::Tool::Pen;
bool _shapesFilled = false;
TextPrefs _textPrefs;
const std::unique_ptr<ColorPicker> _colorPicker;
rpl::variable<PhotoEditorMode> _mode = PhotoEditorMode{
.mode = PhotoEditorMode::Mode::Transform,
.action = PhotoEditorMode::Action::None,
};
bool _textItemSelected = false;
bool _textEditing = false;
bool _shapeItemSelected = false;
bool _videoClipSelected = false;
bool _audioSelected = false;
bool _matchingDurations = false;
bool _colorLineShown = false;
rpl::event_stream<PhotoModifications> _done;
rpl::event_stream<> _cancel;
const bool _hasSaveButton = false;
bool _saveEnabled = true;
rpl::event_stream<PhotoModifications> _save;
};
void InitEditorLayer(
not_null<Ui::LayerWidget*> layer,
not_null<PhotoEditor*> editor,
Fn<void(PhotoModifications)> doneCallback);
} // namespace Editor