A simple example: Let us extend the bitmap class so it will react on a double click.
Usually we define a simple click to call a function in BITMAP:
Code: Select all
#include "hmg.ch"
#include "hbqtgui.ch"
FUNCTION Main()
LOCAL oForm1
HbQt_ErrorSys()
DEFINE MAINWINDOW oForm1
ROW 10
COL 10
WIDTH 300
HEIGHT 200
FONT "ARIAL"; SIZE 09
DEFINE IMAGE oBitmap
ROW 10; COL 10
WIDTH 200; HEIGHT 200
PICTURE "mypicture.png"
ONCLICK { || msginfo( "Click" ) }
END IMAGE
END Window
ACTIVATE WINDOW oForm1
RETURN Nil
Let´s extend the BITMAP class:
1. We define the new CLASS MYIMAGE based on IMAGE:
Code: Select all
CLASS MYIMAGE FROM BITMAP
ENDCLASS
Code: Select all
CLASS MYIMAGE FROM BITMAP
METHOD OnDblClick SETGET
ENDCLASS
METHOD OnDblClick( bValue ) CLASS MYIMAGE
IF PCOUNT() == 0
RETURN ::bOnDblClick
ELSEIF PCOUNT() == 1
IF hb_IsBlock( bValue ) == .T.
::bOnDblClick := bValue
::oQtObject:connect( QEvent_MouseButtonDblClick, bValue )
ELSEIF hb_IsNil( bValue ) == .T.
::bOnDblClick := NIL
::oQtObject:disconnect( QEvent_MouseButtonDblClick )
ENDIF
ENDIF
RETURN Self
3. We change our program code to define a MYIMAGE instead of IMAGE:
Code: Select all
DEFINE MYIMAGE oBitmap
ROW 10; COL 10
WIDTH 200; HEIGHT 200
PICTURE "mypicture.png"
ONDBLCLICK { || msginfo( "Click" ) }
END MYIMAGE
Since we are using oneliners in our define, we only have to change the translate command for the first line. We search for the translate commands of IMAGE in HMG.CH, copy the lines, put them into the head of our program and change IMAGE TO MYIMAGE (we don´t need to understand the rest of #xcommand ):
Code: Select all
#xcommand DEFINE MYIMAGE <tagreference>[ <dummy1: OF, PARENT> <oParent> ] [ TOVAR <varname> ] => ;
With Object [<varname> :=] MYIMAGE():New( <"tagreference">[, <oParent> ] )
#xcommand END MYIMAGE => End With
And the best thing is that we didn´t change anything of the source codes so any update will not influence our work.
Code: Select all
#include "hmg.ch"
#include "hbqtgui.ch"
#include "hbclass.ch"
#xcommand DEFINE MYIMAGE <tagreference>[ <dummy1: OF, PARENT> <oParent> ] [ TOVAR <varname> ] => ;
With Object [<varname> :=] MYIMAGE():New( <"tagreference">[, <oParent> ] )
#xcommand END MYIMAGE => End With
FUNCTION Main()
LOCAL oForm1
HbQt_ErrorSys()
DEFINE MAINWINDOW oForm1
ROW 10
COL 10
WIDTH 300
HEIGHT 200
FONT "ARIAL"; SIZE 09
DEFINE MYIMAGE oBitmap
ROW 10; COL 10
WIDTH 200; HEIGHT 200
PICTURE "mypicture.png"
ONDBLCLICK { || msginfo( "Click" ) }
END IMAGE
END Window
ACTIVATE WINDOW oForm1
RETURN Nil
//-------------------------------------------------------------------------------------------------------------------------------
/*==============================================================================
MYIMAGE class
==============================================================================*/
CLASS MYIMAGE FROM BITMAP
// Methods
METHOD OnDblClick SETGET
ENDCLASS
/*..............................................................................
OnDblClick
..............................................................................*/
METHOD OnDblClick( bValue ) CLASS MYIMAGE
IF PCOUNT() == 0
RETURN ::bOnDblClick
ELSEIF PCOUNT() == 1
IF hb_IsBlock( bValue ) == .T.
::bOnDblClick := bValue
::oQtObject:connect( QEvent_MouseButtonDblClick, bValue )
ELSEIF hb_IsNil( bValue ) == .T.
::bOnDblClick := NIL
::oQtObject:disconnect( QEvent_MouseButtonDblClick )
ENDIF
ENDIF
RETURN Self