]> Shamusworld >> Repos - architektonas/blob - src/forms/lineparalleloptions.cpp
f55bf966a0ea69aee70abf969e49cb7bb0831011
[architektonas] / src / forms / lineparalleloptions.cpp
1 // lineparalleloptions.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 "lineparalleloptions.h"
16
17 #include "rs_actiondrawlineparallel.h"
18 #include "settings.h"
19
20 LineParallelOptions::LineParallelOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
21         QWidget(parent, flags),
22         lDist(new QLabel(tr("Distance:"))),
23         leDist(new QLineEdit(this)),
24         lNumber(new QLabel(tr("Number:"))),
25         sbNumber(new QSpinBox(this))
26 {
27         QHBoxLayout * layout = new QHBoxLayout(this);
28         layout->setContentsMargins(0, 0, 0, 0);
29
30         leDist->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
31
32         layout->addWidget(lDist);
33         layout->addWidget(leDist);
34         layout->addWidget(lNumber);
35         layout->addWidget(sbNumber);
36
37         connect(leDist, SIGNAL(textChanged(QString)), this, SLOT(updateDist(QString)));
38         connect(sbNumber, SIGNAL(valueChanged(int)), this, SLOT(updateNumber(int)));
39
40         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
41         // nothing will show up on the screen. :-)
42         if (parent)
43                 parent->addWidget(this);
44 }
45
46 LineParallelOptions::~LineParallelOptions()
47 {
48         settings.beginGroup("Draw");
49         settings.setValue("LineParallelDistance", leDist->text());
50         settings.setValue("LineParallelNumber", sbNumber->text());
51         settings.endGroup();
52 }
53
54 void LineParallelOptions::setAction(RS_ActionInterface * a, bool update)
55 {
56         if (a != NULL && a->rtti() == RS2::ActionDrawLineParallel)
57         {
58                 action = (RS_ActionDrawLineParallel *)a;
59
60                 QString sd;
61                 QString sn;
62
63                 if (update)
64                 {
65                         sd = QString("%1").arg(action->getDistance());
66                         sn = QString("%1").arg(action->getNumber());
67                 }
68                 else
69                 {
70                         settings.beginGroup("Draw");
71                         sd = settings.value("LineParallelDistance", "1.0").toString();
72                         sn = settings.value("LineParallelNumber", "1").toString();
73                         settings.endGroup();
74                 }
75
76                 leDist->setText(sd);
77                 sbNumber->setValue(sn.toInt());
78         }
79         else
80         {
81                 RS_DEBUG->print(RS_Debug::D_ERROR, "LineParallelOptions::setAction: wrong action type");
82                 action = NULL;
83         }
84 }
85
86 void LineParallelOptions::updateDist(const QString & d)
87 {
88         if (action != NULL)
89                 action->setDistance(RS_Math::eval(d));
90 }
91
92 void LineParallelOptions::updateNumber(int n)
93 {
94         if (action != NULL)
95                 action->setNumber(n);
96 }