seqlinewidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "seqlinewidget.h"
00014
00015
00016 #include <kcursor.h>
00017 #include <kdebug.h>
00018
00019 #include "umlview.h"
00020 #include "objectwidget.h"
00021 #include "messagewidget.h"
00022
00023
00024 int const SeqLineWidget::m_nMouseDownEpsilonX = 20;
00025
00026 SeqLineWidget::SeqLineWidget( UMLView * pView, ObjectWidget * pObject ) : QCanvasLine( pView -> canvas() ) {
00027 m_pView = pView;
00028 m_pObject = pObject;
00029 setPen( QPen( m_pObject->getLineColor(), 0, Qt::DashLine ) );
00030 setZ( 0 );
00031 setVisible( true );
00032 m_DestructionBox.line1 = 0;
00033 m_nLengthY = 250;
00034 setupDestructionBox();
00035 }
00036
00037 SeqLineWidget::~SeqLineWidget() {}
00038
00039 int SeqLineWidget::onWidget( const QPoint & p ) {
00040 int nOnWidget = 0;
00041 QPoint sp = startPoint();
00042 QPoint ep = endPoint();
00043
00044 if( sp.x() - m_nMouseDownEpsilonX < p.x()
00045 && ep.x() + m_nMouseDownEpsilonX > p.x()
00046 && sp.y() < p.y() && ep.y() + 3 > p.y() )
00047 {
00048 nOnWidget = 1;
00049 }
00050 return nOnWidget;
00051 }
00052
00053 void SeqLineWidget::cleanup() {
00054 cleanupDestructionBox();
00055 }
00056
00057 void SeqLineWidget::setStartPoint( int startX, int startY ) {
00058 int endX = startX;
00059 int endY = startY + m_nLengthY;
00060 QCanvasLine::setPoints( startX, startY, endX, endY );
00061 moveDestructionBox();
00062 }
00063
00064 void SeqLineWidget::cleanupDestructionBox() {
00065 if ( m_DestructionBox.line1 ) {
00066 delete m_DestructionBox.line1;
00067 m_DestructionBox.line1 = 0;
00068 delete m_DestructionBox.line2;
00069 m_DestructionBox.line2 = 0;
00070 }
00071 }
00072
00073 void SeqLineWidget::setupDestructionBox() {
00074 cleanupDestructionBox();
00075 if( !m_pObject->getShowDestruction() ) {
00076 return;
00077 }
00078 QRect rect;
00079 rect.setX( m_pObject->getX() + m_pObject->getWidth() / 2 - 10 );
00080 rect.setY( m_pObject->getY() + m_pObject->getHeight() + m_nLengthY );
00081 rect.setWidth( 14 );
00082 rect.setHeight( 14 );
00083
00084 m_DestructionBox.line1 = new QCanvasLine( m_pView->canvas() );
00085 m_DestructionBox.setLine1Points(rect);
00086 m_DestructionBox.line1->setVisible( true );
00087 m_DestructionBox.line1->setPen( QPen(m_pObject->getLineColor(), 2) );
00088 m_DestructionBox.line1->setZ( 3 );
00089
00090 m_DestructionBox.line2 = new QCanvasLine( m_pView -> canvas() );
00091 m_DestructionBox.setLine2Points(rect);
00092 m_DestructionBox.line2->setVisible( true );
00093 m_DestructionBox.line2->setPen( QPen(m_pObject->getLineColor(), 2) );
00094 m_DestructionBox.line2->setZ( 3 );
00095 }
00096
00097 void SeqLineWidget::moveDestructionBox() {
00098 if( !m_DestructionBox.line1 ) {
00099 return;
00100 }
00101 QRect rect;
00102 rect.setX( m_pObject->getX() + m_pObject->getWidth() / 2 - 7 );
00103 rect.setY( m_pObject->getY() + m_pObject->getHeight() + m_nLengthY - 7 );
00104 rect.setWidth( 14 );
00105 rect.setHeight( 14 );
00106 m_DestructionBox.setLine1Points(rect);
00107 m_DestructionBox.setLine2Points(rect);
00108 }
00109
00110 void SeqLineWidget::setEndOfLine(int yPosition) {
00111 QPoint sp = startPoint();
00112 int newY = yPosition;
00113 m_nLengthY = yPosition - m_pObject->getY() - m_pObject->getHeight();
00114
00115
00116 if ( m_nLengthY < 0 ) {
00117 m_nLengthY = 0;
00118 newY = m_pObject->getY() + m_pObject->getHeight();
00119 }
00120 setPoints( sp.x(), sp.y(), sp.x(), newY );
00121 moveDestructionBox();
00122 m_pView->resizeCanvasToItems();
00123 }
00124
This file is part of the documentation for umbrello Version 3.1.0.