From e278bae9758f02ad3c72c6fcc3432ba5ed230149 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Thu, 22 Dec 2011 00:38:58 +0000 Subject: [PATCH] 2011-12-21 16:23 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/qtgui/qth/QPushButton.qth * contrib/hbqt/qtgui/qth/QWidget.qth + Added: PaintEvent = YES to check if engine is working ok. Yes, it is working. * contrib/hbqt/tests/demoqt.prg + Added: functionality to paint a PushButton via user code. Still looking for the how to determine state of the object, in this case, pushbutton, whether it is being pushed or otherwise. * contrib/hbqt/hbmk2_qt.hbs + Implemented: engine to receive protected methods, i.e., events and a way to exploit them. The code needs some more make-over but the proof of concept is working. Lookfor hbqt/tests/demoqt.prg for a live example. NOTE: there is only a minimal need to add few keywords, rest all is handelled by the engine. The next step is to synchronize this methodology with :connect() / :disconnect() protocol. --- harbour/ChangeLog | 37 +- harbour/contrib/hbqt/hbmk2_qt.hbs | 340 +++++++++++------- .../contrib/hbqt/qtgui/qth/QPushButton.qth | 2 + harbour/contrib/hbqt/qtgui/qth/QWidget.qth | 2 +- harbour/contrib/hbqt/tests/demoqt.prg | 12 + 5 files changed, 252 insertions(+), 141 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2cda155fda..7356d19cf1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,12 +16,37 @@ The license applies to all entries newer than 2009-04-28. */ +2011-12-21 16:23 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/qtgui/qth/QPushButton.qth + * contrib/hbqt/qtgui/qth/QWidget.qth + + Added: PaintEvent = YES to check if engine is working ok. + Yes, it is working. + + * contrib/hbqt/tests/demoqt.prg + + Added: functionality to paint a PushButton via user code. + Still looking for the how to determine state of the object, + in this case, pushbutton, whether it is being pushed or + otherwise. + + * contrib/hbqt/hbmk2_qt.hbs + + Implemented: engine to receive protected methods, i.e., events + and a way to exploit them. The code needs some more make-over + but the proof of concept is working. Lookfor hbqt/tests/demoqt.prg + for a live example. + + NOTE: there is only a minimal need to add few keywords, rest all + is handelled by the engine. The next step is to synchronize + this methodology with :connect() / :disconnect() protocol. + 2011-12-20 16:55 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/qtgui/qth/QItemSelection.qth * contrib/hbqt/qtgui/qth/QItemSelectionModel.qth + Enforced: methods with QModelIndexList => QList< QModelIndex ). * contrib/hbqt/qtgui/qth/QWidget.qth + + Added: futuristic keyword "PaintEvent" in section. + + * contrib/hbqt/hbmk2_qt.hbs ! Fixed: to honor QModelIndexList cast. + Added: building blocks to create classes with their protected methods. The constructor methods are valid for only QWidget @@ -29,18 +54,6 @@ Still I am looking for how to include resultant .cpp in final binaries. Till then this code stays as is. - Viktor: can you look into new methods and fix the logic from hbmk2's - point of view ? - qqwidget.h is created ok. - moc_qqwidget.cpp is created ok. - moc_qqwidget.o is missing. - QWidget.cpp is compiled fine. - But when compiling demoqt.prg, it reports missing - vtable for QQWidget which is because moc_qqwidget.cpp - is not being linked. - To invoke, in QWidget.qth, set PaintEvent = YES and - rebuild QWidget.*. - 2011-12-20 13:03 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * src/rdd/usrrdd/rdds/arrayrdd.prg ! formatting/cleanup, removed unncessary e"" string diff --git a/harbour/contrib/hbqt/hbmk2_qt.hbs b/harbour/contrib/hbqt/hbmk2_qt.hbs index 090cf18aa7..826d882da2 100644 --- a/harbour/contrib/hbqt/hbmk2_qt.hbs +++ b/harbour/contrib/hbqt/hbmk2_qt.hbs @@ -142,6 +142,13 @@ FUNCTION hbmk2_plugin_qt( hbmk2 ) hbmk2_AddInput_CPP( hbmk2, cDst ) cDst := hb_PathNormalize( hbmk2_FNameDirExtSet( "class_" + Lower( hb_FNameName( cSrc ) ), hb_FNameDir( cSrc ) + hbmk2[ "vars" ][ "qthdocdir" ] + "en" + hb_ps(), ".txt" ) ) AAdd( hbmk2[ "vars" ][ "aQTH_DOC" ], cDst ) + + IF qth_is_extended( cSrc ) + AAdd( hbmk2[ "vars" ][ "aMOC_Src" ], hbmk2_FNameDirExtSet( "q" + lower( hb_FNameName( cSrc ) ), hbmk2[ "cWorkDir" ], ".h" ) ) + cDst := hbmk2_FNameDirExtSet( "moc_q" + lower( hb_FNameName( cSrc ) ), hbmk2[ "cWorkDir" ], ".cpp" ) + AAdd( hbmk2[ "vars" ][ "aMOC_Dst" ], cDst ) + hbmk2_AddInput_CPP( hbmk2, cDst ) + ENDIF NEXT /* Detect tool locations */ @@ -316,7 +323,7 @@ FUNCTION hbmk2_plugin_qt( hbmk2 ) IF lBuildIt IF ! hbmk2[ "lDONTEXEC" ] - IF ! qth_to_src( cSrc, cDstCPP, cDstDOC, hbmk2[ "vars" ][ "qtmodule" ], hbmk2[ "vars" ][ "qtver" ], hbmk2 ) + IF ! qth_to_src( cSrc, cDstCPP, cDstDOC, hbmk2[ "vars" ][ "qtmodule" ], hbmk2[ "vars" ][ "qtver" ] ) IF ! hbmk2[ "lIGNOREERROR" ] cRetVal := "error" EXIT @@ -1013,10 +1020,10 @@ STATIC FUNCTION hbqtui_stripRear( /* @ */ cString, cTkn ) /*======================================================================*/ -STATIC FUNCTION qth_to_src( cQTHFileName, cCPPFileName, cDOCFileName, cQtModule, cQtVer, hbmk2 ) +STATIC FUNCTION qth_to_src( cQTHFileName, cCPPFileName, cDOCFileName, cQtModule, cQtVer ) LOCAL oSrc - oSrc := HbQtSource():new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileName, hbmk2 ) + oSrc := HbQtSource():new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileName ) oSrc:build() RETURN .T. @@ -1025,7 +1032,6 @@ STATIC FUNCTION qth_to_src( cQTHFileName, cCPPFileName, cDOCFileName, cQtModule, CREATE CLASS HbQtSource - VAR hbmk2 VAR cCPPFileName, cDOCFileName VAR hRef @@ -1076,12 +1082,12 @@ CREATE CLASS HbQtSource VAR lPaintEvent INIT .f. VAR lBuildExtended INIT .f. - METHOD new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileName, hbmk2 ) + METHOD new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileName ) METHOD parseProto( cProto, fBody_ ) METHOD parseVariables( cProto ) METHOD build() METHOD exploreExtensions() - METHOD buildExtendedSource( txt_ ) + METHOD buildExtendedSource( t_ ) METHOD buildExtendedHeader() METHOD getConstructor() METHOD getConstructorW() @@ -1097,7 +1103,7 @@ CREATE CLASS HbQtSource /*----------------------------------------------------------------------*/ -METHOD HbQtSource:new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileName, hbmk2 ) +METHOD HbQtSource:new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileName ) LOCAL cQth, s, n, i, n1, b_, tmp, cOrg, fBody_ LOCAL f @@ -1115,8 +1121,6 @@ METHOD HbQtSource:new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileNa hb_fNameSplit( cQTHFileName,, @tmp ) - ::hbmk2 := hbmk2 - ::cCPPFileName := cCPPFileName ::cDOCFileName := cDOCFileName @@ -1214,6 +1218,10 @@ METHOD HbQtSource:new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileNa AEval( ::constructors_, {| e | AAdd( ::protos_, e ) } ) AEval( tmp, {| e | AAdd( ::protos_, e ) } ) + IF ::lBuildExtended + AAdd( ::protos_, "void hbSetEventBlock( int event, PHB_ITEM block );" ) + ENDIF + /* Pull out Variables */ ::varbls_ := hbqtgen_PullOutSection( @cQth, "VARIABLES" ) @@ -1310,6 +1318,7 @@ METHOD HbQtSource:new( cQtModule, cQtVer, cQTHFileName, cCPPFileName, cDOCFileNa METHOD HbQtSource:build() LOCAL i, s, oMtd, tmp, tmp1, n, k, aLine, uQtObject + LOCAL cObjPfx := iif( ::lBuildExtended, "Q", "" ) uQtObject := Upper( ::cQtObject ) @@ -1449,12 +1458,12 @@ METHOD HbQtSource:build() AAdd( aLine, "typedef struct" ) AAdd( aLine, "{" ) IF ::isObject - AAdd( aLine, " QPointer< "+ ::cQtObject +" > ph;" ) + AAdd( aLine, " QPointer< "+ cObjPfx + ::cQtObject +" > ph;" ) ELSE IF ::isList - AAdd( aLine, " " + ::cQtObject + "< void * > * ph;" ) + AAdd( aLine, " " + cObjPfx + ::cQtObject + "< void * > * ph;" ) ELSE - AAdd( aLine, " " + ::cQtObject + " * ph;" ) + AAdd( aLine, " " + cObjPfx + ::cQtObject + " * ph;" ) ENDIF ENDIF AAdd( aLine, " bool bNew;" ) @@ -1482,35 +1491,35 @@ METHOD HbQtSource:build() AAdd( aLine, " {" ) AAdd( aLine, " if( p->ph )" ) AAdd( aLine, " {" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p %p YES_rel_' + ::cQtObject + ' /.\\ ", ( void * ) p, ( void * ) p->ph ) );' ) - #endif - AAdd( aLine, " delete ( " + ::cQtObject + " * )( p->ph ); " ) - #ifdef _GEN_TRACE_ +#endif + AAdd( aLine, " delete ( " + cObjPfx + ::cQtObject + " * )( p->ph ); " ) +#ifdef _GEN_TRACE_ AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p %p YES_rel_' + ::cQtObject + ' \\./ ", ( void * ) p, ( void * ) p->ph ) );' ) - #endif +#endif AAdd( aLine, " }" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, " else" ) AAdd( aLine, " {" ) AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p DEL_rel_' + ::cQtObject + ' : already deleted!", ( void * ) p->ph ) );' ) AAdd( aLine, " }" ) - #endif +#endif AAdd( aLine, " }" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, " else" ) AAdd( aLine, " {" ) AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p PTR_rel_' + ::cQtObject + ' : not a _new_ object", ( void * ) p->ph ) );' ) AAdd( aLine, " }" ) - #endif +#endif AAdd( aLine, " p->ph = NULL;" ) AAdd( aLine, " }" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, " else" ) AAdd( aLine, " {" ) AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "DEL_rel_' + ::cQtObject + ' : not valid GC object" ) );' ) AAdd( aLine, " }" ) - #endif +#endif ELSE AAdd( aLine, " HBQT_GC_T_" + ::cQtObject + " * p = ( HBQT_GC_T_" + ::cQtObject + " * ) Cargo; " ) AAdd( aLine, " " ) @@ -1520,9 +1529,9 @@ METHOD HbQtSource:build() AAdd( aLine, " {" ) AAdd( aLine, " if( p->ph )" ) AAdd( aLine, " {" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p _rel_' + ::cQtObject + ' /.\\", ( void * ) p->ph ) );' ) - #endif +#endif IF ::isList AAdd( aLine, " int i; " ) AAdd( aLine, " for( i = 0; i < p->ph->size(); i++ )" ) @@ -1530,32 +1539,32 @@ METHOD HbQtSource:build() AAdd( aLine, " hb_itemRelease( p->ph->at( i ) );" ) AAdd( aLine, " }" ) ENDIF - AAdd( aLine, " delete ( ( " + ::cQtObject + iif( ::isList, "< void * >", "" ) + " * ) p->ph ); " ) - #ifdef _GEN_TRACE_ + AAdd( aLine, " delete ( ( " + cObjPfx + ::cQtObject + iif( ::isList, "< void * >", "" ) + " * ) p->ph ); " ) +#ifdef _GEN_TRACE_ AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p YES_rel_' + ::cQtObject + ' \\./", ( void * ) p->ph ) );' ) - #endif +#endif AAdd( aLine, " }" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, " else" ) AAdd( aLine, " {" ) AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p DEL_rel_' + ::cQtObject + ' : object already deleted!", ( void * ) p->ph ) );' ) AAdd( aLine, " }" ) - #endif +#endif AAdd( aLine, " }" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, " else" ) AAdd( aLine, " {" ) AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p DEL_rel_' + ::cQtObject + ' : not a _new_ object!", ( void * ) p->ph ) );' ) AAdd( aLine, " }" ) - #endif +#endif AAdd( aLine, " p->ph = NULL;" ) AAdd( aLine, " }" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, " else" ) AAdd( aLine, " {" ) AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p PTR_rel_' + ::cQtObject + ' : not a valid GC object!", ( void * ) p ) );' ) AAdd( aLine, " }" ) - #endif +#endif ENDIF ELSE AAdd( aLine, " /* CASE else */" ) @@ -1576,9 +1585,9 @@ METHOD HbQtSource:build() ENDIF AAdd( aLine, "" ) IF ::isObject - AAdd( aLine, " new( & p->ph ) QPointer< "+ ::cQtObject +" >( ( " + ::cQtObject + " * ) pObj );" ) + AAdd( aLine, " new( & p->ph ) QPointer< "+ cObjPfx + ::cQtObject +" >( ( " + cObjPfx + ::cQtObject + " * ) pObj );" ) ELSE - AAdd( aLine, " p->ph = ( " + ::cQtObject + iif( ::isList, "< void * >", "" ) + " * ) pObj;" ) + AAdd( aLine, " p->ph = ( " + cObjPfx + ::cQtObject + iif( ::isList, "< void * >", "" ) + " * ) pObj;" ) ENDIF AAdd( aLine, " p->bNew = bNew;" ) AAdd( aLine, " p->func = hbqt_gcRelease_" + ::cQtObject + ";" ) @@ -1589,7 +1598,7 @@ METHOD HbQtSource:build() AAdd( aLine, " p->mark = NULL;" ) endif AAdd( aLine, "" ) - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( aLine, " if( bNew )" ) AAdd( aLine, " {" ) AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p _new_' + ::cQtObject + iif( ::isObject, ' under p->pq', '' ) + '", ( void * ) pObj ) );' ) @@ -1598,7 +1607,7 @@ METHOD HbQtSource:build() AAdd( aLine, " {" ) AAdd( aLine, ' HB_TRACE( ' + ::cTrMode + ', ( "ph=%p NOT_new_' + ::cQtObject + '", ( void * ) pObj ) );' ) AAdd( aLine, " }" ) - #endif +#endif AAdd( aLine, " return p;" ) AAdd( aLine, "}" ) AAdd( aLine, "" ) @@ -1696,96 +1705,57 @@ METHOD HbQtSource:exploreExtensions() /*----------------------------------------------------------------------*/ -METHOD HbQtSource:buildExtendedSource( txt_ ) - - IF ! ::lBuildExtended - RETURN Self - ENDIF - - AAdd( txt_, ' ' ) - AAdd( txt_, '#include "qqwidget.h" ' ) - AAdd( txt_, ' ' ) - AAdd( txt_, 'QQWidget::QQWidget( QWidget * parent, Qt::WindowFlags f ) : QWidget( parent, f )' ) - AAdd( txt_, '{ ' ) - AAdd( txt_, ' pPaintBlock = NULL; ' ) - AAdd( txt_, '} ' ) - AAdd( txt_, 'QQWidget::~QQWidget() ' ) - AAdd( txt_, '{ ' ) - AAdd( txt_, ' if( pPaintBlock ) ' ) - AAdd( txt_, ' { ' ) - AAdd( txt_, ' hb_itemRelease( pPaintBlock ); ' ) - AAdd( txt_, ' pPaintBlock = NULL; ' ) - AAdd( txt_, ' } ' ) - AAdd( txt_, '} ' ) - AAdd( txt_, 'void QQWidget::hbSetEventBlock( int event, PHB_ITEM pBlock ) ' ) - AAdd( txt_, '{ ' ) - AAdd( txt_, ' switch( event ) ' ) - AAdd( txt_, ' { ' ) - AAdd( txt_, ' case QEvent::Paint: ' ) - AAdd( txt_, ' { ' ) - AAdd( txt_, ' if( pPaintBlock ) ' ) - AAdd( txt_, ' { ' ) - AAdd( txt_, ' hb_itemRelease( pPaintBlock ); ' ) - AAdd( txt_, ' } ' ) - AAdd( txt_, ' pPaintBlock = hb_itemNew( pBlock ); ' ) - AAdd( txt_, ' hb_gcUnlock( pPaintBlock ); ' ) - AAdd( txt_, ' break; ' ) - AAdd( txt_, ' } ' ) - AAdd( txt_, ' } ' ) - AAdd( txt_, '} ' ) - AAdd( txt_, 'void QQWidget::paintEvent( QPaintEvent * event ) ' ) - AAdd( txt_, '{ ' ) - AAdd( txt_, ' bool bEventHandelled = false; ' ) - AAdd( txt_, ' if( pPaintBlock ) ' ) - AAdd( txt_, ' { ' ) - AAdd( txt_, ' PHB_ITEM p0 = hb_itemPutNI( NULL, QEvent::Paint ); ' ) - AAdd( txt_, ' PHB_ITEM p1 = hb_itemNew( hbqt_create_objectGC( hbqt_gcAllocate_QPaintEvent( event, false ), "hb_QPaintEvent" ) ); ' ) - AAdd( txt_, ' bEventHandelled = hb_vmEvalBlockV( pPaintBlock, 2, p0, p1 ); ' ) - AAdd( txt_, ' hb_itemRelease( p0 ); ' ) - AAdd( txt_, ' hb_itemRelease( p1 ); ' ) - AAdd( txt_, ' } ' ) - AAdd( txt_, ' if( ! bEventHandelled ) ' ) - AAdd( txt_, ' { ' ) - AAdd( txt_, ' QWidget::paintEvent( event ); ' ) - AAdd( txt_, ' } ' ) - AAdd( txt_, '} ' ) - AAdd( txt_, ' ' ) - - RETURN Self - -/*----------------------------------------------------------------------*/ - METHOD HbQtSource:buildExtendedHeader() - LOCAL cPath, txt_ + LOCAL cPath, txt_, cObj IF ! ::lBuildExtended RETURN Self ENDIF + cObj := ::cQtObject txt_:= {} - aadd( txt_, ' ' ) - aadd( txt_, 'HB_EXTERN_BEGIN ' ) + aadd( txt_, '' ) + aadd( txt_, '#include "hbapiitm.h" ' ) + aadd( txt_, '' ) + aadd( txt_, 'HB_EXTERN_BEGIN' ) + IF ::lPaintEvent AAdd( txt_, 'extern HB_EXPORT void * hbqt_gcAllocate_QPaintEvent( void * pObj, bool bNew );' ) - aadd( txt_, 'HB_EXTERN_END ' ) - aadd( txt_, ' ' ) - aadd( txt_, '#include ' ) - aadd( txt_, '#include ' ) - aadd( txt_, ' ' ) - aadd( txt_, 'class QQWidget : public QWidget ' ) - aadd( txt_, '{ ' ) - aadd( txt_, ' Q_OBJECT ' ) - aadd( txt_, ' ' ) - aadd( txt_, 'public: ' ) - aadd( txt_, ' QQWidget( QWidget * parent = 0, Qt::WindowFlags f = 0 ); ' ) - aadd( txt_, ' virtual ~QQWidget(); ' ) - aadd( txt_, ' ' ) - aadd( txt_, ' void hbSetEventBlock( int event, PHB_ITEM pBlock ); ' ) - aadd( txt_, ' ' ) - aadd( txt_, ' PHB_ITEM pPaintBlock; ' ) - aadd( txt_, ' void paintEvent ( QPaintEvent * event ); ' ) - aadd( txt_, '}; ' ) - aadd( txt_, ' ' ) + AAdd( txt_, 'extern HB_EXPORT void * hbqt_gcAllocate_QPainter( void * pObj, bool bNew );' ) + ENDIF + aadd( txt_, 'HB_EXTERN_END' ) + aadd( txt_, '' ) + aadd( txt_, '#include ' ) + IF ::lPaintEvent + aadd( txt_, '#include ' ) + aadd( txt_, '#include ' ) + ENDIF + aadd( txt_, '' ) + aadd( txt_, 'class Q' + cObj + ' : public ' + cObj ) + aadd( txt_, '{' ) + aadd( txt_, ' Q_OBJECT' ) + aadd( txt_, '' ) + aadd( txt_, 'public:' ) + + SWITCH cObj + CASE "QWidget" + aadd( txt_, ' Q' + cObj + '( QWidget * parent = 0, Qt::WindowFlags f = 0 );' ) + EXIT + OTHERWISE + aadd( txt_, ' Q' + cObj + '( QWidget * parent = 0 );' ) + EXIT + ENDSWITCH + + aadd( txt_, ' virtual ~Q' + cObj + '();' ) + aadd( txt_, '' ) + aadd( txt_, ' void hbSetEventBlock( int event, PHB_ITEM pBlock );' ) + aadd( txt_, '' ) + IF ::lPaintEvent + aadd( txt_, ' PHB_ITEM pPaintBlock;' ) + aadd( txt_, ' void paintEvent ( QPaintEvent * event );' ) + ENDIF + aadd( txt_, '};' ) + aadd( txt_, '' ) aeval( txt_, {|e,i| txt_[ i ] := trim( e ) } ) @@ -1793,9 +1763,88 @@ METHOD HbQtSource:buildExtendedHeader() hbqtgen_CreateTarget( cPath + "q" + lower( ::cQtObject ) + ".h", txt_ ) - aadd( ::hbmk2[ "vars" ][ "aMOC_Src" ], cPath + "q" + lower( ::cQtObject ) + ".h" ) - aadd( ::hbmk2[ "vars" ][ "aMOC_Dst" ], cPath + "moc_q" + lower( ::cQtObject ) + ".cpp" ) - hbmk2_AddInput_CPP( ::hbmk2, cPath + "moc_q" + lower( ::cQtObject ) + ".cpp" ) + RETURN Self + +/*----------------------------------------------------------------------*/ + +METHOD HbQtSource:buildExtendedSource( t_ ) + LOCAL txt_, cObj + + IF ! ::lBuildExtended + RETURN Self + ENDIF + + cObj := ::cQtObject + txt_ := {} + + AAdd( txt_, '' ) + AAdd( txt_, '#include "q' + Lower( cObj ) + '.h"' ) + AAdd( txt_, '' ) + + SWITCH cObj + CASE "QWidget" + AAdd( txt_, 'Q' + cObj + '::Q' + cObj + '( QWidget * parent, Qt::WindowFlags f ) : ' + cObj + '( parent, f )' ) + EXIT + OTHERWISE + AAdd( txt_, 'Q' + cObj + '::Q' + cObj + '( QWidget * parent ) : ' + cObj + '( parent )' ) + EXIT + ENDSWITCH + + AAdd( txt_, '{' ) + IF ::lPaintEvent + AAdd( txt_, ' pPaintBlock = NULL;' ) + ENDIF + AAdd( txt_, '}' ) + AAdd( txt_, 'Q' + cObj + '::~Q' + cObj + '()' ) + AAdd( txt_, '{' ) + IF ::lPaintEvent + AAdd( txt_, ' if( pPaintBlock )' ) + AAdd( txt_, ' {' ) + AAdd( txt_, ' hb_itemRelease( pPaintBlock );' ) + AAdd( txt_, ' pPaintBlock = NULL;' ) + AAdd( txt_, ' }' ) + ENDIF + AAdd( txt_, '}' ) + AAdd( txt_, 'void Q' + cObj + '::hbSetEventBlock( int event, PHB_ITEM pBlock )' ) + AAdd( txt_, '{' ) + AAdd( txt_, ' switch( event )' ) + AAdd( txt_, ' {' ) + IF ::lPaintEvent + AAdd( txt_, ' case QEvent::Paint:' ) + AAdd( txt_, ' {' ) + AAdd( txt_, ' if( pPaintBlock )' ) + AAdd( txt_, ' {' ) + AAdd( txt_, ' hb_itemRelease( pPaintBlock );' ) + AAdd( txt_, ' }' ) + AAdd( txt_, ' pPaintBlock = hb_itemNew( pBlock );' ) + AAdd( txt_, ' hb_gcUnlock( pPaintBlock );' ) + AAdd( txt_, ' break;' ) + AAdd( txt_, ' }' ) + ENDIF + AAdd( txt_, ' }' ) + AAdd( txt_, '}' ) + IF ::lPaintEvent + AAdd( txt_, 'void Q' + cObj + '::paintEvent( QPaintEvent * event )' ) + AAdd( txt_, '{' ) + AAdd( txt_, ' bool bEventHandelled = false;' ) + AAdd( txt_, ' if( pPaintBlock )' ) + AAdd( txt_, ' {' ) + AAdd( txt_, ' QPainter painter( this );' ) + AAdd( txt_, ' PHB_ITEM p0 = hb_itemNew( hbqt_create_objectGC( hbqt_gcAllocate_QPaintEvent( event, false ), "hb_QPaintEvent" ) );' ) + AAdd( txt_, ' PHB_ITEM p1 = hb_itemNew( hbqt_create_objectGC( hbqt_gcAllocate_QPainter( &painter, false ), "hb_QPainter" ) );' ) + AAdd( txt_, ' bEventHandelled = hb_vmEvalBlockV( pPaintBlock, 2, p0, p1 );' ) + AAdd( txt_, ' hb_itemRelease( p0 );' ) + AAdd( txt_, ' hb_itemRelease( p1 );' ) + AAdd( txt_, ' }' ) + AAdd( txt_, ' if( ! bEventHandelled )' ) + AAdd( txt_, ' {' ) + AAdd( txt_, ' ' + cObj + '::paintEvent( event );' ) + AAdd( txt_, ' }' ) + AAdd( txt_, '}' ) + ENDIF + AAdd( txt_, '' ) + + AEval( txt_, {|e| aadd( t_, trim( e ) ) } ) RETURN Self @@ -1803,12 +1852,13 @@ METHOD HbQtSource:buildExtendedHeader() METHOD HbQtSource:getConstructor() LOCAL i, s, aLine := {} + LOCAL cObjPfx := iif( ::lBuildExtended, "Q", "" ) IF ::isConstructor IF ::isList - AAdd( aLine, " " + ::cQtObject + "< void * > * pObj = NULL;" ) + AAdd( aLine, " " + cObjPfx + ::cQtObject + "< void * > * pObj = NULL;" ) ELSE - AAdd( aLine, " " + ::cQtObject + " * pObj = NULL;" ) + AAdd( aLine, " " + cObjPfx + ::cQtObject + " * pObj = NULL;" ) ENDIF AAdd( aLine, " " ) FOR i := 3 TO Len( ::new_ ) - 1 @@ -1820,6 +1870,7 @@ METHOD HbQtSource:getConstructor() s := RTrim( StrTran( s, ");" ) ) + ";" ENDIF s := StrTran( s, "( " + ::cQtObject + "* )" ) + s := StrTran( s, "new ", "new " + cObjPfx ) AAdd( aLine, s ) ELSE AAdd( aLine, ::new_[ i ] ) @@ -2013,10 +2064,9 @@ METHOD HbQtSource:getMethodBody( oMtd, cMtdName, aMethods ) IF ! empty( oMtd:cVersion ) AAdd( txt_, " #if QT_VERSION >= " + oMtd:cVersion ) ENDIF - #ifdef _GEN_TRACE_ +#ifdef _GEN_TRACE_ AAdd( txt_, ' HB_TRACE( ' + ::cTrMode + ', ( "' + ::cQtObject + ":" + oMtd:cHBFunc + '" ) );' ) - //AAdd( txt_, ' HB_TRACE( HB_TR_DEBUG, ( "' + ::cQtObject + ":" + oMtd:cHBFunc + '" ) );' ) - #endif +#endif /* If method is manually written in .qth - no more processing */ IF ! Empty( oMtd:fBody_ ) @@ -2076,7 +2126,7 @@ METHOD HbQtSource:getMethodBody( oMtd, cMtdName, aMethods ) NEXT - cTmp := ::cQtObject + iif( ::isList, "< void * >", "" ) + cTmp := iif( ::lBuildExtended, "Q", "" ) + ::cQtObject + iif( ::isList, "< void * >", "" ) AAdd( txt_, " " + cTmp + " * " + v + " = ( " + cTmp + " * ) hbqt_par_ptr( 0 );" ) AAdd( txt_, " if( " + v + " )" ) @@ -3177,3 +3227,37 @@ STATIC FUNCTION __TY_Method( oMtd, nArgs ) RETURN cRet /*----------------------------------------------------------------------*/ + +STATIC FUNCTION qth_is_extended( cQTHFileName ) + LOCAL lYes := .F. + LOCAL cQth, aTkn, n, s, class_, cls_:= {} + + cQth := hb_MemoRead( cQTHFileName ) + + /* Prepare to be parsed properly */ + IF !( hb_eol() == Chr( 10 ) ) + cQth := StrTran( cQth, hb_eol(), Chr( 10 ) ) + ENDIF + IF !( hb_eol() == Chr( 13 ) + Chr( 10 ) ) + cQth := StrTran( cQth, Chr( 13 ) + Chr( 10 ), Chr( 10 ) ) + ENDIF + + IF ! Empty( class_:= hbqtgen_PullOutSection( @cQth, "CLASS" ) ) + FOR EACH s IN class_ + IF ( n := at( "=", s ) ) > 0 + AAdd( cls_, { Upper( AllTrim( SubStr( s, 1, n - 1 ) ) ), Upper( AllTrim( SubStr( s, n + 1 ) ) ) } ) + ENDIF + NEXT + ENDIF + + FOR EACH aTkn IN cls_ + IF aTkn[ 1 ] $ "PAINTEVENT,xxx" + IF aTkn[ 2 ] == "YES" + lYes := .T. + ENDIF + ENDIF + NEXT + + RETURN lYes + +/*----------------------------------------------------------------------*/ diff --git a/harbour/contrib/hbqt/qtgui/qth/QPushButton.qth b/harbour/contrib/hbqt/qtgui/qth/QPushButton.qth index 076b1c6051..ca6f09cf2d 100644 --- a/harbour/contrib/hbqt/qtgui/qth/QPushButton.qth +++ b/harbour/contrib/hbqt/qtgui/qth/QPushButton.qth @@ -14,6 +14,8 @@ Inherit = QAbstractButton New = pParent + +PaintEvent = YES diff --git a/harbour/contrib/hbqt/qtgui/qth/QWidget.qth b/harbour/contrib/hbqt/qtgui/qth/QWidget.qth index 9aae9d5e71..e14e6bc2f6 100644 --- a/harbour/contrib/hbqt/qtgui/qth/QWidget.qth +++ b/harbour/contrib/hbqt/qtgui/qth/QWidget.qth @@ -15,7 +15,7 @@ Inherit = QObject, QPaintDevice New = pParent, nFlags -PaintEvent = +PaintEvent = YES diff --git a/harbour/contrib/hbqt/tests/demoqt.prg b/harbour/contrib/hbqt/tests/demoqt.prg index 738ee0c154..8021f28307 100644 --- a/harbour/contrib/hbqt/tests/demoqt.prg +++ b/harbour/contrib/hbqt/tests/demoqt.prg @@ -115,6 +115,8 @@ PROCEDURE Main() oProg := Build_ProgressBar( oDA, { 30,300 }, { 200,30 } ) aList := Build_ListBox( oDA, { 310,240 }, { 150, 100 } ) + oBtn:hbSetEventBlock( QEvent_Paint, {|oEvent,oPainter| RePaint( oEvent, oPainter ) } ) + oWnd:connect( 6, {|e| My_Events( e ) } ) oWnd:connect( 19, {|| QApplication():quit() } ) oWnd:Show() @@ -614,3 +616,13 @@ FUNCTION ShowInSystemTray( oWnd ) RETURN nil /*----------------------------------------------------------------------*/ + +FUNCTION RePaint( oPaintEvent, oPainter ) + LOCAL qRect := oPaintEvent:rect() + + oPainter:fillRect( qRect, QColor( 120,12,200 ) ) + oPainter:drawText( 30, 30, "Harbour" ) + + RETURN .f. + +/*----------------------------------------------------------------------*/