1 // printpreviewoptions.cpp
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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/10/2010 Created this file. :-)
17 #include "printpreviewoptions.h"
20 #include "actioninterface.h"
21 #include "actionprintpreview.h"
23 #include "mathextra.h"
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)
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";
57 parent->addWidget(this);
60 PrintPreviewOptions::~PrintPreviewOptions()
63 RS_SETTINGS->beginGroup("/PrintPreview");
64 RS_SETTINGS->writeEntry("/PrintPreviewAngle", leAngle->text());
65 RS_SETTINGS->writeEntry("/PrintPreviewFactor", leFactor->text());
66 RS_SETTINGS->endGroup();
70 void PrintPreviewOptions::setAction(ActionInterface * a, bool/*update*/)
72 if (a != NULL && a->rtti() == RS2::ActionPrintPreview)
74 action = (ActionPrintPreview *)a;
76 updateDisabled = true;
77 RS2::Unit u = action->getUnit();
80 // ui.cbScale->insertStringList(imperialScales);
81 ui.cbScale->addItems(imperialScales);
83 // ui.cbScale->insertStringList(metricScales);
84 ui.cbScale->addItems(metricScales);
88 s.setNum(action->getScale());
89 // ui.cbScale->setCurrentText(s);
90 ui.cbScale->setItemText(ui.cbScale->currentIndex(), s);
93 updateDisabled = false;
99 sAngle = QString("%1").arg(Math::rad2deg(action->getAngle()));
100 sFactor = QString("%1").arg(action->getFactor());
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();
107 leAngle->setText(sAngle);
108 leFactor->setText(sFactor);
114 DEBUG->print(Debug::D_ERROR, "QG_PrintPreviewOptions::setAction: wrong action type");
119 void PrintPreviewOptions::updateData()
124 action->setAngle(Math::deg2rad(Math::eval(leAngle->text())));
125 action->setFactor(Math::eval(leFactor->text()));
130 void PrintPreviewOptions::center()
136 void PrintPreviewOptions::setBlackWhite(bool on)
139 action->setBlackWhite(on);
142 void PrintPreviewOptions::fit()
148 void PrintPreviewOptions::scale(const QString & s)
157 int i = s.indexOf(':');
158 double n = s.left(i).toDouble(&ok1);
159 double d = s.mid(i + 1).toDouble(&ok2);
161 if (ok1 && ok2 && d > 1.0e-6 && n > 0.0)
162 action->setScale(n / d);
164 else if (s.contains('='))
167 int i = s.indexOf('=');
168 double d = s.mid(i + 2, s.length() - i - 3).toDouble(&ok);
170 if (ok && d > 1.0e-6)
171 action->setScale(1.0 / d);
176 double f = Math::eval(s, &ok);