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