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