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