From 2f9fd793717a961b1f4600892806f6483ece86eb Mon Sep 17 00:00:00 2001 From: blacksun Date: Tue, 24 Mar 2015 22:21:58 +0000 Subject: [PATCH] Minor change about how drag view work (diagram editor and element editor) git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3849 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagramview.cpp | 25 +++++++++++++++---------- sources/diagramview.h | 1 - sources/editor/elementview.cpp | 30 ++++++++++++++++-------------- sources/editor/elementview.h | 2 -- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 3644e36e2..e2e27922e 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -470,7 +470,7 @@ void DiagramView::pasteHere() { } /** - Manage the events press click mouse : + Manage the events press click : * click to add an independent text field */ void DiagramView::mousePressEvent(QMouseEvent *e) { @@ -490,11 +490,11 @@ void DiagramView::mousePressEvent(QMouseEvent *e) { } } - //Start drag view when hold the middle button - if (e -> button() == Qt::MidButton) { - rubber_band_origin = mapToScene(e -> pos()); + //Start drag view when hold the middle button + if (e->button() == Qt::MidButton) + { + rubber_band_origin = e->pos(); setCursor(Qt::ClosedHandCursor); - center_view_ = mapToScene(this -> viewport() -> rect().center()); } else QGraphicsView::mousePressEvent(e); @@ -515,11 +515,16 @@ void DiagramView::mouseMoveEvent(QMouseEvent *e) { return; } } - //Drag the view - if (e -> buttons() == Qt::MidButton) { - QPointF move = rubber_band_origin - mapToScene(e -> pos()); - this -> centerOn(center_view_ + move); - center_view_ = mapToScene( this -> viewport() -> rect().center() ); + + //Drag the view + if (e->buttons() == Qt::MidButton) + { + QScrollBar *h = horizontalScrollBar(); + QScrollBar *v = verticalScrollBar(); + QPointF pos = rubber_band_origin - e -> pos(); + rubber_band_origin = e -> pos(); + h -> setValue(h -> value() + pos.x()); + v -> setValue(v -> value() + pos.y()); } else QGraphicsView::mouseMoveEvent(e); diff --git a/sources/diagramview.h b/sources/diagramview.h index 7f5a06d53..e9305cc0f 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -50,7 +50,6 @@ class DiagramView : public QGraphicsView { QAction *find_element_; QPoint paste_here_pos; QPoint next_position_; - QPointF center_view_; QPointF rubber_band_origin; bool fresh_focus_in_; ///< Indicate the focus was freshly gained ElementsLocation next_location_; diff --git a/sources/editor/elementview.cpp b/sources/editor/elementview.cpp index 038c388e0..650ba8799 100644 --- a/sources/editor/elementview.cpp +++ b/sources/editor/elementview.cpp @@ -360,14 +360,13 @@ ElementContent ElementView::pasteWithOffset(const QDomDocument &xml_document) { @param e QMouseEvent decrivant l'evenement souris */ void ElementView::mousePressEvent(QMouseEvent *e) { - // Select visualisation or selection mode - if (e -> buttons() == Qt::MidButton) { - setCursor(Qt::ClosedHandCursor); - reference_view_ = mapToScene(e -> pos()); - center_view_ = mapToScene(this -> viewport() -> rect()).boundingRect().center(); - return; + if (e->buttons() == Qt::MidButton) + { + setCursor( (Qt::ClosedHandCursor)); + reference_view_ = e->pos(); } - QGraphicsView::mousePressEvent(e); + else + QGraphicsView::mousePressEvent(e); } /** @@ -375,14 +374,17 @@ void ElementView::mousePressEvent(QMouseEvent *e) { * Manage the event move mouse */ void ElementView::mouseMoveEvent(QMouseEvent *e) { - if ((e -> buttons() & Qt::MidButton) == Qt::MidButton) { - QPointF move = reference_view_ - mapToScene(e -> pos()); - this -> centerOn(center_view_ + move); - center_view_ = mapToScene(this -> viewport() -> rect()).boundingRect().center(); - adjustSceneRect(); - return; + if (e->buttons() == Qt::MidButton) + { + QScrollBar *h = horizontalScrollBar(); + QScrollBar *v = verticalScrollBar(); + QPointF pos = reference_view_ - e -> pos(); + reference_view_ = e -> pos(); + h -> setValue(h -> value() + pos.x()); + v -> setValue(v -> value() + pos.y()); } - QGraphicsView::mouseMoveEvent(e); + else + QGraphicsView::mouseMoveEvent(e); } /** diff --git a/sources/editor/elementview.h b/sources/editor/elementview.h index cd3238470..4de7c4f0d 100644 --- a/sources/editor/elementview.h +++ b/sources/editor/elementview.h @@ -89,8 +89,6 @@ class ElementView : public QGraphicsView { int offset_paste_count_; QPointF start_top_left_corner_; QPointF reference_view_; - QPointF center_view_; bool gestures() const; - bool is_moving_view_; ///< Indicate whether the visualisation mode has been enabled due to mouse/keyboard interactions }; #endif