From 79b14361c590b8cc6174b8a27dc748ed760dd762 Mon Sep 17 00:00:00 2001 From: Damien Dupuis Date: Mon, 23 Feb 2009 13:43:36 +0000 Subject: [PATCH] - adding copyToImage function to generate jpg file (thanks to JPC) --- hurricane/src/hviewer/CellWidget.cpp | 23 +++++++++++++++ .../src/hviewer/hurricane/viewer/CellWidget.h | 28 ++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/hurricane/src/hviewer/CellWidget.cpp b/hurricane/src/hviewer/CellWidget.cpp index 749691d1..4216f792 100644 --- a/hurricane/src/hviewer/CellWidget.cpp +++ b/hurricane/src/hviewer/CellWidget.cpp @@ -345,6 +345,7 @@ namespace Hurricane { CellWidget::DrawingPlanes::DrawingPlanes ( const QSize& size, CellWidget* cw ) : _cellWidget(cw) , _printer(NULL) + , _image(NULL) , _normalPen() , _linePen() , _workingPlane(0) @@ -560,6 +561,28 @@ namespace Hurricane { } + void CellWidget::DrawingPlanes::copyToImage ( int sx, int sy, int w, int h, QImage* image ) + { + int ximage = 0; + int yimage = 0; + + if ( !image ) return; + _image = image; + + painterBegin ( PlaneId::Image ); + + _painters[PlaneId::Image].setRenderHint(QPainter::Antialiasing, false); + _painters[PlaneId::Image].drawPixmap + ( ximage, yimage + , *_planes[PlaneId::Normal] + , _cellWidget->getOffsetVA().rx()+sx, _cellWidget->getOffsetVA().ry()+sy + , w, h + ); + + painterEnd ( PlaneId::Image ); + _image = NULL; + } + // ------------------------------------------------------------------- // Class : "Hurricane::CellWidget::DrawingQuery". diff --git a/hurricane/src/hviewer/hurricane/viewer/CellWidget.h b/hurricane/src/hviewer/hurricane/viewer/CellWidget.h index fb960c9f..6cf94151 100644 --- a/hurricane/src/hviewer/hurricane/viewer/CellWidget.h +++ b/hurricane/src/hviewer/hurricane/viewer/CellWidget.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -144,6 +145,7 @@ namespace Hurricane { inline QPainter& getPainter ( size_t plane=PlaneId::Working ); inline int getDarkening () const; inline void copyToPrinter ( QPrinter*, bool imageOnly = false ); + inline void copyToImage ( QImage* ); inline const float& getScale () const; inline const QPoint& getMousePosition () const; void setLayerVisible ( const Name& layer, bool visible ); @@ -332,7 +334,8 @@ namespace Hurricane { , Selection = 1 , Widget = 2 , Printer = 3 - , Working = 4 + , Image = 4 + , Working = 5 }; }; @@ -373,8 +376,9 @@ namespace Hurricane { private: CellWidget* _cellWidget; QPrinter* _printer; + QImage* _image; QPixmap* _planes[2]; - QPainter _painters[4]; + QPainter _painters[5]; QPen _normalPen; QPen _linePen; size_t _workingPlane; @@ -712,11 +716,12 @@ namespace Hurricane { inline void CellWidget::DrawingPlanes::painterBegin ( size_t i ) { switch ( i ) { - case 4: i = _workingPlane; + case 5: i = _workingPlane; case 0: case 1: _painters[i].begin ( _planes[i] ); break; case 2: _painters[2].begin ( _cellWidget ); break; case 3: _painters[3].begin ( _printer ); break; + case 4: _painters[4].begin ( _image ); break; } } @@ -729,7 +734,7 @@ namespace Hurricane { inline void CellWidget::DrawingPlanes::painterEnd ( size_t i ) - { _painters[(i>3)?_workingPlane:i].end (); } + { _painters[(i>4)?_workingPlane:i].end (); } inline void CellWidget::DrawingPlanes::paintersEnd () @@ -763,6 +768,17 @@ namespace Hurricane { } + inline void CellWidget::DrawingPlanes::copyToImage ( QImage* image ) + { + copyToImage ( 0 + , 0 + , _cellWidget->geometry().width() + , _cellWidget->geometry().height() + , image + ); + } + + inline void CellWidget::SelectorCriterions::setCellWidget ( CellWidget* cw ) { _cellWidget = cw; } @@ -977,6 +993,10 @@ namespace Hurricane { { _drawingPlanes.copyToPrinter ( printer, imageOnly ); } + inline void CellWidget::copyToImage ( QImage* image ) + { _drawingPlanes.copyToImage ( image ); } + + inline int CellWidget::dbuToDisplayX ( DbU::Unit x ) const { return (int)rint ( (float)( x - _displayArea.getXMin() ) * getScale() ); }