2010-08-24 09:29 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)

* contrib/hbqt/qtgui/doc/en/class_hbqgraphicsitem.txt
  * contrib/hbqt/qtgui/g/HBQGraphicsItem.cpp
  * contrib/hbqt/qtgui/g/THBQGraphicsItem.prg
  * contrib/hbqt/qtgui/hbqt_hbqgraphicsitem.cpp
  * contrib/hbqt/qtgui/hbqt_hbqgraphicsitem.h
  * contrib/hbqt/qtgui/qth/HBQGraphicsItem.qth
  * contrib/hbide/idereportsmanager.prg
    + Implemented: ideReport Designer:
        * Barcode 3of9 - the code belongs to someone I have no 
          idea now. Please speak out who he is so that I post 
          due credit to him. I had adopted this code for Vouch32
          family of libraries many years back. Now adopted to 
          hbQT + hbIDE.  

        * Simple bar-chart. 
       
        Both above implementations are quick ones and I see a 
        lot of avenues for improvement which are scheduled to 
        be addressed later.
This commit is contained in:
Pritpal Bedi
2010-08-24 16:38:54 +00:00
parent 616efab846
commit f7d150322d
8 changed files with 624 additions and 13 deletions

View File

@@ -16,6 +16,27 @@
The license applies to all entries newer than 2009-04-28.
*/
2010-08-24 09:29 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtgui/doc/en/class_hbqgraphicsitem.txt
* contrib/hbqt/qtgui/g/HBQGraphicsItem.cpp
* contrib/hbqt/qtgui/g/THBQGraphicsItem.prg
* contrib/hbqt/qtgui/hbqt_hbqgraphicsitem.cpp
* contrib/hbqt/qtgui/hbqt_hbqgraphicsitem.h
* contrib/hbqt/qtgui/qth/HBQGraphicsItem.qth
* contrib/hbide/idereportsmanager.prg
+ Implemented: ideReport Designer:
* Barcode 3of9 - the code belongs to someone I have no
idea now. Please speak out who he is so that I post
due credit to him. I had adopted this code for Vouch32
family of libraries many years back. Now adopted to
hbQT + hbIDE.
* Simple bar-chart.
Both above implementations are quick ones and I see a
lot of avenues for improvement which are scheduled to
be addressed later.
2010-08-24 11:16 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/contrib/hbwin/olecore.c
! added missing call to Release() method in __OleGetActiveObject()

View File

