]> Shamusworld >> Repos - architektonas/blob - src/forms/imageoptions.cpp
In the middle of major refactoring...
[architektonas] / src / forms / imageoptions.cpp
1 // imageoptions.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  05/12/2010  Created this file. :-)
13 //
14
15 #include "imageoptions.h"
16
17 #include "rs.h"
18 #include "settings.h"
19 #include "actiondrawimage.h"
20 #include "actioninterface.h"
21
22 ImageOptions::ImageOptions(QWidget * parent/*= NULL*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags)
24 {
25         ui.setupUi(this);
26 }
27
28 ImageOptions::~ImageOptions()
29 {
30         settings.beginGroup("Image");
31         settings.setValue("ImageAngle", ui.leAngle->text());
32         settings.setValue("ImageFactor", ui.leFactor->text());
33         settings.endGroup();
34 }
35
36 void ImageOptions::setAction(ActionInterface * a, bool update)
37 {
38         if (a != NULL && a->rtti() == RS2::ActionDrawImage)
39         {
40                 action = (ActionDrawImage *)a;
41
42                 QString sAngle;
43                 QString sFactor;
44
45                 if (update)
46                 {
47                         sAngle = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
48                         sFactor = QString("%1").arg(action->getFactor());
49                 }
50                 else
51                 {
52                         settings.beginGroup("Image");
53                         sAngle = settings.value("ImageAngle", "0.0").toString();
54                         sFactor = settings.value("ImageFactor", "1.0").toString();
55                         settings.endGroup();
56                 }
57
58                 ui.leAngle->setText(sAngle);
59                 ui.leFactor->setText(sFactor);
60                 updateData();
61         }
62         else
63         {
64                 RS_DEBUG->print(RS_Debug::D_ERROR, "ImageOptions::setAction: wrong action type");
65                 action = NULL;
66         }
67 }
68
69 void ImageOptions::updateData()
70 {
71         if (action != NULL)
72         {
73                 action->setAngle(RS_Math::deg2rad(RS_Math::eval(ui.leAngle->text())));
74                 action->setFactor(RS_Math::eval(ui.leFactor->text()));
75         }
76 }