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