X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fforms%2Flibrarywidget.cpp;h=607b5a1ad040d29021e1e36326c6188176f706cd;hb=3239ef39dcee08fa6e8cd68cdf2727fc68cc7a8c;hp=ebb8acb0319e19d11b904f0ba68558da7baa426e;hpb=bd2b29c8735d83ab48df13c3efee53f63570473e;p=architektonas diff --git a/src/forms/librarywidget.cpp b/src/forms/librarywidget.cpp index ebb8acb..607b5a1 100644 --- a/src/forms/librarywidget.cpp +++ b/src/forms/librarywidget.cpp @@ -13,15 +13,26 @@ // --- ---------- ----------------------------------------------------------- // JLH 05/10/2010 Created this file. :-) // JLH 08/28/2010 Restored functionality to library browser +// JLH 09/06/2010 Partially fixed thumbnail rendering +// JLH 09/07/2010 Fully fixed thumbnail rendering // +/* +Note that this is basically just a way to get a block from a file; it's unclear +that it does so and the doco (such as it was) didn't mention it either. So what +we need is to make it very clear that inserting is to the BLOCK list and not +the document--perhaps we need to fold it into the block list, and make the +insert function insert into the block list only... +Also, it would be useful to have some information like base unit, dimensions, etc. +*/ + #include "librarywidget.h" #include "actionhandler.h" #include "actionlibraryinsert.h" #include "drawing.h" -#include "rs_staticgraphicview.h" -#include "rs_system.h" +#include "staticgraphicview.h" +#include "system.h" #include "paintinterface.h" LibraryWidget::LibraryWidget(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/): @@ -150,6 +161,11 @@ void LibraryWidget::appendTree(QTreeWidgetItem * item, QString directory) newItem = (item ? new QTreeWidgetItem(item, list) : new QTreeWidgetItem(ui.lvDirectory, list)); } +//This is picking up the directory tree TWICE, but ONLY if there are no thumbnails! +//Actually, only if there is no corresponding thumbnail DIRECTORY under .architektonas... +//Dunno why... +//It was picking up .architektonas from the home directory in rs_system.cpp, that's why! +//printf("LibraryWidget::appendTree: *it=\"%s\"\n", (*it).toAscii().data()); appendTree(newItem, directory + "/" + (*it)); } } @@ -207,6 +223,7 @@ void LibraryWidget::updatePreview(QTreeWidgetItem * item, int /*column*/) newItem = new QListWidgetItem(QIcon(pixmap), label, ui.ivPreview); //Doesn't do what we want... // newItem->setSizeHint(QSize(64, 64)); +//printf("LibraryWidget: label = \"%s\"\n", label.toAscii().data()); } QApplication::restoreOverrideCursor(); @@ -265,7 +282,7 @@ QString LibraryWidget::getItemPath(QListWidgetItem * item) * @param dir Library directory (e.g. "/mechanical/screws") * @param dxfFile File name (e.g. "screw1.dxf") * @param dxfPath Full path to the existing DXF file on disk - * (e.g. /home/tux/.qcad/library/mechanical/screws/screw1.dxf) + * (e.g. /home/tux/.architektonas/library/mechanical/screws/screw1.dxf) */ QPixmap LibraryWidget::getPixmap(const QString & dir, const QString & dxfFile, const QString & dxfPath) @@ -293,7 +310,7 @@ QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfF // 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); @@ -305,7 +322,6 @@ QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfF for(it=directoryList.begin(); it!=directoryList.end(); ++it) { itemDir = (*it) + dir; -// pngPath = itemDir + "/" + fiDxf.baseName(true) + ".png"; pngPath = itemDir + "/" + fiDxf.completeBaseName() + ".png"; RS_DEBUG->print("LibraryWidget::getPathToPixmap: checking: '%s'", pngPath.toLatin1().data()); @@ -331,83 +347,50 @@ QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfF } } - // 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 ""; - } -} - */ - - QString d = RS_SYSTEM->getHomeDir() + "/.qcad/library" + dir; - -// pngPath = d + "/" + fiDxf.baseName(true) + ".png"; + // 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() + "/.architektonas/library" + dir; pngPath = d + "/" + fiDxf.completeBaseName() + ".png"; - QPixmap * buffer = new QPixmap(128, 128); -// RS_PainterQt * painter = new RS_PainterQt(buffer); - QPainter qpntr(buffer); + 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; + RS_StaticGraphicView view(128, 128, painter); + 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.zoomAuto(false); - gv.drawEntity(&graphic, true); + view.setContainer(&drawing); + view.zoomAuto(false); + view.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 { @@ -415,7 +398,6 @@ QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfF } delete painter; - delete buffer; return pngPath; }