tdesktop/Telegram/SourceFiles/editor/photo_editor.cpp

70 lines
1.9 KiB
C++
Raw Normal View History

/*
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"
#include "styles/style_editor.h"
namespace Editor {
PhotoEditor::PhotoEditor(
not_null<Ui::RpWidget*> parent,
std::shared_ptr<QPixmap> photo,
PhotoModifications modifications)
: RpWidget(parent)
, _modifications(std::move(modifications))
, _content(base::make_unique_q<PhotoEditorContent>(
this,
photo,
_modifications))
, _controls(base::make_unique_q<PhotoEditorControls>(this)) {
sizeValue(
) | rpl::start_with_next([=](const QSize &size) {
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);
}, lifetime());
_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());
_controls->paintModeRequests(
) | rpl::start_with_next([=] {
_content->applyMode(PhotoEditorMode::Paint);
}, lifetime());
_content->applyMode(PhotoEditorMode::Transform);
}
2021-02-08 03:13:40 +00:00
void PhotoEditor::save() {
_content->save(_modifications);
2021-02-08 03:13:40 +00:00
_done.fire_copy(_modifications);
}
rpl::producer<PhotoModifications> PhotoEditor::done() const {
return _done.events();
}
} // namespace Editor