2010-09-05 17:35 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)

* contrib/hbqt/hbqt.ch
    + Added more constants.

  * contrib/hbqt/qtgui/doc/en/class_hbqgraphicsitem.txt
  * contrib/hbqt/qtgui/doc/en/class_hbqgraphicsscene.txt
  * contrib/hbqt/qtgui/g/HBQGraphicsItem.cpp
  * contrib/hbqt/qtgui/g/HBQGraphicsScene.cpp
  * contrib/hbqt/qtgui/g/QLinearGradient.cpp
  * contrib/hbqt/qtgui/g/THBQGraphicsItem.prg
  * contrib/hbqt/qtgui/g/THBQGraphicsScene.prg
  * contrib/hbqt/qtgui/hbqt_hbqgraphicsitem.cpp
  * contrib/hbqt/qtgui/hbqt_hbqgraphicsitem.h
  * contrib/hbqt/qtgui/hbqt_hbqgraphicsscene.cpp
  * contrib/hbqt/qtgui/hbqt_hbqgraphicsscene.h

  * contrib/hbqt/qtgui/qth/HBQGraphicsItem.qth
  * contrib/hbqt/qtgui/qth/HBQGraphicsScene.qth
  * contrib/hbqt/qtgui/qth/QLinearGradient.qth

  * contrib/hbqt/tests/demoqt.prg
    ! One of the main-menu prompt constructed differently.

  * contrib/hbide/hbqreportsmanager.prg
    + HbqReportsManager() class is split in two to manage graphic objects 
      more efficiently.

    + Implemented: Reports Manager - all graphics items drawn on .prg levels.

      This implementation has cleans all c++ code responsible to draw 
      graphics primitives, and hance greatly reducing the c++ dependancy.
      More c++ => prg conversion is on the cards.
This commit is contained in:
Pritpal Bedi
2010-09-06 00:48:13 +00:00
parent 3cd6f5a972
commit 28d12dc858
18 changed files with 952 additions and 1291 deletions

View File

@@ -16,6 +16,39 @@
The license applies to all entries newer than 2009-04-28.
*/
2010-09-05 17:35 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/hbqt.ch
+ Added more constants.
* contrib/hbqt/qtgui/doc/en/class_hbqgraphicsitem.txt
* contrib/hbqt/qtgui/doc/en/class_hbqgraphicsscene.txt
* contrib/hbqt/qtgui/g/HBQGraphicsItem.cpp
* contrib/hbqt/qtgui/g/HBQGraphicsScene.cpp
* contrib/hbqt/qtgui/g/QLinearGradient.cpp
* contrib/hbqt/qtgui/g/THBQGraphicsItem.prg
* contrib/hbqt/qtgui/g/THBQGraphicsScene.prg
* contrib/hbqt/qtgui/hbqt_hbqgraphicsitem.cpp
* contrib/hbqt/qtgui/hbqt_hbqgraphicsitem.h
* contrib/hbqt/qtgui/hbqt_hbqgraphicsscene.cpp
* contrib/hbqt/qtgui/hbqt_hbqgraphicsscene.h
* contrib/hbqt/qtgui/qth/HBQGraphicsItem.qth
* contrib/hbqt/qtgui/qth/HBQGraphicsScene.qth
* contrib/hbqt/qtgui/qth/QLinearGradient.qth
* contrib/hbqt/tests/demoqt.prg
! One of the main-menu prompt constructed differently.
* contrib/hbide/hbqreportsmanager.prg
+ HbqReportsManager() class is split in two to manage graphic objects
more efficiently.
+ Implemented: Reports Manager - all graphics items drawn on .prg levels.
This implementation has cleans all c++ code responsible to draw
graphics primitives, and hance greatly reducing the c++ dependancy.
More c++ => prg conversion is on the cards.
2010-09-04 12:30 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbatomic.h
* added two new build time macros which can be used to control

File diff suppressed because it is too large Load Diff

View File

