From 2791f89f30cdd29ea2cc1debbf771fff88b45f9d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 10 Mar 2021 15:07:04 +0300 Subject: [PATCH] Added initial context menu to items in photo editor. --- .../SourceFiles/editor/scene_item_base.cpp | 20 +++++++++++++++++++ Telegram/SourceFiles/editor/scene_item_base.h | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/Telegram/SourceFiles/editor/scene_item_base.cpp b/Telegram/SourceFiles/editor/scene_item_base.cpp index 96788f8314..46218b44a4 100644 --- a/Telegram/SourceFiles/editor/scene_item_base.cpp +++ b/Telegram/SourceFiles/editor/scene_item_base.cpp @@ -7,8 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "editor/scene_item_base.h" +#include "lang/lang_keys.h" +#include "ui/widgets/popup_menu.h" #include "styles/style_editor.h" +#include #include #include #include @@ -168,6 +171,23 @@ void ItemBase::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { } } +void ItemBase::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { + if (!isSelected() && scene()) { + scene()->clearSelection(); + setSelected(true); + } + + _menu = base::make_unique_q(nullptr); + _menu->addAction(tr::lng_selected_delete(tr::now), [=] { + if (scene()) { + scene()->removeItem(this); // Scene loses ownership of item. + delete this; + } + }); + + _menu->popup(event->screenPos()); +} + int ItemBase::type() const { return Type; } diff --git a/Telegram/SourceFiles/editor/scene_item_base.h b/Telegram/SourceFiles/editor/scene_item_base.h index 49b5c849ae..f7246c1274 100644 --- a/Telegram/SourceFiles/editor/scene_item_base.h +++ b/Telegram/SourceFiles/editor/scene_item_base.h @@ -7,12 +7,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/unique_qptr.h" + #include class QGraphicsSceneHoverEvent; class QGraphicsSceneMouseEvent; class QStyleOptionGraphicsItem; +namespace Ui { +class PopupMenu; +} // namespace Ui + namespace Editor { class NumberedItem : public QGraphicsItem { @@ -51,6 +57,7 @@ protected: void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override; void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; QRectF contentRect() const; QRectF innerRect() const; @@ -71,6 +78,8 @@ private: const QPen _selectPenInactive; const QPen _handlePen; + base::unique_qptr _menu; + float64 _scaledHandleSize = 1.0; QMarginsF _scaledInnerMargins;