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 // 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 06/10/2010 Created this file. :-)
17 #include "linerelangleoptions.h"
19 #include "actiondrawlinerelangle.h"
23 LineRelAngleOptions::LineRelAngleOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
24 QWidget(parent, flags),
25 lAngle(new QLabel(tr("Angle:"))),
26 leAngle(new QLineEdit(this)),
27 lLength(new QLabel(tr("Length:"))),
28 leLength(new QLineEdit(this))
30 QHBoxLayout * layout = new QHBoxLayout(this);
31 layout->setContentsMargins(0, 0, 0, 0);
33 leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
34 leLength->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
36 layout->addWidget(lAngle);
37 layout->addWidget(leAngle);
38 layout->addWidget(lLength);
39 layout->addWidget(leLength);
41 connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateAngle(QString)));
42 connect(leLength, SIGNAL(textChanged(QString)), this, SLOT(updateLength(QString)));
44 // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
45 // nothing will show up on the screen. :-)
47 parent->addWidget(this);
50 LineRelAngleOptions::~LineRelAngleOptions()
54 settings.beginGroup("Draw");
56 if (!action->hasFixedAngle())
57 settings.value("LineRelAngleAngle", Math::rad2deg(action->getAngle()));
59 settings.value("LineRelAngleLength", action->getLength());
64 void LineRelAngleOptions::setAction(ActionInterface * a, bool update)
66 if (a != NULL && a->rtti() == RS2::ActionDrawLineRelAngle)
68 action = (ActionDrawLineRelAngle *)a;
70 if (action->hasFixedAngle())
72 lAngle->setDisabled(true);
73 leAngle->setDisabled(true);
79 // settings from action:
82 sa = QString("%1").arg(Math::rad2deg(action->getAngle()));
83 sl = QString("%1").arg(action->getLength());
85 // settings from config file:
88 settings.beginGroup("Draw");
90 if (!action->hasFixedAngle())
91 sa = settings.value("LineRelAngleAngle", "30.0").toString();
93 sa = QString("%1").arg(Math::rad2deg(action->getAngle()));
95 sl = settings.value("LineRelAngleLength", "10.0").toString();
100 leLength->setText(sl);
104 DEBUG->print(Debug::D_ERROR,
105 "LineRelAngleOptions::setAction: wrong action type");
110 void LineRelAngleOptions::updateAngle(const QString & a)
112 if (action != NULL && !action->hasFixedAngle())
113 action->setAngle(Math::deg2rad(Math::eval(a)));
116 void LineRelAngleOptions::updateLength(const QString & l)
119 action->setLength(Math::eval(l));