1 // printpreviewoptions.cpp
3 // Originally part of QCad Community Edition by Andrew Mustun
4 // Extensively rewritten and refactored by James L. Hammons
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -----------------------------------------------------------
11 // JLH 05/10/2010 Created this file. :-)
14 #include "printpreviewoptions.h"
17 #include "rs_actioninterface.h"
18 #include "rs_actionprintpreview.h"
20 PrintPreviewOptions::PrintPreviewOptions(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
21 QWidget(parent, flags), updateDisabled(false)
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";
51 PrintPreviewOptions::~PrintPreviewOptions()
54 RS_SETTINGS->beginGroup("/PrintPreview");
55 RS_SETTINGS->writeEntry("/PrintPreviewAngle", leAngle->text());
56 RS_SETTINGS->writeEntry("/PrintPreviewFactor", leFactor->text());
57 RS_SETTINGS->endGroup();
61 void PrintPreviewOptions::setAction(RS_ActionInterface* a, bool/*update*/)
63 if (a != NULL && a->rtti() == RS2::ActionPrintPreview)
65 action = (RS_ActionPrintPreview *)a;
67 updateDisabled = true;
68 RS2::Unit u = action->getUnit();
71 // ui.cbScale->insertStringList(imperialScales);
72 ui.cbScale->addItems(imperialScales);
74 // ui.cbScale->insertStringList(metricScales);
75 ui.cbScale->addItems(metricScales);
79 s.setNum(action->getScale());
80 // ui.cbScale->setCurrentText(s);
81 ui.cbScale->setItemText(ui.cbScale->currentIndex(), s);
84 updateDisabled = false;
90 sAngle = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
91 sFactor = QString("%1").arg(action->getFactor());
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();
98 leAngle->setText(sAngle);
99 leFactor->setText(sFactor);
105 RS_DEBUG->print(RS_Debug::D_ERROR, "QG_PrintPreviewOptions::setAction: wrong action type");
110 void PrintPreviewOptions::updateData()
115 action->setAngle(RS_Math::deg2rad(RS_Math::eval(leAngle->text())));
116 action->setFactor(RS_Math::eval(leFactor->text()));
121 void PrintPreviewOptions::center()
127 void PrintPreviewOptions::setBlackWhite(bool on)
130 action->setBlackWhite(on);
133 void PrintPreviewOptions::fit()
139 void PrintPreviewOptions::scale(const QString & s)
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);
153 if (ok1 && ok2 && d > 1.0e-6 && n > 0.0)
154 action->setScale(n / d);
156 else if (s.contains('='))
159 // int i = s.find('=');
160 int i = s.indexOf('=');
161 double d = s.mid(i + 2, s.length() - i - 3).toDouble(&ok);
163 if (ok && d > 1.0e-6)
164 action->setScale(1.0 / d);
169 double f = RS_Math::eval(s, &ok);