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)//, actionHandler(NULL), cadToolBar(NULL)
28 ui.lCoord1->setText("");
29 ui.lCoord2->setText("");
30 ui.lCoord1b->setText("");
31 ui.lCoord2b->setText("");
40 settings.beginGroup("Appearance");
41 fsize = settings.value("StatusBarFontSize", fsize).toInt();
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));
51 format = RS2::Decimal;
53 aformat = RS2::DegreesDecimal;
56 CoordinateWidget::~CoordinateWidget()
60 void CoordinateWidget::setGraphic(Drawing * graphic)
62 this->graphic = graphic;
63 setCoordinates(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
66 /*void CoordinateWidget::setAbsCoordinates(double x, double y) {
67 setAbsCoordinates(Vector(x, y));
70 void CoordinateWidget::setAbsCoordinates(const Vector& v) {
73 str.sprintf("%.4f / %.4f", v.x, v.y);
74 lCoord1->setText(str);
76 double ang = RS_Math::rad2deg(v.angle());
77 double rad = v.magnitude();
78 str.sprintf("%.4f < %.4f", rad, ang);
79 lCoord1b->setText(str);
82 void CoordinateWidget::setAbsCoordinates(const QString& x, const QString& y) {
87 void CoordinateWidget::setRelCoordinates(double x, double y) {
88 setRelCoordinates(Vector(x, y));
91 void CoordinateWidget::setRelCoordinates(const Vector& v) {
93 str.sprintf("@%.4f / %.4f", v.x, v.y);
94 lCoord2->setText(str);
96 double ang = RS_Math::rad2deg(v.angle());
97 double rad = v.magnitude();
98 str.sprintf("@%.4f < %.4f", rad, ang);
99 lCoord2b->setText(str);
102 void CoordinateWidget::setRelCoordinates(const QString& x, const QString& y) {
104 lCoord2b->setText(y);
107 void CoordinateWidget::setCoordinates(double x, double y,
108 double rx, double ry) {
109 setAbsCoordinates(x, y);
110 setRelCoordinates(rx, ry);
113 /*void CoordinateWidget::setAbsCoordinates(const QString& x,
118 lCoord1b->setText(y);
119 lCoord2->setText(rx);
120 lCoord2b->setText(ry);
123 void CoordinateWidget::setCoordinates(const Vector & abs, const Vector & rel, bool updateFormat)
125 setCoordinates(abs.x, abs.y, rel.x, rel.y, updateFormat);
128 void CoordinateWidget::setCoordinates(double x, double y, double rx, double ry, bool updateFormat)
134 format = graphic->getLinearFormat();
135 prec = graphic->getLinearPrecision();
136 aformat = graphic->getAngleFormat();
137 aprec = graphic->getAnglePrecision();
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);
146 ui.lCoord1->setText(absX + " , " + absY);
147 ui.lCoord2->setText(relX + " , " + relY);
149 // polar coordinates:
153 QString rStr = RS_Units::formatLinear(v.magnitude(), graphic->getUnit(), format, prec);
154 QString aStr = RS_Units::formatAngle(v.angle(), aformat, aprec);
156 str = rStr + " < " + aStr;
157 ui.lCoord1b->setText(str);
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);