From 421a6ca8dbc663f55841f6cd7a2fadd5b239d930 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Fri, 23 Dec 2011 22:37:12 +0000 Subject: [PATCH] 2011-12-23 14:34 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/tests/demoqt.prg ! Demonstrated: how hovering effect on a pushbutton can be achieved. ! Decorated: pushbutton with some minor details. --- harbour/ChangeLog | 5 +++ harbour/contrib/hbqt/tests/demoqt.prg | 44 ++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f733fc18b4..19eed35852 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,11 @@ The license applies to all entries newer than 2009-04-28. */ +2011-12-23 14:34 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/tests/demoqt.prg + ! Demonstrated: how hovering effect on a pushbutton can be achieved. + ! Decorated: pushbutton with some minor details. + 2011-12-23 13:09 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/qtcore/hbqt_misc.prg + Embedded: oQt:hbSetEventBlock( QEvent_Paint, bBlock ) diff --git a/harbour/contrib/hbqt/tests/demoqt.prg b/harbour/contrib/hbqt/tests/demoqt.prg index efe18b017f..b0dfa79af1 100644 --- a/harbour/contrib/hbqt/tests/demoqt.prg +++ b/harbour/contrib/hbqt/tests/demoqt.prg @@ -113,6 +113,8 @@ PROCEDURE Main() oProg := Build_ProgressBar( oDA, { 30,300 }, { 200,30 } ) aList := Build_ListBox( oDA, { 310,240 }, { 150, 100 } ) + oBtn:connect( QEvent_Enter, {|oEvent| RePaintHover( oEvent, oBtn, QEvent_Enter ) } ) + oBtn:connect( QEvent_Leave, {|oEvent| RePaintHover( oEvent, oBtn, QEvent_Leave ) } ) oBtn:connect( QEvent_Paint, {|oEvent,oPainter| RePaint( oEvent, oPainter, oBtn ) } ) oWnd:connect( QEvent_KeyPress, {|e| My_Events( e ) } ) @@ -615,20 +617,52 @@ FUNCTION ShowInSystemTray( oWnd ) /*----------------------------------------------------------------------*/ -FUNCTION RePaint( oPaintEvent, oPainter, oBtn ) +STATIC FUNCTION RePaint( oPaintEvent, oPainter, oBtn ) + LOCAL qColor LOCAL qRect := oPaintEvent:rect() IF oBtn:isDown() - oPainter:fillRect( qRect, QColor( 120,12,200 ) ) - oPainter:drawRect( qRect ) + qColor := QColor( 120,12,200 ) + oPainter:fillRect( qRect, qColor ) + oPainter:drawRect( qRect:adjusted( 0,0,-1,-1 ) ) oPainter:drawText( 31, 31, "Harbour" ) ELSE - oPainter:fillRect( qRect, QColor( 220,100,12 ) ) + oPainter:fillRect( qRect, SetButtonColor() ) oPainter:drawText( 30, 30, "Harbour" ) oPainter:setPen( QColor( 255,255,255 ) ) - oPainter:drawRect( qRect ) + oPainter:drawRect( qRect:adjusted( 0,0,-1,-1 ) ) ENDIF RETURN .T. /*----------------------------------------------------------------------*/ + +STATIC FUNCTION RePaintHover( oEvent, oBtn, nEvent ) + + HB_SYMBOL_UNUSED( oEvent ) + + IF nEvent == QEvent_Leave + SetButtonColor( QColor( 220,100,12 ) ) + ELSEIF nEvent == QEvent_Enter + SetButtonColor( QColor( 0,255,0 ) ) + ENDIF + oBtn:repaint() + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +STATIC FUNCTION SetButtonColor( qClr ) + LOCAL l_clr + STATIC s_clr + IF s_clr == NIL + s_clr := QColor( 220,100,12 ) + ENDIF + l_clr := s_clr + IF hb_isObject( qClr ) + s_clr := qClr + ENDIF + RETURN l_clr + +/*----------------------------------------------------------------------*/ +