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