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