]> Shamusworld >> Repos - architektonas/blob - src/forms/lineparallelthroughoptions.cpp
In the middle of major refactoring...
[architektonas] / src / forms / lineparallelthroughoptions.cpp
1 // lineparallelthroughoptions.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 "lineparallelthroughoptions.h"
16
17 #include "actiondrawlineparallelthrough.h"
18 #include "settings.h"
19
20 LineParallelThroughOptions::LineParallelThroughOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
21         QWidget(parent, flags),
22         lNumber(new QLabel(tr("Number:"))),
23         sbNumber(new QSpinBox(this))
24 {
25         QHBoxLayout * layout = new QHBoxLayout(this);
26         layout->setContentsMargins(0, 0, 0, 0);
27
28 //      leDist->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
29
30         layout->addWidget(lNumber);
31         layout->addWidget(sbNumber);
32
33         connect(sbNumber, SIGNAL(valueChanged(int)), this, SLOT(updateNumber(int)));
34
35         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
36         // nothing will show up on the screen. :-)
37         if (parent)
38                 parent->addWidget(this);
39 }
40
41 LineParallelThroughOptions::~LineParallelThroughOptions()
42 {
43         settings.beginGroup("Draw");
44         settings.setValue("LineParallelNumber", sbNumber->text());
45         settings.endGroup();
46 }
47
48 void LineParallelThroughOptions::setAction(ActionInterface * a, bool update)
49 {
50         if (a != NULL && a->rtti() == RS2::ActionDrawLineParallelThrough)
51         {
52                 action = (ActionDrawLineParallelThrough *)a;
53
54                 QString sn;
55
56                 if (update)
57                         sn = QString("%1").arg(action->getNumber());
58                 else
59                 {
60                         settings.beginGroup("Draw");
61                         sn = settings.value("LineParallelNumber", "1").toString();
62                         settings.endGroup();
63                 }
64
65                 sbNumber->setValue(sn.toInt());
66         }
67         else
68         {
69                 RS_DEBUG->print(RS_Debug::D_ERROR, "LineParallelThroughOptions::setAction: wrong action type");
70                 action = NULL;
71         }
72 }
73
74 void LineParallelThroughOptions::updateNumber(int n)
75 {
76         if (action != NULL)
77                 action->setNumber(n);
78 }