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