]> Shamusworld >> Repos - architektonas/blob - src/forms/coordinatewidget.cpp
Fixed problem with MDI activation.
[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 "units.h"
22
23 CoordinateWidget::CoordinateWidget(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
24         QWidget(parent, flags)
25 {
26         ui.setupUi(this);
27
28         ui.lCoord1->setText("");
29         ui.lCoord2->setText("");
30         ui.lCoord1b->setText("");
31         ui.lCoord2b->setText("");
32
33 #ifdef __APPLE__
34         int fsize = 9;
35 #else
36         int fsize = 7;
37 #endif
38
39         settings.beginGroup("Appearance");
40         fsize = settings.value("StatusBarFontSize", fsize).toInt();
41         settings.endGroup();
42
43 //      ui.lCoord1->setFont(QFont("Helvetica", fsize));
44 //      ui.lCoord1b->setFont(QFont("Helvetica", fsize));
45 //      ui.lCoord2->setFont(QFont("Helvetica", fsize));
46 //      ui.lCoord2b->setFont(QFont("Helvetica", fsize));
47         ui.lCoord1->setFont(QFont("Verdana", fsize));
48         ui.lCoord1b->setFont(QFont("Verdana", fsize));
49         ui.lCoord2->setFont(QFont("Verdana", fsize));
50         ui.lCoord2b->setFont(QFont("Verdana", fsize));
51
52         graphic = NULL;
53         prec = 4;
54         format = RS2::Decimal;
55         aprec = 2;
56         aformat = RS2::DegreesDecimal;
57 }
58
59 CoordinateWidget::~CoordinateWidget()
60 {
61 }
62
63 void CoordinateWidget::setGraphic(Drawing * graphic)
64 {
65         this->graphic = graphic;
66         setCoordinates(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
67 }
68
69 /*void CoordinateWidget::setAbsCoordinates(double x, double y) {
70         setAbsCoordinates(Vector(x, y));
71 }
72
73 void CoordinateWidget::setAbsCoordinates(const Vector& v) {
74         QString str;
75
76         str.sprintf("%.4f / %.4f", v.x, v.y);
77         lCoord1->setText(str);
78
79         double ang = Math::rad2deg(v.angle());
80         double rad = v.magnitude();
81         str.sprintf("%.4f < %.4f", rad, ang);
82         lCoord1b->setText(str);
83 }
84
85 void CoordinateWidget::setAbsCoordinates(const QString& x, const QString& y) {
86         lCoord1->setText(x);
87         lCoord1b->setText(y);
88 }
89
90 void CoordinateWidget::setRelCoordinates(double x, double y) {
91         setRelCoordinates(Vector(x, y));
92 }
93
94 void CoordinateWidget::setRelCoordinates(const Vector& v) {
95         QString str;
96         str.sprintf("@%.4f / %.4f", v.x, v.y);
97         lCoord2->setText(str);
98
99         double ang = Math::rad2deg(v.angle());
100         double rad = v.magnitude();
101         str.sprintf("@%.4f < %.4f", rad, ang);
102         lCoord2b->setText(str);
103 }
104
105 void CoordinateWidget::setRelCoordinates(const QString& x, const QString& y) {
106         lCoord2->setText(x);
107         lCoord2b->setText(y);
108 }
109
110 void CoordinateWidget::setCoordinates(double x, double y,
111                 double rx, double ry) {
112         setAbsCoordinates(x, y);
113         setRelCoordinates(rx, ry);
114 }*/
115
116 /*void CoordinateWidget::setAbsCoordinates(const QString& x,
117                                                                                         const QString& y,
118                                                                                         const QString& rx,
119                                                                                         const QString& ry) {
120         lCoord1->setText(x);
121         lCoord1b->setText(y);
122         lCoord2->setText(rx);
123         lCoord2b->setText(ry);
124 }*/
125
126 void CoordinateWidget::setCoordinates(const Vector & abs, const Vector & rel, bool updateFormat)
127 {
128         setCoordinates(abs.x, abs.y, rel.x, rel.y, updateFormat);
129 }
130
131 void CoordinateWidget::setCoordinates(double x, double y, double rx, double ry, bool updateFormat)
132 {
133         if (!graphic)
134                 return;
135
136         if (updateFormat)
137         {
138                 format = graphic->getLinearFormat();
139                 prec = graphic->getLinearPrecision();
140                 aformat = graphic->getAngleFormat();
141                 aprec = graphic->getAnglePrecision();
142         }
143
144         // abs / rel coordinates:
145         QString absX = Units::formatLinear(x, graphic->getUnit(), format, prec);
146         QString absY = Units::formatLinear(y, graphic->getUnit(), format, prec);
147         QString relX = Units::formatLinear(rx, graphic->getUnit(), format, prec);
148         QString relY = Units::formatLinear(ry, graphic->getUnit(), format, prec);
149
150         ui.lCoord1->setText(absX + ", " + absY);
151         ui.lCoord2->setText(relX + ", " + relY);
152
153         // polar coordinates:
154         Vector v = Vector(x, y);
155         QString rStr = Units::formatLinear(v.magnitude(), graphic->getUnit(), format, prec);
156         QString aStr = Units::formatAngle(v.angle(), aformat, aprec);
157
158         // U+2221 = Measured angle
159         QString str = rStr + " " + QChar(0x2221) + aStr;
160         ui.lCoord1b->setText(str);
161
162         v = Vector(rx, ry);
163         rStr = Units::formatLinear(v.magnitude(), graphic->getUnit(), format, prec);
164         aStr = Units::formatAngle(v.angle(), aformat, aprec);
165         str = rStr + " " + QChar(0x2221) + aStr;
166         ui.lCoord2b->setText(str);
167 }