1 // coordinatewidget.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/10/2010 Created this file. :-)
15 #include "coordinatewidget.h"
17 #include "rs_graphic.h"
21 CoordinateWidget::CoordinateWidget(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
22 QWidget(parent, flags)//, actionHandler(NULL), cadToolBar(NULL)
26 ui.lCoord1->setText("");
27 ui.lCoord2->setText("");
28 ui.lCoord1b->setText("");
29 ui.lCoord2b->setText("");
38 settings.beginGroup("Appearance");
39 fsize = settings.value("StatusBarFontSize", fsize).toInt();
42 ui.lCoord1->setFont(QFont("Helvetica", fsize));
43 ui.lCoord1b->setFont(QFont("Helvetica", fsize));
44 ui.lCoord2->setFont(QFont("Helvetica", fsize));
45 ui.lCoord2b->setFont(QFont("Helvetica", fsize));
49 format = RS2::Decimal;
51 aformat = RS2::DegreesDecimal;
54 CoordinateWidget::~CoordinateWidget()
58 void CoordinateWidget::setGraphic(RS_Graphic * graphic)
60 this->graphic = graphic;
61 setCoordinates(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
64 /*void CoordinateWidget::setAbsCoordinates(double x, double y) {
65 setAbsCoordinates(Vector(x, y));
68 void CoordinateWidget::setAbsCoordinates(const Vector& v) {
71 str.sprintf("%.4f / %.4f", v.x, v.y);
72 lCoord1->setText(str);
74 double ang = RS_Math::rad2deg(v.angle());
75 double rad = v.magnitude();
76 str.sprintf("%.4f < %.4f", rad, ang);
77 lCoord1b->setText(str);
80 void CoordinateWidget::setAbsCoordinates(const QString& x, const QString& y) {
85 void CoordinateWidget::setRelCoordinates(double x, double y) {
86 setRelCoordinates(Vector(x, y));
89 void CoordinateWidget::setRelCoordinates(const Vector& v) {
91 str.sprintf("@%.4f / %.4f", v.x, v.y);
92 lCoord2->setText(str);
94 double ang = RS_Math::rad2deg(v.angle());
95 double rad = v.magnitude();
96 str.sprintf("@%.4f < %.4f", rad, ang);
97 lCoord2b->setText(str);
100 void CoordinateWidget::setRelCoordinates(const QString& x, const QString& y) {
102 lCoord2b->setText(y);
105 void CoordinateWidget::setCoordinates(double x, double y,
106 double rx, double ry) {
107 setAbsCoordinates(x, y);
108 setRelCoordinates(rx, ry);
111 /*void CoordinateWidget::setAbsCoordinates(const QString& x,
116 lCoord1b->setText(y);
117 lCoord2->setText(rx);
118 lCoord2b->setText(ry);
121 void CoordinateWidget::setCoordinates(const Vector & abs, const Vector & rel, bool updateFormat)
123 setCoordinates(abs.x, abs.y, rel.x, rel.y, updateFormat);
126 void CoordinateWidget::setCoordinates(double x, double y, double rx, double ry, bool updateFormat)
132 format = graphic->getLinearFormat();
133 prec = graphic->getLinearPrecision();
134 aformat = graphic->getAngleFormat();
135 aprec = graphic->getAnglePrecision();
138 // abs / rel coordinates:
139 QString absX = RS_Units::formatLinear(x, graphic->getUnit(), format, prec);
140 QString absY = RS_Units::formatLinear(y, graphic->getUnit(), format, prec);
141 QString relX = RS_Units::formatLinear(rx, graphic->getUnit(), format, prec);
142 QString relY = RS_Units::formatLinear(ry, graphic->getUnit(), format, prec);
144 ui.lCoord1->setText(absX + " , " + absY);
145 ui.lCoord2->setText(relX + " , " + relY);
147 // polar coordinates:
151 QString rStr = RS_Units::formatLinear(v.magnitude(), graphic->getUnit(), format, prec);
152 QString aStr = RS_Units::formatAngle(v.angle(), aformat, aprec);
154 str = rStr + " < " + aStr;
155 ui.lCoord1b->setText(str);
158 rStr = RS_Units::formatLinear(v.magnitude(), graphic->getUnit(), format, prec);
159 aStr = RS_Units::formatAngle(v.angle(), aformat, aprec);
160 str = rStr + " < " + aStr;
161 ui.lCoord2b->setText(str);