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