From 34a9acf5388684a2c5663d4bd9c5c8bf2dd3e034 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Fri, 23 Dec 2011 21:21:00 +0000 Subject: [PATCH] 2011-12-23 13:09 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/qtcore/hbqt_misc.prg + Embedded: oQt:hbSetEventBlock( QEvent_Paint, bBlock ) => oQt:connect( QEvent_Paint, bBlock ) NOTE: the difference is that in all other events only one parameter is passed to bBlock, i.e., an object of type relevant QEvent, whereas, for paintEvent two parameters are passed, first as usual qPaintEvent, the other qPainter. * contrib/hbqt/tests/demoqt.prg ! Replaced: oBtn:hbSetEventBlock( QEvent_Paint, bBlock ) => oBtn:connect( QEvent_Paint, bBlock ) --- harbour/ChangeLog | 18 +++++++++- harbour/contrib/hbqt/qtcore/hbqt_misc.prg | 41 +++++++++++++---------- harbour/contrib/hbqt/tests/demoqt.prg | 13 +++---- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2411b8fe74..f733fc18b4 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,7 +16,23 @@ The license applies to all entries newer than 2009-04-28. */ -2011-12-23 23:43 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) +2011-12-23 13:09 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/qtcore/hbqt_misc.prg + + Embedded: oQt:hbSetEventBlock( QEvent_Paint, bBlock ) + => + oQt:connect( QEvent_Paint, bBlock ) + NOTE: the difference is that in all other events only one + parameter is passed to bBlock, i.e., an object of + type relevant QEvent, whereas, for paintEvent two + parameters are passed, first as usual qPaintEvent, + the other qPainter. + + * contrib/hbqt/tests/demoqt.prg + ! Replaced: oBtn:hbSetEventBlock( QEvent_Paint, bBlock ) + => + oBtn:connect( QEvent_Paint, bBlock ) + +2011-12-23 11:43 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/hbmk2_qt.hbs ! Fixed: a strategic omission where return value of a block was not being retrieved properly. Now newly introduced diff --git a/harbour/contrib/hbqt/qtcore/hbqt_misc.prg b/harbour/contrib/hbqt/qtcore/hbqt_misc.prg index af03778939..98693bfb76 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_misc.prg +++ b/harbour/contrib/hbqt/qtcore/hbqt_misc.prg @@ -5,7 +5,7 @@ /* * Harbour Project source code: * - * Copyright 2009 Pritpal Bedi + * Copyright 2009-2011 Pritpal Bedi * www - http://harbour-project.org * * This program is free software; you can redistribute it and/or modify @@ -54,6 +54,8 @@ #include "error.ch" #include "hbtrace.ch" +#define QEvent_Paint 12 + /*----------------------------------------------------------------------*/ CREATE CLASS HbQtObjectHandler @@ -63,7 +65,6 @@ CREATE CLASS HbQtObjectHandler VAR __pSlots PROTECTED VAR __pEvents PROTECTED - //METHOD fromPointer( pPtr ) METHOD hasValidPointer() METHOD connect( cnEvent, bBlock ) @@ -76,9 +77,6 @@ ENDCLASS /*----------------------------------------------------------------------*/ -/* TODO: Drop this function, as it's not desired to have invalid QT pointers wrapped - into valid .prg level QT objects. - Currently it will return .F. for objects created using :fromPointer() */ METHOD HbQtObjectHandler:hasValidPointer() RETURN __hbqt_isPointer( ::pPtr ) @@ -135,17 +133,26 @@ METHOD HbQtObjectHandler:connect( cnEvent, bBlock ) EXIT CASE "N" - IF Empty( ::__pEvents ) - ::__pEvents := HBQEvents( Self ) - ENDIF - nResult := ::__pEvents:hbConnect( Self, cnEvent, bBlock ) + IF cnEvent == QEvent_Paint + IF __objHasMethod( Self, "HBSETEVENTBLOCK" ) + ::hbSetEventBlock( QEvent_Paint, bBlock ) + RETURN .T. + ELSE + RETURN .F. + ENDIF + ELSE + IF Empty( ::__pEvents ) + ::__pEvents := HBQEvents( Self ) + ENDIF + nResult := ::__pEvents:hbConnect( Self, cnEvent, bBlock ) - SWITCH nResult - CASE 0 - RETURN .T. - CASE -3 /* bBlock not supplied */ - RETURN .F. - ENDSWITCH + SWITCH nResult + CASE 0 + RETURN .T. + CASE -3 /* bBlock not supplied */ + RETURN .F. + ENDSWITCH + ENDIF EXIT OTHERWISE @@ -205,8 +212,8 @@ METHOD HbQtObjectHandler:disconnect( cnEvent ) METHOD HbQtObjectHandler:_destroy() -// ::__pSlots := NIL -// ::__pEvents := NIL + ::__pSlots := NIL + ::__pEvents := NIL RETURN NIL diff --git a/harbour/contrib/hbqt/tests/demoqt.prg b/harbour/contrib/hbqt/tests/demoqt.prg index ffdc250908..efe18b017f 100644 --- a/harbour/contrib/hbqt/tests/demoqt.prg +++ b/harbour/contrib/hbqt/tests/demoqt.prg @@ -53,7 +53,7 @@ /*----------------------------------------------------------------------*/ #include "hbqtgui.ch" - +#include "common.ch" #include "hbtrace.ch" /*----------------------------------------------------------------------*/ @@ -71,8 +71,6 @@ */ /*----------------------------------------------------------------------*/ -#include "common.ch" - STATIC oSys, oMenuSys, oActShow, oActHide /*----------------------------------------------------------------------*/ @@ -115,10 +113,10 @@ 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, oBtn ) } ) + oBtn:connect( QEvent_Paint, {|oEvent,oPainter| RePaint( oEvent, oPainter, oBtn ) } ) - oWnd:connect( 6, {|e| My_Events( e ) } ) - oWnd:connect( 19, {|| QApplication():quit() } ) + oWnd:connect( QEvent_KeyPress, {|e| My_Events( e ) } ) + oWnd:connect( QEvent_Close, {|| QApplication():quit() } ) oWnd:Show() QApplication():exec() @@ -620,11 +618,10 @@ FUNCTION ShowInSystemTray( oWnd ) FUNCTION RePaint( oPaintEvent, oPainter, oBtn ) LOCAL qRect := oPaintEvent:rect() - IF oBtn:isDown() oPainter:fillRect( qRect, QColor( 120,12,200 ) ) oPainter:drawRect( qRect ) - oPainter:drawText( 32, 32, "Harbour" ) + oPainter:drawText( 31, 31, "Harbour" ) ELSE oPainter:fillRect( qRect, QColor( 220,100,12 ) ) oPainter:drawText( 30, 30, "Harbour" )