]> Shamusworld >> Repos - architektonas/blobdiff - src/forms/librarywidget.cpp
Phase two of adding polyline functionality...
[architektonas] / src / forms / librarywidget.cpp
index 3f8d67ecc89450329b289b14e417733d75e75820..19a194dd1feff2c60931e27edad4fcf00e5b8485 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*/):
@@ -40,7 +44,7 @@ std::cout << "LibraryWidget::LibraryWidget()" << std::endl;
        ui.setupUi(this);
        ui.lvDirectory->setColumnCount(1);
 
-       QStringList directoryList = RS_SYSTEM->getDirectoryList("library");
+       QStringList directoryList = SYSTEM->getDirectoryList("library");
 #if 0
 std::cout << "directorySize = " << directoryList.size() << std::endl;
 
@@ -101,14 +105,14 @@ void LibraryWidget::insert()
                        }
                        else
                        {
-                               RS_DEBUG->print(RS_Debug::D_ERROR, "LibraryWidget::insert:"
+                               DEBUG->print(Debug::D_ERROR, "LibraryWidget::insert:"
                                        "Cannot create action ActionLibraryInsert");
                        }
                }
        }
        else
        {
-               RS_DEBUG->print(RS_Debug::D_ERROR,
+               DEBUG->print(Debug::D_ERROR,
                        "LibraryWidget::insert: Can't read file: '%s'", dxfPath.toLatin1().data());
        }
 }
@@ -182,7 +186,7 @@ void LibraryWidget::updatePreview(QTreeWidgetItem * item, int /*column*/)
        ui.ivPreview->clear();
 
        // List of all directories that contain part libraries:
-       QStringList directoryList = RS_SYSTEM->getDirectoryList("library");
+       QStringList directoryList = SYSTEM->getDirectoryList("library");
        QStringList::Iterator it;
        QDir itemDir;
        QStringList itemPathList;
@@ -249,7 +253,7 @@ QString LibraryWidget::getItemPath(QListWidgetItem * item)
        if (item)
        {
                // List of all directories that contain part libraries:
-               QStringList directoryList = RS_SYSTEM->getDirectoryList("library");
+               QStringList directoryList = SYSTEM->getDirectoryList("library");
                QStringList::Iterator it;
                QDir itemDir;
 
@@ -278,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)
@@ -301,12 +305,12 @@ QPixmap LibraryWidget::getPixmap(const QString & dir, const QString & dxfFile,
 QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfFile,
        const QString & dxfPath)
 {
-       RS_DEBUG->print("LibraryWidget::getPathToPixmap: dir: '%s' dxfFile: '%s' dxfPath: '%s'",
+       DEBUG->print("LibraryWidget::getPathToPixmap: dir: '%s' dxfFile: '%s' dxfPath: '%s'",
                dir.toLatin1().data(), dxfFile.toLatin1().data(), dxfPath.toLatin1().data());
 
        // List of all directories that contain part libraries:
-       QStringList directoryList = RS_SYSTEM->getDirectoryList("library");
-       directoryList.prepend(RS_SYSTEM->getHomeDir() + "/.architektonas/library");
+       QStringList directoryList = SYSTEM->getDirectoryList("library");
+       directoryList.prepend(SYSTEM->getHomeDir() + "/.architektonas/library");
        QStringList::Iterator it;
 
        QFileInfo fiDxf(dxfPath);
@@ -318,27 +322,26 @@ 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'",
+               DEBUG->print("LibraryWidget::getPathToPixmap: checking: '%s'",
                        pngPath.toLatin1().data());
                QFileInfo fiPng(pngPath);
 
                // the thumbnail exists:
                if (fiPng.isFile())
                {
-                       RS_DEBUG->print("LibraryWidget::getPathToPixmap: dxf date: %s, png date: %s",
+                       DEBUG->print("LibraryWidget::getPathToPixmap: dxf date: %s, png date: %s",
                                fiDxf.lastModified().toString().toLatin1().data(), fiPng.lastModified().toString().toLatin1().data());
 
                        if (fiPng.lastModified() > fiDxf.lastModified())
                        {
-                               RS_DEBUG->print("LibraryWidget::getPathToPixmap: thumbnail found: '%s'",
+                               DEBUG->print("LibraryWidget::getPathToPixmap: thumbnail found: '%s'",
                                        pngPath.toLatin1().data());
                                return pngPath;
                        }
                        else
                        {
-                               RS_DEBUG->print("LibraryWidget::getPathToPixmap: thumbnail needs to be updated: '%s'",
+                               DEBUG->print("LibraryWidget::getPathToPixmap: thumbnail needs to be updated: '%s'",
                                        pngPath.toLatin1().data());
                        }
                }
@@ -346,28 +349,9 @@ 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";
+       SYSTEM->createHomePath("/.architektonas/library" + dir);
+       QString d = SYSTEM->getHomeDir() + "/.architektonas/library" + dir;
        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);
@@ -375,25 +359,24 @@ It only fails for certain DXFs. Dunno why.
        qpntr.setBackground(Qt::white);
        qpntr.eraseRect(0, 0, 128, 128);
 
-       RS_StaticGraphicView gv(128, 128, painter);
+       StaticGraphicView view(128, 128, painter);
        Drawing drawing;
 
        if (drawing.open(dxfPath, RS2::FormatUnknown))
        {
-               RS_Color black(0, 0, 0);
+               Color black(0, 0, 0);
 
                // Set all pens in the drawing to BLACK
-               for(RS_Entity * e=drawing.firstEntity(RS2::ResolveAll); e!=NULL; e=drawing.nextEntity(RS2::ResolveAll))
+               for(Entity * e=drawing.firstEntity(RS2::ResolveAll); e!=NULL; e=drawing.nextEntity(RS2::ResolveAll))
                {
-                       RS_Pen pen = e->getPen();
+                       Pen pen = e->getPen();
                        pen.setColor(black);
                        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();
@@ -403,7 +386,7 @@ It only fails for certain DXFs. Dunno why.
 
                if (!writer.write(image))
                {
-                       RS_DEBUG->print(RS_Debug::D_ERROR,
+                       DEBUG->print(Debug::D_ERROR,
                                "LibraryWidget::getPathToPixmap: Cannot write thumbnail: '%s'",
                                pngPath.toLatin1().data());
                        pngPath = "";
@@ -411,27 +394,10 @@ It only fails for certain DXFs. Dunno why.
        }
        else
        {
-               RS_DEBUG->print(RS_Debug::D_ERROR, "LibraryWidget::getPathToPixmap: Cannot open file: '%s'", dxfPath.toLatin1().data());
+               DEBUG->print(Debug::D_ERROR, "LibraryWidget::getPathToPixmap: Cannot open file: '%s'", dxfPath.toLatin1().data());
        }
 
        delete painter;
 
        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