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