X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpainter.cpp;h=df1d7d5d1c548a6cfe8014300485362d6f02bce8;hb=ccac11461956c9c0cc9756f8963436b5d88dfbb7;hp=08068119afde63c7ccd3b5b0eb263b3ab774663a;hpb=3f1e5ba1d42ab40edf75cf05df16b0e25d0821cb;p=architektonas diff --git a/src/painter.cpp b/src/painter.cpp index 0806811..df1d7d5 100644 --- a/src/painter.cpp +++ b/src/painter.cpp @@ -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));