1 // lineangleoptions.cpp
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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/10/2010 Created this file. :-)
17 #include "lineangleoptions.h"
19 #include "actiondrawlineangle.h"
23 LineAngleOptions::LineAngleOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
24 QWidget(parent, flags),
25 lAngle(new QLabel(tr("Angle:"))),
26 leAngle(new QLineEdit(this)),
27 lLength(new QLabel(tr("Length:"))),
28 leLength(new QLineEdit(this)),
29 lSnapPoint(new QLabel(tr("Snap Point:"))),
30 cbSnapPoint(new QComboBox(this))
32 QHBoxLayout * layout = new QHBoxLayout(this);
33 layout->setContentsMargins(0, 0, 0, 0);
36 items << "Start" << "Middle" << "End";
37 cbSnapPoint->addItems(items);
39 leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
40 leLength->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
42 layout->addWidget(lAngle);
43 layout->addWidget(leAngle);
44 layout->addWidget(lLength);
45 layout->addWidget(leLength);
46 layout->addWidget(lSnapPoint);
47 layout->addWidget(cbSnapPoint);
49 connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateAngle(QString)));
50 connect(leLength, SIGNAL(textChanged(QString)), this, SLOT(updateLength(QString)));
51 connect(cbSnapPoint, SIGNAL(activated(int)), this, SLOT(updateSnapPoint(int)));
53 // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
54 // nothing will show up on the screen. :-)
56 parent->addWidget(this);
59 LineAngleOptions::~LineAngleOptions()
63 settings.beginGroup("Draw");
65 if (!action->hasFixedAngle())
66 settings.setValue("LineAngleAngle", Math::rad2deg(action->getAngle()));
68 settings.setValue("LineAngleLength", action->getLength());
69 settings.setValue("LineAngleSnapPoint", action->getSnapPoint());
74 void LineAngleOptions::setAction(ActionInterface * a, bool update)
76 if (a && a->rtti() == RS2::ActionDrawLineAngle)
78 action = (ActionDrawLineAngle *)a;
80 if (action->hasFixedAngle())
89 // settings from action:
92 sa = QString("%1").arg(Math::rad2deg(action->getAngle()));
93 sl = QString("%1").arg(action->getLength());
94 sp = action->getSnapPoint();
96 // settings from config file:
99 settings.beginGroup("Draw");
101 if (!action->hasFixedAngle())
102 sa = settings.value("LineAngleAngle", "30.0").toString();
104 sa = QString("%1").arg(action->getAngle());
106 sl = settings.value("LineAngleLength", "10.0").toString();
107 sp = settings.value("LineAngleSnapPoint", 0).toInt();
109 action->setSnapPoint(sp);
112 leAngle->setText(sa);
113 leLength->setText(sl);
114 cbSnapPoint->setCurrentIndex(sp);
118 DEBUG->print(Debug::D_ERROR, "LineAngleOptions::setAction: wrong action type");
123 void LineAngleOptions::updateAngle(const QString & a)
125 if (action && !action->hasFixedAngle())
126 action->setAngle(Math::deg2rad(Math::eval(a)));
129 void LineAngleOptions::updateLength(const QString & l)
132 action->setLength(Math::eval(l));
135 void LineAngleOptions::updateSnapPoint(int sp)
138 action->setSnapPoint(sp);