@@ -150,6 +150,7 @@ CLASS IdeReportsManager INHERIT IdeObject
METHOD buildDesignReport()
METHOD addField( qPos, cAlias, cField )
METHOD addObject( qPos, cType )
METHOD fetchBarString( cCode, lCheck )
METHOD loadReport( cName )
METHOD saveReport()
METHOD prepareReport()
@@ -540,23 +541,23 @@ METHOD IdeReportsManager:execEvent( cEvent, p, p1, p2 )
/*----------------------------------------------------------------------*/
METHOD IdeReportsManager:addObject( qPos, cType )
LOCAL oWidget, cName, nW, nH, qGrad
LOCAL oWidget, cName, nW, nH, qGrad, cCode, qStrList, i
cName := cType + "_" + hb_ntos( hbide_getNextID( cType ) )
SWITCH cType
CASE "Image"
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_PICTURE )
nW := 300 ; nH := 300
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_PICTURE )
oWidget:setPixmap( QPixmap():new( hbide_image( "hbide" ) ) )
oWidget:setBorderWidth( 2 )
EXIT
CASE "Chart"
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_ELLIPSE )
nW := 300 ; nH := 200
oWidget:setBrush( QBrush():new( "QColor", QColor():new( 200,114,127 ) ) )
nW := 400 ; nH := 250
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_CHART )
EXIT
CASE "Gradient"
nW := 300 ; nH := 50
qGrad := QLinearGradient():new()// 0, 0, 1, 1 )
qGrad:setColorAt( 0, QColor():new( 195,225,255 ) )
//qGrad:setColorAt( 1, ( QColor():new( 195,225,255 ) ):darker( 150 ) )
@@ -564,18 +565,26 @@ METHOD IdeReportsManager:addObject( qPos, cType )
qGrad:setCoordinateMode( QGradient_StretchToDeviceMode )
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_RECT )
nW := 300 ; nH := 50
oWidget:setBrush( QBrush():new( "QGradient", qGrad ) )
oWidget:setPen( QPen():new( Qt_NoPen ) )
EXIT
CASE "Barcode"
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_RECT )
nW := 300 ; nH := 200
oWidget:setBrush( QBrush():new( "QColor", QColor():new( 120,200,245 ) ) )
cCode := ::fetchBarString( "Harbour" )
qStrList := QStringList():new()
FOR i := 1 TO len( cCode )
IF substr( cCode, i, 1 ) == "1"
qStrList:append( "-" )
ELSE
qStrList:append( "." )
ENDIF
NEXT
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_BARCODE )
oWidget:setBarValues( qStrList )
EXIT
CASE "Text"
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_SIMPLETEXT )
nW := 300 ; nH := 50
oWidget := HBQGraphicsItem():new( HBQT_GRAPHICSITEM_SIMPLETEXT )
oWidget:setBrush( QBrush():new( "QColor", QColor():new( 200,200,245 ) ) )
oWidget:setText( "Harbour" )
EXIT
@@ -766,3 +775,84 @@ METHOD IdeReportsManager:buildStatusBar()
RETURN Self
/*----------------------------------------------------------------------*/
/* */
/* NOTE: the code below is works of someone else I do not remmeber */
/* the name. Please let me know who that is so due credits be */
/* given to him. I had downloaded this code many years back */
/* and adopted to Vouch32 library and Vouch32 Active-X Server. */
METHOD IdeReportsManager:fetchBarString( cCode, lCheck )
STATIC cCars := '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%'
STATIC aBarras := { '1110100010101110',; // 1
'1011100010101110',; // 2
'1110111000101010',; // 3
'1010001110101110',; // 4
'1110100011101010',; // 5
'1011100011101010',; // 6
'1010001011101110',; // 7
'1110100010111010',; // 8
'1011100010111010',; // 9
'1010001110111010',; // 0
'1110101000101110',; // A
'1011101000101110',; // B
'1110111010001010',; // C
'1010111000101110',; // D
'1110101110001010',; // E
'1011101110001010',;
'1010100011101110',;
'1110101000111010',;
'1011101000111010',;
'1010111000111010',;
'1110101010001110',; // K
'1011101010001110',;
'1110111010100010',;
'1010111010001110',;
'1110101110100010',;
'1011101110100010',; // p
'1010101110001110',;
'1110101011100010',;
'1011101011100010',;
'1010111011100010',;
'1110001010101110',;
'1000111010101110',;
'1110001110101010',;
'1000101110101110',;
'1110001011101010',;
'1000111011101010',; // Z
'1000101011101110',; // -
'1110001010111010',; // .
'1000111010111010',; // ' '
'1000101110111010',; // *
'1000100010100010',;
'1000100010100010',;
'1000101000100010',;
'1010001000100010' }
LOCAL cCar, m, n, cBarra := '', nCheck := 0
DEFAULT lCheck TO .f.
cCode := upper( cCode )
IF len( cCode ) > 32
cCode := left( cCode,32 )
ENDIF
cCode := '*' + cCode + '*'
FOR n := 1 TO len( cCode )
cCar := substr( cCode,n,1 )
m := at( cCar, cCars )
IF m > 0
cBarra := cBarra + aBarras[ m ]
nCheck += ( m-1 )
ENDIF
NEXT
IF lCheck
cBarra += aBarras[ nCheck % 43 + 1 ]
ENDIF
RETURN cBarra
/*----------------------------------------------------------------------*/

View File

@@ -77,6 +77,17 @@
* :setResizeFlags( nResizeFlags ) -> NIL
* :resizeHandle() -> nInt
* :setResizeHandle( nResizeHandle ) -> NIL
* :barsIdentation() -> nInt
* :setBarsIdentation( nBarsIdentation ) -> NIL
* :drawBorder() -> lBool
* :setDrawBorder( lDrawBorder ) -> NIL
* :showGrid() -> lBool
* :setShowGrid( lShowGrid ) -> NIL
* :showLabels() -> lBool
* :setShowLabels( lShowLabels ) -> NIL
* :toColorFactor() -> nQreal
* :setToColorFactor( nToColorFactor ) -> NIL
* :setBarValues( pList ) -> NIL
*
* $DESCRIPTION$
*

