Allow accepting video userpic suggestions.
This commit is contained in:
50
Telegram/SourceFiles/editor/editor_layer_widget.cpp
Normal file
50
Telegram/SourceFiles/editor/editor_layer_widget.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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/editor_layer_widget.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
namespace Editor {
|
||||
|
||||
LayerWidget::LayerWidget(
|
||||
not_null<QWidget*> parent,
|
||||
base::unique_qptr<Ui::RpWidget> content)
|
||||
: Ui::LayerWidget(parent)
|
||||
, _content(std::move(content)) {
|
||||
_content->setParent(this);
|
||||
_content->show();
|
||||
|
||||
paintRequest(
|
||||
) | rpl::start_with_next([=](const QRect &clip) {
|
||||
auto p = QPainter(this);
|
||||
p.fillRect(clip, st::photoEditorBg);
|
||||
}, lifetime());
|
||||
|
||||
sizeValue(
|
||||
) | rpl::start_with_next([=](const QSize &size) {
|
||||
_content->resize(size);
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void LayerWidget::parentResized() {
|
||||
resizeToWidth(parentWidget()->width());
|
||||
}
|
||||
|
||||
void LayerWidget::keyPressEvent(QKeyEvent *e) {
|
||||
QGuiApplication::sendEvent(_content.get(), e);
|
||||
}
|
||||
|
||||
int LayerWidget::resizeGetHeight(int newWidth) {
|
||||
return parentWidget()->height();
|
||||
}
|
||||
|
||||
bool LayerWidget::closeByOutsideClick() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
42
Telegram/SourceFiles/editor/editor_layer_widget.h
Normal file
42
Telegram/SourceFiles/editor/editor_layer_widget.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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 "ui/image/image.h"
|
||||
#include "editor/photo_editor_common.h"
|
||||
#include "base/unique_qptr.h"
|
||||
|
||||
enum class ImageRoundRadius;
|
||||
|
||||
namespace Window {
|
||||
class Controller;
|
||||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Editor {
|
||||
|
||||
class LayerWidget final : public Ui::LayerWidget {
|
||||
public:
|
||||
LayerWidget(
|
||||
not_null<QWidget*> parent,
|
||||
base::unique_qptr<Ui::RpWidget> content);
|
||||
|
||||
void parentResized() override;
|
||||
bool closeByOutsideClick() const override;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
|
||||
private:
|
||||
const base::unique_qptr<Ui::RpWidget> _content;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Editor
|
||||
@@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "editor/photo_editor_controls.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "ui/layers/layer_widget.h"
|
||||
#include "styles/style_editor.h"
|
||||
|
||||
namespace Editor {
|
||||
@@ -46,7 +47,7 @@ constexpr auto kPrecision = 100000;
|
||||
} // namespace
|
||||
|
||||
PhotoEditor::PhotoEditor(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::Controller*> controller,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
@@ -174,7 +175,7 @@ PhotoEditor::PhotoEditor(
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void PhotoEditor::handleKeyPress(not_null<QKeyEvent*> e) {
|
||||
void PhotoEditor::keyPressEvent(QKeyEvent *e) {
|
||||
if (!_colorPicker->preventHandleKeyPress()) {
|
||||
_content->handleKeyPress(e) || _controls->handleKeyPress(e);
|
||||
}
|
||||
@@ -193,4 +194,24 @@ rpl::producer<> PhotoEditor::cancelRequests() const {
|
||||
return _cancel.events();
|
||||
}
|
||||
|
||||
void InitEditorLayer(
|
||||
not_null<Ui::LayerWidget*> layer,
|
||||
not_null<PhotoEditor*> editor,
|
||||
Fn<void(PhotoModifications)> doneCallback) {
|
||||
editor->cancelRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
layer->closeLayer();
|
||||
}, editor->lifetime());
|
||||
|
||||
const auto weak = Ui::MakeWeak(layer.get());
|
||||
editor->doneRequests(
|
||||
) | rpl::start_with_next([=, done = std::move(doneCallback)](
|
||||
const PhotoModifications &mods) {
|
||||
done(mods);
|
||||
if (const auto strong = weak.data()) {
|
||||
strong->closeLayer();
|
||||
}
|
||||
}, editor->lifetime());
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
||||
@@ -8,11 +8,14 @@ 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 "ui/image/image.h"
|
||||
|
||||
namespace Ui {
|
||||
class LayerWidget;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Window {
|
||||
class Controller;
|
||||
@@ -28,19 +31,18 @@ struct Controllers;
|
||||
class PhotoEditor final : public Ui::RpWidget {
|
||||
public:
|
||||
PhotoEditor(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::Controller*> controller,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
EditorData data = EditorData());
|
||||
|
||||
void save();
|
||||
rpl::producer<PhotoModifications> doneRequests() const;
|
||||
rpl::producer<> cancelRequests() const;
|
||||
|
||||
void handleKeyPress(not_null<QKeyEvent*> e);
|
||||
[[nodiscard]] rpl::producer<PhotoModifications> doneRequests() const;
|
||||
[[nodiscard]] rpl::producer<> cancelRequests() const;
|
||||
|
||||
private:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
PhotoModifications _modifications;
|
||||
|
||||
@@ -59,4 +61,9 @@ private:
|
||||
|
||||
};
|
||||
|
||||
void InitEditorLayer(
|
||||
not_null<Ui::LayerWidget*> layer,
|
||||
not_null<PhotoEditor*> editor,
|
||||
Fn<void(PhotoModifications)> doneCallback);
|
||||
|
||||
} // namespace Editor
|
||||
|
||||
@@ -8,12 +8,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "editor/photo_editor_layer_widget.h"
|
||||
|
||||
#include "ui/boxes/confirm_box.h" // InformBox
|
||||
#include "editor/editor_layer_widget.h"
|
||||
#include "editor/photo_editor.h"
|
||||
#include "storage/storage_media_prepare.h"
|
||||
#include "ui/chat/attach/attach_prepare.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "window/window_session_controller.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
namespace Editor {
|
||||
namespace {
|
||||
|
||||
@@ -22,7 +25,7 @@ constexpr auto kProfilePhotoSize = 640;
|
||||
} // namespace
|
||||
|
||||
void OpenWithPreparedFile(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::PreparedFile*> file,
|
||||
int previewWidth,
|
||||
@@ -54,18 +57,19 @@ void OpenWithPreparedFile(
|
||||
};
|
||||
auto copy = image->data;
|
||||
const auto fileImage = std::make_shared<Image>(std::move(copy));
|
||||
controller->showLayer(
|
||||
std::make_unique<LayerWidget>(
|
||||
parent,
|
||||
&controller->window(),
|
||||
fileImage,
|
||||
image->modifications,
|
||||
std::move(callback)),
|
||||
Ui::LayerOption::KeepOther);
|
||||
auto editor = base::make_unique_q<PhotoEditor>(
|
||||
parent,
|
||||
&controller->window(),
|
||||
fileImage,
|
||||
image->modifications);
|
||||
const auto raw = editor.get();
|
||||
auto layer = std::make_unique<LayerWidget>(parent, std::move(editor));
|
||||
InitEditorLayer(layer.get(), raw, std::move(callback));
|
||||
controller->showLayer(std::move(layer), Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
void PrepareProfilePhoto(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::Controller*> controller,
|
||||
ImageRoundRadius radius,
|
||||
Fn<void(QImage &&image)> &&doneCallback,
|
||||
@@ -112,24 +116,25 @@ void PrepareProfilePhoto(
|
||||
minSide);
|
||||
}();
|
||||
|
||||
controller->showLayer(
|
||||
std::make_unique<LayerWidget>(
|
||||
parent,
|
||||
controller,
|
||||
fileImage,
|
||||
PhotoModifications{ .crop = std::move(crop) },
|
||||
std::move(applyModifications),
|
||||
EditorData{
|
||||
.cropType = (radius == ImageRoundRadius::Ellipse
|
||||
? EditorData::CropType::Ellipse
|
||||
: EditorData::CropType::RoundedRect),
|
||||
.keepAspectRatio = true,
|
||||
}),
|
||||
Ui::LayerOption::KeepOther);
|
||||
auto editor = base::make_unique_q<PhotoEditor>(
|
||||
parent,
|
||||
controller,
|
||||
fileImage,
|
||||
PhotoModifications{ .crop = std::move(crop) },
|
||||
EditorData{
|
||||
.cropType = (radius == ImageRoundRadius::Ellipse
|
||||
? EditorData::CropType::Ellipse
|
||||
: EditorData::CropType::RoundedRect),
|
||||
.keepAspectRatio = true,
|
||||
});
|
||||
const auto raw = editor.get();
|
||||
auto layer = std::make_unique<LayerWidget>(parent, std::move(editor));
|
||||
InitEditorLayer(layer.get(), raw, std::move(applyModifications));
|
||||
controller->showLayer(std::move(layer), Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
void PrepareProfilePhotoFromFile(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::Controller*> controller,
|
||||
ImageRoundRadius radius,
|
||||
Fn<void(QImage &&image)> &&doneCallback) {
|
||||
@@ -158,60 +163,4 @@ void PrepareProfilePhotoFromFile(
|
||||
crl::guard(parent, callback));
|
||||
}
|
||||
|
||||
LayerWidget::LayerWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Window::Controller*> window,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
Fn<void(PhotoModifications)> &&doneCallback,
|
||||
EditorData data)
|
||||
: Ui::LayerWidget(parent)
|
||||
, _content(base::make_unique_q<PhotoEditor>(
|
||||
this,
|
||||
window,
|
||||
photo,
|
||||
std::move(modifications),
|
||||
std::move(data))) {
|
||||
|
||||
paintRequest(
|
||||
) | rpl::start_with_next([=](const QRect &clip) {
|
||||
auto p = QPainter(this);
|
||||
p.fillRect(clip, st::photoEditorBg);
|
||||
}, lifetime());
|
||||
|
||||
_content->cancelRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
closeLayer();
|
||||
}, lifetime());
|
||||
|
||||
const auto weak = Ui::MakeWeak(_content.get());
|
||||
_content->doneRequests(
|
||||
) | rpl::start_with_next([=, done = std::move(doneCallback)](
|
||||
const PhotoModifications &mods) {
|
||||
done(mods);
|
||||
if (weak) closeLayer();
|
||||
}, lifetime());
|
||||
|
||||
sizeValue(
|
||||
) | rpl::start_with_next([=](const QSize &size) {
|
||||
_content->resize(size);
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void LayerWidget::parentResized() {
|
||||
resizeToWidth(parentWidget()->width());
|
||||
}
|
||||
|
||||
void LayerWidget::keyPressEvent(QKeyEvent *e) {
|
||||
_content->handleKeyPress(e);
|
||||
}
|
||||
|
||||
int LayerWidget::resizeGetHeight(int newWidth) {
|
||||
return parentWidget()->height();
|
||||
}
|
||||
|
||||
bool LayerWidget::closeByOutsideClick() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
||||
@@ -6,16 +6,15 @@ 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 "base/unique_qptr.h"
|
||||
#include "editor/photo_editor_common.h"
|
||||
#include "ui/image/image.h"
|
||||
//
|
||||
//#include "ui/image/image.h"
|
||||
//#include "editor/photo_editor_common.h"
|
||||
//#include "base/unique_qptr.h"
|
||||
|
||||
enum class ImageRoundRadius;
|
||||
|
||||
namespace Ui {
|
||||
class RpWidget;
|
||||
struct PreparedFile;
|
||||
} // namespace Ui
|
||||
|
||||
@@ -27,47 +26,23 @@ class SessionController;
|
||||
namespace Editor {
|
||||
|
||||
void OpenWithPreparedFile(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::PreparedFile*> file,
|
||||
int previewWidth,
|
||||
Fn<void()> &&doneCallback);
|
||||
|
||||
void PrepareProfilePhoto(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::Controller*> controller,
|
||||
ImageRoundRadius radius,
|
||||
Fn<void(QImage &&image)> &&doneCallback,
|
||||
QImage &&image);
|
||||
|
||||
void PrepareProfilePhotoFromFile(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::Controller*> controller,
|
||||
ImageRoundRadius radius,
|
||||
Fn<void(QImage &&image)> &&doneCallback);
|
||||
|
||||
class PhotoEditor;
|
||||
|
||||
class LayerWidget : public Ui::LayerWidget {
|
||||
public:
|
||||
LayerWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Window::Controller*> window,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
Fn<void(PhotoModifications)> &&doneCallback,
|
||||
EditorData data = EditorData());
|
||||
|
||||
void parentResized() override;
|
||||
bool closeByOutsideClick() const override;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
|
||||
private:
|
||||
const base::unique_qptr<PhotoEditor> _content;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Editor
|
||||
|
||||
Reference in New Issue
Block a user