mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added draft menu to SendFilesBox to open photo editor.
This commit is contained in:
parent
09768ce28a
commit
3ce315111f
8 changed files with 91 additions and 0 deletions
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "chat_helpers/tabbed_panel.h"
|
||||
#include "chat_helpers/tabbed_selector.h"
|
||||
#include "confirm_box.h"
|
||||
#include "editor/photo_editor_layer_widget.h"
|
||||
#include "history/history_drag_area.h"
|
||||
#include "history/view/history_view_schedule_box.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
@ -187,6 +188,22 @@ rpl::producer<int> SendFilesBox::Block::itemReplaceRequest() const {
|
|||
}
|
||||
}
|
||||
|
||||
rpl::producer<int> SendFilesBox::Block::itemModifyRequest() const {
|
||||
using namespace rpl::mappers;
|
||||
|
||||
const auto preview = _preview.get();
|
||||
const auto from = _from;
|
||||
if (_isAlbum) {
|
||||
const auto album = static_cast<Ui::AlbumPreview*>(preview);
|
||||
return album->thumbModified() | rpl::map(_1 + from);
|
||||
} else if (_isSingleMedia) {
|
||||
const auto media = static_cast<Ui::SingleMediaPreview*>(preview);
|
||||
return media->modifyRequests() | rpl::map_to(from);
|
||||
} else {
|
||||
return rpl::never<int>();
|
||||
}
|
||||
}
|
||||
|
||||
void SendFilesBox::Block::setSendWay(Ui::SendFilesWay way) {
|
||||
if (!_isAlbum) {
|
||||
return;
|
||||
|
@ -601,6 +618,41 @@ void SendFilesBox::pushBlock(int from, int till) {
|
|||
FileDialog::AllOrImagesFilter(),
|
||||
crl::guard(this, callback));
|
||||
}, widget->lifetime());
|
||||
|
||||
const auto pp = std::make_shared<QPixmap>();
|
||||
block.itemModifyRequest(
|
||||
) | rpl::start_with_next([=, controller = _controller](int index) {
|
||||
auto &file = _list.files[index];
|
||||
if (file.type != Ui::PreparedFile::Type::Photo) {
|
||||
return;
|
||||
}
|
||||
using Image = Ui::PreparedFileInformation::Image;
|
||||
const auto image = std::get_if<Image>(&file.information->media);
|
||||
if (!image) {
|
||||
return;
|
||||
}
|
||||
|
||||
*pp = QPixmap::fromImage(
|
||||
image->data,
|
||||
Qt::ColorOnly);
|
||||
|
||||
auto callback = [=](const Editor::PhotoModifications &mods) {
|
||||
image->modifications = mods;
|
||||
Storage::UpdateImageDetails(
|
||||
_list.files[index],
|
||||
st::sendMediaPreviewSize);
|
||||
refreshAllAfterChanges(from);
|
||||
};
|
||||
|
||||
controller->showLayer(
|
||||
std::make_unique<Editor::LayerWidget>(
|
||||
this,
|
||||
&controller->window(),
|
||||
pp,
|
||||
image->modifications,
|
||||
std::move(callback)),
|
||||
Ui::LayerOption::KeepOther);
|
||||
}, widget->lifetime());
|
||||
}
|
||||
|
||||
void SendFilesBox::refreshControls() {
|
||||
|
|
|
@ -102,6 +102,7 @@ private:
|
|||
|
||||
[[nodiscard]] rpl::producer<int> itemDeleteRequest() const;
|
||||
[[nodiscard]] rpl::producer<int> itemReplaceRequest() const;
|
||||
[[nodiscard]] rpl::producer<int> itemModifyRequest() const;
|
||||
|
||||
void setSendWay(Ui::SendFilesWay way);
|
||||
void applyAlbumOrder();
|
||||
|
|
|
@ -30,6 +30,10 @@ AlbumPreview::AlbumPreview(
|
|||
prepareThumbs(items);
|
||||
updateSize();
|
||||
updateFileRows();
|
||||
|
||||
AddPhotoEditorMenu(this, [=] {
|
||||
_thumbModified.fire(thumbIndex(thumbUnderCursor()));
|
||||
});
|
||||
}
|
||||
|
||||
AlbumPreview::~AlbumPreview() = default;
|
||||
|
@ -491,4 +495,8 @@ void AlbumPreview::mouseReleaseEvent(QMouseEvent *e) {
|
|||
}
|
||||
}
|
||||
|
||||
rpl::producer<int> AlbumPreview::thumbModified() const {
|
||||
return _thumbModified.events();
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -35,6 +35,8 @@ public:
|
|||
return _thumbChanged.events();
|
||||
}
|
||||
|
||||
rpl::producer<int> thumbModified() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
|
@ -89,6 +91,7 @@ private:
|
|||
|
||||
rpl::event_stream<int> _thumbDeleted;
|
||||
rpl::event_stream<int> _thumbChanged;
|
||||
rpl::event_stream<int> _thumbModified;
|
||||
|
||||
mutable Animations::Simple _thumbsHeightAnimation;
|
||||
mutable Animations::Simple _shrinkAnimation;
|
||||
|
|
|
@ -7,6 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "ui/chat/attach/attach_prepare.h"
|
||||
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
|
||||
#include "ui/chat/attach/attach_send_files_way.h"
|
||||
#include "ui/image/image_prepare.h"
|
||||
#include "ui/ui_utility.h"
|
||||
|
@ -273,4 +276,16 @@ QPixmap PrepareSongCoverForThumbnail(QImage image, int size) {
|
|||
&st::songCoverOverlayFg));
|
||||
}
|
||||
|
||||
void AddPhotoEditorMenu(not_null<Ui::RpWidget*> parent, Fn<void()> callback) {
|
||||
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
|
||||
parent->events(
|
||||
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||
if (e->type() == QEvent::ContextMenu) {
|
||||
*menu = base::make_unique_q<Ui::PopupMenu>(parent);
|
||||
(*menu)->addAction("Photo Editor", callback);
|
||||
(*menu)->popup(QCursor::pos());
|
||||
}
|
||||
}, parent->lifetime());
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace Ui {
|
||||
|
||||
class RpWidget;
|
||||
class SendFilesWay;
|
||||
|
||||
struct PreparedFileInformation {
|
||||
|
@ -137,4 +138,6 @@ struct PreparedGroup {
|
|||
|
||||
[[nodiscard]] QPixmap PrepareSongCoverForThumbnail(QImage image, int size);
|
||||
|
||||
void AddPhotoEditorMenu(not_null<Ui::RpWidget*> parent, Fn<void()> callback);
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -76,6 +76,8 @@ SingleMediaPreview::SingleMediaPreview(
|
|||
_deleteMedia->setIconOverride(&st::sendBoxAlbumGroupButtonMediaDelete);
|
||||
|
||||
preparePreview(preview, animatedPreviewPath);
|
||||
|
||||
Ui::AddPhotoEditorMenu(this, [=] { _modifyRequests.fire({}); });
|
||||
}
|
||||
|
||||
SingleMediaPreview::~SingleMediaPreview() = default;
|
||||
|
@ -88,6 +90,10 @@ rpl::producer<> SingleMediaPreview::editRequests() const {
|
|||
return _editMedia->clicks() | rpl::to_empty;
|
||||
}
|
||||
|
||||
rpl::producer<> SingleMediaPreview::modifyRequests() const {
|
||||
return _modifyRequests.events();
|
||||
}
|
||||
|
||||
void SingleMediaPreview::preparePreview(
|
||||
QImage preview,
|
||||
const QString &animatedPreviewPath) {
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
[[nodiscard]] rpl::producer<> deleteRequests() const;
|
||||
[[nodiscard]] rpl::producer<> editRequests() const;
|
||||
[[nodiscard]] rpl::producer<> modifyRequests() const;
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
@ -65,6 +66,8 @@ private:
|
|||
object_ptr<IconButton> _deleteMedia = { nullptr };
|
||||
RoundRect _buttonsRect;
|
||||
|
||||
rpl::event_stream<> _modifyRequests;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui
|
||||
|
|
Loading…
Add table
Reference in a new issue