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 06/11/2010 Created this file. :-)
19 #include "entitycontainer.h"
22 #include "patternlist.h"
25 DlgHatch::DlgHatch(QWidget * parent/*= NULL*/, Qt::WindowFlags flags/*= 0*/):
26 QDialog(parent, flags)
34 preview = new EntityContainer();
35 ui.gvPreview->setContainer(preview);
36 ui.gvPreview->setBorders(15, 15, 15, 15);
45 settings.beginGroup("Draw");
46 settings.setValue("HatchSolid", ui.cbSolid->isChecked());
47 settings.setValue("HatchPattern", ui.cbPattern->currentText());
48 settings.setValue("HatchScale", ui.leScale->text());
49 settings.setValue("HatchAngle", ui.leAngle->text());
50 settings.setValue("HatchPreview", ui.cbEnablePreview->isChecked());
57 void DlgHatch::polish()
59 //WTF is this supposed to be for???
61 ui.gvPreview->zoomAuto();
64 void DlgHatch::showEvent(QShowEvent * e)
66 QDialog::showEvent(e);
67 ui.gvPreview->zoomAuto();
70 void DlgHatch::setHatch(Hatch & h, bool isNew)
75 settings.beginGroup("Draw");
76 bool enablePrev = settings.value("HatchPreview", false).toBool();
79 ui.cbEnablePreview->setChecked(enablePrev);
81 // read defaults from config file:
84 settings.beginGroup("Draw");
85 bool solid = settings.value("HatchSolid", false).toBool();
86 QString pat = settings.value("HatchPattern", "ANSI31").toString();
87 QString scale = settings.value("HatchScale", "1.0").toString();
88 QString angle = settings.value("HatchAngle", "0.0").toString();
91 ui.cbSolid->setChecked(solid);
93 ui.leScale->setText(scale);
94 ui.leAngle->setText(angle);
96 // initialize dialog based on given hatch:
99 ui.cbSolid->setChecked(hatch->isSolid());
100 setPattern(hatch->getPattern());
102 s.setNum(hatch->getScale());
103 ui.leScale->setText(s);
104 s.setNum(Math::rad2deg(hatch->getAngle()));
105 ui.leAngle->setText(s);
109 void DlgHatch::updateHatch()
114 hatch->setSolid(ui.cbSolid->isChecked());
115 hatch->setPattern(ui.cbPattern->currentText());
116 hatch->setScale(Math::eval(ui.leScale->text()));
117 hatch->setAngle(Math::deg2rad(Math::eval(ui.leAngle->text())));
120 void DlgHatch::setPattern(const QString & p)
122 if (!PATTERNLIST->contains(p))
123 // ui.cbPattern->insertItem(p);
124 ui.cbPattern->addItem(p);
126 // ui.cbPattern->setCurrentText(p);
127 ui.cbPattern->setCurrentIndex(ui.cbPattern->findText(p));
128 pattern = ui.cbPattern->getPattern();
131 void DlgHatch::resizeEvent(QResizeEvent *)
136 void DlgHatch::updatePreview()
141 void DlgHatch::updatePreview(Pattern *)
146 if (!hatch || !ui.cbEnablePreview->isChecked())
149 ui.gvPreview->zoomAuto();
153 QString patName = ui.cbPattern->currentText();
154 bool isSolid = ui.cbSolid->isChecked();
156 //double scale = Math::eval(leScale->text(), 1.0);
157 double angle = Math::deg2rad(Math::eval(ui.leAngle->text(), 0.0));
160 prevSize = pattern->getSize().x * 10;
166 Hatch * prevHatch = new Hatch(preview, HatchData(isSolid, 0.2, angle, patName));
167 prevHatch->setPen(hatch->getPen());
169 EntityContainer * loop = new EntityContainer(prevHatch);
170 loop->setPen(Pen(RS2::FlagInvalid));
171 loop->addEntity(new Line(loop, LineData(Vector(0.0, 0.0), Vector(10.0, 0.0))));
172 loop->addEntity(new Line(loop, LineData(Vector(10.0, 0.0), Vector(10.0, 10.0))));
173 loop->addEntity(new Line(loop, LineData(Vector(10.0, 10.0), Vector(0.0, 10.0))));
174 loop->addEntity(new Line(loop, LineData(Vector(0.0, 10.0), Vector(0.0, 0.0))));
175 prevHatch->addEntity(loop);
176 preview->addEntity(prevHatch);
181 ui.gvPreview->zoomAuto();