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

Gopala Krishna A krishna.ggk at gmail.com
Thu Aug 21 16:51:46 UTC 2008


SVN commit 850493 by gopala:

Implemented a utility method to draw an Arrow head.
OT: Yay! First commit from my laptop :)



 M  +25 -1     widget_utils.cpp  
 M  +13 -0     widget_utils.h  


--- branches/work/soc-umbrello/umbrello/widget_utils.cpp #850492:850493
@@ -99,7 +99,7 @@
     }
 
 	void drawTriangledRect(QPainter *painter,
-										 const QRectF& rect, const QSizeF& triSize)
+                           const QRectF& rect, const QSizeF& triSize)
 	{
 		// Draw outer boundary defined by polygon "poly".
 		QPolygonF poly(5);
@@ -117,6 +117,30 @@
 		painter->drawLine(baseEdge);
 	}
 
+    void drawArrowHead(QPainter *painter, const QPointF &arrowPos,
+                       const QSizeF& arrowSize, Qt::ArrowType arrowType,
+                       bool  solid)
+    {
+        QPolygonF poly;
+        if (arrowType == Qt::LeftArrow) {
+            poly << QPointF(arrowPos.x() + arrowSize.width(), arrowPos.y() - .5 * arrowSize.height())
+                 << arrowPos
+                 << QPointF(arrowPos.x() + arrowSize.width(), arrowPos.y() + .5 * arrowSize.height());
+        }
+        else if (arrowType == Qt::RightArrow) {
+            poly << QPointF(arrowPos.x() - arrowSize.width(), arrowPos.y() - .5 * arrowSize.height())
+                 << arrowPos
+                 << QPointF(arrowPos.x() - arrowSize.width(), arrowPos.y() + .5 * arrowSize.height());
+        }
+
+        if (solid) {
+            painter->drawPolygon(poly);
+        }
+        else {
+            painter->drawPolyline(poly);
+        }
+    }
+
     QString pointToString(const QPointF& point)
     {
         return QString("%1,%2").arg(point.x()).arg(point.y());
--- branches/work/soc-umbrello/umbrello/widget_utils.h #850492:850493
@@ -71,6 +71,19 @@
 	void drawTriangledRect(QPainter *painter, const QRectF& rect, const QSizeF& triSize);
 
     /**
+     * Draws an arrow head with the given painter, with the arrow
+     * sharp point at \a headPos.
+     *
+     * @param painter    The painter with which this arrow should be drawn.
+     * @param headPos    The position where the head of the arrow should lie.
+     * @param arrowSize  This indicates the size of the arrow head.
+     * @param arrowType  This indicates direction of arrow as in LeftArrow, RightArrow..
+     * @param solid      If true, a solid head is drawn. Otherwise 2 lines are drawn.
+     */
+    void drawArrowHead(QPainter *painter, const QPointF& arrowPos,
+                       const QSizeF& arrowSize, Qt::ArrowType arrowType,
+                       bool solid = false);
+    /**
      * 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