]> Shamusworld >> Repos - architektonas/blob - src/forms/coordinatewidget.cpp
fd136569897d3b9704e7a5a2276fa1b52a906cf3
[architektonas] / src / forms / coordinatewidget.cpp
1 // coordinatewidget.cpp
2 //
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
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/10/2010  Created this file. :-)
13 //
14
15 #include "coordinatewidget.h"
16
17 #include "rs_graphic.h"
18 #include "settings.h"
19 #include "rs_units.h"
20
21 CoordinateWidget::CoordinateWidget(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
22         QWidget(parent, flags)//, actionHandler(NULL), cadToolBar(NULL)
23 {
24         ui.setupUi(this);
25
26         ui.lCoord1->setText("");
27         ui.lCoord2->setText("");
28         ui.lCoord1b->setText("");
29         ui.lCoord2b->setText("");
30
31         int fsize;
32 #ifdef __APPLE__
33         fsize = 9;
34 #else
35         fsize = 7;
36 #endif
37
38         settings.beginGroup("Appearance");
39         fsize = settings.value("StatusBarFontSize", fsize).toInt();
40         settings.endGroup();
41
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));
46
47         graphic = NULL;
48         prec = 4;
49         format = RS2::Decimal;
50         aprec = 2;
51         aformat = RS2::DegreesDecimal;
52 }
53
54 CoordinateWidget::~CoordinateWidget()
55 {
56 }
57
58 void CoordinateWidget::setGraphic(RS_Graphic * graphic)
59 {
60         this->graphic = graphic;
61         setCoordinates(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
62 }
63
64 /*void CoordinateWidget::setAbsCoordinates(double x, double y) {
65         setAbsCoordinates(Vector(x, y));
66 }
67
68 void CoordinateWidget::setAbsCoordinates(const Vector& v) {
69         QString str;
70
71         str.sprintf("%.4f / %.4f", v.x, v.y);
72         lCoord1->setText(str);
73
74         double ang = RS_Math::rad2deg(v.angle());
75         double rad = v.magnitude();
76         str.sprintf("%.4f < %.4f", rad, ang);
77         lCoord1b->setText(str);
78 }
79
80 void CoordinateWidget::setAbsCoordinates(const QString& x, const QString& y) {
81         lCoord1->setText(x);
82         lCoord1b->setText(y);
83 }
84
85 void CoordinateWidget::setRelCoordinates(double x, double y) {
86         setRelCoordinates(Vector(x, y));
87 }
88
89 void CoordinateWidget::setRelCoordinates(const Vector& v) {
90         QString str;
91         str.sprintf("@%.4f / %.4f", v.x, v.y);
92         lCoord2->setText(str);
93
94         double ang = RS_Math::rad2deg(v.angle());
95         double rad = v.magnitude();
96         str.sprintf("@%.4f < %.4f", rad, ang);
97         lCoord2b->setText(str);
98 }
99
100 void CoordinateWidget::setRelCoordinates(const QString& x, const QString& y) {
101         lCoord2->setText(x);
102         lCoord2b->setText(y);
103 }
104
105 void CoordinateWidget::setCoordinates(double x, double y,
106                 double rx, double ry) {
107         setAbsCoordinates(x, y);
108         setRelCoordinates(rx, ry);
109 }*/
110
111 /*void CoordinateWidget::setAbsCoordinates(const QString& x,
112                                                                                         const QString& y,
113                                                                                         const QString& rx,
114                                                                                         const QString& ry) {
115         lCoord1->setText(x);
116         lCoord1b->setText(y);
117         lCoord2->setText(rx);
118         lCoord2b->setText(ry);
119 }*/
120
121 void CoordinateWidget::setCoordinates(const Vector & abs, const Vector & rel, bool updateFormat)
122 {
123         setCoordinates(abs.x, abs.y, rel.x, rel.y, updateFormat);
124 }
125
126 void CoordinateWidget::setCoordinates(double x, double y, double rx, double ry, bool updateFormat)
127 {
128         if (graphic != NULL)
129         {
130                 if (updateFormat)
131                 {
132                         format = graphic->getLinearFormat();
133                         prec = graphic->getLinearPrecision();
134                         aformat = graphic->getAngleFormat();
135                         aprec = graphic->getAnglePrecision();
136                 }
137
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);
143
144                 ui.lCoord1->setText(absX + " , " + absY);
145                 ui.lCoord2->setText(relX + " , " + relY);
146
147                 // polar coordinates:
148                 Vector v;
149                 v = Vector(x, y);
150                 QString str;
151                 QString rStr = RS_Units::formatLinear(v.magnitude(), graphic->getUnit(), format, prec);
152                 QString aStr = RS_Units::formatAngle(v.angle(), aformat, aprec);
153
154                 str = rStr + " < " + aStr;
155                 ui.lCoord1b->setText(str);
156
157                 v = Vector(rx, ry);
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);
162         }
163 }