]> Shamusworld >> Repos - architektonas/blob - src/forms/linerelangleoptions.cpp
0861cda7736f1b228a7ca3ffb6d34a8540bbf772
[architektonas] / src / forms / linerelangleoptions.cpp
1 // linerelangleoptions.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  06/10/2010  Created this file. :-)
15 //
16
17 #include "linerelangleoptions.h"
18
19 #include "actiondrawlinerelangle.h"
20 #include "settings.h"
21
22 LineRelAngleOptions::LineRelAngleOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags),
24         lAngle(new QLabel(tr("Angle:"))),
25         leAngle(new QLineEdit(this)),
26         lLength(new QLabel(tr("Length:"))),
27         leLength(new QLineEdit(this))
28 {
29         QHBoxLayout * layout = new QHBoxLayout(this);
30         layout->setContentsMargins(0, 0, 0, 0);
31
32         leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
33         leLength->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
34
35         layout->addWidget(lAngle);
36         layout->addWidget(leAngle);
37         layout->addWidget(lLength);
38         layout->addWidget(leLength);
39
40         connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateAngle(QString)));
41         connect(leLength, SIGNAL(textChanged(QString)), this, SLOT(updateLength(QString)));
42
43         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
44         // nothing will show up on the screen. :-)
45         if (parent)
46                 parent->addWidget(this);
47 }
48
49 LineRelAngleOptions::~LineRelAngleOptions()
50 {
51         if (action != NULL)
52         {
53                 settings.beginGroup("Draw");
54
55                 if (!action->hasFixedAngle())
56                         settings.value("LineRelAngleAngle", RS_Math::rad2deg(action->getAngle()));
57
58                 settings.value("LineRelAngleLength", action->getLength());
59                 settings.endGroup();
60         }
61 }
62
63 void LineRelAngleOptions::setAction(ActionInterface * a, bool update)
64 {
65         if (a != NULL && a->rtti() == RS2::ActionDrawLineRelAngle)
66         {
67                 action = (ActionDrawLineRelAngle *)a;
68
69                 if (action->hasFixedAngle())
70                 {
71                         lAngle->setDisabled(true);
72                         leAngle->setDisabled(true);
73                 }
74
75                 QString sa;
76                 QString sl;
77
78                 // settings from action:
79                 if (update)
80                 {
81                         sa = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
82                         sl = QString("%1").arg(action->getLength());
83                 }
84                 // settings from config file:
85                 else
86                 {
87                         settings.beginGroup("Draw");
88
89                         if (!action->hasFixedAngle())
90                                 sa = settings.value("LineRelAngleAngle", "30.0").toString();
91                         else
92                                 sa = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
93
94                         sl = settings.value("LineRelAngleLength", "10.0").toString();
95                         settings.endGroup();
96                 }
97
98                 leAngle->setText(sa);
99                 leLength->setText(sl);
100         }
101         else
102         {
103                 RS_DEBUG->print(RS_Debug::D_ERROR,
104                         "LineRelAngleOptions::setAction: wrong action type");
105                 this->action = NULL;
106         }
107 }
108
109 void LineRelAngleOptions::updateAngle(const QString & a)
110 {
111         if (action != NULL && !action->hasFixedAngle())
112                 action->setAngle(RS_Math::deg2rad(RS_Math::eval(a)));
113 }
114
115 void LineRelAngleOptions::updateLength(const QString & l)
116 {
117         if (action != NULL)
118                 action->setLength(RS_Math::eval(l));
119 }