[Uml-devel] branches/work/soc-umbrello/umbrello

Gopala Krishna A krishna.ggk at gmail.com
Sat Jul 12 19:55:13 UTC 2008


SVN commit 831470 by gopala:

1) Fixed the math for drawing cross lines inside the ellipse of ActivityWidget in Final mode.
2) Also fixed some colour issues in the ActivityWidget.



 M  +21 -34    activitywidget.cpp  
 M  +42 -9     widget_utils.cpp  
 M  +7 -0      widget_utils.h  


--- branches/work/soc-umbrello/umbrello/activitywidget.cpp #831469:831470
@@ -30,6 +30,7 @@
 #include "umlscene.h"
 #include "textitemgroup.h"
 #include "textitem.h"
+#include "widget_utils.h"
 
 //Added by qt3to4:
 #include <QMouseEvent>
@@ -98,56 +99,42 @@
     qreal w = sz.width();
     qreal h = sz.height();
 
+    p->setPen(QPen(lineColor(), lineWidth()));
+    p->setBrush(brush());
+
     switch(m_activityType) {
     case Normal:
-        p->setPen(QPen(lineColor(), lineWidth()));
-        p->setBrush(brush());
-        p->drawRoundRect(r, (r.height() * 60) / r.width(), 60);
+        p->drawRoundRect(r, (h * 60) / w, 60);
         break;
 
     case Initial:
-        p->setPen(QPen(lineColor(), lineWidth()));
-        p->setBrush(QBrush(lineColor()));
         p->drawEllipse(r);
         break;
 
     case Final:
-        p->setPen(QPen(Qt::red, 2));
-        p->setBrush(Qt::white);
-        p->drawEllipse(rect());
-
-        {
-            qreal x = w / 2;
-            qreal y = h / 2;
-            qreal w2  = .7071 * w / 2.0;
-            p->drawLine((x - w2 + 1), (y - w2 + 1), (x + w2), (y + w2));
-            p->drawLine((x + w2 - 1), (y - w2 + 1), (x - w2), (y + w2));
-        }
+        p->setBrush(Qt::NoBrush);
+        p->drawEllipse(r);
+        Widget_Utils::drawCrossInEllipse(p, r);
         break;
 
     case End :
-        p->setPen( QPen(lineColor(), 1) );
-        p->setBrush(QBrush(lineColor()));
-        p->drawEllipse(rect());
-        p->setBrush(Qt::white);
-        p->drawEllipse(1, 1, w - 2, h - 2);
+        p->setBrush(Qt::NoBrush);
+        p->drawEllipse(r.adjusted(+1, +1, -1, -1));
+
         p->setBrush(lineColor());
-        p->drawEllipse(3, 3, w - 6, h - 6);
+        p->drawEllipse(r.adjusted(+3, +3, -3, -3));
         break;
 
     case Branch :
-        p->setPen(QPen(lineColor(), lineWidth()));
-        p->setBrush(brush());
-        {
-            QPolygon array( 4 );
-            array[ 0 ] = QPoint(w / 2, 0);
-            array[ 1 ] = QPoint(w, h / 2);
-            array[ 2 ] = QPoint(w / 2, h);
-            array[ 3 ] = QPoint(0, h / 2);
-            p->drawPolygon( array );
-            p->drawPolyline( array );
-        }
-        break;
+    {
+        QPolygon array( 4 );
+        array[0] = QPoint(w / 2, 0);
+        array[1] = QPoint(w, h / 2);
+        array[2] = QPoint(w / 2, h);
+        array[3] = QPoint(0, h / 2);
+        p->drawPolygon(array);
+    }
+    break;
 
     case Invok :
         p->setPen(QPen(lineColor(), lineWidth()));
--- branches/work/soc-umbrello/umbrello/widget_utils.cpp #831469:831470
@@ -12,25 +12,26 @@
 // own header
 #include "widget_utils.h"
 
-// qt/kde includes
-#include <q3canvas.h>
-#include <QtGui/QBrush>
-#include <QtGui/QPen>
-#include <kdebug.h>
 // app includes
+#include "objectwidget.h"
 #include "uml.h"
+#include "umlscene.h"
 #include "umlview.h"
 #include "umlwidget.h"
-#include "objectwidget.h"
-#include "umlscene.h"
 
+// qt/kde includes
+#include <QtGui/QBrush>
+#include <QtGui/QPen>
 
+// c++ include
+#include <cmath>
+
 namespace Widget_Utils
 {
 
     NewUMLRectWidget* findWidget(Uml::IDType id,
-                          const UMLWidgetList& widgets,
-                          const MessageWidgetList* pMessages /* = NULL */)
+                                 const UMLWidgetList& widgets,
+                                 const MessageWidgetList* pMessages /* = NULL */)
     {
         UMLWidgetListIt it( widgets );
         foreach ( NewUMLRectWidget* obj , widgets ) {
@@ -64,6 +65,38 @@
         return rect;
     }
 
+    void drawCrossInEllipse(QPainter *p, const QRectF& r)
+    {
+        QRectF ellipse = r;
+        ellipse.moveCenter(QPointF(0, 0));
+        qreal a = ellipse.width() * 0.5;
+        qreal b = ellipse.height() * .5;
+        qreal xc = ellipse.center().x();
+        qreal yc = ellipse.center().y();
+
+        // The first point's x value is chose to be center.x() + 70% of x radius.
+        qreal x1 = ellipse.center().x() + .7 * .5 * ellipse.width();
+        // Calculate y1 correspoding to x1 using formula.
+        qreal y1_sqr = b*b*(1 - (x1 * x1) / (a*a));
+        qreal y1 = std::sqrt(y1_sqr);
+
+        // Mirror x1, y1 along both the axes to get 4 points for the cross.
+        QPointF p1(xc + x1, yc + y1);
+        QPointF p2(xc - x1, yc + y1);
+        QPointF p3(xc + x1, yc - y1);
+        QPointF p4(xc - x1, yc - y1);
+
+        // Translate as we calculate for ellipse with (0, 0) as center.
+        p->translate(r.center().x(), r.center().y());
+
+        // Draw the cross now
+        p->drawLine(QLineF(p1, p4));
+        p->drawLine(QLineF(p2, p3));
+
+        // Restore the translate on painter.
+        p->translate(-r.center().x(), -r.center().y());
+    }
+
     QString pointToString(const QPointF& point)
     {
         return QString("%1,%2").arg(point.x()).arg(point.y());
--- branches/work/soc-umbrello/umbrello/widget_utils.h #831469:831470
@@ -53,6 +53,13 @@
     QGraphicsRectItem *decoratePoint(const QPointF& p);
 
     /**
+     * Calculates and draws a cross inside an ellipse
+     * @param p Pointer to a QPainter object.
+     * @param ellipse The rectangle describing the ellipse.
+     */
+    void drawCrossInEllipse(QPainter *p, const QRectF& ellipse);
+
+    /**
      * Converts a point to a comma separated string i.e "x,y"
      */
     QString pointToString(const QPointF& point);




More information about the umbrello-devel mailing list