View File

@@ -864,6 +864,160 @@ HB_FUNC( QT_HBQGRAPHICSITEM_SETRESIZEHANDLE )
}
}
/*
* int barsIdentation()
*/
HB_FUNC( QT_HBQGRAPHICSITEM_BARSIDENTATION )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
hb_retni( ( p )->barsIdentation() );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_BARSIDENTATION FP=hb_retni( ( p )->barsIdentation() ); p is NULL" ) );
}
}
/*
* void setBarsIdentation( int barsIdentation )
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SETBARSIDENTATION )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
( p )->setBarsIdentation( hb_parni( 2 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SETBARSIDENTATION FP=( p )->setBarsIdentation( hb_parni( 2 ) ); p is NULL" ) );
}
}
/*
* bool drawBorder()
*/
HB_FUNC( QT_HBQGRAPHICSITEM_DRAWBORDER )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
hb_retl( ( p )->drawBorder() );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_DRAWBORDER FP=hb_retl( ( p )->drawBorder() ); p is NULL" ) );
}
}
/*
* void setDrawBorder( bool drawBorder )
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SETDRAWBORDER )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
( p )->setDrawBorder( hb_parl( 2 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SETDRAWBORDER FP=( p )->setDrawBorder( hb_parl( 2 ) ); p is NULL" ) );
}
}
/*
* bool showGrid()
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SHOWGRID )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
hb_retl( ( p )->showGrid() );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SHOWGRID FP=hb_retl( ( p )->showGrid() ); p is NULL" ) );
}
}
/*
* void setShowGrid( bool showGrid )
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SETSHOWGRID )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
( p )->setShowGrid( hb_parl( 2 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SETSHOWGRID FP=( p )->setShowGrid( hb_parl( 2 ) ); p is NULL" ) );
}
}
/*
* bool showLabels()
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SHOWLABELS )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
hb_retl( ( p )->showLabels() );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SHOWLABELS FP=hb_retl( ( p )->showLabels() ); p is NULL" ) );
}
}
/*
* void setShowLabels( bool showLabels )
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SETSHOWLABELS )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
( p )->setShowLabels( hb_parl( 2 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SETSHOWLABELS FP=( p )->setShowLabels( hb_parl( 2 ) ); p is NULL" ) );
}
}
/*
* qreal toColorFactor()
*/
HB_FUNC( QT_HBQGRAPHICSITEM_TOCOLORFACTOR )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
hb_retnd( ( p )->toColorFactor() );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_TOCOLORFACTOR FP=hb_retnd( ( p )->toColorFactor() ); p is NULL" ) );
}
}
/*
* void setToColorFactor( qreal toColorFactor )
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SETTOCOLORFACTOR )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
( p )->setToColorFactor( hb_parnd( 2 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SETTOCOLORFACTOR FP=( p )->setToColorFactor( hb_parnd( 2 ) ); p is NULL" ) );
}
}
/*
* void setBarValues( const QStringList & list )
*/
HB_FUNC( QT_HBQGRAPHICSITEM_SETBARVALUES )
{
HBQGraphicsItem * p = hbqt_par_HBQGraphicsItem( 1 );
if( p )
( p )->setBarValues( *hbqt_par_QStringList( 2 ) );
else
{
HB_TRACE( HB_TR_DEBUG, ( "............................... F=QT_HBQGRAPHICSITEM_SETBARVALUES FP=( p )->setBarValues( *hbqt_par_QStringList( 2 ) ); p is NULL" ) );
}
}
/*----------------------------------------------------------------------*/
#endif /* #if QT_VERSION >= 0x040500 */

View File

