]> Shamusworld >> Repos - architektonas/commitdiff
Partially fixed thumbnail rendering on Library Browser.
authorShamus Hammons <jlhamm@acm.org>
Mon, 6 Sep 2010 13:36:07 +0000 (13:36 +0000)
committerShamus Hammons <jlhamm@acm.org>
Mon, 6 Sep 2010 13:36:07 +0000 (13:36 +0000)
architektonas.pro
src/base/rs_staticgraphicview.cpp
src/base/rs_units.cpp
src/forms/librarywidget.cpp
src/widgets/blockwidget.cpp
src/widgets/layerbox.cpp
src/widgets/layerwidget.cpp
src/widgets/qg_graphicview.cpp

index 3b99e2d9044ef301a9708dd8666cd5ffa241a406..a14334393c6cac1d5c959774b84e998bec8d530a 100644 (file)
@@ -2,9 +2,10 @@
 # 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
index 2451576a6797b61b54e46a0e372431304b8136a5..4064573066e17b64f2df09628055c2662163a582 100644 (file)
@@ -33,6 +33,8 @@ just me. >:-)
  */
 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);
index fd3557d11bfa089cf756ccb2064bc60d1b025510..0c193fdc783e8dc61cdd415340bdfd41dc18e6b7 100644 (file)
@@ -245,89 +245,47 @@ RS2::Unit RS_Units::stringToUnit(const QString & u)
        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;
 }
@@ -470,37 +428,37 @@ QString RS_Units::formatLinear(double length, RS2::Unit unit, RS2::LinearFormat
         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;
 }
 
 /**
index ebb8acb0319e19d11b904f0ba68558da7baa426e..8ca7ca1b5f361d746ead6144ad3231f1f9cec3af 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
 //
 
+/*
+BUGS:
+
+- Picks up thumbnail directories twice--only once if thumbnail dir doesn't exist
+*/
+
 #include "librarywidget.h"
 
 #include "actionhandler.h"
@@ -293,7 +300,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);
@@ -331,83 +338,70 @@ 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 "";
-               }
-}
-       */
+       // 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
        {
@@ -415,7 +409,23 @@ QString LibraryWidget::getPathToPixmap(const QString & dir, const QString & dxfF
        }
 
        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
index 50f6a4240bd48949cf49c7714c1140cd47e8c91e..813bebf64f2a2669244357fe7f05c3ca492013ed 100644 (file)
@@ -313,6 +313,7 @@ void BlockWidget::slotMouseButtonClicked(QListWidgetItem * item)
        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();
index f40cf92bc85490a10d7dc18a4ac7c267805e357d..360d30ce70598a517cfc4be9a0297ca73922b48e 100644 (file)
@@ -118,9 +118,8 @@ bool LayerBox::isUnchanged()
 }
 
 /**
- * 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)
index f60a6c1f0b16a742f5052cfa4949b21a3f7efb15..a590f01ed3741c17228f29af4fc7f7a09d1dc784 100644 (file)
@@ -307,6 +307,7 @@ void LayerWidget::slotMouseButtonClicked(QListWidgetItem * item)
        RS_Layer * l = lastLayer;
 
 #warning "!!! Bad implementation of lock/freeze functionality !!!"
+//This is crap.
        if (p.x() < 23)
        {
                actionHandler->slotLayersToggleView();
index 40aaa7f07eae0cb583c1ba69bef7cb51c475a634..963738c4d09c2274a61002589eb971c6c6d91fbc 100644 (file)
@@ -810,7 +810,7 @@ of VectorWorks & etc. as well...
 
 // 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);
@@ -823,30 +823,13 @@ of VectorWorks & etc. as well...
 //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;