]> Shamusworld >> Repos - architektonas/blob - src/forms/lineangleoptions.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / lineangleoptions.cpp
1 // lineangleoptions.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 "lineangleoptions.h"
18
19 #include "actiondrawlineangle.h"
20 #include "debug.h"
21 #include "settings.h"
22
23 LineAngleOptions::LineAngleOptions(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         lSnapPoint(new QLabel(tr("Snap Point:"))),
30         cbSnapPoint(new QComboBox(this))
31 {
32         QHBoxLayout * layout = new QHBoxLayout(this);
33         layout->setContentsMargins(0, 0, 0, 0);
34
35         QStringList items;
36         items << "Start" << "Middle" << "End";
37         cbSnapPoint->addItems(items);
38
39         leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
40         leLength->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
41
42         layout->addWidget(lAngle);
43         layout->addWidget(leAngle);
44         layout->addWidget(lLength);
45         layout->addWidget(leLength);
46         layout->addWidget(lSnapPoint);
47         layout->addWidget(cbSnapPoint);
48
49         connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateAngle(QString)));
50         connect(leLength, SIGNAL(textChanged(QString)), this, SLOT(updateLength(QString)));
51         connect(cbSnapPoint, SIGNAL(activated(int)), this, SLOT(updateSnapPoint(int)));
52
53         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
54         // nothing will show up on the screen. :-)
55         if (parent)
56                 parent->addWidget(this);
57 }
58
59 LineAngleOptions::~LineAngleOptions()
60 {
61         if (action)
62         {
63                 settings.beginGroup("Draw");
64
65                 if (!action->hasFixedAngle())
66                         settings.setValue("LineAngleAngle", Math::rad2deg(action->getAngle()));
67
68                 settings.setValue("LineAngleLength", action->getLength());
69                 settings.setValue("LineAngleSnapPoint", action->getSnapPoint());
70                 settings.endGroup();
71         }
72 }
73
74 void LineAngleOptions::setAction(ActionInterface * a, bool update)
75 {
76         if (a && a->rtti() == RS2::ActionDrawLineAngle)
77         {
78                 action = (ActionDrawLineAngle *)a;
79
80                 if (action->hasFixedAngle())
81                 {
82                         lAngle->hide();
83                         leAngle->hide();
84                 }
85
86                 QString sa, sl;
87                 int sp;
88
89                 // settings from action:
90                 if (update)
91                 {
92                         sa = QString("%1").arg(Math::rad2deg(action->getAngle()));
93                         sl = QString("%1").arg(action->getLength());
94                         sp = action->getSnapPoint();
95                 }
96                 // settings from config file:
97                 else
98                 {
99                         settings.beginGroup("Draw");
100
101                         if (!action->hasFixedAngle())
102                                 sa = settings.value("LineAngleAngle", "30.0").toString();
103                         else
104                                 sa = QString("%1").arg(action->getAngle());
105
106                         sl = settings.value("LineAngleLength", "10.0").toString();
107                         sp = settings.value("LineAngleSnapPoint", 0).toInt();
108                         settings.endGroup();
109                         action->setSnapPoint(sp);
110                 }
111
112                 leAngle->setText(sa);
113                 leLength->setText(sl);
114                 cbSnapPoint->setCurrentIndex(sp);
115         }
116         else
117         {
118                 DEBUG->print(Debug::D_ERROR, "LineAngleOptions::setAction: wrong action type");
119                 this->action = NULL;
120         }
121 }
122
123 void LineAngleOptions::updateAngle(const QString & a)
124 {
125         if (action && !action->hasFixedAngle())
126                 action->setAngle(Math::deg2rad(Math::eval(a)));
127 }
128
129 void LineAngleOptions::updateLength(const QString & l)
130 {
131         if (action)
132                 action->setLength(Math::eval(l));
133 }
134
135 void LineAngleOptions::updateSnapPoint(int sp)
136 {
137         if (action)
138                 action->setSnapPoint(sp);
139 }