mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added custom layer widget with photo editor.
This commit is contained in:
parent
4909ba5a1e
commit
c9affe0da5
7 changed files with 131 additions and 10 deletions
|
@ -522,6 +522,8 @@ PRIVATE
|
||||||
editor/photo_editor_content.h
|
editor/photo_editor_content.h
|
||||||
editor/photo_editor_controls.cpp
|
editor/photo_editor_controls.cpp
|
||||||
editor/photo_editor_controls.h
|
editor/photo_editor_controls.h
|
||||||
|
editor/photo_editor_layer_widget.cpp
|
||||||
|
editor/photo_editor_layer_widget.h
|
||||||
editor/undo_controller.cpp
|
editor/undo_controller.cpp
|
||||||
editor/undo_controller.h
|
editor/undo_controller.h
|
||||||
export/export_manager.cpp
|
export/export_manager.cpp
|
||||||
|
|
|
@ -308,7 +308,7 @@ void ColorPicker::setVisible(bool visible) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<Brush> ColorPicker::saveBrushRequests() const {
|
rpl::producer<Brush> ColorPicker::saveBrushRequests() const {
|
||||||
return _saveBrushRequests.events();
|
return _saveBrushRequests.events_starting_with_copy(_brush);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ColorPicker::colorToPosition(const QColor &color) const {
|
int ColorPicker::colorToPosition(const QColor &color) const {
|
||||||
|
|
|
@ -110,28 +110,31 @@ PhotoEditor::PhotoEditor(
|
||||||
|
|
||||||
_controls->doneRequests(
|
_controls->doneRequests(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (_mode.current().mode == PhotoEditorMode::Mode::Paint) {
|
const auto mode = _mode.current().mode;
|
||||||
|
if (mode == PhotoEditorMode::Mode::Paint) {
|
||||||
_mode = PhotoEditorMode{
|
_mode = PhotoEditorMode{
|
||||||
.mode = PhotoEditorMode::Mode::Transform,
|
.mode = PhotoEditorMode::Mode::Transform,
|
||||||
.action = PhotoEditorMode::Action::Save,
|
.action = PhotoEditorMode::Action::Save,
|
||||||
};
|
};
|
||||||
|
} else if (mode == PhotoEditorMode::Mode::Transform) {
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
_controls->cancelRequests(
|
_controls->cancelRequests(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (_mode.current().mode == PhotoEditorMode::Mode::Paint) {
|
const auto mode = _mode.current().mode;
|
||||||
|
if (mode == PhotoEditorMode::Mode::Paint) {
|
||||||
_mode = PhotoEditorMode{
|
_mode = PhotoEditorMode{
|
||||||
.mode = PhotoEditorMode::Mode::Transform,
|
.mode = PhotoEditorMode::Mode::Transform,
|
||||||
.action = PhotoEditorMode::Action::Discard,
|
.action = PhotoEditorMode::Action::Discard,
|
||||||
};
|
};
|
||||||
|
} else if (mode == PhotoEditorMode::Mode::Transform) {
|
||||||
|
_cancel.fire({});
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
rpl::single(
|
_colorPicker->saveBrushRequests(
|
||||||
Deserialize(Core::App().settings().photoEditorBrush())
|
|
||||||
) | rpl::then(
|
|
||||||
_colorPicker->saveBrushRequests()
|
|
||||||
) | rpl::start_with_next([=](const Brush &brush) {
|
) | rpl::start_with_next([=](const Brush &brush) {
|
||||||
_content->applyBrush(brush);
|
_content->applyBrush(brush);
|
||||||
|
|
||||||
|
@ -148,8 +151,12 @@ void PhotoEditor::save() {
|
||||||
_done.fire_copy(_modifications);
|
_done.fire_copy(_modifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<PhotoModifications> PhotoEditor::done() const {
|
rpl::producer<PhotoModifications> PhotoEditor::doneRequests() const {
|
||||||
return _done.events();
|
return _done.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<> PhotoEditor::cancelRequests() const {
|
||||||
|
return _cancel.events();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Editor
|
} // namespace Editor
|
||||||
|
|
|
@ -28,7 +28,8 @@ public:
|
||||||
PhotoModifications modifications);
|
PhotoModifications modifications);
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
rpl::producer<PhotoModifications> done() const;
|
rpl::producer<PhotoModifications> doneRequests() const;
|
||||||
|
rpl::producer<> cancelRequests() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ private:
|
||||||
.action = PhotoEditorMode::Action::None,
|
.action = PhotoEditorMode::Action::None,
|
||||||
};
|
};
|
||||||
rpl::event_stream<PhotoModifications> _done;
|
rpl::event_stream<PhotoModifications> _done;
|
||||||
|
rpl::event_stream<> _cancel;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -186,9 +186,13 @@ PhotoEditorControls::PhotoEditorControls(
|
||||||
) | rpl::start_with_next([=](const QRect &clip) {
|
) | rpl::start_with_next([=](const QRect &clip) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
|
|
||||||
|
const auto ¤t = _transformButtons->isHidden()
|
||||||
|
? _paintButtons
|
||||||
|
: _transformButtons;
|
||||||
|
|
||||||
p.setPen(Qt::NoPen);
|
p.setPen(Qt::NoPen);
|
||||||
p.setBrush(_bg);
|
p.setBrush(_bg);
|
||||||
p.drawRect(_transformButtons->geometry());
|
p.drawRect(current->geometry());
|
||||||
|
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
|
63
Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp
Normal file
63
Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
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_layer_widget.h"
|
||||||
|
|
||||||
|
#include "editor/photo_editor.h"
|
||||||
|
|
||||||
|
namespace Editor {
|
||||||
|
|
||||||
|
LayerWidget::LayerWidget(
|
||||||
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
not_null<Window::Controller*> window,
|
||||||
|
std::shared_ptr<QPixmap> photo,
|
||||||
|
PhotoModifications modifications,
|
||||||
|
Fn<void(PhotoModifications)> &&doneCallback)
|
||||||
|
: Ui::LayerWidget(parent)
|
||||||
|
, _content(base::make_unique_q<PhotoEditor>(
|
||||||
|
this,
|
||||||
|
std::move(photo),
|
||||||
|
std::move(modifications))) {
|
||||||
|
|
||||||
|
paintRequest(
|
||||||
|
) | rpl::start_with_next([=](const QRect &clip) {
|
||||||
|
Painter p(this);
|
||||||
|
|
||||||
|
p.fillRect(clip, st::boxBg);
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
|
_content->cancelRequests(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
closeLayer();
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
|
_content->doneRequests(
|
||||||
|
) | rpl::start_with_next([=, done = std::move(doneCallback)](
|
||||||
|
const PhotoModifications &mods) {
|
||||||
|
doneCallback(mods);
|
||||||
|
closeLayer();
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
|
sizeValue(
|
||||||
|
) | rpl::start_with_next([=](const QSize &size) {
|
||||||
|
_content->resize(size);
|
||||||
|
}, lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LayerWidget::parentResized() {
|
||||||
|
resizeToWidth(parentWidget()->width());
|
||||||
|
}
|
||||||
|
|
||||||
|
int LayerWidget::resizeGetHeight(int newWidth) {
|
||||||
|
return parentWidget()->height();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LayerWidget::closeByOutsideClick() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Editor
|
43
Telegram/SourceFiles/editor/photo_editor_layer_widget.h
Normal file
43
Telegram/SourceFiles/editor/photo_editor_layer_widget.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
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/layers/layer_widget.h"
|
||||||
|
|
||||||
|
#include "editor/photo_editor_common.h"
|
||||||
|
#include "base/unique_qptr.h"
|
||||||
|
|
||||||
|
namespace Window {
|
||||||
|
class Controller;
|
||||||
|
} // namespace Window
|
||||||
|
|
||||||
|
namespace Editor {
|
||||||
|
|
||||||
|
class PhotoEditor;
|
||||||
|
|
||||||
|
class LayerWidget : public Ui::LayerWidget {
|
||||||
|
public:
|
||||||
|
LayerWidget(
|
||||||
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
not_null<Window::Controller*> window,
|
||||||
|
std::shared_ptr<QPixmap> photo,
|
||||||
|
PhotoModifications modifications,
|
||||||
|
Fn<void(PhotoModifications)> &&doneCallback);
|
||||||
|
|
||||||
|
void parentResized() override;
|
||||||
|
bool closeByOutsideClick() const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int resizeGetHeight(int newWidth) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const base::unique_qptr<PhotoEditor> _content;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Editor
|
Loading…
Add table
Reference in a new issue