+// dimoptions.cpp
+//
+// Part of the Architektonas Project
+// Originally part of QCad Community Edition by Andrew Mustun
+// Extensively rewritten and refactored by James L. Hammons
+// (C) 2010 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who When What
+// --- ---------- -----------------------------------------------------------
+// JLH 06/09/2010 Created this file. :-)
+//
+
+#include "dimoptions.h"
+
+#include "rs_actiondimension.h"
+#include "rs_actioninterface.h"
+#include "settings.h"
+
+DimOptions::DimOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
+ QWidget(parent, flags),
+ lLabel(new QLabel(tr("Label:"))),
+ bDiameter(new QToolButton(this)),
+ leLabel(new QLineEdit(this)),
+ cbSymbol(new QComboBox(this)),
+ lTol1(new QLabel()),
+ leTol1(new QLineEdit(this)),
+ lTol2(new QLabel()),
+ leTol2(new QLineEdit(this))
+{
+ QHBoxLayout * layout = new QHBoxLayout(this);
+ layout->setContentsMargins(0, 0, 0, 0);
+
+ leLabel->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
+ leTol1->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
+ leTol2->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
+ bDiameter->setCheckable(true);
+ bDiameter->setIcon(QIcon(":/res/qg_dimdia"));
+ lTol1->setPixmap(QPixmap(":/res/qg_dimtol1"));
+ lTol2->setPixmap(QPixmap(":/res/qg_dimtol2"));
+
+ QStringList symbols;
+ symbols
+ << QString::fromUtf8("\303\270")
+ << QString::fromUtf8("\302\260")
+ << QString::fromUtf8("\302\261")
+ << QString::fromUtf8("\302\266")
+ << QString::fromUtf8("\303\227")
+ << QString::fromUtf8("\303\267");
+ cbSymbol->addItems(symbols);
+
+ layout->addWidget(lLabel);
+ layout->addWidget(bDiameter);
+ layout->addWidget(leLabel);
+ layout->addWidget(cbSymbol);
+ layout->addWidget(lTol1);
+ layout->addWidget(leTol1);
+ layout->addWidget(lTol2);
+ layout->addWidget(leTol2);
+
+ connect(leLabel, SIGNAL(textChanged(QString)), this, SLOT(updateLabel()));
+ connect(bDiameter, SIGNAL(toggled(bool)), this, SLOT(updateLabel()));
+ connect(leTol1, SIGNAL(textChanged(QString)), this, SLOT(updateLabel()));
+ connect(leTol2, SIGNAL(textChanged(QString)), this, SLOT(updateLabel()));
+ connect(cbSymbol, SIGNAL(activated(QString)), this, SLOT(insertSign(QString)));
+
+ // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
+ // nothing will show up on the screen. :-)
+ if (parent)
+ parent->addWidget(this);
+}
+
+DimOptions::~DimOptions()
+{
+ settings.beginGroup("Draw");
+ settings.setValue("DimLabel", leLabel->text());
+ settings.setValue("DimTol1", leTol1->text());
+ settings.setValue("DimTol2", leTol2->text());
+ settings.endGroup();
+}
+
+void DimOptions::setAction(RS_ActionInterface * a, bool update)
+{
+ if (a != NULL && RS_ActionDimension::isDimensionAction(a->rtti()))
+ {
+ action = (RS_ActionDimension *)a;
+
+ QString st;
+ QString stol1;
+ QString stol2;
+ bool diam;
+
+ if (update)
+ {
+ st = action->getLabel();
+ stol1 = action->getTol1();
+ stol2 = action->getTol2();
+ diam = action->getDiameter();
+ }
+ else
+ {
+ settings.beginGroup("Draw");
+ st = settings.value("DimLabel", "").toString();
+ stol1 = settings.value("DimTol1", "").toString();
+ stol2 = settings.value("DimTol2", "").toString();
+ diam = settings.value("DimDiameter", false).toBool();
+ settings.endGroup();
+ }
+
+ leLabel->setText(st);
+ leTol1->setText(stol1);
+ leTol2->setText(stol2);
+ bDiameter->setChecked(diam);
+ }
+ else
+ {
+ RS_DEBUG->print(RS_Debug::D_ERROR, "DimensionOptions::setAction: wrong action type");
+ action = NULL;
+ }
+}
+
+void DimOptions::updateLabel()
+{
+ if (!action)
+ return;
+
+ action->setText("");
+ action->setLabel(leLabel->text());
+ action->setDiameter(bDiameter->isChecked());
+ action->setTol1(leTol1->text());
+ action->setTol2(leTol2->text());
+ action->setText(action->getText());
+}
+
+void DimOptions::insertSign(const QString & c)
+{
+ leLabel->insert(c);
+}