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