]> Shamusworld >> Repos - architektonas/blob - src/forms/dimlinearoptions.cpp
Sanity check stage II: rename classes...
[architektonas] / src / forms / dimlinearoptions.cpp
1 // dimlinearoptions.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 "dimlinearoptions.h"
18
19 #include "actiondimlinear.h"
20 #include "actioninterface.h"
21 #include "rs_debug.h"
22 #include "settings.h"
23
24 DimLinearOptions::DimLinearOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
25         QWidget(parent, flags),
26         lAngle(new QLabel(tr("Angle:"))),
27         leAngle(new QLineEdit(this)),
28         bHor(new QToolButton(this)),
29         bVer(new QToolButton(this))
30 {
31         QHBoxLayout * layout = new QHBoxLayout(this);
32         layout->setContentsMargins(0, 0, 0, 0);
33
34         leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
35 //still need to tweak this so it displays properly...
36         bHor->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
37         bHor->setIcon(QIcon(":/res/qg_dimhor"));
38         bVer->setIcon(QIcon(":/res/qg_dimver"));
39
40         layout->addWidget(lAngle);
41         layout->addWidget(leAngle);
42         layout->addWidget(bHor);
43         layout->addWidget(bVer);
44
45         connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateAngle(QString)));
46         connect(bHor, SIGNAL(clicked()), this, SLOT(setHor()));
47         connect(bVer, SIGNAL(clicked()), this, SLOT(setVer()));
48
49         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
50         // nothing will show up on the screen. :-)
51         if (parent)
52                 parent->addWidget(this);
53 }
54
55 DimLinearOptions::~DimLinearOptions()
56 {
57         settings.beginGroup("Dimension");
58         settings.setValue("Angle", leAngle->text());
59         settings.endGroup();
60 }
61
62 void DimLinearOptions::setAction(ActionInterface * a, bool update)
63 {
64         if (a != NULL && a->rtti() == RS2::ActionDimLinear)
65         {
66                 action = (ActionDimLinear *)a;
67
68                 QString sa;
69
70                 if (update)
71                         sa = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
72                 else
73                 {
74                         settings.beginGroup("Dimension");
75                         sa = settings.value("Angle", "0.0").toString();
76                         settings.endGroup();
77                 }
78                 leAngle->setText(sa);
79         }
80         else
81         {
82                 RS_DEBUG->print(RS_Debug::D_ERROR, "DimLinearOptions::setAction: wrong action type");
83                 action = NULL;
84         }
85 }
86
87 void DimLinearOptions::updateAngle(const QString & a)
88 {
89         if (action != NULL)
90                 action->setAngle(RS_Math::deg2rad(RS_Math::eval(a)));
91 }
92
93 void DimLinearOptions::setHor()
94 {
95         leAngle->setText("0");
96 }
97
98 void DimLinearOptions::setVer()
99 {
100         leAngle->setText("90");
101 }
102