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