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 "actioninterface.h"
18 #include "actionprintpreview.h"
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)
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";
54 parent->addWidget(this);
57 PrintPreviewOptions::~PrintPreviewOptions()
60 RS_SETTINGS->beginGroup("/PrintPreview");
61 RS_SETTINGS->writeEntry("/PrintPreviewAngle", leAngle->text());
62 RS_SETTINGS->writeEntry("/PrintPreviewFactor", leFactor->text());
63 RS_SETTINGS->endGroup();
67 void PrintPreviewOptions::setAction(ActionInterface * a, bool/*update*/)
69 if (a != NULL && a->rtti() == RS2::ActionPrintPreview)
71 action = (ActionPrintPreview *)a;
73 updateDisabled = true;
74 RS2::Unit u = action->getUnit();
77 // ui.cbScale->insertStringList(imperialScales);
78 ui.cbScale->addItems(imperialScales);
80 // ui.cbScale->insertStringList(metricScales);
81 ui.cbScale->addItems(metricScales);
85 s.setNum(action->getScale());
86 // ui.cbScale->setCurrentText(s);
87 ui.cbScale->setItemText(ui.cbScale->currentIndex(), s);
90 updateDisabled = false;
96 sAngle = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
97 sFactor = QString("%1").arg(action->getFactor());
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();
104 leAngle->setText(sAngle);
105 leFactor->setText(sFactor);
111 RS_DEBUG->print(RS_Debug::D_ERROR, "QG_PrintPreviewOptions::setAction: wrong action type");
116 void PrintPreviewOptions::updateData()
121 action->setAngle(RS_Math::deg2rad(RS_Math::eval(leAngle->text())));
122 action->setFactor(RS_Math::eval(leFactor->text()));
127 void PrintPreviewOptions::center()
133 void PrintPreviewOptions::setBlackWhite(bool on)
136 action->setBlackWhite(on);
139 void PrintPreviewOptions::fit()
145 void PrintPreviewOptions::scale(const QString & s)
154 int i = s.indexOf(':');
155 double n = s.left(i).toDouble(&ok1);
156 double d = s.mid(i + 1).toDouble(&ok2);
158 if (ok1 && ok2 && d > 1.0e-6 && n > 0.0)
159 action->setScale(n / d);
161 else if (s.contains('='))
164 int i = s.indexOf('=');
165 double d = s.mid(i + 2, s.length() - i - 3).toDouble(&ok);
167 if (ok && d > 1.0e-6)
168 action->setScale(1.0 / d);
173 double f = RS_Math::eval(s, &ok);