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