1 // linerelangleoptions.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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/10/2010 Created this file. :-)
15 #include "linerelangleoptions.h"
17 #include "actiondrawlinerelangle.h"
20 LineRelAngleOptions::LineRelAngleOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
21 QWidget(parent, flags),
22 lAngle(new QLabel(tr("Angle:"))),
23 leAngle(new QLineEdit(this)),
24 lLength(new QLabel(tr("Length:"))),
25 leLength(new QLineEdit(this))
27 QHBoxLayout * layout = new QHBoxLayout(this);
28 layout->setContentsMargins(0, 0, 0, 0);
30 leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
31 leLength->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
33 layout->addWidget(lAngle);
34 layout->addWidget(leAngle);
35 layout->addWidget(lLength);
36 layout->addWidget(leLength);
38 connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateAngle(QString)));
39 connect(leLength, SIGNAL(textChanged(QString)), this, SLOT(updateLength(QString)));
41 // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
42 // nothing will show up on the screen. :-)
44 parent->addWidget(this);
47 LineRelAngleOptions::~LineRelAngleOptions()
51 settings.beginGroup("Draw");
53 if (!action->hasFixedAngle())
54 settings.value("LineRelAngleAngle", RS_Math::rad2deg(action->getAngle()));
56 settings.value("LineRelAngleLength", action->getLength());
61 void LineRelAngleOptions::setAction(ActionInterface * a, bool update)
63 if (a != NULL && a->rtti() == RS2::ActionDrawLineRelAngle)
65 action = (ActionDrawLineRelAngle *)a;
67 if (action->hasFixedAngle())
69 lAngle->setDisabled(true);
70 leAngle->setDisabled(true);
76 // settings from action:
79 sa = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
80 sl = QString("%1").arg(action->getLength());
82 // settings from config file:
85 settings.beginGroup("Draw");
87 if (!action->hasFixedAngle())
88 sa = settings.value("LineRelAngleAngle", "30.0").toString();
90 sa = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
92 sl = settings.value("LineRelAngleLength", "10.0").toString();
97 leLength->setText(sl);
101 RS_DEBUG->print(RS_Debug::D_ERROR,
102 "LineRelAngleOptions::setAction: wrong action type");
107 void LineRelAngleOptions::updateAngle(const QString & a)
109 if (action != NULL && !action->hasFixedAngle())
110 action->setAngle(RS_Math::deg2rad(RS_Math::eval(a)));
113 void LineRelAngleOptions::updateLength(const QString & l)
116 action->setLength(RS_Math::eval(l));