diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bd9e6617827818fd043452c08c606f07b78014a0 (patch) | |
tree | 425bb4c3168f9c02f10150f235d2cb998dcc6108 /umbrello/umbrello/floatingtextwidgetcontroller.cpp | |
download | tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.tar.gz tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'umbrello/umbrello/floatingtextwidgetcontroller.cpp')
-rw-r--r-- | umbrello/umbrello/floatingtextwidgetcontroller.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/umbrello/umbrello/floatingtextwidgetcontroller.cpp b/umbrello/umbrello/floatingtextwidgetcontroller.cpp new file mode 100644 index 00000000..4c6a4aa8 --- /dev/null +++ b/umbrello/umbrello/floatingtextwidgetcontroller.cpp @@ -0,0 +1,119 @@ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * copyright (C) 2006 * + * Umbrello UML Modeller Authors <uml-devel@uml.sf.net> * + ***************************************************************************/ + +// own header +#include "floatingtextwidgetcontroller.h" +// qt/kde includes +#include <kdebug.h> +// app includes +#include "floatingtextwidget.h" +#include "messagewidget.h" +#include "objectwidget.h" + +FloatingTextWidgetController::FloatingTextWidgetController(FloatingTextWidget *floatingTextWidget): + UMLWidgetController(floatingTextWidget) { + m_floatingTextWidget = floatingTextWidget; + m_unconstrainedPositionX = 0; + m_unconstrainedPositionY = 0; + m_movementDirectionX = 0; + m_movementDirectionY = 0; +} + +FloatingTextWidgetController::~FloatingTextWidgetController() { +} + +void FloatingTextWidgetController::saveWidgetValues(QMouseEvent *me) { + UMLWidgetController::saveWidgetValues(me); + + m_unconstrainedPositionX = m_widget->getX(); + m_unconstrainedPositionY = m_widget->getY(); + m_movementDirectionX = 0; + m_movementDirectionY = 0; +} + +bool FloatingTextWidgetController::isInResizeArea(QMouseEvent* /*me*/) { + return false; +} + +void FloatingTextWidgetController::moveWidgetBy(int diffX, int diffY) { + if (m_floatingTextWidget->m_Role == Uml::tr_Seq_Message_Self) + return; + + if (m_floatingTextWidget->m_Role == Uml::tr_Seq_Message + && ((MessageWidget*)m_floatingTextWidget->m_pLink)->getSelected()) { + return; + } + + m_unconstrainedPositionX += diffX; + m_unconstrainedPositionY += diffY; + QPoint constrainedPosition = constrainPosition(diffX, diffY); + + int newX = constrainedPosition.x(); + int newY = constrainedPosition.y(); + + if (!m_movementDirectionX) { + if (m_unconstrainedPositionX != constrainedPosition.x()) { + m_movementDirectionX = (diffX > 0)? 1: -1; + } + } else if ((m_movementDirectionX < 0 && m_unconstrainedPositionX > m_floatingTextWidget->getX()) || + (m_movementDirectionX > 0 && m_unconstrainedPositionX < m_floatingTextWidget->getX()) ) { + newX = m_unconstrainedPositionX; + m_movementDirectionX = 0; + } + + if (!m_movementDirectionY) { + if (m_unconstrainedPositionY != constrainedPosition.y()) { + m_movementDirectionY = (diffY > 0)? 1: -1; + } + } else if ((m_movementDirectionY < 0 && m_unconstrainedPositionY > m_floatingTextWidget->getY()) || + (m_movementDirectionY > 0 && m_unconstrainedPositionY < m_floatingTextWidget->getY()) ) { + newY = m_unconstrainedPositionY; + m_movementDirectionY = 0; + } + + m_floatingTextWidget->setX(newX); + m_floatingTextWidget->setY(newY); + + if (m_floatingTextWidget->m_pLink) { + m_floatingTextWidget->m_pLink->calculateNameTextSegment(); + if (m_floatingTextWidget->m_Role == Uml::tr_Seq_Message) { + MessageWidget* messageWidget = (MessageWidget*)m_floatingTextWidget->m_pLink; + messageWidget->setY(newY + m_floatingTextWidget->getHeight()); + + //TODO This should be moved to somewhere in MessageWidget, refactor with messagewidgetcontroller.cpp:44 + if (messageWidget->getSequenceMessageType() == Uml::sequence_message_creation) { + const int objWidgetHalfHeight = messageWidget->getWidget(Uml::B)->getHeight() / 2; + messageWidget->getWidget(Uml::B)->UMLWidget::setY(messageWidget->getY() - objWidgetHalfHeight); + } + } + } +} + +void FloatingTextWidgetController::constrainMovementForAllWidgets(int &diffX, int &diffY) { + QPoint constrainedPosition = constrainPosition(diffX, diffY); + + diffX = constrainedPosition.x() - m_floatingTextWidget->getX(); + diffY = constrainedPosition.y() - m_floatingTextWidget->getY(); +} + +QPoint FloatingTextWidgetController::constrainPosition(int diffX, int diffY) { + int newX = m_floatingTextWidget->getX() + diffX; + int newY = m_floatingTextWidget->getY() + diffY; + + if (m_floatingTextWidget->m_pLink) { + m_floatingTextWidget->m_pLink->constrainTextPos(newX, newY, + m_floatingTextWidget->width(), m_floatingTextWidget->height(), + m_floatingTextWidget->m_Role); + } + + return QPoint(newX, newY); +} + |