@@ -118,6 +118,17 @@ CREATE CLASS HBQGraphicsItem INHERIT HbQtObjectHandler, QGraphicsItem
METHOD setResizeFlags( nResizeFlags )
METHOD resizeHandle()
METHOD setResizeHandle( nResizeHandle )
METHOD barsIdentation()
METHOD setBarsIdentation( nBarsIdentation )
METHOD drawBorder()
METHOD setDrawBorder( lDrawBorder )
METHOD showGrid()
METHOD setShowGrid( lShowGrid )
METHOD showLabels()
METHOD setShowLabels( lShowLabels )
METHOD toColorFactor()
METHOD setToColorFactor( nToColorFactor )
METHOD setBarValues( pList )
ENDCLASS
@@ -334,3 +345,47 @@ METHOD HBQGraphicsItem:resizeHandle()
METHOD HBQGraphicsItem:setResizeHandle( nResizeHandle )
RETURN Qt_HBQGraphicsItem_setResizeHandle( ::pPtr, nResizeHandle )
METHOD HBQGraphicsItem:barsIdentation()
RETURN Qt_HBQGraphicsItem_barsIdentation( ::pPtr )
METHOD HBQGraphicsItem:setBarsIdentation( nBarsIdentation )
RETURN Qt_HBQGraphicsItem_setBarsIdentation( ::pPtr, nBarsIdentation )
METHOD HBQGraphicsItem:drawBorder()
RETURN Qt_HBQGraphicsItem_drawBorder( ::pPtr )
METHOD HBQGraphicsItem:setDrawBorder( lDrawBorder )
RETURN Qt_HBQGraphicsItem_setDrawBorder( ::pPtr, lDrawBorder )
METHOD HBQGraphicsItem:showGrid()
RETURN Qt_HBQGraphicsItem_showGrid( ::pPtr )
METHOD HBQGraphicsItem:setShowGrid( lShowGrid )
RETURN Qt_HBQGraphicsItem_setShowGrid( ::pPtr, lShowGrid )
METHOD HBQGraphicsItem:showLabels()
RETURN Qt_HBQGraphicsItem_showLabels( ::pPtr )
METHOD HBQGraphicsItem:setShowLabels( lShowLabels )
RETURN Qt_HBQGraphicsItem_setShowLabels( ::pPtr, lShowLabels )
METHOD HBQGraphicsItem:toColorFactor()
RETURN Qt_HBQGraphicsItem_toColorFactor( ::pPtr )
METHOD HBQGraphicsItem:setToColorFactor( nToColorFactor )
RETURN Qt_HBQGraphicsItem_setToColorFactor( ::pPtr, nToColorFactor )
METHOD HBQGraphicsItem:setBarValues( pList )
RETURN Qt_HBQGraphicsItem_setBarValues( ::pPtr, hbqt_ptr( pList ) )

View File

