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