[qet] [3593] Qet graphics item : disable context menu from view when right button is holded |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3593
Author: blacksun
Date: 2015-01-08 19:59:23 +0100 (Thu, 08 Jan 2015)
Log Message:
-----------
Qet graphics item : disable context menu from view when right button is holded
Modified Paths:
--------------
trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
trunk/sources/qetgraphicsitem/qetgraphicsitem.h
Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp 2015-01-07 19:35:42 UTC (rev 3592)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp 2015-01-08 18:59:23 UTC (rev 3593)
@@ -90,11 +90,20 @@
*handle the mouse click
* @param e
*/
-void QetGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *e) {
- first_move_ = true;
- if (e -> modifiers() & Qt::ControlModifier) {
- setSelected(!isSelected());
+void QetGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
+{
+ if (e -> button() == Qt::LeftButton)
+ {
+ //Disable views context menu
+ if (scene())
+ foreach (QGraphicsView *view, scene()->views())
+ view->setContextMenuPolicy(Qt::NoContextMenu);
+
+ first_move_ = true;
+ if (e -> modifiers() & Qt::ControlModifier)
+ setSelected(!isSelected());
}
+
QGraphicsItem::mousePressEvent(e);
}
@@ -148,5 +157,13 @@
*/
void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
if (diagram()) diagram() -> endMoveElements();
- if (!(e -> modifiers() & Qt::ControlModifier)) QGraphicsItem::mouseReleaseEvent(e);
+
+ if (!(e -> modifiers() & Qt::ControlModifier))
+ QGraphicsItem::mouseReleaseEvent(e);
+
+ //Enable views context menu
+ if (e -> button() == Qt::LeftButton)
+ if (scene())
+ foreach (QGraphicsView *view, scene()->views())
+ view -> setContextMenuPolicy(Qt::DefaultContextMenu);
}
Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.h 2015-01-07 19:35:42 UTC (rev 3592)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.h 2015-01-08 18:59:23 UTC (rev 3593)
@@ -22,39 +22,36 @@
class Diagram;
-class QetGraphicsItem : public QGraphicsObject {
+class QetGraphicsItem : public QGraphicsObject
+{
Q_OBJECT
public:
- //constructor destructor
- QetGraphicsItem(QGraphicsItem *parent = 0);
- virtual ~QetGraphicsItem() = 0;
+ //constructor destructor
+ QetGraphicsItem(QGraphicsItem *parent = 0);
+ virtual ~QetGraphicsItem() = 0;
- //public methode
- Diagram * diagram() const;
- virtual void setPos(const QPointF &p);
- virtual void setPos(qreal x, qreal y);
- virtual void rotateBy(const qreal &);
- virtual void applyRotation(const qreal &);
- virtual void editProperty (){}
- virtual QString name()const {return QString("");}
+ //public methode
+ Diagram *diagram () const;
+ virtual void setPos (const QPointF &p);
+ virtual void setPos (qreal x, qreal y);
+ virtual void rotateBy (const qreal &);
+ virtual void applyRotation (const qreal &);
+ virtual void editProperty () {}
+ virtual QString name ()const {return QString("");}
- signals:
-
- public slots:
-
- //protected method
+ //protected method
protected:
- virtual void mousePressEvent(QGraphicsSceneMouseEvent *e);
- virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e);
- virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
- virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *e);
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *e);
+ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e);
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *e);
protected:
- bool is_movable_;
- bool first_move_;
- bool snap_to_grid_;
- QPointF mouse_to_origin_movement_;
+ bool is_movable_;
+ bool first_move_;
+ bool snap_to_grid_;
+ QPointF mouse_to_origin_movement_;
};