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