]> Shamusworld >> Repos - architektonas/blob - src/forms/splineoptions.cpp
GPL compliance check...
[architektonas] / src / forms / splineoptions.cpp
1 // splineoptions.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 "splineoptions.h"
18
19 #include "actiondrawspline.h"
20 #include "actioninterface.h"
21 #include "settings.h"
22
23 SplineOptions::SplineOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
24         QWidget(parent, flags),
25         lDegree(new QLabel(tr("Degree:"))),
26         cbDegree(new QComboBox(this)),
27         cbClosed(new QCheckBox(tr("Closed"))),
28         bUndo(new QToolButton(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         QStringList degrees;
35         degrees << "1" << "2" << "3";
36         cbDegree->addItems(degrees);
37         bUndo->setText(tr("Undo"));
38
39         layout->addWidget(lDegree);
40         layout->addWidget(cbDegree);
41         layout->addWidget(cbClosed);
42         layout->addWidget(bUndo);
43
44         connect(cbDegree, SIGNAL(activated(QString)), this, SLOT(setDegree(QString)));
45         connect(cbClosed, SIGNAL(toggled(bool)), this, SLOT(setClosed(bool)));
46         connect(bUndo, SIGNAL(clicked()), this, SLOT(undo()));
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 SplineOptions::~SplineOptions()
55 {
56         settings.beginGroup("Draw");
57         settings.setValue("SplineDegree", cbDegree->currentText().toInt());
58         settings.setValue("SplineClosed", cbClosed->isChecked());
59         settings.endGroup();
60 }
61
62 void SplineOptions::setAction(ActionInterface * a, bool update)
63 {
64         if (a != NULL && a->rtti() == RS2::ActionDrawSpline)
65         {
66                 action = (ActionDrawSpline *)a;
67
68                 int degree;
69                 bool closed;
70
71                 if (update)
72                 {
73                         degree = action->getDegree();
74                         closed = action->isClosed();
75                 }
76                 else
77                 {
78                         settings.beginGroup("Draw");
79                         degree = settings.value("SplineDegree", 3).toInt();
80                         closed = settings.value("SplineClosed", false).toBool();
81                         settings.endGroup();
82                         action->setDegree(degree);
83                         action->setClosed(closed);
84                 }
85
86                 cbDegree->setCurrentIndex(cbDegree->findText(QString("%1").arg(degree)));
87                 cbClosed->setChecked(closed);
88         }
89         else
90         {
91                 RS_DEBUG->print(RS_Debug::D_ERROR, "SplineOptions::setAction: wrong action type");
92                 action = NULL;
93         }
94 }
95
96 void SplineOptions::setClosed(bool c)
97 {
98         if (action != NULL)
99                 action->setClosed(c);
100 }
101
102 void SplineOptions::undo()
103 {
104         if (action != NULL)
105                 action->undo();
106 }
107
108 void SplineOptions::setDegree(const QString & deg)
109 {
110         if (action != NULL)
111                 action->setDegree(deg.toInt());
112 }