No HMG4 Font object

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: No HMG4 Font object

Post by Rathinagiri »

Thanks a lot for your wish to join the team.

You have been added to the developers list. :)

Regarding the button caption,

yes there is a bug.

Change the line# 732 of /hmg.4/svn/source/control.prg to as follows and re-build hmg library:

Code: Select all

         ::oQTObject:setText( cValue )
I will update the svn today. Thanks a lot for reporting.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: No HMG4 Font object

Post by concentra »

Hi.
I found some other weird thinks...
While playing with fonts, if I change font properties and attribute this changed font to a button ( I am using buttons to test ) the button text font do not change.
But if I change a button ( not a font ) attribute related to font the font changes. And the weird part is that all the other changes made to the font attribute ( not the button ) are now applied !!!
Seems that when a font is attributed to a button object ( I did not tried other objects ) no "refresh" is made in the button font but when the change is made in a button atrtibute the font is "refreshed".
Could you inspect this please ?
In the folowing code the font is unchanged, but if you uncomment // oButton1:FontStrikeOut := .T. the changes are appied.

[[]] Mauricio Faria

--------------------------------------------------------
#include "hmg.ch"

Function Main

Local oWindow , oButton1

With Object oWindow := Window():New()
:Width := 240
:Height := 80
:Type := WND_MAIN
:OnInit := { || oWindow:Center() }

With Object oButton1 := Button():New()
:Row := 20
:Col := 20
:Width := 200
:Caption := 'Click to Change Font'
:OnClick := { || ChangeFont(oButton1) }
End With

End With

oWindow:Activate()

Return


FUNCTION ChangeFont(oButton1)

Static oFont1
Static lFont1

IF lFont1 == NIL
lFont1 := .T.
oFont1 := QFont()
ENDIF

IF lFont1

oFont1:setBold( .T. )
oFont1:setItalic( .T. )
oFont1:setUnderline( .T. )

oButton1:oFont := oFont1

// oButton1:FontStrikeOut := .T.
oButton1:Caption := 'Bold, Italic, Strike and Underline'

ELSE

oFont1:setBold( .F. )
oFont1:setItalic( .F. )
oFont1:setUnderline( .F. )

oButton1:oFont := oFont1

// oButton1:FontStrikeOut := .F.
oButton1:Caption := 'Normal Font'
ENDIF

lFont1 := ! lFont1

RETURN NIL
[[]] Mauricio Ventura Faria
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: No HMG4 Font object

Post by Rathinagiri »

I will check that out. Thanks for reporting.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: No HMG4 Font object

Post by Rathinagiri »

Hi,

The thing is, you are mingling both internal variables and external properties.

Actually, HMG is a wrapper of QT. You need not use any QT object directly. In this case, kindly see your sample modified as below:

This is how we have to use HMG.

Code: Select all

#include "hmg.ch"

Function Main

Local oWindow , oButton1

With Object oWindow := Window():New()
   :Width := 240
   :Height := 80
   :Type := WND_MAIN
   :OnInit := { || oWindow:Center() }

   With Object oButton1 := Button():New()
      :Row := 20
      :Col := 20
      :Width := 200
      :Caption := 'Click to Change Font'
      :OnClick := { || ChangeFont(oButton1) }
   End With

End With

oWindow:Activate()

Return


FUNCTION ChangeFont(oButton1)

Static lFont1

   IF lFont1 == NIL
      lFont1 := .T.
   ENDIF

   IF lFont1
      oButton1:FontBold := .t.
      oButton1:FontItalic := .t.
      oButton1:FontUnderline := .t.
      oButton1:FontStrikeOut := .t.
      oButton1:Caption := 'Bold, Italic, Strike and Underline'
   ELSE

      oButton1:FontBold := .f.
      oButton1:FontItalic := .f.
      oButton1:FontUnderline := .f.
      oButton1:FontStrikeOut := .f.
      oButton1:Caption := 'Normal Font'
   ENDIF

   lFont1 := ! lFont1

RETURN NIL
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: No HMG4 Font object

Post by concentra »