@@ -2423,6 +2423,46 @@
#define QGradient_NoGradient 3 // No gradient is used.
#define QPainter_CompositionMode_SourceOver 0
#define QPainter_CompositionMode_DestinationOver 1
#define QPainter_CompositionMode_Clear 2
#define QPainter_CompositionMode_Source 3
#define QPainter_CompositionMode_Destination 4
#define QPainter_CompositionMode_SourceIn 5
#define QPainter_CompositionMode_DestinationIn 6
#define QPainter_CompositionMode_SourceOut 7
#define QPainter_CompositionMode_DestinationOut 8
#define QPainter_CompositionMode_SourceAtop 9
#define QPainter_CompositionMode_DestinationAtop 10
#define QPainter_CompositionMode_Xor 11
#define QPainter_CompositionMode_Plus 12
#define QPainter_CompositionMode_Multiply 13
#define QPainter_CompositionMode_Screen 14
#define QPainter_CompositionMode_Overlay 15
#define QPainter_CompositionMode_Darken 16
#define QPainter_CompositionMode_Lighten 17
#define QPainter_CompositionMode_ColorDodge 18
#define QPainter_CompositionMode_ColorBurn 19
#define QPainter_CompositionMode_HardLight 20
#define QPainter_CompositionMode_SoftLight 21
#define QPainter_CompositionMode_Difference 22
#define QPainter_CompositionMode_Exclusion 23
#define QPainter_RasterOp_SourceOrDestination 24
#define QPainter_RasterOp_SourceAndDestination 25
#define QPainter_RasterOp_SourceXorDestination 26
#define QPainter_RasterOp_NotSourceAndNotDestination 27
#define QPainter_RasterOp_NotSourceOrNotDestination 28
#define QPainter_RasterOp_NotSourceXorDestination 29
#define QPainter_RasterOp_NotSource 30
#define QPainter_RasterOp_NotSourceAndDestination 31
#define QPainter_RasterOp_SourceAndNotDestination 32
#define QPainter_Antialiasing 0x01
#define QPainter_TextAntialiasing 0x02
#define QPainter_SmoothPixmapTransform 0x04
#define QPainter_HighQualityAntialiasing 0x08
#define QPainter_NonCosmeticDefaultPen 0x10
/*----------------------------------------------------------------------*/
#endif

View File

@@ -32,8 +32,6 @@
* :determineResizeMode( pPos ) -> nInt
* :adjustRect( pRect ) -> pQRectF
* :prepare( pPainter ) -> NIL
* :drawSelection( pPainter, pRect ) -> NIL
* :setupPainter( pPainter ) -> NIL
* :pen() -> pQPen
* :setPen( pPen ) -> NIL
* :brush() -> pQBrush

View File

@@ -39,10 +39,6 @@
* :setMagnetArea( nMagnetArea ) -> NIL
* :showGrid() -> lBool
* :setShowGrid( lShowGrid ) -> NIL
* :zoomWYSIWYG() -> NIL
* :zoomIn() -> NIL
* :zoomOut() -> NIL
* :zoomOriginal() -> NIL
* :setLeftMagnet( lMagneted ) -> NIL
* :setRightMagnet( lMagneted ) -> NIL
* :setTopMagnet( lMagneted ) -> NIL

View File

@@ -234,34 +234,6 @@ HB_FUNC( QT_HBQGRAPHICSITEM_PREPARE )
}
}
/*
* void drawSelection( QPainter * painter, const QRectF & rect )
*/
HB_FUNC( QT_HBQGRAPHICSITEM_DRAWSELECTION )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
( p )->drawSelection( hbqt_par_QPainter( 2 ), *hbqt_par_QRectF( 3 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_DRAWSELECTION FP=( p )->drawSelection( hbqt_par_QPainter( 2 ), *hbqt_par_QRectF( 3 ) ); p is NULL" ) );
}
}
/*
* void setupPainter( QPainter * painter )
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SETUPPAINTER )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
( p )->setupPainter( hbqt_par_QPainter( 2 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SETUPPAINTER FP=( p )->setupPainter( hbqt_par_QPainter( 2 ) ); p is NULL" ) );
}
}
/*
* QPen pen()
*/

View File

@@ -344,62 +344,6 @@ HB_FUNC( QT_HBQGRAPHICSSCENE_SETSHOWGRID )
}
}
/*
* virtual void zoomWYSIWYG();
*/
HB_FUNC( QT_HBQGRAPHICSSCENE_ZOOMWYSIWYG )
{
HBQGraphicsScene * p = hbqt_par_HBQGraphicsScene( 1 );
if( p )
( p )->zoomWYSIWYG();
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSSCENE_ZOOMWYSIWYG FP=( p )->zoomWYSIWYG(); p is NULL" ) );
}
}
/*
* virtual void zoomIn();
*/
HB_FUNC( QT_HBQGRAPHICSSCENE_ZOOMIN )
{
HBQGraphicsScene * p = hbqt_par_HBQGraphicsScene( 1 );
if( p )
( p )->zoomIn();
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSSCENE_ZOOMIN FP=( p )->zoomIn(); p is NULL" ) );
}
}
/*
* virtual void zoomOut();
*/
HB_FUNC( QT_HBQGRAPHICSSCENE_ZOOMOUT )
{
HBQGraphicsScene * p = hbqt_par_HBQGraphicsScene( 1 );
if( p )
( p )->zoomOut();
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSSCENE_ZOOMOUT FP=( p )->zoomOut(); p is NULL" ) );
}
}
/*
* virtual void zoomOriginal();
*/
HB_FUNC( QT_HBQGRAPHICSSCENE_ZOOMORIGINAL )
{
HBQGraphicsScene * p = hbqt_par_HBQGraphicsScene( 1 );
if( p )
( p )->zoomOriginal();
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSSCENE_ZOOMORIGINAL FP=( p )->zoomOriginal(); p is NULL" ) );
}
}
/*
* virtual void setLeftMagnet( bool magneted )
*/

