mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Improve free selection behavior
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5732 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -399,6 +399,8 @@ void DiagramView::pasteHere() {
|
|||||||
*/
|
*/
|
||||||
void DiagramView::mousePressEvent(QMouseEvent *e)
|
void DiagramView::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
|
e->ignore();
|
||||||
|
|
||||||
if (m_fresh_focus_in)
|
if (m_fresh_focus_in)
|
||||||
{
|
{
|
||||||
switchToVisualisationModeIfNeeded(e);
|
switchToVisualisationModeIfNeeded(e);
|
||||||
@@ -412,16 +414,40 @@ void DiagramView::mousePressEvent(QMouseEvent *e)
|
|||||||
{
|
{
|
||||||
m_drag_last_pos = e->pos();
|
m_drag_last_pos = e->pos();
|
||||||
viewport()->setCursor(Qt::ClosedHandCursor);
|
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_rubberbanding = true;
|
||||||
m_free_rubberband = QPolygon();
|
m_free_rubberband = QPolygon();
|
||||||
QGraphicsView::mousePressEvent(e);
|
e->accept();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else QGraphicsView::mousePressEvent(e);
|
if (!e->isAccepted()) {
|
||||||
|
QGraphicsView::mousePressEvent(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -516,7 +542,7 @@ void DiagramView::mouseReleaseEvent(QMouseEvent *e)
|
|||||||
|
|
||||||
//Popup a menu with an action to create conductors between
|
//Popup a menu with an action to create conductors between
|
||||||
//all selected terminals.
|
//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;
|
QPolygonF polygon_ = m_free_rubberband;
|
||||||
connect(act, &QAction::triggered, [this, polygon_]()
|
connect(act, &QAction::triggered, [this, polygon_]()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2019 The QElectroTech Team
|
Copyright 2006-2017 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent):
|
QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent):
|
||||||
QGraphicsObject(parent),
|
QGraphicsObject(parent),
|
||||||
is_movable_(true),
|
is_movable_(true),
|
||||||
first_move_(true),
|
m_first_move(true),
|
||||||
snap_to_grid_(true)
|
snap_to_grid_(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -75,66 +75,71 @@ QET::GraphicsItemState QetGraphicsItem::state() const {
|
|||||||
/**
|
/**
|
||||||
* @brief QetGraphicsItem::mousePressEvent
|
* @brief QetGraphicsItem::mousePressEvent
|
||||||
*handle the mouse click
|
*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
|
m_first_move = true;
|
||||||
if (scene())
|
if (event->modifiers() & Qt::ControlModifier) {
|
||||||
foreach (QGraphicsView *view, scene()->views())
|
|
||||||
view->setContextMenuPolicy(Qt::NoContextMenu);
|
|
||||||
|
|
||||||
first_move_ = true;
|
|
||||||
if (e -> modifiers() & Qt::ControlModifier)
|
|
||||||
setSelected(!isSelected());
|
setSelected(!isSelected());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsItem::mousePressEvent(e);
|
QGraphicsItem::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief QetGraphicsItem::mouseDoubleClickEvent
|
* @brief QetGraphicsItem::mouseDoubleClickEvent
|
||||||
*handle the mouse double click
|
*handle the mouse double click
|
||||||
* @param e
|
* @param event
|
||||||
*/
|
*/
|
||||||
void QetGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) {
|
void QetGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||||
Q_UNUSED (e);
|
{
|
||||||
editProperty();
|
editProperty();
|
||||||
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief QetGraphicsItem::mouseMoveEvent
|
* @brief QetGraphicsItem::mouseMoveEvent
|
||||||
*handle mouse movement
|
*handle mouse movement
|
||||||
* @param e
|
* @param event
|
||||||
*/
|
*/
|
||||||
void QetGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
void QetGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
if (isSelected() && e -> buttons() & Qt::LeftButton) {
|
{
|
||||||
//Item is moving
|
if (isSelected() && event->buttons() & Qt::LeftButton)
|
||||||
if(diagram() && first_move_) {
|
{
|
||||||
//It's the first movement, we signal it to parent diagram
|
//Item is moving
|
||||||
|
if(diagram() && m_first_move) {
|
||||||
|
//It's the first movement, we signal it to parent diagram
|
||||||
diagram()->elementsMover().beginMovement(diagram(), this);
|
diagram()->elementsMover().beginMovement(diagram(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//we apply the mouse movement
|
//we apply the mouse movement
|
||||||
QPointF old_pos = pos();
|
QPointF old_pos = pos();
|
||||||
if (first_move_) {
|
if (m_first_move) {
|
||||||
mouse_to_origin_movement_ = old_pos - e -> buttonDownScenePos(Qt::LeftButton);
|
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
|
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;
|
QPointF effective_movement = pos() - old_pos;
|
||||||
if (diagram()) {
|
if (diagram()) {
|
||||||
//we signal the real movement apply to diagram,
|
//we signal the real movement apply to diagram,
|
||||||
//who he apply to other selected item
|
//who he apply to other selected item
|
||||||
diagram()->elementsMover().continueMovement(effective_movement);
|
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 @@ void QetGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
*handle mouse release click
|
*handle mouse release click
|
||||||
* @param e
|
* @param e
|
||||||
*/
|
*/
|
||||||
void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
if (diagram())
|
{
|
||||||
|
if (diagram()) {
|
||||||
diagram()->elementsMover().endMovement();
|
diagram()->elementsMover().endMovement();
|
||||||
|
event->accept();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2019 The QElectroTech Team
|
Copyright 2006-2017 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -47,16 +47,16 @@ class QetGraphicsItem : public QGraphicsObject
|
|||||||
|
|
||||||
//protected method
|
//protected method
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *e) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) override;
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override;
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool is_movable_;
|
bool is_movable_;
|
||||||
bool first_move_;
|
bool m_first_move;
|
||||||
bool snap_to_grid_;
|
bool snap_to_grid_;
|
||||||
QPointF mouse_to_origin_movement_;
|
QPointF m_mouse_to_origin_movement;
|
||||||
QET::GraphicsItemState m_state = QET:: GIOK;
|
QET::GraphicsItemState m_state = QET:: GIOK;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user