]> Shamusworld >> Repos - architektonas/blob - src/forms/moverotateoptions.cpp
In the middle of major refactoring...
[architektonas] / src / forms / moverotateoptions.cpp
1 // moverotateoptions.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 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/09/2010  Created this file. :-)
13 //
14
15 #include "moverotateoptions.h"
16
17 #include "actionmodifymoverotate.h"
18 #include "settings.h"
19
20 MoveRotateOptions::MoveRotateOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
21         QWidget(parent, flags),
22         lAngle(new QLabel(tr("Angle:"))),
23         leAngle(new QLineEdit(this))
24 {
25         QHBoxLayout * layout = new QHBoxLayout(this);
26         layout->setContentsMargins(0, 0, 0, 0);
27
28         leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
29
30         layout->addWidget(lAngle);
31         layout->addWidget(leAngle);
32
33         connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateAngle(QString)));
34
35         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
36         // nothing will show up on the screen. :-)
37         if (parent)
38                 parent->addWidget(this);
39 }
40
41 MoveRotateOptions::~MoveRotateOptions()
42 {
43         settings.beginGroup("Modify");
44         settings.setValue("MoveRotate", leAngle->text());
45         settings.endGroup();
46 }
47
48 void MoveRotateOptions::setAction(ActionInterface * a, bool update)
49 {
50         if (a != NULL && a->rtti() == RS2::ActionModifyMoveRotate)
51         {
52                 action = (ActionModifyMoveRotate *)a;
53
54                 QString sa;
55
56                 if (update)
57                         sa = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
58                 else
59                 {
60                         settings.beginGroup("Modify");
61                         sa = settings.value("MoveRotate", "30").toString();
62                         settings.endGroup();
63                         action->setAngle(RS_Math::deg2rad(sa.toDouble()));
64                 }
65
66                 leAngle->setText(sa);
67         }
68         else
69         {
70                 RS_DEBUG->print(RS_Debug::D_ERROR, "CircleOptions::setAction: wrong action type");
71                 action = NULL;
72         }
73 }
74
75 void MoveRotateOptions::updateAngle(const QString & a)
76 {
77         if (action != NULL)
78                 action->setAngle(RS_Math::deg2rad(RS_Math::eval(a)));
79 }
80