2021-02-05 05:44:04 +00:00
|
|
|
/*
|
|
|
|
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 "editor/photo_editor.h"
|
|
|
|
|
|
|
|
#include "editor/photo_editor_content.h"
|
|
|
|
#include "editor/photo_editor_controls.h"
|
2021-03-14 09:42:18 +00:00
|
|
|
#include "editor/undo_controller.h"
|
2021-02-05 09:24:26 +00:00
|
|
|
#include "styles/style_editor.h"
|
2021-02-05 05:44:04 +00:00
|
|
|
|
|
|
|
namespace Editor {
|
|
|
|
|
|
|
|
PhotoEditor::PhotoEditor(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
2021-02-08 03:38:07 +00:00
|
|
|
std::shared_ptr<QPixmap> photo,
|
|
|
|
PhotoModifications modifications)
|
2021-02-05 07:08:20 +00:00
|
|
|
: RpWidget(parent)
|
2021-02-13 04:29:31 +00:00
|
|
|
, _modifications(std::move(modifications))
|
2021-03-14 09:42:18 +00:00
|
|
|
, _undoController(std::make_shared<UndoController>())
|
2021-02-08 03:38:07 +00:00
|
|
|
, _content(base::make_unique_q<PhotoEditorContent>(
|
|
|
|
this,
|
|
|
|
photo,
|
2021-03-14 09:42:18 +00:00
|
|
|
_modifications,
|
|
|
|
_undoController))
|
|
|
|
, _controls(base::make_unique_q<PhotoEditorControls>(this, _undoController)) {
|
2021-02-05 07:08:20 +00:00
|
|
|
sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &size) {
|
2021-02-05 09:24:26 +00:00
|
|
|
const auto geometry = QRect(QPoint(), size);
|
|
|
|
const auto contentRect = geometry
|
|
|
|
- style::margins(0, 0, 0, st::photoEditorControlsHeight);
|
|
|
|
_content->setGeometry(contentRect);
|
|
|
|
const auto controlsRect = geometry
|
|
|
|
- style::margins(0, contentRect.height(), 0, 0);
|
|
|
|
_controls->setGeometry(controlsRect);
|
2021-02-05 07:08:20 +00:00
|
|
|
}, lifetime());
|
2021-02-07 23:10:30 +00:00
|
|
|
|
2021-03-14 09:39:55 +00:00
|
|
|
_mode.value(
|
|
|
|
) | rpl::start_with_next([=](const PhotoEditorMode &mode) {
|
|
|
|
_content->applyMode(mode);
|
|
|
|
_controls->applyMode(mode);
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-02-07 23:10:30 +00:00
|
|
|
_controls->rotateRequests(
|
|
|
|
) | rpl::start_with_next([=](int angle) {
|
|
|
|
_modifications.angle += 90;
|
|
|
|
if (_modifications.angle >= 360) {
|
|
|
|
_modifications.angle -= 360;
|
|
|
|
}
|
|
|
|
_content->applyModifications(_modifications);
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_controls->flipRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_modifications.flipped = !_modifications.flipped;
|
|
|
|
_content->applyModifications(_modifications);
|
|
|
|
}, lifetime());
|
2021-02-13 04:29:31 +00:00
|
|
|
|
|
|
|
_controls->paintModeRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
2021-03-14 09:39:55 +00:00
|
|
|
_mode = PhotoEditorMode{
|
|
|
|
.mode = PhotoEditorMode::Mode::Paint,
|
|
|
|
.action = PhotoEditorMode::Action::None,
|
|
|
|
};
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_controls->doneRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (_mode.current().mode == PhotoEditorMode::Mode::Paint) {
|
|
|
|
_mode = PhotoEditorMode{
|
|
|
|
.mode = PhotoEditorMode::Mode::Transform,
|
|
|
|
.action = PhotoEditorMode::Action::Save,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_controls->cancelRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (_mode.current().mode == PhotoEditorMode::Mode::Paint) {
|
|
|
|
_mode = PhotoEditorMode{
|
|
|
|
.mode = PhotoEditorMode::Mode::Transform,
|
|
|
|
.action = PhotoEditorMode::Action::Discard,
|
|
|
|
};
|
|
|
|
}
|
2021-02-13 04:29:31 +00:00
|
|
|
}, lifetime());
|
2021-02-05 05:44:04 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 03:13:40 +00:00
|
|
|
void PhotoEditor::save() {
|
2021-02-13 04:29:31 +00:00
|
|
|
_content->save(_modifications);
|
2021-02-08 03:13:40 +00:00
|
|
|
_done.fire_copy(_modifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<PhotoModifications> PhotoEditor::done() const {
|
|
|
|
return _done.events();
|
|
|
|
}
|
|
|
|
|
2021-02-05 05:44:04 +00:00
|
|
|
} // namespace Editor
|