mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
fix the bug when drag a image item
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2450 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -21,7 +21,8 @@
|
|||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
|
|
||||||
DiagramImageItem::DiagramImageItem(Diagram *parent_diagram) :
|
DiagramImageItem::DiagramImageItem(Diagram *parent_diagram) :
|
||||||
QGraphicsPixmapItem(0, parent_diagram)
|
QGraphicsPixmapItem(0, parent_diagram),
|
||||||
|
first_move_(false)
|
||||||
{
|
{
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
||||||
#if QT_VERSION >= 0x040600
|
#if QT_VERSION >= 0x040600
|
||||||
@@ -246,10 +247,14 @@ void DiagramImageItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
|
|
||||||
//we apply the mouse movement
|
//we apply the mouse movement
|
||||||
QPointF old_pos = pos();
|
QPointF old_pos = pos();
|
||||||
setPos(mapToParent(e -> pos()) - matrix().map(e -> buttonDownPos(Qt::LeftButton)));
|
if (first_move_) {
|
||||||
|
mouse_to_origin_movement_ = old_pos - e -> buttonDownScenePos(Qt::LeftButton);
|
||||||
|
}
|
||||||
|
QPointF expected_pos = e-> scenePos() + 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;
|
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
|
||||||
|
|||||||
@@ -81,5 +81,6 @@ class DiagramImageItem : public QObject, public QGraphicsPixmapItem {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool first_move_;
|
bool first_move_;
|
||||||
|
QPointF mouse_to_origin_movement_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user