// --- ---------- -----------------------------------------------------------
// 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