umbrello API Documentation

seqlinewidget.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2002-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "seqlinewidget.h"
00014 
00015 //kde includes
00016 #include <kcursor.h>
00017 #include <kdebug.h>
00018 //app includes
00019 #include "umlview.h"
00020 #include "objectwidget.h"
00021 #include "messagewidget.h"
00022 
00023 // class members
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     //see if on widget ( for message creation )
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     // normally the managing Objectwidget is responsible for the call of this function
00115     // but to be sure - make a double check _against current position_
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 
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:08:00 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003