[qet] qet/qet: [5732] Improve free selection behavior |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5732
Author: blacksun
Date: 2019-02-04 20:00:46 +0100 (Mon, 04 Feb 2019)
Log Message:
-----------
Improve free selection behavior
Modified Paths:
--------------
trunk/sources/diagramview.cpp
trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
trunk/sources/qetgraphicsitem/qetgraphicsitem.h
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2019-02-04 17:44:33 UTC (rev 5731)
+++ trunk/sources/diagramview.cpp 2019-02-04 19:00:46 UTC (rev 5732)
@@ -399,6 +399,8 @@
*/
void DiagramView::mousePressEvent(QMouseEvent *e)
{
+ e->ignore();
+
if (m_fresh_focus_in)
{
switchToVisualisationModeIfNeeded(e);
@@ -412,16 +414,40 @@
{
m_drag_last_pos = e->pos();
viewport()->setCursor(Qt::ClosedHandCursor);
+ e->accept();
+ return;
}
- else if (e->button() == Qt::LeftButton &&
- e->modifiers() == Qt::SHIFT)
+
+ //There is a good luck that user want to do a free selection
+ //In this case we temporally disable the dragmode because if the QGraphicsScene don't accept the event,
+ //and the drag mode is set to rubberbanddrag, the QGraphicsView start rubber band drag, and accept the event.
+ if (e->button() == Qt::LeftButton &&
+ e->modifiers() == Qt::CTRL)
{
+ QGraphicsView::DragMode dm = dragMode();
+ setDragMode(QGraphicsView::NoDrag);
+ QGraphicsView::mousePressEvent(e);
+ setDragMode(dm);
+ } else {
+ QGraphicsView::mousePressEvent(e);
+ }
+
+ if (e->isAccepted()) {
+ return;
+ }
+
+ if (e->button() == Qt::LeftButton &&
+ e->modifiers() == Qt::CTRL)
+ {
m_free_rubberbanding = true;
m_free_rubberband = QPolygon();
+ e->accept();
+ return;
+ }
+
+ if (!e->isAccepted()) {
QGraphicsView::mousePressEvent(e);
- }
-
- else QGraphicsView::mousePressEvent(e);
+ }
}
/**
@@ -516,7 +542,7 @@
//Popup a menu with an action to create conductors between
//all selected terminals.
- QAction *act = new QAction(tr("Connecter les bornes sélectionnées"), this);
+ QAction *act = new QAction(tr("Connecter les bornes sélectionné"), this);
QPolygonF polygon_ = m_free_rubberband;
connect(act, &QAction::triggered, [this, polygon_]()
{
Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp 2019-02-04 17:44:33 UTC (rev 5731)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp 2019-02-04 19:00:46 UTC (rev 5732)
@@ -1,5 +1,5 @@
/*
- Copyright 2006-2019 The QElectroTech Team
+ Copyright 2006-2017 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
@@ -27,7 +27,7 @@
QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent):
QGraphicsObject(parent),
is_movable_(true),
- first_move_(true),
+ m_first_move(true),
snap_to_grid_(true)
{}
@@ -75,66 +75,71 @@
/**
* @brief QetGraphicsItem::mousePressEvent
*handle the mouse click
- * @param e
+ * @param event
*/
-void QetGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
+void QetGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- if (e -> button() == Qt::LeftButton)
+ if (event->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)
+ m_first_move = true;
+ if (event->modifiers() & Qt::ControlModifier) {
setSelected(!isSelected());
+ }
}
- QGraphicsItem::mousePressEvent(e);
+ QGraphicsItem::mousePressEvent(event);
}
/**
* @brief QetGraphicsItem::mouseDoubleClickEvent
*handle the mouse double click
- * @param e
+ * @param event
*/
-void QetGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) {
- Q_UNUSED (e);
+void QetGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
editProperty();
+ event->accept();
}
/**
* @brief QetGraphicsItem::mouseMoveEvent
*handle mouse movement
- * @param e
+ * @param event
*/
-void QetGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
- if (isSelected() && e -> buttons() & Qt::LeftButton) {
- //Item is moving
- if(diagram() && first_move_) {
- //It's the first movement, we signal it to parent diagram
+void QetGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (isSelected() && event->buttons() & Qt::LeftButton)
+ {
+ //Item is moving
+ if(diagram() && m_first_move) {
+ //It's the first movement, we signal it to parent diagram
diagram()->elementsMover().beginMovement(diagram(), this);
}
- //we apply the mouse movement
+ //we apply the mouse movement
QPointF old_pos = pos();
- if (first_move_) {
- mouse_to_origin_movement_ = old_pos - e -> buttonDownScenePos(Qt::LeftButton);
+ if (m_first_move) {
+ m_mouse_to_origin_movement = old_pos - event -> buttonDownScenePos(Qt::LeftButton);
}
- QPointF expected_pos = e -> scenePos() + mouse_to_origin_movement_;
+ QPointF expected_pos = event->scenePos() + m_mouse_to_origin_movement;
setPos(expected_pos); // setPos() will snap the expected position to the grid
- //we calcul the real movement apply by setPos()
+ //we calcul the real movement apply by setPos()
QPointF effective_movement = pos() - old_pos;
if (diagram()) {
- //we signal the real movement apply to diagram,
- //who he apply to other selected item
+ //we signal the real movement apply to diagram,
+ //who he apply to other selected item
diagram()->elementsMover().continueMovement(effective_movement);
}
- } else e -> ignore();
+ event->accept();
+ }
+ else {
+ event->ignore();
+ }
- if (first_move_) first_move_ = false;
+ if (m_first_move) {
+ m_first_move = false;
+ }
}
/**
@@ -142,16 +147,10 @@
*handle mouse release click
* @param e
*/
-void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
- if (diagram())
+void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (diagram()) {
diagram()->elementsMover().endMovement();
-
- 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);
+ event->accept();
+ }
}
Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.h 2019-02-04 17:44:33 UTC (rev 5731)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.h 2019-02-04 19:00:46 UTC (rev 5732)
@@ -1,5 +1,5 @@
/*
- Copyright 2006-2019 The QElectroTech Team
+ Copyright 2006-2017 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
@@ -47,16 +47,16 @@
//protected method
protected:
- void mousePressEvent(QGraphicsSceneMouseEvent *e) override;
- void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) override;
- void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override;
+ void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
+ void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
protected:
bool is_movable_;
- bool first_move_;
+ bool m_first_move;
bool snap_to_grid_;
- QPointF mouse_to_origin_movement_;
+ QPointF m_mouse_to_origin_movement;
QET::GraphicsItemState m_state = QET:: GIOK;
};