]> Shamusworld >> Repos - architektonas/blob - src/forms/dimoptions.cpp
Added more missing forms...
[architektonas] / src / forms / dimoptions.cpp
1 // dimoptions.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/09/2010  Created this file. :-)
13 //
14
15 #include "dimoptions.h"
16
17 #include "rs_actiondimension.h"
18 #include "rs_actioninterface.h"
19 #include "settings.h"
20
21 DimOptions::DimOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
22         QWidget(parent, flags),
23         lLabel(new QLabel(tr("Label:"))),
24         bDiameter(new QToolButton(this)),
25         leLabel(new QLineEdit(this)),
26         cbSymbol(new QComboBox(this)),
27         lTol1(new QLabel()),
28         leTol1(new QLineEdit(this)),
29         lTol2(new QLabel()),
30         leTol2(new QLineEdit(this))
31 {
32         QHBoxLayout * layout = new QHBoxLayout(this);
33         layout->setContentsMargins(0, 0, 0, 0);
34
35         leLabel->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
36         leTol1->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
37         leTol2->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
38         bDiameter->setCheckable(true);
39         bDiameter->setIcon(QIcon(":/res/qg_dimdia"));
40         lTol1->setPixmap(QPixmap(":/res/qg_dimtol1"));
41         lTol2->setPixmap(QPixmap(":/res/qg_dimtol2"));
42
43         QStringList symbols;
44         symbols
45                 << QString::fromUtf8("\303\270")
46                 << QString::fromUtf8("\302\260")
47                 << QString::fromUtf8("\302\261")
48                 << QString::fromUtf8("\302\266")
49                 << QString::fromUtf8("\303\227")
50                 << QString::fromUtf8("\303\267");
51         cbSymbol->addItems(symbols);
52
53         layout->addWidget(lLabel);
54         layout->addWidget(bDiameter);
55         layout->addWidget(leLabel);
56         layout->addWidget(cbSymbol);
57         layout->addWidget(lTol1);
58         layout->addWidget(leTol1);
59         layout->addWidget(lTol2);
60         layout->addWidget(leTol2);
61
62         connect(leLabel, SIGNAL(textChanged(QString)), this, SLOT(updateLabel()));
63         connect(bDiameter, SIGNAL(toggled(bool)), this, SLOT(updateLabel()));
64         connect(leTol1, SIGNAL(textChanged(QString)), this, SLOT(updateLabel()));
65         connect(leTol2, SIGNAL(textChanged(QString)), this, SLOT(updateLabel()));
66         connect(cbSymbol, SIGNAL(activated(QString)), this, SLOT(insertSign(QString)));
67
68         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
69         // nothing will show up on the screen. :-)
70         if (parent)
71                 parent->addWidget(this);
72 }
73
74 DimOptions::~DimOptions()
75 {
76         settings.beginGroup("Draw");
77         settings.setValue("DimLabel", leLabel->text());
78         settings.setValue("DimTol1", leTol1->text());
79         settings.setValue("DimTol2", leTol2->text());
80         settings.endGroup();
81 }
82
83 void DimOptions::setAction(RS_ActionInterface * a, bool update)
84 {
85         if (a != NULL && RS_ActionDimension::isDimensionAction(a->rtti()))
86         {
87                 action = (RS_ActionDimension *)a;
88
89                 QString st;
90                 QString stol1;
91                 QString stol2;
92                 bool diam;
93
94                 if (update)
95                 {
96                         st = action->getLabel();
97                         stol1 = action->getTol1();
98                         stol2 = action->getTol2();
99                         diam = action->getDiameter();
100                 }
101                 else
102                 {
103                         settings.beginGroup("Draw");
104                         st = settings.value("DimLabel", "").toString();
105                         stol1 = settings.value("DimTol1", "").toString();
106                         stol2 = settings.value("DimTol2", "").toString();
107                         diam = settings.value("DimDiameter", false).toBool();
108                         settings.endGroup();
109                 }
110
111                 leLabel->setText(st);
112                 leTol1->setText(stol1);
113                 leTol2->setText(stol2);
114                 bDiameter->setChecked(diam);
115         }
116         else
117         {
118                 RS_DEBUG->print(RS_Debug::D_ERROR, "DimensionOptions::setAction: wrong action type");
119                 action = NULL;
120         }
121 }
122
123 void DimOptions::updateLabel()
124 {
125         if (!action)
126                 return;
127
128         action->setText("");
129         action->setLabel(leLabel->text());
130         action->setDiameter(bDiameter->isChecked());
131         action->setTol1(leTol1->text());
132         action->setTol2(leTol2->text());
133         action->setText(action->getText());
134 }
135
136 void DimOptions::insertSign(const QString & c)
137 {
138         leLabel->insert(c);
139 }