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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/10/2010 Created this file. :-)
17 #include "insertoptions.h"
19 #include "actionblocksinsert.h"
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))
36 QHBoxLayout * layout = new QHBoxLayout(this);
37 layout->setContentsMargins(0, 0, 0, 0);
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);
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);
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()));
65 // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
66 // nothing will show up on the screen. :-)
68 parent->addWidget(this);
71 InsertOptions::~InsertOptions()
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());
83 void InsertOptions::setAction(ActionInterface * a, bool update)
85 if (a != NULL && a->rtti() == RS2::ActionBlocksInsert)
87 action = (ActionBlocksInsert *)a;
93 QString sColumnSpacing;
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());
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();
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);
126 DEBUG->print(Debug::D_ERROR, "InsertOptions::setAction: wrong action type");
131 void InsertOptions::updateData()
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()));