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