mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added photo painting to PhotoEditorContent.
This commit is contained in:
parent
45f8e68203
commit
f7fa36ca1d
4 changed files with 41 additions and 1 deletions
|
@ -15,7 +15,13 @@ namespace Editor {
|
|||
PhotoEditor::PhotoEditor(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<QPixmap> photo)
|
||||
: RpWidget(parent) {
|
||||
: RpWidget(parent)
|
||||
, _content(base::make_unique_q<PhotoEditorContent>(this, photo))
|
||||
, _controls(base::make_unique_q<PhotoEditorControls>(this)) {
|
||||
sizeValue(
|
||||
) | rpl::start_with_next([=](const QSize &size) {
|
||||
_content->resize(size);
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
#include "base/unique_qptr.h"
|
||||
|
||||
namespace Editor {
|
||||
|
||||
class PhotoEditorContent;
|
||||
|
@ -22,6 +24,9 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
base::unique_qptr<PhotoEditorContent> _content;
|
||||
base::unique_qptr<PhotoEditorControls> _controls;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -13,6 +13,33 @@ PhotoEditorContent::PhotoEditorContent(
|
|||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<QPixmap> photo)
|
||||
: RpWidget(parent) {
|
||||
|
||||
sizeValue(
|
||||
) | rpl::start_with_next([=](const QSize &size) {
|
||||
const auto imageSize = [&] {
|
||||
const auto originalSize = photo->size() / cIntRetinaFactor();
|
||||
if ((originalSize.width() > size.width())
|
||||
&& (originalSize.height() > size.height())) {
|
||||
return originalSize.scaled(
|
||||
size,
|
||||
Qt::KeepAspectRatio);
|
||||
}
|
||||
return originalSize;
|
||||
}();
|
||||
_imageRect = QRect(
|
||||
QPoint(
|
||||
(size.width() - imageSize.width()) / 2,
|
||||
(size.height() - imageSize.height()) / 2),
|
||||
imageSize);
|
||||
}, lifetime());
|
||||
|
||||
paintRequest(
|
||||
) | rpl::start_with_next([=](const QRect &clip) {
|
||||
Painter p(this);
|
||||
|
||||
p.fillRect(clip, Qt::transparent);
|
||||
p.drawPixmap(_imageRect, *photo, photo->rect());
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -19,6 +19,8 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
QRect _imageRect;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Editor
|
||||
|
|
Loading…
Add table
Reference in a new issue