[Uml-devel] branches/work/soc-umbrello/umbrello
Gopala Krishna A
krishna.ggk at gmail.com
Fri Aug 1 15:38:30 UTC 2008
SVN commit 840704 by gopala:
Ported SeqLineWidget.
M +12 -11 objectwidget.cpp
M +1 -1 objectwidgetcontroller.cpp
M +75 -111 seqlinewidget.cpp
M +48 -97 seqlinewidget.h
M +1 -1 umlscene.cpp
--- branches/work/soc-umbrello/umbrello/objectwidget.cpp #840703:840704
@@ -43,6 +43,7 @@
init();
if( lid != Uml::id_None )
m_nLocalID = lid;
+ setShowDestruction(true);
//updateComponentSize();
// Doing this during loadFromXMI() gives futile updates.
// Instead, it is done afterwards by NewUMLRectWidget::activate()
@@ -56,7 +57,7 @@
m_bDrawAsActor = false;
m_bShowDestruction = false;
if( umlScene() != NULL && umlScene()->getType() == Uml::dt_Sequence ) {
- m_pLine = new SeqLineWidget( umlScene(), this );
+ m_pLine = new SeqLineWidget( this );
//Sets specific widget controller for sequence diagrams
// delete m_widgetController;
@@ -169,7 +170,7 @@
if (! NewUMLRectWidget::activate(ChangeLog))
return false;
if (m_bShowDestruction && m_pLine)
- m_pLine->setupDestructionBox();
+ m_pLine->updateDestructionBoxVisibility();
moveEvent(0);
return true;
}
@@ -192,7 +193,7 @@
const qreal w = getWidth();
const qreal y = getY();
const qreal h = getHeight();
- m_pLine->setStartPoint(x + w / 2, y + h);
+ m_pLine->setPos(x + w / 2, y + h);
}
}
@@ -200,17 +201,17 @@
NewUMLRectWidget::setFillColour( umlScene()->getFillColor() );
NewUMLRectWidget::setLineColor( umlScene()->getLineColor() );
- if( m_pLine)
- m_pLine->setPen( QPen( NewUMLRectWidget::getLineColor(), NewUMLRectWidget::getLineWidth(), Qt::DashLine ) );
+ if( m_pLine) {
+ m_pLine->setLineColor(lineColor());
+ m_pLine->setLineWidth(lineWidth());
+ }
}
void ObjectWidget::cleanup() {
NewUMLRectWidget::cleanup();
- if( m_pLine ) {
- m_pLine->cleanup();
- delete m_pLine;
- }
+ delete m_pLine;
+ m_pLine = 0;
}
void ObjectWidget::showProperties() {
@@ -314,7 +315,7 @@
void ObjectWidget::setShowDestruction( bool bShow ) {
m_bShowDestruction = bShow;
if( m_pLine )
- m_pLine->setupDestructionBox();
+ m_pLine->updateDestructionBoxVisibility();
}
void ObjectWidget::setEndLine(int yPosition) {
@@ -324,7 +325,7 @@
int ObjectWidget::getEndLineY() {
int y = this->getY() + getHeight();
if( m_pLine)
- y += m_pLine->getLineLength();
+ y += m_pLine->length();
if ( m_bShowDestruction )
y += 10;
return y;
--- branches/work/soc-umbrello/umbrello/objectwidgetcontroller.cpp #840703:840704
@@ -52,7 +52,7 @@
isOnDestructionBox = false;
SeqLineWidget * pLine = dynamic_cast<ObjectWidget*>(m_widget)->getSeqLine();
- if (pLine->onDestructionBox(me->pos())) {
+ if (pLine->onDestructionBox(pLine->mapFromScene(me->scenePos()))) {
isOnDestructionBox = true;
m_oldX = dynamic_cast<ObjectWidget*>(m_widget)->getX() + dynamic_cast<ObjectWidget*>(m_widget)->getWidth() / 2;
m_oldY = dynamic_cast<ObjectWidget*>(m_widget)->getEndLineY() - 10;
--- branches/work/soc-umbrello/umbrello/seqlinewidget.cpp #840703:840704
@@ -12,144 +12,108 @@
// own header
#include "seqlinewidget.h"
-//kde includes
-#include <kcursor.h>
-#include <kdebug.h>
-
-//qt includes
-#include <QPainter>
-#include <QGraphicsLineItem>
//app includes
-#include "umlview.h"
#include "objectwidget.h"
-#include "messagewidget.h"
-#include "umlscene.h"
-// class members
-qreal const SeqLineWidget::m_nMouseDownEpsilonX = 20;
+const qreal SeqLineWidget::DestructionBoxSize = 14;
-SeqLineWidget::SeqLineWidget( UMLScene * pScene, ObjectWidget * pObject ) :
- QGraphicsLineItem()
+static void addLineToPath(const QLineF& line, QPainterPath &path)
{
- m_pUMLScene = pScene;
- m_pUMLScene->addItem(this);
- m_pUMLObject = pObject;
- setPen( QPen( m_pUMLObject->getLineColor(), 0, Qt::DashLine ) );
- setZValue( 0 );
- setVisible( true );
- m_DestructionBox.line1 = 0;
- m_nLengthY = 250;
- setupDestructionBox();
+ if (!line.isNull()) {
+ path.moveTo(line.p1());
+ path.lineTo(line.p2());
+ }
}
-SeqLineWidget::~SeqLineWidget() {}
-
-qreal SeqLineWidget::onWidget( const QPointF & p )
+SeqLineWidget::SeqLineWidget( ObjectWidget * pObject ) :
+ QGraphicsItem(pObject),
+ m_objectWidget(pObject),
+ m_length(250),
+ m_lineColor(pObject->lineColor()),
+ m_lineWidth(pObject->lineWidth())
{
- qreal nOnWidget = 0;
- QPointF sp = QGraphicsLineItem::line().p1();
- QPointF ep = QGraphicsLineItem::line().p2();
- //see if on widget ( for message creation )
- if( sp.x() - m_nMouseDownEpsilonX < p.x()
- && ep.x() + m_nMouseDownEpsilonX > p.x()
- && sp.y() < p.y() && ep.y() + 3 > p.y() )
- {
- nOnWidget = 1;
- }
- return nOnWidget;
+ updateDestructionBoxVisibility();
}
-qreal SeqLineWidget::onDestructionBox ( const QPointF & p ) {
- qreal nOnDestructionBox = 0;
- qreal x = m_pUMLObject->getX() + m_pUMLObject->getWidth() / 2;
- qreal y = m_pUMLObject->getY() + m_pUMLObject->getHeight() + m_nLengthY;
-
- //see if on destruction box
- if( !m_pUMLObject->getShowDestruction() ) {
- return 0;
- }
- if( x - 10 < p.x() && x + 10 > p.x()
- && y - 10 < p.y() && y + 10 > p.y() )
- {
- nOnDestructionBox = 1;
- }
- return nOnDestructionBox;
+SeqLineWidget::~SeqLineWidget()
+{
}
-
-void SeqLineWidget::cleanup() {
- cleanupDestructionBox();
+void SeqLineWidget::setLineColor(const QColor& col)
+{
+ m_lineColor = col;
+ update();
}
-void SeqLineWidget::setStartPoint( qreal startX, qreal startY ) {
- qreal endX = startX;
- qreal endY = startY + m_nLengthY;
- QGraphicsLineItem::setLine( startX, startY, endX, endY );
- moveDestructionBox();
+void SeqLineWidget::setLineWidth(qreal w)
+{
+ m_lineWidth = w;
+ updateGeometry();
}
-void SeqLineWidget::cleanupDestructionBox()
+void SeqLineWidget::updateDestructionBoxVisibility()
{
- if ( m_DestructionBox.line1 ) {
- delete m_DestructionBox.line1;
- m_DestructionBox.line1 = 0;
- delete m_DestructionBox.line2;
- m_DestructionBox.line2 = 0;
+ m_destructionBoxLines[0] = m_destructionBoxLines[1] = QLineF();
+
+ if( m_objectWidget->getShowDestruction() ) {
+ QRectF rect(0, 0,
+ SeqLineWidget::DestructionBoxSize, SeqLineWidget::DestructionBoxSize);
+ rect.moveCenter(QPointF(pos().x(), pos().y() + m_length));
+
+ m_destructionBoxLines[0].setPoints(rect.topLeft(), rect.bottomRight());
+ m_destructionBoxLines[1].setPoints(rect.bottomLeft(), rect.topRight());
}
+
+ updateGeometry();
}
-void SeqLineWidget::setupDestructionBox()
+bool SeqLineWidget::onDestructionBox(const QPointF& localPos)
{
- cleanupDestructionBox();
- if( !m_pUMLObject->getShowDestruction() ) {
- return;
- }
- QRectF rect;
- rect.setX( m_pUMLObject->getX() + m_pUMLObject->getWidth() / 2 - 10 );
- rect.setY( m_pUMLObject->getY() + m_pUMLObject->getHeight() + m_nLengthY );
- rect.setWidth( 14 );
- rect.setHeight( 14 );
+ QRectF rect(0, 0,
+ SeqLineWidget::DestructionBoxSize, SeqLineWidget::DestructionBoxSize);
+ rect.moveCenter(QPointF(pos().x(), pos().y() + m_length));
- m_DestructionBox.line1 = new QGraphicsLineItem();
- m_pUMLScene->addItem(m_DestructionBox.line1);
- m_DestructionBox.setLine1Points(rect);
- m_DestructionBox.line1->setVisible( true );
- m_DestructionBox.line1->setPen( QPen(m_pUMLObject->getLineColor(), 2) );
- m_DestructionBox.line1->setZValue( 3 );
+ return m_objectWidget->getShowDestruction() && rect.contains(localPos);
+}
- m_DestructionBox.line2 = new QGraphicsLineItem();
- m_pUMLScene->addItem(m_DestructionBox.line2);
- m_DestructionBox.setLine2Points(rect);
- m_DestructionBox.line2->setVisible( true );
- m_DestructionBox.line2->setPen( QPen(m_pUMLObject->getLineColor(), 2) );
- m_DestructionBox.line2->setZValue( 3 );
+void SeqLineWidget::setLength(qreal len)
+{
+ m_length = len;
+ const QPointF p = pos();
+ m_sequentialLine.setP1(p);
+ m_sequentialLine.setP2(QPointF(p.x(), p.y() + m_length));
+
+ updateDestructionBoxVisibility();
}
-void SeqLineWidget::moveDestructionBox()
+void SeqLineWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
{
- if( !m_DestructionBox.line1 ) {
- return;
+ QPen pen(m_lineColor, m_lineWidth, Qt::DashLine);
+ painter->setPen(pen);
+
+ painter->drawLine(m_sequentialLine);
+
+ if (!m_destructionBoxLines[0].isNull() && !m_destructionBoxLines[1].isNull()) {
+ pen.setStyle(Qt::SolidLine);
+ pen.setWidth(m_lineWidth + 2);
+ painter->setPen(pen);
+
+ painter->drawLines(m_destructionBoxLines, 2);
}
- QRectF rect;
- rect.setX( m_pUMLObject->getX() + m_pUMLObject->getWidth() / 2 - 7 );
- rect.setY( m_pUMLObject->getY() + m_pUMLObject->getHeight() + m_nLengthY - 7 );
- rect.setWidth( 14 );
- rect.setHeight( 14 );
- m_DestructionBox.setLine1Points(rect);
- m_DestructionBox.setLine2Points(rect);
}
-void SeqLineWidget::setEndOfLine(qreal yPosition) {
- QPointF sp = QGraphicsLineItem::line().p1();
- qreal newY = yPosition;
- m_nLengthY = yPosition - m_pUMLObject->getY() - m_pUMLObject->getHeight();
- // normally the managing Objectwidget is responsible for the call of this function
- // but to be sure - make a double check _against current position_
- if ( m_nLengthY < 0 ) {
- m_nLengthY = 0;
- newY = m_pUMLObject->getY() + m_pUMLObject->getHeight();
- }
- setLine( sp.x(), sp.y(), sp.x(), newY );
- moveDestructionBox();
- m_pUMLScene->resizeCanvasToItems();
+void SeqLineWidget::updateGeometry()
+{
+ QPainterPath linePath;
+ addLineToPath(m_sequentialLine, linePath);
+ addLineToPath(m_destructionBoxLines[0], linePath);
+ addLineToPath(m_destructionBoxLines[1], linePath);
+
+ QPainterPathStroker stroker;
+ stroker.setWidth(m_lineWidth + 5);
+ m_shape = stroker.createStroke(linePath);
+
+ prepareGeometryChange();
+ m_boundingRect = m_shape.boundingRect();
}
+
--- branches/work/soc-umbrello/umbrello/seqlinewidget.h #840703:840704
@@ -12,135 +12,86 @@
#ifndef SEQLINEWIDGET_H
#define SEQLINEWIDGET_H
-#include <QGraphicsScene>
-#include <QGraphicsLineItem>
+#include <QtGui/QGraphicsItem>
-class UMLScene;
class ObjectWidget;
/**
* @short Widget class for graphical representation of sequence lines
+ *
* @author Paul Hensgen
+ * @author Gopala Krishna
+ *
* Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
+ *
+ * @todo Should rename to SeqLineItem to differentiate between actual
+ * uml widgets and other items.
*/
-class SeqLineWidget : public QGraphicsLineItem
+class SeqLineWidget : public QGraphicsItem
{
public:
- /**
- * Constructor.
- */
- SeqLineWidget( UMLScene * scene, ObjectWidget * pObject );
+ SeqLineWidget( ObjectWidget * pObject );
+ virtual ~SeqLineWidget();
- /**
- * Destructor.
- */
- ~SeqLineWidget();
+ QColor lineColor() const {
+ return m_lineColor;
+ }
+ void setLineColor(const QColor & col);
- /**
- * Return whether on seq. line.
- * Takes into account destruction box if shown.
- *
- * @param p The point to investigate.
- * @return Non-zero if point is on this sequence line.
- */
- qreal onWidget(const QPointF & p);
+ qreal lineWidth() const {
+ return m_lineWidth;
+ }
+ void setLineWidth(qreal w);
- /**
- * Return whether on the destruction box.
- *
- * @param p The point to investigate.
- * @return Non-zero if point is on the destruction box of this sequence line.
- */
- qreal onDestructionBox ( const QPointF & p );
+ void updateDestructionBoxVisibility();
+ bool onDestructionBox(const QPointF& localPos);
+ qreal length() const {
+ return m_length;
+ }
+ void setLength(qreal length);
/**
- * Clean up anything before deletion.
- */
- void cleanup();
-
- /**
- * Set up destruction box.
- */
- void setupDestructionBox();
-
- /**
- * Set the start point of the line.
+ * Sets the y position of the bottom of the vertical line.
*
- * @param startX X coordinate of the start point.
- * @param startY Y coordinate of the start point.
+ * @param yPosition The y coordinate for the bottom of the line.
*/
- void setStartPoint( qreal startX, qreal startY );
-
- /**
- * Gets the length of the line.
- *
- * @return Length of the line.
- */
- qreal getLineLength() {
- return m_nLengthY;
+ void setEndOfLine(qreal yPosition) {
+ setLength(yPosition - pos().y());
}
/**
- * Returns the @ref ObjectWidget associated with this sequence line.
- *
* @return Pointer to the associated ObjectWidget.
*/
- ObjectWidget * getObjectWidget() {
- return m_pUMLObject;
+ ObjectWidget * objectWidget() const{
+ return m_objectWidget;
}
- /**
- * Sets the y position of the bottom of the vertical line.
- *
- * @param yPosition The y coordinate for the bottom of the line.
- */
- void setEndOfLine(qreal yPosition);
+ virtual QRectF boundingRect() const {
+ return m_boundingRect;
+ }
+ virtual QPainterPath shape() const {
+ return m_shape;
+ }
-protected:
- /**
- * Clean up destruction box.
- */
- void cleanupDestructionBox();
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*);
- /**
- * Move destruction box.
- */
- void moveDestructionBox();
+private:
+ static const qreal DestructionBoxSize;
- /**
- * ObjectWidget associated with this sequence line.
- */
- ObjectWidget * m_pUMLObject;
+ void updateGeometry();
- /**
- * View displayed on.
- */
- UMLScene * m_pUMLScene;
+ ObjectWidget * m_objectWidget;
+ qreal m_length;
- /// The destruction box.
- struct DestructionBox {
- QGraphicsLineItem * line1;
- QGraphicsLineItem * line2;
- void setLine1Points(QRectF rect) {
- line1->setLine( rect.x(), rect.y(),
- rect.x() + rect.width(), rect.y() + rect.height() );
- }
- void setLine2Points(QRectF rect) {
- line2->setLine( rect.x(), rect.y() + rect.height(),
- rect.x() + rect.width(), rect.y() );
- }
- } m_DestructionBox;
+ QColor m_lineColor;
+ int m_lineWidth;
- /**
- * The length of the line.
- */
- qreal m_nLengthY;
+ QLineF m_sequentialLine;
+ QLineF m_destructionBoxLines[2];
- /**
- * Margin used for mouse clicks.
- */
- static qreal const m_nMouseDownEpsilonX;
+ QRectF m_boundingRect;
+ QPainterPath m_shape;
};
#endif
--- branches/work/soc-umbrello/umbrello/umlscene.cpp #840703:840704
@@ -641,7 +641,7 @@
<< " (id=" << ID2STR(ow->getLocalID()) << ") is NULL" << endl;
continue;
}
- if (pLine->onWidget(point))
+ if (pLine->contains(pLine->mapFromScene(point)))
return ow;
}
return 0;
More information about the umbrello-devel
mailing list