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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/10/2010 Created this file. :-)
17 #include "coordinatewidget.h"
23 CoordinateWidget::CoordinateWidget(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
24 QWidget(parent, flags)
28 ui.lCoord1->setText("");
29 ui.lCoord2->setText("");
30 ui.lCoord1b->setText("");
31 ui.lCoord2b->setText("");
39 settings.beginGroup("Appearance");
40 fsize = settings.value("StatusBarFontSize", fsize).toInt();
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));
54 format = RS2::Decimal;
56 aformat = RS2::DegreesDecimal;
59 CoordinateWidget::~CoordinateWidget()
63 void CoordinateWidget::setGraphic(Drawing * graphic)
65 this->graphic = graphic;
66 setCoordinates(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
69 /*void CoordinateWidget::setAbsCoordinates(double x, double y) {
70 setAbsCoordinates(Vector(x, y));
73 void CoordinateWidget::setAbsCoordinates(const Vector& v) {
76 str.sprintf("%.4f / %.4f", v.x, v.y);
77 lCoord1->setText(str);
79 double ang = Math::rad2deg(v.angle());
80 double rad = v.magnitude();
81 str.sprintf("%.4f < %.4f", rad, ang);
82 lCoord1b->setText(str);
85 void CoordinateWidget::setAbsCoordinates(const QString& x, const QString& y) {
90 void CoordinateWidget::setRelCoordinates(double x, double y) {
91 setRelCoordinates(Vector(x, y));
94 void CoordinateWidget::setRelCoordinates(const Vector& v) {
96 str.sprintf("@%.4f / %.4f", v.x, v.y);
97 lCoord2->setText(str);
99 double ang = Math::rad2deg(v.angle());
100 double rad = v.magnitude();
101 str.sprintf("@%.4f < %.4f", rad, ang);
102 lCoord2b->setText(str);
105 void CoordinateWidget::setRelCoordinates(const QString& x, const QString& y) {
107 lCoord2b->setText(y);
110 void CoordinateWidget::setCoordinates(double x, double y,
111 double rx, double ry) {
112 setAbsCoordinates(x, y);
113 setRelCoordinates(rx, ry);
116 /*void CoordinateWidget::setAbsCoordinates(const QString& x,
121 lCoord1b->setText(y);
122 lCoord2->setText(rx);
123 lCoord2b->setText(ry);
126 void CoordinateWidget::setCoordinates(const Vector & abs, const Vector & rel, bool updateFormat)
128 setCoordinates(abs.x, abs.y, rel.x, rel.y, updateFormat);
131 void CoordinateWidget::setCoordinates(double x, double y, double rx, double ry, bool updateFormat)
138 format = graphic->getLinearFormat();
139 prec = graphic->getLinearPrecision();
140 aformat = graphic->getAngleFormat();
141 aprec = graphic->getAnglePrecision();
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);
150 ui.lCoord1->setText(absX + ", " + absY);
151 ui.lCoord2->setText(relX + ", " + relY);
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);
158 // U+2221 = Measured angle
159 QString str = rStr + " " + QChar(0x2221) + aStr;
160 ui.lCoord1b->setText(str);
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);