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