]> Shamusworld >> Repos - architektonas/blob - src/forms/trimamountoptions.cpp
dde64764687063c00eeb9b184440aa907b739443
[architektonas] / src / forms / trimamountoptions.cpp
1 // trimamountoptions.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/10/2010  Created this file. :-)
13 //
14
15 #include "trimamountoptions.h"
16
17 #include "actionmodifytrimamount.h"
18 #include "actioninterface.h"
19 #include "rs_debug.h"
20 #include "rs_math.h"
21 #include "settings.h"
22
23 TrimAmountOptions::TrimAmountOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
24         QWidget(parent, flags),
25         lDist(new QLabel(tr("Amount:"))),
26         leDist(new QLineEdit(this))
27 {
28         QHBoxLayout * layout = new QHBoxLayout(this);
29         layout->setContentsMargins(0, 0, 0, 0);
30
31         leDist->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
32
33         layout->addWidget(lDist);
34         layout->addWidget(leDist);
35
36         connect(leDist, SIGNAL(textChanged(QString)), this, SLOT(updateDist(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 TrimAmountOptions::~TrimAmountOptions()
45 {
46         settings.beginGroup("Modify");
47         settings.setValue("TrimAmount", leDist->text());
48         settings.endGroup();
49 }
50
51 void TrimAmountOptions::setAction(ActionInterface * a, bool update)
52 {
53         if (a != NULL && a->rtti() == RS2::ActionModifyTrimAmount)
54         {
55                 action = (ActionModifyTrimAmount *)a;
56
57                 QString sd;
58
59                 // settings from action:
60                 if (update)
61                         sd = QString("%1").arg(action->getDistance());
62                 // settings from config file:
63                 else
64                 {
65                         settings.beginGroup("Modify");
66                         sd = settings.value("TrimAmount", "1.0").toString();
67                         settings.endGroup();
68                 }
69
70                 leDist->setText(sd);
71         }
72         else
73         {
74                 RS_DEBUG->print(RS_Debug::D_ERROR, "ModifyTrimAmountOptions::setAction: wrong action type");
75                 this->action = NULL;
76         }
77 }
78
79 void TrimAmountOptions::updateDist(const QString & d)
80 {
81         if (action != NULL)
82                 action->setDistance(RS_Math::eval(d, 1.0));
83 }