[Uml-devel] CVS: kdesdk/umbrello/umbrello floatingtext.cpp,1.2,1.3 floatingtext.h,1.1,1.2 objectwidget.cpp,1.4,1.5 objectwidget.h,1.1,1.2 uml.cpp,1.8,1.9 umlwidget.cpp,1.3,1.4 umlwidget.h,1.1,1.2

kde at office.kde.org kde at office.kde.org
Sat Feb 1 16:48:33 UTC 2003


Update of /home/kde/kdesdk/umbrello/umbrello
In directory office:/tmp/cvs-serv1613

Modified Files:
	floatingtext.cpp floatingtext.h objectwidget.cpp 
	objectwidget.h uml.cpp umlwidget.cpp umlwidget.h 
Log Message:
refactoring UMLWidget::mouseMoveEvent to remove code duplication


Index: floatingtext.cpp
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/floatingtext.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- floatingtext.cpp	25 Jan 2003 19:00:40 -0000	1.2
+++ floatingtext.cpp	2 Feb 2003 00:47:42 -0000	1.3
@@ -302,63 +302,33 @@
 	setPositionFromMessage(); //force it to display
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-void FloatingText::mouseMoveEvent(QMouseEvent *me) {
-	int newX = 0, newY = 0, count;
-	int moveX, moveY;
-	if( !m_bSelected )
-		m_pView -> setSelected( this, me );
-	m_bSelected = true;
-	count = m_pView -> getSelectCount();
-
-	if( !m_bMouseDown )
-		if( me -> button() != LeftButton )
-			return;
-	//If not m_bStartMove means moving as part of selection
-	//me->pos() will have the amount we need to move.
-	if(!m_bStartMove) {
-		moveX = (int)me -> x();
-		moveY = (int)me -> y();
-	} else {
-		//we started the move so..
-		//move any others we are selected
-		moveX = (int)me -> x() - m_nOldX - m_nPressOffsetX;
-		moveY = (int)me -> y() - m_nOldY - m_nPressOffsetY;
-		if( ((int)x() + moveX) < 0 )
-			moveX = 0;
-		if( ( (int)y() + moveY) < 0 )
-			moveY = 0;
-		if( count > 1 )
-			if( m_pView -> getType() == dt_Sequence )
-				m_pView -> moveSelected( this, moveX, 0 );
-			else
-				m_pView -> moveSelected( this, moveX, moveY );
-	}
-	newX = (int)x() + moveX;
-	newY = (int)y() + moveY;
+void FloatingText::mouseMoveEvent(QMouseEvent* me) {
+	if( m_bMouseDown ) {
+		QPoint newPosition = doMouseMove(me);
+		int newX = newPosition.x();
+		int newY = newPosition.y();
 
-	newX = newX < 0?0:newX;
-	newY = newY < 0?0:newY;
+		//implement specific rules for a sequence diagram
+		if( getRole()  == tr_Seq_Message || getRole()  == tr_Seq_Message_Self) {
+			newX = (int)m_pMessage->x() + 5;
+			int minHeight = m_pMessage->getMinHeight();
+			newY = newY < minHeight ? minHeight : newY;
 
-	//implement specific rules for a sequence diagram
-	if( getRole()  == tr_Seq_Message || getRole()  == tr_Seq_Message_Self) {
-		newX = (int)m_pMessage -> x() + 5;
-		int minHeight = m_pMessage -> getMinHeight();
-		newY = newY < minHeight ? minHeight : newY;
-		//int lineY = (int)m_pMessage -> getWidgetA() -> y() +
-		//	m_pView -> getLineLength() + m_pMessage -> getWidgetA() -> height() - height() - 5;
-		int maxHeight = m_pMessage -> getMaxHeight() - height() - 5;
-		newY = newY < maxHeight ? newY : maxHeight;
-		m_pMessage -> setX( newX - 5 );
+			int maxHeight = m_pMessage->getMaxHeight() - height() - 5;
+			newY = newY < maxHeight ? newY : maxHeight;
+			m_pMessage->setX( newX - 5 );
 
-		m_pMessage -> setY( newY + height() );
+			m_pMessage->setY( newY + height() );
+		}
+		m_nOldX = newX;
+		m_nOldY = newY;
+		setX( newX );
+		setY( newY );
+		if(m_pAssoc) {
+			m_pAssoc->calculateRoleTextSegment();
+		}
+		moveEvent(0);
 	}
-	m_nOldX = newX;
-	m_nOldY = newY;
-	setX( newX );
-	setY( newY );
-	if(m_pAssoc)
-		m_pAssoc->calculateRoleTextSegment();
-	moveEvent(0);
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 QString FloatingText::getText() {

Index: floatingtext.h
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/floatingtext.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- floatingtext.h	23 Jan 2003 22:21:13 -0000	1.1
+++ floatingtext.h	2 Feb 2003 00:47:42 -0000	1.2
@@ -252,9 +252,10 @@
 	void showOpDlg();
 
 	/**
-	 *   	Override default method
+	 *   	Override default method and keeps position in sync with
+	 *       a sequence diagram message if appropriate
 	 */
-	void mouseMoveEvent(QMouseEvent * me);
+	void mouseMoveEvent(QMouseEvent* me);
 
 public slots:
 	/**

Index: objectwidget.cpp
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/objectwidget.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- objectwidget.cpp	30 Jan 2003 23:16:39 -0000	1.4
+++ objectwidget.cpp	2 Feb 2003 00:47:42 -0000	1.5
@@ -249,72 +249,23 @@
 	p.drawText(offsetX + A_MARGIN, offsetY + textStartY, w - A_MARGIN * 2, fontHeight, AlignCenter, t);
 }
 
-void ObjectWidget::mouseMoveEvent(QMouseEvent *me) {
-	int newX = 0, newY = 0, count;
-	int moveX, moveY;
-	int maxX = m_pView->canvas()->width();
-	int maxY = m_pView->canvas()->height();
-
-	if( !m_bSelected ) {
-		m_pView->setSelected( this, me );
-	}
-	m_bSelected = true;
-	count = m_pView->getSelectCount();
-
-	if( !(m_bMouseDown || me->button() == LeftButton) ) {
-		return;
-	}
-	//If not m_bStartMove means moving as part of selection
-	//me->pos() will have the amount we need to move.
-	if(!m_bStartMove) {
-		moveX = (int)me -> x();
-		moveY = (int)me -> y();
-	} else {
-		//we started the move so..
-		//move any others we are selected
-		moveX = (int)me -> x() - m_nOldX - m_nPressOffsetX;
-		moveY = (int)me -> y() - m_nOldY - m_nPressOffsetY;
-
-		//if mouse moves off the edge of the canvas this moves the widget to 0 or canvasSize
-		if( ((int)x() + moveX) < 0 ) {
-			moveX = moveX - (int)x();
-		}
-		if( ((int)y() + moveY) < 0 ) {
-			moveY = moveY - (int)y();
-		}
-		if( ((int)x() + moveX) > (maxX - width()) ) {
-			moveX = maxX - (int)x() - width();
-		}
-		if( ((int)y() + moveY) > (maxY - height()) ) {
-			moveY = maxY - (int)y() - height();
-		}
+void ObjectWidget::mouseMoveEvent(QMouseEvent* me) {
+	if( m_bMouseDown ) {
+		QPoint newPosition = doMouseMove(me);
+		int newX = newPosition.x();
+		int newY = newPosition.y();
 
-		if( count > 1 ) {
-			if( m_pView -> getType() == dt_Sequence ) {
-				m_pView -> moveSelected( this, moveX, 0 );
-			} else {
-				m_pView -> moveSelected( this, moveX, moveY );
-			}
+		//implement rule for sequence diagram
+		if( m_pView -> getType() == dt_Sequence ) {
+			newY = (int)this -> y();
 		}
+		m_nOldX = newX;
+		m_nOldY = newY;
+		setX( newX );
+		setY( newY );
+		adjustAssocs(newX, newY);
+		moveEvent(0);
 	}
-	newX = (int)x() + moveX;
-	newY = (int)y() + moveY;
-
-	newX = newX<0 ? 0 : newX;
-	newY = newY<0 ? 0 : newY;
-	newX = newX>maxX ? maxX : newX;
-	newY = newY>maxY ? maxY : newY;
-
-	//implement rule for sequence diagram
-	if( m_pView -> getType() == dt_Sequence ) {
-		newY = (int)this -> y();
-	}
-	m_nOldX = newX;
-	m_nOldY = newY;
-	setX( newX );
-	setY( newY );
-	adjustAssocs(newX, newY);
-	moveEvent(0);
 }
 
 void ObjectWidget::tabUp() {

Index: objectwidget.h
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/objectwidget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- objectwidget.h	23 Jan 2003 22:21:13 -0000	1.1
+++ objectwidget.h	2 Feb 2003 00:47:42 -0000	1.2
@@ -188,9 +188,9 @@
 	}
 
 	/**
-	 *		Overrides the standard operation.
+	 *  Overrides the standard operation keeping it at the correct height
 	 */
-	virtual void mouseMoveEvent(QMouseEvent *me);
+	virtual void mouseMoveEvent(QMouseEvent* me);
 
 	/**
 	 *		Sets whether to show deconstruction on sequence line

Index: uml.cpp
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/uml.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- uml.cpp	1 Feb 2003 22:45:00 -0000	1.8
+++ uml.cpp	2 Feb 2003 00:47:42 -0000	1.9
@@ -254,7 +254,6 @@
 	zoomSelect->setItemChecked(zoom,true);
 }
 
-
 void UMLApp::zoomIn()
 {
 	doc->getCurrentView()->zoomIn();

Index: umlwidget.cpp
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/umlwidget.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- umlwidget.cpp	30 Jan 2003 23:16:39 -0000	1.3
+++ umlwidget.cpp	2 Feb 2003 00:47:42 -0000	1.4
@@ -56,9 +56,8 @@
 	//slotRemovePopupMenu();
 	cleanup();
 }
-
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-void UMLWidget::mouseMoveEvent(QMouseEvent *me) {
+QPoint UMLWidget::doMouseMove(QMouseEvent* me) {
 	int newX = 0, newY = 0, count;
 	int moveX, moveY;
 	int maxX = m_pView->canvas()->width();
@@ -70,9 +69,6 @@
 	m_bSelected = true;
 	count = m_pView->getSelectCount();
 
-	if( !(m_bMouseDown || me->button() == LeftButton) ) {
-		return;
-	}
 	//If not m_bStartMove means moving as part of selection
 	//me->pos() will have the amount we need to move.
 	if(!m_bStartMove) {
@@ -114,24 +110,24 @@
 	newX = newX>maxX ? maxX : newX;
 	newY = newY>maxY ? maxY : newY;
 
-	//implement rule for sequence diagram
-	if (m_pView->getType() == dt_Sequence) {
-		if (count > 1) {
-			newY = (int)this -> y();
-		}
-		//when a seq. diagram, you can't move an object down
-		//so fix vertial attribute
-		if (m_pData->m_Type == wt_Object) {
-			newY = 80 - height();
-		}
-	}//end if seq. diagram
-	if (m_nOldX != newX || m_nOldY != newY)
+	if (m_nOldX != newX || m_nOldY != newY) {
 		m_bMoved = true;
-	m_nOldX = newX;
-	m_nOldY = newY;
-	setX( newX );
-	setY( newY );
-	adjustAssocs(newX, newY);
+	}
+	return QPoint(newX, newY);
+}
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void UMLWidget::mouseMoveEvent(QMouseEvent* me) {
+	if( m_bMouseDown ) {
+		QPoint newPosition = doMouseMove(me);
+		int newX = newPosition.x();
+		int newY = newPosition.y();
+
+		m_nOldX = newX;
+		m_nOldY = newY;
+		setX( newX );
+		setY( newY );
+		adjustAssocs(newX, newY);
+	}
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 void UMLWidget::mousePressEvent(QMouseEvent *me) {

Index: umlwidget.h
===================================================================
RCS file: /home/kde/kdesdk/umbrello/umbrello/umlwidget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- umlwidget.h	23 Jan 2003 22:21:13 -0000	1.1
+++ umlwidget.h	2 Feb 2003 00:47:42 -0000	1.2
@@ -206,10 +206,19 @@
 
 	/**
 	 * Overrides the standard operation.
+	 * Any code specific to this type of widget is here after it
+	 * has called doMouseMove()
 	 *
 	 * @param me
 	 */
-	virtual void mouseMoveEvent(QMouseEvent *me);
+	virtual void mouseMoveEvent(QMouseEvent* me);
+
+	/**
+	 * Moves the item to it's new position (called from mouseMoveEvent)
+	 *
+	 * @param me
+	 */
+	QPoint doMouseMove(QMouseEvent* me);
 
 	/**
 	 * Returns wether this is a line of text.





More information about the umbrello-devel mailing list