# Architektonas Qt project file
#
# by James L. Hammons
-# (C) 2010 Underground Software
+# Copyright (C) 2010 Underground Software
#
# Parts are based on QCad Community Edition by Andrew Mustun
+# See the README and GPLv2 files for licensing and warranty information
#
CONFIG += qt warn_on release debug
*/
RS_StaticGraphicView::RS_StaticGraphicView(int w, int h, PaintInterface * p): /*painter(p),*/ width(w), height(h)
{
+//#warning "!!! PaintInterface * p passed in constructor is IGNORED !!!"
+//Not strictly true: it sets painter down below there...
setBackground(RS_Color(255, 255, 255));
painter = p;
setBorders(5, 5, 5, 5);
RS2::Unit ret = RS2::None;
if (u == "None")
- {
ret = RS2::None;
- }
else if (u == QObject::tr("Inch"))
- {
ret = RS2::Inch;
- }
- else if (u==QObject::tr("Foot"))
- {
+ else if (u == QObject::tr("Foot"))
ret = RS2::Foot;
- }
- else if (u==QObject::tr("Mile"))
- {
+ else if (u == QObject::tr("Mile"))
ret = RS2::Mile;
- }
- else if (u==QObject::tr("Millimeter"))
- {
+ else if (u == QObject::tr("Millimeter"))
ret = RS2::Millimeter;
- }
- else if (u==QObject::tr("Centimeter"))
- {
+ else if (u == QObject::tr("Centimeter"))
ret = RS2::Centimeter;
- }
- else if (u==QObject::tr("Meter"))
- {
+ else if (u == QObject::tr("Meter"))
ret = RS2::Meter;
- }
- else if (u==QObject::tr("Kilometer"))
- {
+ else if (u == QObject::tr("Kilometer"))
ret = RS2::Kilometer;
- }
- else if (u==QObject::tr("Microinch"))
- {
+ else if (u == QObject::tr("Microinch"))
ret = RS2::Microinch;
- }
- else if (u==QObject::tr("Mil"))
- {
+ else if (u == QObject::tr("Mil"))
ret = RS2::Mil;
- }
- else if (u==QObject::tr("Yard"))
- {
+ else if (u == QObject::tr("Yard"))
ret = RS2::Yard;
- }
- else if (u==QObject::tr("Angstrom"))
- {
+ else if (u == QObject::tr("Angstrom"))
ret = RS2::Angstrom;
- }
- else if (u==QObject::tr("Nanometer"))
- {
+ else if (u == QObject::tr("Nanometer"))
ret = RS2::Nanometer;
- }
- else if (u==QObject::tr("Micron"))
- {
+ else if (u == QObject::tr("Micron"))
ret = RS2::Micron;
- }
- else if (u==QObject::tr("Decimeter"))
- {
+ else if (u == QObject::tr("Decimeter"))
ret = RS2::Decimeter;
- }
- else if (u==QObject::tr("Decameter"))
- {
+ else if (u == QObject::tr("Decameter"))
ret = RS2::Decameter;
- }
- else if (u==QObject::tr("Hectometer"))
- {
+ else if (u == QObject::tr("Hectometer"))
ret = RS2::Hectometer;
- }
- else if (u==QObject::tr("Gigameter"))
- {
+ else if (u == QObject::tr("Gigameter"))
ret = RS2::Gigameter;
- }
- else if (u==QObject::tr("Astro"))
- {
+ else if (u == QObject::tr("Astro"))
ret = RS2::Astro;
- }
- else if (u==QObject::tr("Lightyear"))
- {
+ else if (u == QObject::tr("Lightyear"))
ret = RS2::Lightyear;
- }
- else if (u==QObject::tr("Parsec"))
- {
+ else if (u == QObject::tr("Parsec"))
ret = RS2::Parsec;
- }
return ret;
}
unitString = unitToSign(unit);
}*/
- // barbarian display: show as fraction:
- switch (format)
+ // Barbarian display: Show as fraction:
+ switch (format)
{
- case RS2::Scientific:
- ret = formatScientific(length, unit, prec, showUnit);
- break;
+ case RS2::Scientific:
+ ret = formatScientific(length, unit, prec, showUnit);
+ break;
- case RS2::Decimal:
- ret = formatDecimal(length, unit, prec, showUnit);
- break;
+ case RS2::Decimal:
+ ret = formatDecimal(length, unit, prec, showUnit);
+ break;
- case RS2::Engineering:
- ret = formatEngineering(length, unit, prec, showUnit);
- break;
+ case RS2::Engineering:
+ ret = formatEngineering(length, unit, prec, showUnit);
+ break;
- case RS2::Architectural:
- ret = formatArchitectural(length, unit, prec, showUnit);
- break;
+ case RS2::Architectural:
+ ret = formatArchitectural(length, unit, prec, showUnit);
+ break;
- case RS2::Fractional:
- ret = formatFractional(length, unit, prec, showUnit);
- break;
+ case RS2::Fractional:
+ ret = formatFractional(length, unit, prec, showUnit);
+ break;
- default:
- RS_DEBUG->print(RS_Debug::D_WARNING,
+ default:
+ RS_DEBUG->print(RS_Debug::D_WARNING,
"RS_Units::formatLinear: Unknown format");
- ret = "";
- break;
- }
+ ret = "";
+ break;
+ }
- return ret;
+ return ret;
}
/**
// --- ---------- -----------------------------------------------------------
// JLH 05/10/2010 Created this file. :-)
// JLH 08/28/2010 Restored functionality to library browser
+// JLH 09/06/2010 Partially fixed thumbnail rendering
//
+/*
+BUGS:
+
+- Picks up thumbnail directories twice--only once if thumbnail dir doesn't exist
+*/
+
#include "librarywidget.h"
#include "actionhandler.h"
// List of all directories that contain part libraries:
QStringList directoryList = RS_SYSTEM->getDirectoryList("library");
- directoryList.prepend(RS_SYSTEM->getHomeDir() + "/.qcad/library");
+ directoryList.prepend(RS_SYSTEM->getHomeDir() + "/.architektonas/library");
QStringList::Iterator it;
QFileInfo fiDxf(dxfPath);
}
}
- // the thumbnail must be created in the user's home.
-
- // create all directories needed:
- RS_SYSTEM->createHomePath("/.qcad/library" + dir);
- /*QString d = "/.qcad/library" + dir;
- QDir dr;
-
- QStringList dirs = QStringList::split('/', d, false);
- QString created = RS_SYSTEM->getHomeDir();
- for (it=dirs.begin(); it!=dirs.end(); ++it) {
- created += QString("/%1").arg(*it);
-
- if (created.isEmpty() || QFileInfo(created).isDir() || dr.mkdir(created, true)) {
- RS_DEBUG->print("LibraryWidget: Created directory '%s'",
- created.toLatin1().data());
- }
- else {
- RS_DEBUG->print(RS_Debug::D_ERROR,
- "LibraryWidget: Cannot create directory '%s'",
- created.toLatin1().data());
- return "";
- }
-}
- */
+ // The thumbnail must be created in the user's home.
+ // So, create all directories needed:
+ RS_SYSTEM->createHomePath("/.architektonas/library" + dir);
- QString d = RS_SYSTEM->getHomeDir() + "/.qcad/library" + dir;
+ QString d = RS_SYSTEM->getHomeDir() + "/.architektonas/library" + dir;
+//printf("librarywidget: d = \"%s\"\n", d.toAscii().data());
// pngPath = d + "/" + fiDxf.baseName(true) + ".png";
pngPath = d + "/" + fiDxf.completeBaseName() + ".png";
+//printf("librarywidget: pngPath = \"%s\"\n", pngPath.toAscii().data());
- QPixmap * buffer = new QPixmap(128, 128);
-// RS_PainterQt * painter = new RS_PainterQt(buffer);
- QPainter qpntr(buffer);
+ // Ugh. This is a mess and doesn't work right anyway...
+ // Problem is StaticGraphicView doesn't follow a standard rendering path,
+ // so all this crap just ends in failure. Not sure how to fix.
+/**
+I suppose one way to do it would be to make a CreateImage() function in GraphicView,
+then we wouldn't have all this messiness...
+I think the way the redraw works is like that--it creates its own PaintInterface
+and QPainter and sets "painter" equal to it... That being the case, it would be
+a simple matter to modify StaticGraphicView to utilize that... Let's see...
+Which it should be doing, but, for some reason, it fails. Dunno why.
+
+It only fails for certain DXFs. Dunno why.
+*/
+
+ QPixmap buffer(128, 128);
+ QPainter qpntr(&buffer);
PaintInterface * painter = new PaintInterface(&qpntr);
-// painter->setBackgroundColor(RS_Color(255, 255, 255));
-// painter->eraseRect(0, 0, 128, 128);
-// qpntr.setBackgroundColor(RS_Color(255, 255, 255));
qpntr.setBackground(Qt::white);
qpntr.eraseRect(0, 0, 128, 128);
RS_StaticGraphicView gv(128, 128, painter);
- Drawing graphic;
+ Drawing drawing;
- if (graphic.open(dxfPath, RS2::FormatUnknown))
+ if (drawing.open(dxfPath, RS2::FormatUnknown))
{
RS_Color black(0, 0, 0);
- for(RS_Entity * e=graphic.firstEntity(RS2::ResolveAll); e!=NULL; e=graphic.nextEntity(RS2::ResolveAll))
+ // Set all pens in the drawing to BLACK
+ for(RS_Entity * e=drawing.firstEntity(RS2::ResolveAll); e!=NULL; e=drawing.nextEntity(RS2::ResolveAll))
{
RS_Pen pen = e->getPen();
pen.setColor(black);
e->setPen(pen);
}
- gv.setContainer(&graphic);
+ gv.setContainer(&drawing);
gv.zoomAuto(false);
- gv.drawEntity(&graphic, true);
+//This works, but somehow doesn't work ALL the time
+ gv.drawEntity(&drawing, true);
-#if 0
- QImageIO iio;
- QImage img;
- img = *buffer;
- img = img.smoothScale(64, 64);
- iio.setImage(img);
- iio.setFileName(pngPath);
- iio.setFormat("PNG");
-
- if (!iio.write())
+ QImageWriter writer;
+ QImage image = buffer.toImage();
+ image.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ writer.setFileName(pngPath);
+ writer.setFormat("png");
+
+ if (!writer.write(image))
{
- pngPath = "";
RS_DEBUG->print(RS_Debug::D_ERROR,
"LibraryWidget::getPathToPixmap: Cannot write thumbnail: '%s'",
pngPath.toLatin1().data());
+ pngPath = "";
}
-#else
-#warning "LibraryWidget::getPathToPixmap(): Needs porting to Qt4... !!! FIX !!!"
-#endif
}
else
{
}
delete painter;
- delete buffer;
return pngPath;
}
+
+#if 0
+
+QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible
+QPaintDevice: Cannot destroy paint device that is being painted
+
+Program received signal SIGSEGV, Segmentation fault.
+0x085cd068 in ?? ()
+(gdb) bt
+#0 0x085cd068 in ?? ()
+#1 0xb7818bd0 in QPainter::~QPainter() () from /usr/lib/qt4/libQtGui.so.4
+#2 0x081c1e8e in LibraryWidget::getPathToPixmap(QString const&, QString const&, QString const&) ()
+#3 0x081c0fa6 in LibraryWidget::getPixmap(QString const&, QString const&, QString const&) ()
+#4 0x081c0775 in LibraryWidget::updatePreview(QTreeWidgetItem*, int) ()
+#5 0x08237d5e in LibraryWidget::qt_metacall(QMetaObject::Call, int, void**) ()
+
+#endif
QPoint p = mapFromGlobal(QCursor::pos());
RS_Block * b = lastBlock;
+//This is crap. We need to fix this so it's not so shitty.
if (p.x() < 23)
{
actionHandler->slotBlocksToggleView();
}
/**
- * Called when the color has changed. This method
- * sets the current color to the value chosen or even
- * offers a dialog to the user that allows him/ her to
+ * Called when the color has changed. This method sets the current color to
+ * the value chosen or even offers a dialog to the user that allows him/her to
* choose an individual color.
*/
void LayerBox::slotLayerChanged(int index)
RS_Layer * l = lastLayer;
#warning "!!! Bad implementation of lock/freeze functionality !!!"
+//This is crap.
if (p.x() < 23)
{
actionHandler->slotLayersToggleView();
// Qt4 handles double buffering of screen writes now, so this needs
// a rewrite.
-#warning "!!! Need to pass a valid QPainter to drawIt() !!!"
+//#warning "!!! Need to pass a valid QPainter to drawIt() !!!"
QPainter pntr(this);
pntr.setBackgroundMode(Qt::OpaqueMode);
//just may go that way...
drawIt();
- // Draw the snapper first, we want to be able to see the preview on top of
- // this...
+ // Draw the snapper first, because we want to be able to see the preview on
+ // top of this...
if (snapper.Visible())
snapper.Draw(this, painter);
if (preview.Visible())
-#if 0
- {
- painter->setPen(RS_Pen(RS_Color(60, 255, 80), RS2::Width00, RS2::SolidLine));
- painter->setOffset(preview.Offset());
-
- // We have to traverse the container ourselves, because RS_Container::draw()
- // uses drawEntity() instead of drawEntityPlain()...
- for(RS_Entity * e=preview.firstEntity(RS2::ResolveNone); e!=NULL;
- e = preview.nextEntity(RS2::ResolveNone))
- {
- drawEntityPlain(e);
- }
-
- painter->setOffset(Vector(0, 0));
- }
-#else
preview.Draw(this, painter);
-#endif
delete painter;
painter = NULL;