]> Shamusworld >> Repos - architektonas/blob - src/forms/linebisectoroptions.cpp
In the middle of major refactoring...
[architektonas] / src / forms / linebisectoroptions.cpp
1 // linebisectoroptions.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 "linebisectoroptions.h"
16
17 #include "actiondrawlinebisector.h"
18 #include "settings.h"
19
20 LineBisectorOptions::LineBisectorOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
21         QWidget(parent, flags),
22         lLength(new QLabel(tr("Length:"))),
23         leLength(new QLineEdit(this)),
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         leLength->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
31
32         layout->addWidget(lLength);
33         layout->addWidget(leLength);
34         layout->addWidget(lNumber);
35         layout->addWidget(sbNumber);
36
37         connect(leLength, SIGNAL(textChanged(QString)), this, SLOT(updateLength(QString)));
38         connect(sbNumber, SIGNAL(valueChanged(int)), this, SLOT(updateNumber(int)));
39
40         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
41         // nothing will show up on the screen. :-)
42         if (parent)
43                 parent->addWidget(this);
44 }
45
46 LineBisectorOptions::~LineBisectorOptions()
47 {
48         settings.beginGroup("Draw");
49         settings.setValue("LineBisectorLength", leLength->text());
50         settings.setValue("LineBisectorNumber", sbNumber->text());
51         settings.endGroup();
52 }
53
54 void LineBisectorOptions::setAction(ActionInterface * a, bool update)
55 {
56         if (a != NULL && a->rtti() == RS2::ActionDrawLineBisector)
57         {
58                 action = (ActionDrawLineBisector *)a;
59
60                 QString sl;
61                 QString sn;
62
63                 if (update)
64                 {
65                         sl = QString("%1").arg(action->getLength());
66                         sn = QString("%1").arg(action->getNumber());
67                 }
68                 else
69                 {
70                         settings.beginGroup("Draw");
71                         sl = settings.value("LineBisectorLength", "1.0").toString();
72                         sn = settings.value("LineBisectorNumber", "1").toString();
73                         settings.endGroup();
74                 }
75
76                 leLength->setText(sl);
77                 sbNumber->setValue(sn.toInt());
78         }
79         else
80         {
81                 RS_DEBUG->print(RS_Debug::D_ERROR, "LineBisectorOptions::setAction: wrong action type");
82                 action = NULL;
83         }
84 }
85
86 void LineBisectorOptions::updateLength(const QString & l)
87 {
88         if (action != NULL)
89                 action->setLength(RS_Math::eval(l));
90 }
91
92 void LineBisectorOptions::updateNumber(int n)
93 {
94         if (action != NULL)
95                 action->setNumber(n);
96 }