mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added initial context menu to items in photo editor.
This commit is contained in:
parent
858b5831e8
commit
2791f89f30
2 changed files with 29 additions and 0 deletions
|
@ -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 <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
@ -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<Ui::PopupMenu>(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;
|
||||
}
|
||||
|
|
|
@ -7,12 +7,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/unique_qptr.h"
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
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<Ui::PopupMenu> _menu;
|
||||
|
||||
float64 _scaledHandleSize = 1.0;
|
||||
QMarginsF _scaledInnerMargins;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue