mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-06-24 00:14:12 +02:00
Merge pull request #520 from ispyisail/fix/element-editor-first-click-481
fixed: view jumps, but graphic primitives stay at position all parts can be moved as before compile-warning is gone thank you @ispyisail
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
|
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
#include "../elementscene.h"
|
#include "../elementscene.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +40,8 @@ CustomElementGraphicPart::CustomElementGraphicPart(QETElementEditor *editor,
|
|||||||
_lineweight(NormalWeight),
|
_lineweight(NormalWeight),
|
||||||
_filling(NoneFilling),
|
_filling(NoneFilling),
|
||||||
_color(BlackColor),
|
_color(BlackColor),
|
||||||
_antialiased(false)
|
_antialiased(false),
|
||||||
|
m_first_move (false)
|
||||||
{
|
{
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable
|
setFlags(QGraphicsItem::ItemIsSelectable
|
||||||
| QGraphicsItem::ItemIsMovable
|
| QGraphicsItem::ItemIsMovable
|
||||||
@@ -1332,27 +1334,25 @@ void CustomElementGraphicPart::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
|
|
||||||
void CustomElementGraphicPart::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void CustomElementGraphicPart::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
//m_first_move is used to avoid an unwanted behavior
|
if (m_first_move) {
|
||||||
//when the properties dock widget is displayed :
|
// Suppress spurious move events fired when the properties dock
|
||||||
//1 there is no selection
|
// widget expands on first selection of a new item type, causing
|
||||||
//2 the dock widget width is set to minimum
|
// the QGraphicsView to shrink and re-map coordinates. Screen
|
||||||
//3 select a part, the dock widget gain new widgets used to edit
|
// coordinates are stable across viewport changes; scene coords
|
||||||
//the current selected part and the width of the dock grow
|
// are not — so use screenPos() for the threshold check.
|
||||||
//so the width of the QGraphicsView is reduced and cause a mouse move event.
|
const QPointF d = event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton);
|
||||||
//When this case occur the part is moved but they should not. This bool fix it.
|
if (d.manhattanLength() < QApplication::startDragDistance())
|
||||||
if (Q_UNLIKELY(m_first_move)) {
|
|
||||||
m_first_move = false;
|
|
||||||
return;
|
return;
|
||||||
|
m_first_move = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable))
|
if ((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||||
{
|
|
||||||
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
||||||
event->modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene()->snapToGrid(pos));
|
event->modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene()->snapToGrid(pos));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
QGraphicsObject::mouseMoveEvent(event);
|
QGraphicsObject::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CustomElementGraphicPart::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void CustomElementGraphicPart::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
|
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
#include "../../qetapp.h"
|
#include "../../qetapp.h"
|
||||||
#include "../elementscene.h"
|
#include "../elementscene.h"
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
@@ -496,12 +497,16 @@ bool PartDynamicTextField::keepVisualRotation() const {
|
|||||||
*/
|
*/
|
||||||
void PartDynamicTextField::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
void PartDynamicTextField::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
if ((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
if ((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||||
|
// Suppress spurious moves from the properties dock resizing the viewport.
|
||||||
|
const QPointF d = event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton);
|
||||||
|
if (d.manhattanLength() < QApplication::startDragDistance())
|
||||||
|
return;
|
||||||
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
||||||
event->modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene()->snapToGrid(pos));
|
event->modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene()->snapToGrid(pos));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
QGraphicsObject::mouseMoveEvent(event);
|
QGraphicsObject::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief PartDynamicTextField::mousePressEvent
|
@brief PartDynamicTextField::mousePressEvent
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "parttext.h"
|
#include "parttext.h"
|
||||||
|
|
||||||
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
|
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
#include <QApplication>
|
||||||
#include "../../qetapp.h"
|
#include "../../qetapp.h"
|
||||||
#include "../elementprimitivedecorator.h"
|
#include "../elementprimitivedecorator.h"
|
||||||
#include "../elementscene.h"
|
#include "../elementscene.h"
|
||||||
@@ -325,10 +326,13 @@ void PartText::setFont(const QFont &font) {
|
|||||||
|
|
||||||
void PartText::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
void PartText::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
if ((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
if ((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
||||||
|
// Suppress spurious moves from the properties dock resizing the viewport.
|
||||||
|
const QPointF d = event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton);
|
||||||
|
if (d.manhattanLength() < QApplication::startDragDistance())
|
||||||
|
return;
|
||||||
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
QPointF pos = event->scenePos() + (m_origin_pos - event->buttonDownScenePos(Qt::LeftButton));
|
||||||
event->modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene()->snapToGrid(pos));
|
event->modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene()->snapToGrid(pos));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
QGraphicsObject::mouseMoveEvent(event);
|
QGraphicsObject::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user