]> Shamusworld >> Repos - architektonas/blob - src/forms/printpreviewoptions.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / printpreviewoptions.cpp
1 // printpreviewoptions.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/10/2010  Created this file. :-)
15 //
16
17 #include "printpreviewoptions.h"
18
19 #include "enums.h"
20 #include "actioninterface.h"
21 #include "actionprintpreview.h"
22 #include "debug.h"
23 #include "mathextra.h"
24
25 //PrintPreviewOptions::PrintPreviewOptions(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
26 PrintPreviewOptions::PrintPreviewOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
27         QWidget(parent, flags), updateDisabled(false)
28 {
29         imperialScales
30                 << "1\" = 1\""
31                 << "1\" = 2\""
32                 << "1\" = 4\""
33                 << "1\" = 8\""
34                 << "1\" = 16\""
35                 << "1\" = 32\""
36                 << "1\" = 64\""
37                 << "1\" = 128\""
38                 << "1\" = 256\"";
39
40         metricScales
41                 << "1:1" << "1:2" << "1:5" << "1:10"
42                 << "1:20" << "1:25" << "1:50" << "1:75" << "1:100"
43                 << "1:125" << "1:150" << "1:175" << "1:200"
44                 << "1:250" << "1:500" << "1:750" << "1:1000"
45                 << "1:2500" << "1:5000" << "1:7500" << "1:10000"
46                 << "1:25000" << "1:50000" << "1:75000" << "1:100000"
47                 << "2:1" << "5:1" << "10:1"
48                 << "20:1" << "25:1" << "50:1" << "75:1" << "100:1"
49                 << "125:1" << "150:1" << "175:1" << "200:1"
50                 << "250:1" << "500:1" << "750:1" << "1000:1"
51                 << "2500:1" << "5000:1" << "7500:1" << "10000:1"
52                 << "25000:1" << "50000:1" << "75000:1" << "100000:1";
53
54         ui.setupUi(this);
55
56         if (parent)
57                 parent->addWidget(this);
58 }
59
60 PrintPreviewOptions::~PrintPreviewOptions()
61 {
62         /*
63         RS_SETTINGS->beginGroup("/PrintPreview");
64         RS_SETTINGS->writeEntry("/PrintPreviewAngle", leAngle->text());
65         RS_SETTINGS->writeEntry("/PrintPreviewFactor", leFactor->text());
66         RS_SETTINGS->endGroup();
67         */
68 }
69
70 void PrintPreviewOptions::setAction(ActionInterface * a, bool/*update*/)
71 {
72         if (a != NULL && a->rtti() == RS2::ActionPrintPreview)
73         {
74                 action = (ActionPrintPreview *)a;
75
76                 updateDisabled = true;
77                 RS2::Unit u = action->getUnit();
78
79                 if (u==RS2::Inch)
80 //                      ui.cbScale->insertStringList(imperialScales);
81                         ui.cbScale->addItems(imperialScales);
82                 else
83 //                      ui.cbScale->insertStringList(metricScales);
84                         ui.cbScale->addItems(metricScales);
85
86                 //if (update) {
87                 QString s;
88                 s.setNum(action->getScale());
89 //              ui.cbScale->setCurrentText(s);
90                 ui.cbScale->setItemText(ui.cbScale->currentIndex(), s);
91         //}
92
93                 updateDisabled = false;
94
95                 /*
96                 QString sAngle;
97                 QString sFactor;
98                 if (update) {
99                         sAngle = QString("%1").arg(Math::rad2deg(action->getAngle()));
100                         sFactor = QString("%1").arg(action->getFactor());
101         } else {
102                         RS_SETTINGS->beginGroup("/PrintPreview");
103                         sAngle = RS_SETTINGS->readEntry("/PrintPreviewAngle", "0.0");
104                         sFactor = RS_SETTINGS->readEntry("/PrintPreviewFactor", "1.0");
105                         RS_SETTINGS->endGroup();
106         }
107                 leAngle->setText(sAngle);
108                 leFactor->setText(sFactor);
109                 updateData();
110                 */
111         }
112         else
113         {
114                 DEBUG->print(Debug::D_ERROR, "QG_PrintPreviewOptions::setAction: wrong action type");
115                 action = NULL;
116         }
117 }
118
119 void PrintPreviewOptions::updateData()
120 {
121         if (action != NULL)
122         {
123                 /*
124                 action->setAngle(Math::deg2rad(Math::eval(leAngle->text())));
125                 action->setFactor(Math::eval(leFactor->text()));
126                 */
127         }
128 }
129
130 void PrintPreviewOptions::center()
131 {
132         if (action != NULL)
133                 action->center();
134 }
135
136 void PrintPreviewOptions::setBlackWhite(bool on)
137 {
138         if (action != NULL)
139                 action->setBlackWhite(on);
140 }
141
142 void PrintPreviewOptions::fit()
143 {
144         if (action != NULL)
145                 action->fit();
146 }
147
148 void PrintPreviewOptions::scale(const QString & s)
149 {
150         if (updateDisabled)
151                 return;
152
153         if (s.contains(':'))
154         {
155                 bool ok1 = false;
156                 bool ok2 = false;
157                 int i = s.indexOf(':');
158                 double n = s.left(i).toDouble(&ok1);
159                 double d = s.mid(i + 1).toDouble(&ok2);
160
161                 if (ok1 && ok2 && d > 1.0e-6 && n > 0.0)
162                         action->setScale(n / d);
163         }
164         else if (s.contains('='))
165         {
166                 bool ok = false;
167                 int i = s.indexOf('=');
168                 double d = s.mid(i + 2, s.length() - i - 3).toDouble(&ok);
169
170                 if (ok && d > 1.0e-6)
171                         action->setScale(1.0 / d);
172         }
173         else
174         {
175                 bool ok = false;
176                 double f = Math::eval(s, &ok);
177
178                 if (ok)
179                         action->setScale(f);
180         }
181 }