]> Shamusworld >> Repos - architektonas/blob - src/forms/trimamountoptions.cpp
Bugfixes related to removing Snapper class.
[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 // 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/10/2010  Created this file. :-)
15 //
16
17 #include "trimamountoptions.h"
18
19 #include "actionmodifytrimamount.h"
20 #include "actioninterface.h"
21 #include "debug.h"
22 #include "mathextra.h"
23 #include "settings.h"
24
25 TrimAmountOptions::TrimAmountOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
26         QWidget(parent, flags),
27         lDist(new QLabel(tr("Amount:"))),
28         leDist(new QLineEdit(this))
29 {
30         QHBoxLayout * layout = new QHBoxLayout(this);
31         layout->setContentsMargins(0, 0, 0, 0);
32
33         leDist->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
34
35         layout->addWidget(lDist);
36         layout->addWidget(leDist);
37
38         connect(leDist, SIGNAL(textChanged(QString)), this, SLOT(updateDist(QString)));
39
40         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
41         // nothing will show up on the screen. :-)
42         if (parent)
43                 parent->addWidget(this);
44 }
45
46 TrimAmountOptions::~TrimAmountOptions()
47 {
48         settings.beginGroup("Modify");
49         settings.setValue("TrimAmount", leDist->text());
50         settings.endGroup();
51 }
52
53 void TrimAmountOptions::setAction(ActionInterface * a, bool update)
54 {
55         if (a != NULL && a->rtti() == RS2::ActionModifyTrimAmount)
56         {
57                 action = (ActionModifyTrimAmount *)a;
58
59                 QString sd;
60
61                 // settings from action:
62                 if (update)
63                         sd = QString("%1").arg(action->getDistance());
64                 // settings from config file:
65                 else
66                 {
67                         settings.beginGroup("Modify");
68                         sd = settings.value("TrimAmount", "1.0").toString();
69                         settings.endGroup();
70                 }
71
72                 leDist->setText(sd);
73         }
74         else
75         {
76                 DEBUG->print(Debug::D_ERROR, "ModifyTrimAmountOptions::setAction: wrong action type");
77                 this->action = NULL;
78         }
79 }
80
81 void TrimAmountOptions::updateDist(const QString & d)
82 {
83         if (action != NULL)
84                 action->setDistance(Math::eval(d, 1.0));
85 }