Page 90 of 106

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 3:31 am
by Rathinagiri
mrduck wrote:Last message for today, I promise :-)

see this code:

Code: Select all

METHOD OnClick( bValue ) CLASS CONTROL

   IF ::lCreated
      IF Pcount() == 0
         RETURN ::bOnClick
      ELSEIF Pcount() == 1
         ::bOnClick := bValue
         *::oQTObject:DisConnect( "clicked()" )
         ::oQTObject:Connect( "clicked()" , ::bOnClick )
      ENDIF
   ELSE
      IF pcount() == 0
         RETURN ::bOnClick
      ELSEIF pcount() == 1
         ::bOnClick := bValue
      ENDIF
   ENDIF

   RETURN NIL
I propose some changes (code not tested, it's just a proposal)

Code: Select all

METHOD OnClick( bValue ) CLASS CONTROL

      // one code for  both ::lCreated values
      IF Pcount() > 1
         // error
         ::bOnClick := NIL
      ELSEIF Pcount() == 1
         IF HB_isBlock( bValue )  // check parameter type to avoid chaos
             ::bOnClick := bValue
         ELSE
             // Generate error and/or
             ::bOnClick := NIL   // must remove old codeblock
             return NIL
          ENDIF

         IF ::lCreated .and. hb_isblock( ::bOnClick )
            // force disconnect, ignore return value
            ::oQTObject:DisConnect( "clicked()" )
            // connect
            if ! ::oQTObject:Connect( "clicked()" , ::bOnClick ) 
                // generate error (some errors already generated by :connect,
                // if it returns .F. after a :disconnect there may be other problems...
                ::bOnClick := NIL
         ENDIF  //::lCreated
      ENDIF
 
   RETURN ::bOnClick
A bit of code refactoring, a bit of parameter checking, a bit of error reporting.... just an idea....
Yes. This would be really make HMG working in a bug free environment. Thanks man. We can change all the signals and events like this.

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 6:37 am
by Rathinagiri
Hi Francesco,

source/widget.prg is not available in svn. Kindly commit that too.

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 10:59 am
by mrduck
rathinagiri wrote:
Perhaps we should think about adding [dis]connect methods to class CONTROL
Yes, that is a nice idea. However, some signals/events are widget specific and on change of one widget is different from on change of another widget.
Yes, but instead of calling

oLabel:oQTObject:connect(....)

we will call directly
oLabel:connect(....)

In this way we may "centralize" all connect/disconnect and:
- check that QT objects has been created
- if needed, store the situation

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 11:01 am
by mrduck
rathinagiri wrote:Hi Francesco,

source/widget.prg is not available in svn. Kindly commit that too.
Sorry sorry sorry....

I can't access svn from work, so can you please commit this code ?

Code: Select all

#include "hbclass.ch"
#include "common.ch"
#include "hbqtgui.ch"
#include "hmg.ch"

/*----------------------------------------------------------------------*/

CLASS WIDGET FROM CONTROL

   DATA cClass     INIT       "WIDGET"
   DATA oCentral   INIT       NIL
   // Methods
   METHOD Create
   METHOD CentralWidgetOf   SETGET
PROTECTED:
   METHOD setCentralWidget

ENDCLASS

/*----------------------------------------------------------------------*/

METHOD setCentralWidget( oWindow ) CLASS WIDGET
  IF ::lCreated
        oWindow:oQTObject:setCentralWidget( ::oQTObject )
        RETURN .T.
  ENDIF

  RETURN .F.



METHOD CentralWidgetOf( oValue ) CLASS WIDGET
Local o

   IF Pcount() == 0
      RETURN ::oCentral
   ELSEIF Pcount() == 1 .AND. valtype( ::oCentral ) == "U"
      ::oCentral := oValue
      // Protection: we can't reassign multiple Widget to Central Widget
      // retrieve current central Widget
      o := oValue:oQTObject:centralWidget()
      // if returned pointer is not valid (means there is no central widget already set)
      //     and widget is created
      IF ! o:hasvalidPointer() .AND. ::lCreated
         ::setCentralWidget( oValue )
         RETURN .T.
      ENDIF
   ENDIF

   RETURN .F.


METHOD Create() CLASS WIDGET

   // Create QT Object and other initialization tasks
   IF valtype( ::oContainer ) == 'U'
      ::oQTObject := QWidget( ::oParent:oQTObject )
   ELSE
      ::oQTObject := QWidget( ::oContainer:oQTObject )
   ENDIF
   ::oParent:AddData( ::cName , Self )

   ::oFont := QFont()

   // Setting '::lCreated' flag, so, runtime properties can be invoked
   ::lCreated := .T.

   IF ValType( ::oCentral )           != 'U'; Self:CentralWidgetoF   := ::oCentral           ; ENDIF

   // Set Properties And Events

   ::oQTObject:show()

   RETURN Self

/*----------------------------------------------------------------------*/


Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 4:54 pm
by Rathinagiri
Ok Francesco. Thanks. I will update.

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 6:03 pm
by Rathinagiri
Uploaded and verified.

It is really nice Francesco.

I wish to know the following:

1. What would be the width and height of the central widget?
2. Will that in direct relationship with the window width and height?
3. Will it change because of adding/removing toolbar(s)?

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 6:55 pm
by Carlos Britos
rathinagiri wrote:Uploaded and verified.

It is really nice Francesco.

I wish to know the following:

1. What would be the width and height of the central widget?
2. Will that in direct relationship with the window width and height?
3. Will it change because of adding/removing toolbar(s)?
Hi Francesco, Rathinagiri
Testing the demo3b.prg I have an object (size 100 x 30) over the toolbar buttons and they don't work ok,
I put this to the code at line 62 and seems to work.
::oQTObject:resize( 0, 0 )
::oQTObject:move( 0,0 )
Can you check this please ? Thanks.

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 9:07 pm
by mrduck
rathinagiri wrote: I wish to know the following:

1. What would be the width and height of the central widget?
2. Will that in direct relationship with the window width and height?
3. Will it change because of adding/removing toolbar(s)?
1 & 2 & 3: yes

Open Qt Assistant and search "QMainWindow"

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 9:14 pm
by mrduck
Carlos Britos wrote: Hi Francesco, Rathinagiri
Testing the demo3b.prg I have an object (size 100 x 30) over the toolbar buttons and they don't work ok,
I put this to the code at line 62 and seems to work.
::oQTObject:resize( 0, 0 )
::oQTObject:move( 0,0 )
Can you check this please ? Thanks.
Sorry Carlos, I don't understand....to test demo3b you must click on one of the buttons before moving the toolbar.

at line 62 you move resize and move L2...

Re: Welcome to the Project Developers' Table

Posted: Mon Nov 08, 2010 9:49 pm
by mimmo-italia
hello,
how can I define a length of characters in a texbox?
Thanks