From af32602b9d8075080d5805143f1cd47fc10672e1 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 6 Sep 2010 13:36:07 +0000 Subject: [PATCH] Partially fixed thumbnail rendering on Library Browser. --- architektonas.pro | 3 +- src/base/rs_staticgraphicview.cpp | 2 + src/base/rs_units.cpp | 126 ++++++++++-------------------- src/forms/librarywidget.cpp | 114 +++++++++++++++------------ src/widgets/blockwidget.cpp | 1 + src/widgets/layerbox.cpp | 5 +- src/widgets/layerwidget.cpp | 1 + src/widgets/qg_graphicview.cpp | 23 +----- 8 files changed, 115 insertions(+), 160 deletions(-) diff --git a/architektonas.pro b/architektonas.pro index 3b99e2d..a143343 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -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 diff --git a/src/base/rs_staticgraphicview.cpp b/src/base/rs_staticgraphicview.cpp index 2451576..4064573 100644 --- a/src/base/rs_staticgraphicview.cpp +++ b/src/base/rs_staticgraphicview.cpp @@ -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); diff --git a/src/base/rs_units.cpp b/src/base/rs_units.cpp index fd3557d..0c193fd 100644 --- a/src/base/rs_units.cpp +++ b/src/base/rs_units.cpp @@ -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; } /** diff --git a/src/forms/librarywidget.cpp b/src/forms/librarywidget.cpp index ebb8acb..8ca7ca1 100644 --- a/src/forms/librarywidget.cpp +++ b/src/forms/librarywidget.cpp @@ -13,8 +13,15 @@ // --- ---------- ----------------------------------------------------------- // 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 diff --git a/src/widgets/blockwidget.cpp b/src/widgets/blockwidget.cpp index 50f6a42..813bebf 100644 --- a/src/widgets/blockwidget.cpp +++ b/src/widgets/blockwidget.cpp @@ -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(); diff --git a/src/widgets/layerbox.cpp b/src/widgets/layerbox.cpp index f40cf92..360d30c 100644 --- a/src/widgets/layerbox.cpp +++ b/src/widgets/layerbox.cpp @@ -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) diff --git a/src/widgets/layerwidget.cpp b/src/widgets/layerwidget.cpp index f60a6c1..a590f01 100644 --- a/src/widgets/layerwidget.cpp +++ b/src/widgets/layerwidget.cpp @@ -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(); diff --git a/src/widgets/qg_graphicview.cpp b/src/widgets/qg_graphicview.cpp index 40aaa7f..963738c 100644 --- a/src/widgets/qg_graphicview.cpp +++ b/src/widgets/qg_graphicview.cpp @@ -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; -- 2.37.2