]> Shamusworld >> Repos - architektonas/blobdiff - src/forms/librarywidget.cpp
Initial removal of unnecessary rs_ prefixes from files.
[architektonas] / src / forms / librarywidget.cpp
index 8ca7ca1b5f361d746ead6144ad3231f1f9cec3af..607b5a1ad040d29021e1e36326c6188176f706cd 100644 (file)
 // 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
 //
 
 /*
-BUGS:
-
-- Picks up thumbnail directories twice--only once if thumbnail dir doesn't exist
+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"
@@ -27,8 +31,8 @@ BUGS:
 #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*/):
@@ -157,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));
                }
        }
@@ -214,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();
@@ -272,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)
@@ -312,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());
@@ -341,27 +350,8 @@ QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfF
        // 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;
-//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());
-
-       // 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);
@@ -369,7 +359,7 @@ It only fails for certain DXFs. Dunno why.
        qpntr.setBackground(Qt::white);
        qpntr.eraseRect(0, 0, 128, 128);
 
-       RS_StaticGraphicView gv(128, 128, painter);
+       RS_StaticGraphicView view(128, 128, painter);
        Drawing drawing;
 
        if (drawing.open(dxfPath, RS2::FormatUnknown))
@@ -384,10 +374,9 @@ It only fails for certain DXFs. Dunno why.
                        e->setPen(pen);
                }
 
-               gv.setContainer(&drawing);
-               gv.zoomAuto(false);
-//This works, but somehow doesn't work ALL the time
-               gv.drawEntity(&drawing, true);
+               view.setContainer(&drawing);
+               view.zoomAuto(false);
+               view.drawEntity(&drawing, true);
 
                QImageWriter writer;
                QImage image = buffer.toImage();
@@ -412,20 +401,3 @@ It only fails for certain DXFs. Dunno why.
 
        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