I am a bit confused here...
You need not use any QT object directly.
Need not or can´t ?
It "half" worked in my sample...
Actually, HMG is a wrapper of QT.
Actually I do not know what exactly a wrapper is ( have an idea ).
Could you explain a bit how it works and why shouldn´t I use QT objects directly ?

[[]] Maurício Faria
[[]] Mauricio Ventura Faria
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: No HMG4 Font object

Post by Rathinagiri »

It is only 'you need not'. And it is not 'You can not'.

For this, I have to tell you about HMG version 1 to 3. You might have known about the difficulties of Win32 API (with various Handles and functions). HMG had done away with these API calls by simple XBase like commands by making a wrapper around the Win32 API. However, for some advanced things we might call Win32 API sometimes.

Once we have QT, we are wrapping QT. Even now, we can use QT objects in some advanced/specialized requirements apart from the HMG general functionality.

Now, why it had worked half:

When you change the attribute via an internal variable, like in your example:

Code: Select all

oButton1:oFont := oFont1
The command is not passed on to QT. It is still in Harbour Level. Only when you call

Code: Select all

oButton1:FontStrikeOut := .F. 
The "FontStrikeOut" method of Control class is called. In this method we have a line like this:

Code: Select all

         ::oQTObject:SetFont( ::oFont )
This is where QT is called actually. So, when you had commented out this line, the fonts are not updated.

I am sure you can understand my example.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: No HMG4 Font object

Post by concentra »

Ok I got it ( maybe :) )

So, all this begun because of the need to manipulate separate font objects and then assign this particular font object to a control in order change it´s font.

If I understood, whenever I change some attributes in a control, an associated function is called to manipulate this change and send a message to QT to do this particular change.
Is this what you call a wraper ?

Ok, what should I change in the code in order to do exactly the same whenever I change the control´s font ?

In other words, why wrap when I change ::FontStrikeOut and not when I change ::oFont ?

If we do the same thing with both we do not need to write a FONT class to manipulate fonts in HMG4 since the QT one can do all the job...
[[]] Mauricio Ventura Faria
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: No HMG4 Font object

Post by Rathinagiri »

If I understood, whenever I change some attributes in a control, an associated function is called to manipulate this change and send a message to QT to do this particular change.
Is this what you call a wrapper ?
Exactly.
In other words, why wrap when I change ::FontStrikeOut and not when I change ::oFont ?
Because, ::oFont is a class variable and ::FontStrikeOut is a class method. ::oFont is fundamentally a holder of the font object. It will not be applied unless we call setFont( ::oFont ) QT function.
If we do the same thing with both we do not need to write a FONT class to manipulate fonts in HMG4 since the QT one can do all the job...
Yes. IMHO, that's why a separate font class is not created. Now also, QT is doing all the jobs.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: No HMG4 Font object

Post by dhaine_adp »

Hi Rathi,

Very good explanation.


Regards,

Danny
Regards,

Danny
Manila, Philippines
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: No HMG4 Font object

Post by concentra »

Hi
::oFont is a class variable and ::FontStrikeOut is a class method. ::oFont is fundamentally a holder of the font object. It will not be applied unless we call setFont( ::oFont ) QT function.

Yes. IMHO, that's why a separate font class is not created. Now also, QT is doing all the jobs.
Ok, I got it.
May I sugest creating a ::Font method to apply font objects to controls ?
METHOD Font SETGET

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

METHOD Font( xValue ) CLASS CONTROL

IF ::lCreated
IF Pcount() == 0
RETURN ::oFont
ELSEIF Pcount() == 1
IF Valtype( xValue ) == "C"
RETURN FontName( xValue )
ELSEIF Valtype( xValue ) == "O"
::oFont := xValue
::oQTObject:SetFont( ::oFont )
ENDIF
ENDIF
ELSE
IF Pcount() == 0
RETURN ::oFont
ELSEIF Pcount() == 1
IF Valtype( xValue ) == "C"
RETURN FontName( xValue )
ELSEIF Valtype( xValue ) == "O"
::oFont := xValue
::oQTObject:SetFont( ::oFont )
ENDIF
ENDIF
ENDIF

RETURN NIL

/*----------------------------------------------------------------------*/
[[]] Mauricio Ventura Faria
Post Reply