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:
blacksun
2013-08-24 15:32:07 +00:00
parent 0b9adb77d5
commit 6ba45839ed
2 changed files with 9 additions and 3 deletions

View File

@@ -21,7 +21,8 @@
#include "qetapp.h"
DiagramImageItem::DiagramImageItem(Diagram *parent_diagram) :
QGraphicsPixmapItem(0, parent_diagram)
QGraphicsPixmapItem(0, parent_diagram),
first_move_(false)
{
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
#if QT_VERSION >= 0x040600
@@ -246,10 +247,14 @@ void DiagramImageItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
//we apply the mouse movement
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()
QPointF effective_movement = pos() - old_pos;
if (diagram()) {
//we signal the real movement apply to diagram,
//who he apply to other selected item

View File

@@ -81,5 +81,6 @@ class DiagramImageItem : public QObject, public QGraphicsPixmapItem {
private:
bool first_move_;
QPointF mouse_to_origin_movement_;
};
#endif