]> Shamusworld >> Repos - architektonas/blob - src/forms/insertoptions.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / insertoptions.cpp
1 // insertoptions.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 "insertoptions.h"
18
19 #include "actionblocksinsert.h"
20 #include "settings.h"
21
22 InsertOptions::InsertOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags),
24         lAngle(new QLabel(tr("Angle:"))),
25         leAngle(new QLineEdit(this)),
26         lFactor(new QLabel(tr("Factor:"))),
27         leFactor(new QLineEdit(this)),
28         sep1(new QFrame(this)),
29         lArray(new QLabel(tr("Array:"))),
30         sbColumns(new QSpinBox(this)),
31         sbRows(new QSpinBox(this)),
32         lSpacing(new QLabel(tr("Spacing:"))),
33         leColumnSpacing(new QLineEdit(this)),
34         leRowSpacing(new QLineEdit(this))
35 {
36         QHBoxLayout * layout = new QHBoxLayout(this);
37         layout->setContentsMargins(0, 0, 0, 0);
38
39         leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
40         leFactor->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
41         leColumnSpacing->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
42         leRowSpacing->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
43         sep1->setFrameShape(QFrame::VLine);
44         sep1->setFrameShadow(QFrame::Sunken);
45
46         layout->addWidget(lAngle);
47         layout->addWidget(leAngle);
48         layout->addWidget(lFactor);
49         layout->addWidget(leFactor);
50         layout->addWidget(sep1);
51         layout->addWidget(lArray);
52         layout->addWidget(sbColumns);
53         layout->addWidget(sbRows);
54         layout->addWidget(lSpacing);
55         layout->addWidget(leColumnSpacing);
56         layout->addWidget(leRowSpacing);
57
58         connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
59         connect(leFactor, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
60         connect(sbColumns, SIGNAL(valueChanged(int)), this, SLOT(updateData()));
61         connect(sbRows, SIGNAL(valueChanged(int)), this, SLOT(updateData()));
62         connect(leColumnSpacing, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
63         connect(leRowSpacing, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
64
65         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
66         // nothing will show up on the screen. :-)
67         if (parent)
68                 parent->addWidget(this);
69 }
70
71 InsertOptions::~InsertOptions()
72 {
73         settings.beginGroup("Insert");
74         settings.setValue("InsertAngle", leAngle->text());
75         settings.setValue("InsertFactor", leFactor->text());
76         settings.setValue("InsertColumns", sbColumns->text());
77         settings.setValue("InsertRows", sbRows->text());
78         settings.setValue("InsertColumnSpacing", leColumnSpacing->text());
79         settings.setValue("InsertRowSpacing", leRowSpacing->text());
80         settings.endGroup();
81 }
82
83 void InsertOptions::setAction(ActionInterface * a, bool update)
84 {
85         if (a != NULL && a->rtti() == RS2::ActionBlocksInsert)
86         {
87                 action = (ActionBlocksInsert *)a;
88
89                 QString sAngle;
90                 QString sFactor;
91                 QString sColumns;
92                 QString sRows;
93                 QString sColumnSpacing;
94                 QString sRowSpacing;
95
96                 if (update)
97                 {
98                         sAngle = QString("%1").arg(Math::rad2deg(action->getAngle()));
99                         sFactor = QString("%1").arg(action->getFactor());
100                         sColumns = QString("%1").arg(action->getColumns());
101                         sRows = QString("%1").arg(action->getRows());
102                         sColumnSpacing = QString("%1").arg(action->getColumnSpacing());
103                         sRowSpacing = QString("%1").arg(action->getRowSpacing());
104                 }
105                 else
106                 {
107                         settings.beginGroup("Insert");
108                         sAngle = settings.value("InsertAngle", "0.0").toString();
109                         sFactor = settings.value("InsertFactor", "1.0").toString();
110                         sColumns = settings.value("InsertColumns", "1").toString();
111                         sRows = settings.value("InsertRows", "1").toString();
112                         sColumnSpacing = settings.value("InsertColumnSpacing", "1.0").toString();
113                         sRowSpacing = settings.value("InsertRowSpacing", "1.0").toString();
114                         settings.endGroup();
115                 }
116
117                 leAngle->setText(sAngle);
118                 leFactor->setText(sFactor);
119                 sbColumns->setValue(sColumns.toInt());
120                 sbRows->setValue(sRows.toInt());
121                 leColumnSpacing->setText(sColumnSpacing);
122                 leRowSpacing->setText(sRowSpacing);
123         }
124         else
125         {
126                 DEBUG->print(Debug::D_ERROR, "InsertOptions::setAction: wrong action type");
127                 action = NULL;
128         }
129 }
130
131 void InsertOptions::updateData()
132 {
133         if (action != NULL)
134         {
135                 action->setAngle(Math::deg2rad(Math::eval(leAngle->text())));
136                 action->setFactor(Math::eval(leFactor->text()));
137                 action->setColumns(sbColumns->value());
138                 action->setRows(sbRows->value());
139                 action->setColumnSpacing(Math::eval(leColumnSpacing->text()));
140                 action->setRowSpacing(Math::eval(leRowSpacing->text()));
141         }
142 }