- adding copyToImage function to generate jpg file (thanks to JPC)

This commit is contained in:
Damien Dupuis 2009-02-23 13:43:36 +00:00
parent c3f4af9cbf
commit 79b14361c5
2 changed files with 47 additions and 4 deletions

View File

@ -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".

View File

@ -36,6 +36,7 @@
#include <QPixmap>
#include <QPainter>
#include <QPrinter>
#include <QImage>
#include <QRect>
#include <QPoint>
@ -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() ); }