mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Added initial context menu to items in photo editor.
This commit is contained in:
@@ -7,8 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
*/
|
*/
|
||||||
#include "editor/scene_item_base.h"
|
#include "editor/scene_item_base.h"
|
||||||
|
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "styles/style_editor.h"
|
#include "styles/style_editor.h"
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsSceneHoverEvent>
|
#include <QGraphicsSceneHoverEvent>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#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 {
|
int ItemBase::type() const {
|
||||||
return Type;
|
return Type;
|
||||||
}
|
}
|
||||||
|
@@ -7,12 +7,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/unique_qptr.h"
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
class QGraphicsSceneHoverEvent;
|
class QGraphicsSceneHoverEvent;
|
||||||
class QGraphicsSceneMouseEvent;
|
class QGraphicsSceneMouseEvent;
|
||||||
class QStyleOptionGraphicsItem;
|
class QStyleOptionGraphicsItem;
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class PopupMenu;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
namespace Editor {
|
namespace Editor {
|
||||||
|
|
||||||
class NumberedItem : public QGraphicsItem {
|
class NumberedItem : public QGraphicsItem {
|
||||||
@@ -51,6 +57,7 @@ protected:
|
|||||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
|
|
||||||
QRectF contentRect() const;
|
QRectF contentRect() const;
|
||||||
QRectF innerRect() const;
|
QRectF innerRect() const;
|
||||||
@@ -71,6 +78,8 @@ private:
|
|||||||
const QPen _selectPenInactive;
|
const QPen _selectPenInactive;
|
||||||
const QPen _handlePen;
|
const QPen _handlePen;
|
||||||
|
|
||||||
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||||
|
|
||||||
float64 _scaledHandleSize = 1.0;
|
float64 _scaledHandleSize = 1.0;
|
||||||
QMarginsF _scaledInnerMargins;
|
QMarginsF _scaledInnerMargins;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user