]> Shamusworld >> Repos - architektonas/blobdiff - src/painter.cpp
Added ability to manipulate Text objects.
[architektonas] / src / painter.cpp
index 08068119afde63c7ccd3b5b0eb263b3ab774663a..df1d7d5d1c548a6cfe8014300485362d6f02bce8 100644 (file)
@@ -183,6 +183,25 @@ void Painter::DrawTextObject(Point p, QString text, double size, double angle/*=
 }
 
 
+//
+// Return the non-rotated rectangle containing the extents of the text in
+// Cartesian coordiates (starting from <0, 0>, the lower left hand side)
+//
+Rect Painter::MeasureTextObject(QString text, double size)
+{
+       if (!painter)
+               return Rect();
+
+       painter->setFont(QFont("Arial", Global::zoom * size));
+       int textWidth = QFontMetrics(painter->font()).width(text);
+       int textHeight = QFontMetrics(painter->font()).height();
+       Point measured((double)textWidth / Global::zoom, (double)textHeight / Global::zoom);// = QtToCartesianCoords(Point(textWidth, textHeight));
+//printf("QFontMetrics w/h=%i/%i, measured=%lf/%lf\n", textWidth, textHeight, measured.x, measured.y);
+
+       return Rect(Point(0, 0), measured);
+}
+
+
 void Painter::DrawArc(Vector center, double radius, double startAngle, double span)
 {
        if (!painter)
@@ -245,13 +264,8 @@ void Painter::DrawRectCorners(Rect rect)
        if (!painter)
                return;
 
-//     QRectF screenRect(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
-       
        Vector v1 = CartesianToQtCoords(Vector(rect.l, rect.t));
        Vector v2 = CartesianToQtCoords(Vector(rect.r, rect.b));
-//     QRectF screenRect(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
-//     screenRect.adjust(-8, 8, 8, -8);        // Left/top, right/bottom
-//     painter->drawRect(screenRect);
        v1 += Vector(-8.0, -8.0);
        v2 += Vector(+8.0, +8.0);
        painter->setPen(QPen(Qt::red, 2.0, Qt::DashLine));