]> Shamusworld >> Repos - architektonas/blob - src/forms/beveloptions.cpp
a464f10df77062f74d16ad986ec1ee949aa57ed8
[architektonas] / src / forms / beveloptions.cpp
1 // beveloptions.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/08/2010  Created this file. :-)
13 //
14
15 #include "beveloptions.h"
16
17 #include "rs.h"
18 #include "actioninterface.h"
19 #include "actionmodifybevel.h"
20 #include "settings.h"
21
22 BevelOptions::BevelOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags),
24         cbTrim(new QCheckBox(tr("Trim"))),
25         lLength1(new QLabel(tr("Length 1:"))),
26         lLength2(new QLabel(tr("Length 2:"))),
27         leLength1(new QLineEdit(this)),
28         leLength2(new QLineEdit(this)),
29         sep1(new QFrame(this))
30 {
31         QHBoxLayout * layout = new QHBoxLayout(this);
32         layout->setContentsMargins(0, 0, 0, 0);
33
34         leLength1->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
35         leLength2->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
36         sep1->setFrameShape(QFrame::VLine);
37         sep1->setFrameShadow(QFrame::Sunken);
38
39         layout->addWidget(cbTrim);
40         layout->addWidget(sep1);
41         layout->addWidget(lLength1);
42         layout->addWidget(leLength1);
43         layout->addWidget(lLength2);
44         layout->addWidget(leLength2);
45
46         connect(cbTrim, SIGNAL(toggled(bool)), this, SLOT(updateData()));
47         connect(leLength1, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
48         connect(leLength2, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
49
50         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
51         // nothing will show up on the screen. :-)
52         if (parent)
53                 parent->addWidget(this);
54 }
55
56 BevelOptions::~BevelOptions()
57 {
58         settings.beginGroup("Modify");
59         settings.setValue("BevelLength1", leLength1->text());
60         settings.setValue("BevelLength2", leLength2->text());
61         settings.setValue("BevelTrim", cbTrim->isChecked());
62         settings.endGroup();
63 }
64
65 void BevelOptions::setAction(ActionInterface * a, bool update)
66 {
67         if (a != NULL && a->rtti() == RS2::ActionModifyBevel)
68         {
69                 action = (ActionModifyBevel *)a;
70
71                 QString sd1;
72                 QString sd2;
73                 bool st;
74
75                 if (update)
76                 {
77                         sd1 = QString("%1").arg(action->getLength1());
78                         sd2 = QString("%1").arg(action->getLength2());
79                         st = action->isTrimOn();
80                 }
81                 else
82                 {
83                         settings.beginGroup("Modify");
84                         sd1 = settings.value("BevelLength1", "1.0").toString();
85                         sd2 = settings.value("BevelLength2", "1.0").toString();
86                         st = settings.value("BevelTrim", true).toBool();
87                         settings.endGroup();
88                 }
89
90                 leLength1->setText(sd1);
91                 leLength2->setText(sd2);
92                 cbTrim->setChecked(st);
93         }
94         else
95         {
96                 RS_DEBUG->print(RS_Debug::D_ERROR, "BevelOptions::setAction: wrong action type");
97                 action = NULL;
98         }
99 }
100
101 void BevelOptions::updateData()
102 {
103         if (action != NULL)
104         {
105                 action->setTrim(cbTrim->isChecked());
106                 action->setLength1(RS_Math::eval(leLength1->text()));
107                 action->setLength2(RS_Math::eval(leLength2->text()));
108         }
109 }