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