View File

@@ -147,7 +147,7 @@ HB_FUNC( QT_QLINEARGRADIENT )
}
else if( hb_pcount() == 2 && HB_ISPOINTER( 1 ) && HB_ISPOINTER( 2 ) )
{
pObj = new QLinearGradient( *hbqt_par_QPoint( 1 ), *hbqt_par_QPoint( 2 ) ) ;
pObj = new QLinearGradient( *hbqt_par_QPointF( 1 ), *hbqt_par_QPointF( 2 ) ) ;
}
else if( hb_pcount() == 4 && HB_ISNUM( 1 ) && HB_ISNUM( 2 ) && HB_ISNUM( 3 ) && HB_ISNUM( 4 ) )
{

View File

@@ -73,8 +73,6 @@ CREATE CLASS HBQGraphicsItem INHERIT HbQtObjectHandler, QGraphicsItem
METHOD determineResizeMode( pPos )
METHOD adjustRect( pRect )
METHOD prepare( pPainter )
METHOD drawSelection( pPainter, pRect )
METHOD setupPainter( pPainter )
METHOD pen()
METHOD setPen( pPen )
METHOD brush()
@@ -174,14 +172,6 @@ METHOD HBQGraphicsItem:prepare( pPainter )
RETURN Qt_HBQGraphicsItem_prepare( ::pPtr, hbqt_ptr( pPainter ) )
METHOD HBQGraphicsItem:drawSelection( pPainter, pRect )
RETURN Qt_HBQGraphicsItem_drawSelection( ::pPtr, hbqt_ptr( pPainter ), hbqt_ptr( pRect ) )
METHOD HBQGraphicsItem:setupPainter( pPainter )
RETURN Qt_HBQGraphicsItem_setupPainter( ::pPtr, hbqt_ptr( pPainter ) )
METHOD HBQGraphicsItem:pen()
RETURN Qt_HBQGraphicsItem_pen( ::pPtr )

View File

@@ -80,10 +80,6 @@ CREATE CLASS HBQGraphicsScene INHERIT HbQtObjectHandler, QGraphicsScene
METHOD setMagnetArea( nMagnetArea )
METHOD showGrid()
METHOD setShowGrid( lShowGrid )
METHOD zoomWYSIWYG()
METHOD zoomIn()
METHOD zoomOut()
METHOD zoomOriginal()
METHOD setLeftMagnet( lMagneted )
METHOD setRightMagnet( lMagneted )
METHOD setTopMagnet( lMagneted )
@@ -155,22 +151,6 @@ METHOD HBQGraphicsScene:setShowGrid( lShowGrid )
RETURN Qt_HBQGraphicsScene_setShowGrid( ::pPtr, lShowGrid )
METHOD HBQGraphicsScene:zoomWYSIWYG()
RETURN Qt_HBQGraphicsScene_zoomWYSIWYG( ::pPtr )
METHOD HBQGraphicsScene:zoomIn()
RETURN Qt_HBQGraphicsScene_zoomIn( ::pPtr )
METHOD HBQGraphicsScene:zoomOut()
RETURN Qt_HBQGraphicsScene_zoomOut( ::pPtr )
METHOD HBQGraphicsScene:zoomOriginal()
RETURN Qt_HBQGraphicsScene_zoomOriginal( ::pPtr )
METHOD HBQGraphicsScene:setLeftMagnet( lMagneted )
RETURN Qt_HBQGraphicsScene_setLeftMagnet( ::pPtr, lMagneted )

View File

@@ -129,16 +129,6 @@ void HBQGraphicsItem::hbSetBlock( PHB_ITEM b )
{
if( b ){
block = hb_itemNew( b );
QDesktopWidget * qWid = new QDesktopWidget();
PHB_ITEM p1 = hb_itemPutNI( NULL, 21001 );
PHB_ITEM p2 = hb_itemPutNI( NULL, qWid->screen()->physicalDpiX() );
PHB_ITEM p3 = hb_itemPutNI( NULL, qWid->screen()->physicalDpiY() );
hb_vmEvalBlockV( block, 3, p1, p2, p3 );
hb_itemRelease( p1 );
hb_itemRelease( p2 );
hb_itemRelease( p3 );
}
}
@@ -741,8 +731,6 @@ QRectF HBQGraphicsItem::boundingRect() const
void HBQGraphicsItem::prepare( QPainter * painter )
{
setupPainter( painter );
switch( iType )
{
case HBQT_GRAPHICSITEM_SIMPLETEXT :
@@ -771,82 +759,14 @@ void HBQGraphicsItem::prepare( QPainter * painter )
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::setupPainter( QPainter * painter )
{
if( ! painter ){
return;
}
painter->setPen( pen() );
painter->setBackgroundMode( ( Qt::BGMode ) iBGMode );
painter->setBackground( backgroundBrush() );
QFont f=font();
f.setPixelSize( font().pointSizeF() / UNIT );
painter->setFont( f );
painter->setOpacity( ( qreal ) iOpacity / 100.0 );
painter->setBrush( brush() );
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * /* widget */ )
{
switch( iType )
{
case HBQT_GRAPHICSITEM_NONE :
break;
case HBQT_GRAPHICSITEM_RECT :
drawRect( painter, option );
break;
case HBQT_GRAPHICSITEM_LINE :
drawLine( painter, option );
break;
case HBQT_GRAPHICSITEM_ELLIPSE :
drawEllipse( painter, option );
break;
case HBQT_GRAPHICSITEM_ARC :
drawArc( painter, option );
break;
case HBQT_GRAPHICSITEM_CHORD :
drawChord( painter, option );
break;
case HBQT_GRAPHICSITEM_PIE :
drawPie( painter, option );
break;
case HBQT_GRAPHICSITEM_POLYGON :
break;
case HBQT_GRAPHICSITEM_PATH :
break;
case HBQT_GRAPHICSITEM_CHART :
drawBarChart( painter, option );
break;
case HBQT_GRAPHICSITEM_GRADIENT :
break;
case HBQT_GRAPHICSITEM_PICTURE :
drawPicture( painter, option );
break;
case HBQT_GRAPHICSITEM_BARCODE :
//drawBarcode39( painter, option );
break;
case HBQT_GRAPHICSITEM_TEXT :
break;
case HBQT_GRAPHICSITEM_SIMPLETEXT :
drawText( painter, option );
break;
}
if( block ){
QRectF rect = ( option->type == QStyleOption::SO_GraphicsItem ) ? boundingRect() : option->exposedRect;
PHB_ITEM p1 = hb_itemPutNI( NULL, 21017 );
PHB_ITEM p2 = hb_itemPutPtr( NULL, painter );
PHB_ITEM p3 = hb_itemNew( NULL );
hb_arrayNew( p3, 2 );
hb_arraySetPtr( p3, 1, &rect );
hb_arraySetC( p3, 2, objectName().toLatin1().data() );
PHB_ITEM p3 = hb_itemPutPtr( NULL, &rect );
hb_vmEvalBlockV( block, 3, p1, p2, p3 );
hb_itemRelease( p1 );
hb_itemRelease( p2 );
@@ -855,77 +775,6 @@ void HBQGraphicsItem::paint( QPainter * painter, const QStyleOptionGraphicsItem
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawSelection( QPainter * painter, const QRectF & rect )
{
painter->save();
if( isSelected() )
{
QBrush a;
//a.setColor( QColor( 200,0,0,150 ) );
a.setColor( QColor( 255,0,0 ) );
a.setStyle( Qt::SolidPattern );
if( bDrawSelectionBorder )
{
QPen p( Qt::DashLine );
p.setBrush( a );
painter->setPen( p );
painter->drawRect( rect );
}
QPainterPath lt;
lt.moveTo( 0,0 );
lt.lineTo( 0,iResizeHandle );
lt.lineTo( iResizeHandle, 0 );
painter->fillPath( lt,a );
QPainterPath rt;
rt.moveTo( rect.width(),0 );
rt.lineTo( rect.width(),iResizeHandle );
rt.lineTo( rect.width()-iResizeHandle,0 );
painter->fillPath( rt,a );
QPainterPath lb;
lb.moveTo( 0,rect.height() );
lb.lineTo( 0,rect.height()-iResizeHandle );
lb.lineTo( iResizeHandle,rect.height() );
painter->fillPath( lb,a );
QPainterPath rb;
rb.moveTo( rect.width(),rect.height() );
rb.lineTo( rect.width(),rect.height()-iResizeHandle );
rb.lineTo( rect.width()-iResizeHandle,rect.height() );
painter->fillPath( rb,a );
}
else
{
if( bDrawSelectionBorder )
{
QBrush a;
a.setColor( QColor( 100,100,100,200 ) );
a.setStyle( Qt::SolidPattern );
QPen p( Qt::DashDotDotLine );
p.setBrush( a );
painter->setPen( p );
painter->drawRect( rect );
}
else
{
painter->setPen( QColor( 0,0,0,100 ) );
painter->drawLine( 0,0,0,2*iResizeHandle );
painter->drawLine( 0,0,2*iResizeHandle,0 );
painter->drawLine( rect.width(),0,rect.width()-2*iResizeHandle,0 );
painter->drawLine( rect.width(),0,rect.width(),2*iResizeHandle );
painter->drawLine( rect.width(),rect.height(),rect.width()-2*iResizeHandle, rect.height() );
painter->drawLine( rect.width(),rect.height(),rect.width(), rect.height()-2*iResizeHandle );
painter->drawLine( 0,rect.height(), 2*iResizeHandle, rect.height() );
painter->drawLine( 0,rect.height(), 0, rect.height()-2*iResizeHandle );
}
}
painter->restore();
}
/*----------------------------------------------------------------------*/
QRectF HBQGraphicsItem::adjustRect( QRectF & rect )
{
qreal penwidth = pen().widthF();
@@ -936,379 +785,14 @@ QRectF HBQGraphicsItem::adjustRect( QRectF & rect )
QRectF HBQGraphicsItem::adjustOption( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
Q_UNUSED( painter );
QRectF rect = ( option->type == QStyleOption::SO_GraphicsItem ) ? boundingRect() : option->exposedRect;
if( option->type == QStyleOption::SO_GraphicsItem ){
drawSelection( painter, rect );
}
setupPainter( painter );
adjustRect( rect );
return rect;
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawRect( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QRectF rect = adjustOption( painter, option );
//painter->drawRoundRect( rect, xRadius(), yRadius() );
painter->drawRect( rect );
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawEllipse( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QRectF rect = adjustOption( painter, option );
painter->drawEllipse( rect );
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawLine( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QRectF rect = adjustOption( painter, option );
switch( lineStyle() )
{
case HBQT_GRAPHICSITEM_LINE_VERTICAL:
painter->drawLine( rect.x() + rect.width() / 2, rect.y(), rect.x() + rect.width() / 2, rect.y() + rect.height() );
break;
case HBQT_GRAPHICSITEM_LINE_HORIZONTAL:
painter->drawLine( rect.x(), rect.y() + rect.height() / 2, rect.x() + rect.width(), rect.y() + rect.height() / 2 );
break;
case HBQT_GRAPHICSITEM_LINE_BACKWARDDIAGONAL:
painter->drawLine( rect.right(), rect.y(), rect.x(), rect.bottom() );
break;
case HBQT_GRAPHICSITEM_LINE_FORWARDDIAGONAL:
painter->drawLine( rect.x(), rect.y(), rect.right(), rect.bottom() );
break;
}
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawPie( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QRectF rect = adjustOption( painter, option );
painter->drawPie( rect, iStartAngle * 16, iSpanAngle * 16 );
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawArc( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QRectF rect = adjustOption( painter, option );
painter->drawArc( rect, iStartAngle * 16, iSpanAngle * 16 );
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawChord( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QRectF rect = adjustOption( painter, option );
painter->drawChord( rect, iStartAngle * 16, iSpanAngle * 16 );
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawPicture( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QRectF rect = adjustOption( painter, option );
QString m_text = QString_text;
qreal textH = 0;
qreal sw = 0;
qreal sh = 0;
if( m_drawTextType == HBQT_GRAPHICSITEM_TEXT_DRAW_ABOVE || m_drawTextType == HBQT_GRAPHICSITEM_TEXT_DRAW_BELOW ){
textH = QFontMetricsF( painter->font() ).height();
}
if( m_image.isNull() )
{
( option->type == QStyleOption::SO_GraphicsItem ) ?
painter->drawRect( rect ) : painter->drawText( rect, Qt::AlignCenter, "No Picture" );
}
else
{
QImage img( 0, 0 /*,QImage::Format_ARGB32_Premultiplied*/ );
QPointF point = rect.topLeft();
int cx = 0, cy = 0, cw = m_image.width(), ch = m_image.height();
switch( m_paintType )
{
case HBQT_GRAPHICSITEM_RESIZE_PICTURE_TO_ITEM_KEEP_ASPECT_RATIO:
img = m_image.scaled( rect.width(), rect.height() - textH, Qt::KeepAspectRatio, Qt::SmoothTransformation );
break;
case HBQT_GRAPHICSITEM_RESIZE_PICTURE_TO_ITEM_IGNORE_ASPECT_RATIO:
img = m_image.scaled( rect.width(), rect.height() - textH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
break;
case HBQT_GRAPHICSITEM_CENTER_PICTURE_TO_ITEM:
point.setX( point.x() + ( rect.width() - m_image.width() ) / 2 );
point.setY( point.y() + ( rect.height() - m_image.height() - textH ) / 2 );
if( point.x() < 0 )
{
cx = abs( point.x() );
cw -= 2 * cx;
point.setX( 0 );
}
if( point.y() < 0 )
{
cy = abs( point.y() );
ch -= 2 * cy;
point.setY( 0 );
}
img = m_image.copy( cx, cy, cw, ch );
break;
case HBQT_GRAPHICSITEM_RESIZE_ITEM_TO_PICTURE:
img = m_image;
sw = img.width()-width();
sh = img.height() - ( height() - textH );
break;
}
if( m_drawTextType == HBQT_GRAPHICSITEM_TEXT_DRAW_ABOVE ){
point.setY( point.y() + textH );
}
painter->drawImage( point, img );
}
painter->setPen( m_textColor );
switch( m_drawTextType )
{
case HBQT_GRAPHICSITEM_TEXT_DRAW_TOP:
painter->drawText( rect, Qt::AlignTop | Qt::AlignHCenter, m_text );
break;
case HBQT_GRAPHICSITEM_TEXT_DRAW_BOTTOM:
painter->drawText( rect, Qt::AlignBottom | Qt::AlignHCenter, m_text );
break;
case HBQT_GRAPHICSITEM_TEXT_DRAW_ABOVE:
painter->drawText( rect, Qt::AlignTop | Qt::AlignHCenter, m_text );
break;
case HBQT_GRAPHICSITEM_TEXT_DRAW_BELOW:
painter->drawText( rect, Qt::AlignBottom | Qt::AlignHCenter, m_text );
break;
default:
break;
}
if( sw || sh ){
setWidth( width() + sw );
setHeight( height() + sh );
}
if( m_borderWidth > 0 )
{
QPen pen;
pen.setWidth( m_borderWidth );
pen.setColor( m_borderColor );
pen.setJoinStyle( Qt::MiterJoin );
painter->setPen( pen );
painter->setBrush( Qt::NoBrush );
painter->drawRect( rect.x() + m_borderWidth / 2, rect.y() + m_borderWidth / 2,
rect.width() - m_borderWidth, rect.height() - m_borderWidth );
}
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawText( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QRectF rect = adjustOption( painter, option );
painter->setRenderHint( QPainter::TextAntialiasing );
painter->drawText( rect, textFlags(), QString_text );
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawBarChart( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
QList< _chartValue > val;
PHB_ITEM values = NULL;
if( block )
{
// Get Values from Application
}
if( values == NULL )
{
_chartValue v;
v.key = "Bananas";
v.value = 120.0;
v.color = generateNextColor();
val << v;
v.key = "Oranges";
v.value = 150.0;
v.color = generateNextColor();
val << v;
v.key = "Mangoes";
v.value = 40.0;
v.color = generateNextColor();
val << v;
}
if( ! val.size() ){
return;
}
QRectF rect = adjustOption( painter, option );
qreal maxpv = 0;
qreal minnv = 0;
foreach( _chartValue cv, val )
{
if( cv.value > 0 && cv.value > maxpv )
maxpv = cv.value;
if( cv.value < 0 && cv.value < minnv )
minnv = cv.value;
}
qreal absMaxVal = maxpv - minnv;
qreal powVal = ( absMaxVal < 1 ) ? pow( 10.0, QString::number( absMaxVal ).right( QString::number( absMaxVal ).indexOf( '.' ) ).length() + 1 ) : 1;
maxpv *= powVal;
minnv *= powVal;
maxpv = ( quint64 ) maxpv;
minnv = ( quint64 )( -minnv );
minnv = -minnv;
painter->fillRect( rect,brush() );
if( m_drawBorder )
painter->drawRect( rect );
int pw = abs( pen().widthF() ) ? abs( pen().widthF() ) : 1;
QRectF rc = rect.adjusted( pw / 2, pw / 2, -pw, -pw );
qreal f = 2;
qreal chartStep = pow( 10.0, ( QString::number( absMaxVal ).left( QString::number( absMaxVal ).indexOf( '.' ) ).length() ) - 1 ) / f;
qreal powStep = ( chartStep < 1 ) ? 10 : 1;
chartStep *= powStep;
maxpv *= powStep;
minnv *= powStep;
powVal *= powStep;
maxpv = maxpv + ( ( ( ( quint64 ) maxpv % ( quint64 ) chartStep ) ? ( ( quint64 ) chartStep - ( ( quint64 ) maxpv % ( quint64 ) chartStep ) ) : 0 ) ) / powVal;
minnv = minnv - ( ( ( -( quint64 ) minnv % ( quint64 ) chartStep ) ? ( ( quint64 ) chartStep - ( -( quint64 ) minnv % ( quint64 ) chartStep ) ) : 0 ) ) / powVal;
quint64 maxVal = maxpv - minnv;
qreal maxHeight = rc.height() - painter->fontMetrics().height();
qreal valstep = maxHeight / ( maxVal / chartStep );
if( valstep < painter->fontMetrics().height() )
{
chartStep *= ( ( ( quint64 ) ( painter->fontMetrics().height() / valstep ) ) + 1 );
valstep = ( ( ( quint64 ) ( painter->fontMetrics().height() / valstep ) ) + 1 ) * valstep;
}
if( m_showLabels )
{
qreal maxLabelWidth = 0;
for( int i = 0; i < maxVal / chartStep + 1 + ( ( quint64 ) maxVal % ( quint64 ) chartStep ? 1 : 0 ); i++ )
{
if( maxLabelWidth < painter->fontMetrics().width( QString::number( ( maxVal * i - chartStep * i ) / powVal ) ) ){
maxLabelWidth = painter->fontMetrics().width( QString::number( ( maxVal * i - chartStep * i ) / powVal ) );
}
}
int y = 0;
for( int i = 0; i < maxVal / chartStep + 1 + ( ( quint64 ) maxVal % ( quint64 ) chartStep ? 1 : 0 ); i++ )
{
painter->drawText( QRectF( rc.x(), rc.y() + y, maxLabelWidth, painter->fontMetrics().height() ),
Qt::AlignRight | Qt::AlignVCenter, QString::number( ( maxpv - chartStep * i ) / powVal ) );
y += valstep;
}
painter->drawLine( rc.x() + maxLabelWidth + 1 / UNIT / 4, rc.y(), rc.x() + maxLabelWidth + 1 / UNIT / 4, rc.y() + rect.height() );
rc = rc.adjusted( maxLabelWidth + 1 / UNIT / 4, 0, 0, 0 );
}
if( m_showGrid )
{
int y = ( double ) painter->fontMetrics().height() / 2;
for( int i = 0; i < maxVal / chartStep + 1 + ( ( quint64 ) maxVal % ( quint64 ) chartStep ? 1 : 0 ); i++ )
{
painter->drawLine( rc.x(), rc.y() + y, rc.x() + rc.width(), rc.y() + y );
y += valstep;
}
}
rc = rc.adjusted( 0, ( double ) painter->fontMetrics().height() / 2, 0, 0 );
int x = m_barsIdentation;
qreal barWidth = ( rc.width() - m_barsIdentation * ( val.size() + 1 ) ) / val.size();
qreal py = maxHeight / maxVal;
foreach( _chartValue cv, val )
{
QLinearGradient lg( QPointF( x + barWidth / 2, 0 ), QPointF( x + barWidth , 0 ) );
lg.setSpread( QGradient::ReflectSpread );
lg.setColorAt( 0, cv.color );
lg.setColorAt( 1, QColor( cv.color.red() * m_toColorFactor, cv.color.green() * m_toColorFactor, cv.color.blue() * m_toColorFactor, cv.color.alpha() ) );
painter->fillRect( QRectF( rc.x() + x, rc.y() + py * maxpv - py * cv.value * powVal, barWidth, py * cv.value * powVal ), QBrush( lg ) );
if( m_showLabels ){
painter->drawText( QRectF( rc.x() + x - m_barsIdentation / 2, rc.y() + py * maxpv - ( ( cv.value >= 0 ) ? painter->fontMetrics().height() : 0 ),
barWidth + m_barsIdentation, painter->fontMetrics().height() ), Qt::AlignCenter, QString( "%1" ).arg( cv.value ) );
}
x += barWidth + m_barsIdentation;
}
#if 0 /* Legend */
painter->fillRect( rect, brush() );
painter->drawRect( rect );
painter->translate( rect.topLeft() );
qreal y = 1 / UNIT;
qreal vstep = ( rect.height() - y - 1 / UNIT * val.size() ) / val.size();
foreach( _chartValue cv, val )
{
painter->fillRect( QRectF( 1 / UNIT / 2, y, m_legendColorRectWidth, vstep ), QBrush( cv.color ) );
painter->drawText( QRectF( 1 / UNIT + m_legendColorRectWidth, y, rect.width() - ( 1 / UNIT + m_legendColorRectWidth ), vstep ),
Qt::AlignVCenter | Qt::AlignLeft, cv.key );
y += vstep + 1 / UNIT;
}
#endif
}
/*----------------------------------------------------------------------*/
void HBQGraphicsItem::drawBarcode39( QPainter * painter, const QStyleOptionGraphicsItem * option )
{
if( ! m_barValues.size() )
{
return;
}
QRectF rect = adjustOption( painter, option );
QRectF rc = rect.adjusted( 5, 5, -10, -10 );
QColor fl( Qt::white );
QColor clr( Qt::black );
int iBars = m_barValues.size();
qreal w = rc.width() / iBars;
qreal x = 0.0;
for( int i = 0; i < iBars; i++ )
{
if( m_barValues.at( i ) == "-" )
{
painter->fillRect( QRectF( rc.x() + x, rc.y(), w, rc.height() ), clr );
}
else
{
painter->fillRect( QRectF( rc.x() + x, rc.y(), w, rc.height() ), fl );
}
x += w;
}
}
/*----------------------------------------------------------------------*/
#endif

View File

@@ -135,8 +135,6 @@ public:
int determineResizeMode( const QPointF & pos );
QRectF adjustRect( QRectF & rect );
virtual void prepare( QPainter * painter );
void drawSelection( QPainter * painter, const QRectF & rect );
void setupPainter( QPainter * painter );
private:
int iType;
@@ -181,17 +179,6 @@ private:
QColor generateNextColor();
QRectF adjustOption( QPainter * painter, const QStyleOptionGraphicsItem * option );
//
void drawRect( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawEllipse( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawLine( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawPie( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawArc( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawChord( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawPicture( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawText( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawBarChart( QPainter * painter, const QStyleOptionGraphicsItem * option );
void drawBarcode39( QPainter * painter, const QStyleOptionGraphicsItem * option );
protected:
void dragEnterEvent( QGraphicsSceneDragDropEvent * event );

View File

@@ -99,6 +99,16 @@ void HBQGraphicsScene::hbSetBlock( PHB_ITEM b )
{
if( b ){
block = hb_itemNew( b );
QDesktopWidget * qWid = new QDesktopWidget();
PHB_ITEM p1 = hb_itemPutNI( NULL, 21001 );
PHB_ITEM p2 = hb_itemPutNI( NULL, qWid->screen()->physicalDpiX() );
PHB_ITEM p3 = hb_itemPutNI( NULL, qWid->screen()->physicalDpiY() );
hb_vmEvalBlockV( block, 3, p1, p2, p3 );
hb_itemRelease( p1 );
hb_itemRelease( p2 );
hb_itemRelease( p3 );
}
}
@@ -727,45 +737,6 @@ void HBQGraphicsScene::drawMagnets( HBQGraphicsItem * item )
}
}
/*----------------------------------------------------------------------*/
// Zooming
/*----------------------------------------------------------------------*/
void HBQGraphicsScene::zoomIn()
{
if( views().size() )
{
views()[ 0 ]->scale( 1.1, 1.1 );
}
}
void HBQGraphicsScene::zoomOut()
{
if( views().size() )
{
views()[ 0 ]->scale( 0.9, 0.9 );
}
}
void HBQGraphicsScene::zoomWYSIWYG()
{
if( views().size() )
{
views()[ 0 ]->resetMatrix();
views()[ 0 ]->scale( ( double ) QDesktopWidget().screen()->width() / ( hbqt_screen_widthMM * 10 ),
( double ) QDesktopWidget().screen()->height() / ( hbqt_screen_heightMM * 10 ) );
views()[ 0 ]->centerOn( 0, 0 );
}
}
void HBQGraphicsScene::zoomOriginal()
{
if( views().size() )
{
views()[ 0 ]->resetMatrix();
views()[ 0 ]->centerOn( 0, 0 );
}
}
/*----------------------------------------------------------------------*/
#endif

View File

@@ -109,10 +109,6 @@ public:
void setMagnetArea( int magnetArea );
virtual bool showGrid();
virtual void setShowGrid( bool showGrid );
virtual void zoomWYSIWYG();
virtual void zoomIn();
virtual void zoomOut();
virtual void zoomOriginal();
public slots:
virtual void setLeftMagnet( bool magneted );

View File

@@ -98,8 +98,6 @@ HB_FUNC( QT_HBQGRAPHICSITEM )
int determineResizeMode( const QPointF & pos )
QRectF adjustRect( QRectF & rect )
virtual void prepare( QPainter * painter )
void drawSelection( QPainter * painter, const QRectF & rect )
void setupPainter( QPainter * painter )
QPen pen()
void setPen( const QPen & pen )

View File

@@ -102,10 +102,6 @@ HB_FUNC( QT_HBQGRAPHICSSCENE )
void setMagnetArea( int magnetArea )
virtual bool showGrid()
virtual void setShowGrid( bool showGrid )
virtual void zoomWYSIWYG();
virtual void zoomIn();
virtual void zoomOut();
virtual void zoomOriginal();
</PROTOS>

View File

@@ -85,7 +85,7 @@ HB_FUNC( QT_QLINEARGRADIENT )
}
else if( hb_pcount() == 2 && HB_ISPOINTER( 1 ) && HB_ISPOINTER( 2 ) )
{
hb_retptr( ( QLinearGradient* ) new QLinearGradient( *hbqt_par_QPoint( 1 ), *hbqt_par_QPoint( 2 ) ) );
hb_retptr( ( QLinearGradient* ) new QLinearGradient( *hbqt_par_QPointF( 1 ), *hbqt_par_QPointF( 2 ) ) );
}
else if( hb_pcount() == 4 && HB_ISNUM( 1 ) && HB_ISNUM( 2 ) && HB_ISNUM( 3 ) && HB_ISNUM( 4 ) )
{

View File

@@ -234,8 +234,11 @@ STATIC FUNCTION Build_MenuBar( oWnd )
oMenu1 := QMenu():new()
oMenu1:setTitle( "&File" )
oActNew := QAction():from( oMenu1:addAction_1( "new.png" , "&New" ) )
oActNew:connect( QT_EVE_TRIGGERED_B, {|w,l| FileDialog( "New" , w, l ) } )
oActNew := QAction():new( oMenu1 )
oActNew:setText( "&New" )
oActNew:setIcon( "new.png" )
oActNew:connect( "triggered(bool)", {|w,l| FileDialog( "New" , w, l ) } )
oMenu1:addAction_4( oActNew )
oActOpen := QAction():from( oMenu1:addAction_1( "open.png", "&Open" ) )
oActOpen:connect( QT_EVE_TRIGGERED_B, {|w,l| FileDialog( "Open" , w, l ) } )