]> Shamusworld >> Repos - architektonas/blob - src/forms/libraryinsertoptions.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / libraryinsertoptions.cpp
1 // libraryinsertoptions.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/10/2010  Created this file. :-)
15 //
16
17 #include "libraryinsertoptions.h"
18
19 #include "actionlibraryinsert.h"
20 #include "settings.h"
21
22 LibraryInsertOptions::LibraryInsertOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags),
24         lAngle(new QLabel(tr("Angle:"))),
25         leAngle(new QLineEdit(this)),
26         lFactor(new QLabel(tr("Factor:"))),
27         leFactor(new QLineEdit(this))
28 {
29         QHBoxLayout * layout = new QHBoxLayout(this);
30         layout->setContentsMargins(0, 0, 0, 0);
31
32         leAngle->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
33         leFactor->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
34
35         layout->addWidget(lAngle);
36         layout->addWidget(leAngle);
37         layout->addWidget(lFactor);
38         layout->addWidget(leFactor);
39
40         connect(leAngle, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
41         connect(leFactor, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
42
43         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
44         // nothing will show up on the screen. :-)
45         if (parent)
46                 parent->addWidget(this);
47 }
48
49 LibraryInsertOptions::~LibraryInsertOptions()
50 {
51         settings.beginGroup("LibraryInsert");
52         settings.setValue("LibraryInsertAngle", leAngle->text());
53         settings.setValue("LibraryInsertFactor", leFactor->text());
54         settings.endGroup();
55 }
56
57 void LibraryInsertOptions::setAction(ActionInterface * a, bool update)
58 {
59         if (a != NULL && a->rtti() == RS2::ActionLibraryInsert)
60         {
61                 action = (ActionLibraryInsert *)a;
62
63                 QString sAngle;
64                 QString sFactor;
65
66                 if (update)
67                 {
68                         sAngle = QString("%1").arg(Math::rad2deg(action->getAngle()));
69                         sFactor = QString("%1").arg(action->getFactor());
70                 }
71                 else
72                 {
73                         settings.beginGroup("LibraryInsert");
74                         sAngle = settings.value("LibraryInsertAngle", "0.0").toString();
75                         sFactor = settings.value("LibraryInsertFactor", "1.0").toString();
76                         settings.endGroup();
77                 }
78
79                 leAngle->setText(sAngle);
80                 leFactor->setText(sFactor);
81         }
82         else
83         {
84                 DEBUG->print(Debug::D_ERROR, "LibraryInsertOptions::setAction: wrong action type");
85                 action = NULL;
86         }
87 }
88
89 void LibraryInsertOptions::updateData()
90 {
91         if (action != NULL)
92         {
93                 action->setAngle(Math::deg2rad(Math::eval(leAngle->text())));
94                 action->setFactor(Math::eval(leFactor->text()));
95         }
96 }
97