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