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