@@ -63,6 +63,8 @@
#include "hbqt_hbqgraphicsitem.h"
#include <math.h>
HBQGraphicsItem::HBQGraphicsItem( int type, QGraphicsItem * parent ) : QGraphicsItem( parent )
{
iType = type;
@@ -105,6 +107,14 @@ HBQGraphicsItem::HBQGraphicsItem( int type, QGraphicsItem * parent ) : QGraphics
m_borderColor = Qt::black;
m_borderWidth = 0;
m_drawTextType = HBQT_GRAPHICSITEM_TEXT_DRAW_NONE;
m_barsIdentation = 1 / UNIT;
m_showLabels = true;
m_toColorFactor = 2;
m_drawBorder = true;
m_showGrid = true;
// m_barValues = NULL;
}
HBQGraphicsItem::~HBQGraphicsItem()
@@ -392,15 +402,81 @@ void HBQGraphicsItem::setResizeHandle( int resizeHandle )
{
iResizeHandle = resizeHandle;
#if 0
if( m_minWidth < m_resizeHandle * 2 + 1 )
m_minWidth = m_resizeHandle * 2 + 1;
if( m_minWidth < iResizeHandle * 2 + 1 )
m_minWidth = iResizeHandle * 2 + 1;
if( m_minHeight < m_resizeHandle * 2 + 1 )
m_minHeight = m_resizeHandle * 2 + 1;
if( m_minHeight < iResizeHandle * 2 + 1 )
m_minHeight = iResizeHandle * 2 + 1;
#endif
update( boundingRect() );
}
int HBQGraphicsItem::barsIdentation()
{
return m_barsIdentation;
}
void HBQGraphicsItem::setBarsIdentation(int barsIdentation)
{
if( barsIdentation < 1 )
barsIdentation = 1;
m_barsIdentation = barsIdentation;
update();
}
bool HBQGraphicsItem::showLabels()
{
return m_showLabels;
}
void HBQGraphicsItem::setShowLabels( bool showLabels )
{
m_showLabels = showLabels;
update();
}
bool HBQGraphicsItem::showGrid()
{
return m_showGrid;
}
void HBQGraphicsItem::setShowGrid( bool showGrid )
{
m_showGrid = showGrid;
update();
}
qreal HBQGraphicsItem::toColorFactor()
{
return m_toColorFactor;
}
void HBQGraphicsItem::setToColorFactor( qreal toColorFactor )
{
if( toColorFactor > 10 )
toColorFactor = 10;
if( toColorFactor < 0.1 )
toColorFactor = 0.1;
m_toColorFactor = toColorFactor;
update();
}
bool HBQGraphicsItem::drawBorder()
{
return m_drawBorder;
}
void HBQGraphicsItem::setDrawBorder( bool drawBorder )
{
m_drawBorder = drawBorder;
update();
}
QColor HBQGraphicsItem::generateNextColor()
{
return QColor( qrand() % 255, qrand() % 255, qrand() % 255, 255 );
}
void HBQGraphicsItem::setBarValues( const QStringList & barValues )
{
m_barValues = barValues;
}
/*----------------------------------------------------------------------*/
// Mouse Events
/*----------------------------------------------------------------------*/
@@ -720,6 +796,7 @@ void HBQGraphicsItem::paint( QPainter * painter, const QStyleOptionGraphicsItem
case HBQT_GRAPHICSITEM_PATH :
break;
case HBQT_GRAPHICSITEM_CHART :
drawBarChart( painter, option );
break;
case HBQT_GRAPHICSITEM_GRADIENT :
break;
@@ -727,6 +804,7 @@ void HBQGraphicsItem::paint( QPainter * painter, const QStyleOptionGraphicsItem
drawPicture( painter, option );
break;
case HBQT_GRAPHICSITEM_BARCODE :
drawBarcode39( painter, option );
break;
case HBQT_GRAPHICSITEM_TEXT :
break;
@@ -1021,4 +1099,166 @@ void HBQGraphicsItem::drawText( QPainter * painter, const QStyleOptionGraphicsIt
}
/*----------------------------------------------------------------------*/
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;
}
}
/*----------------------------------------------------------------------*/
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 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 );
}
x += w;
}
}
/*----------------------------------------------------------------------*/
#endif

View File

@@ -171,6 +171,14 @@ private:
int m_sizePolicy;
int m_textFlags;
int m_barsIdentation;
bool m_showLabels;
qreal m_toColorFactor;
bool m_drawBorder;
bool m_showGrid;
QStringList m_barValues;
QColor generateNextColor();
QRectF adjustOption( QPainter * painter, const QStyleOptionGraphicsItem * option );
//
void drawRect( QPainter * painter, const QStyleOptionGraphicsItem * option );
@@ -181,6 +189,8 @@ private:
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 );
@@ -250,6 +260,24 @@ public slots:
int resizeHandle();
void setResizeHandle( int resizeHandle );
int barsIdentation();
void setBarsIdentation( int barsIdentation );
bool drawBorder();
void setDrawBorder( bool drawBorder );
bool showGrid();
void setShowGrid( bool showGrid );
bool showLabels();
void setShowLabels( bool showLabels );
qreal toColorFactor();
void setToColorFactor( qreal toColorFactor );
void setBarValues( const QStringList & list );
struct _chartValue
{
QString key;
qreal value;
QColor color;
};
};
#endif

View File

@@ -144,6 +144,18 @@ HB_FUNC( QT_HBQGRAPHICSITEM )
int resizeHandle()
void setResizeHandle( int resizeHandle )
int barsIdentation()
void setBarsIdentation( int barsIdentation )
bool drawBorder()
void setDrawBorder( bool drawBorder )
bool showGrid()
void setShowGrid( bool showGrid )
bool showLabels()
void setShowLabels( bool showLabels )
qreal toColorFactor()
void setToColorFactor( qreal toColorFactor )
void setBarValues( const QStringList & list )
</PROTOS>
<SLOTS>