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