Code: Select all
#include "hbclass.ch"
#include "common.ch"
#include "hbqtgui.ch"
#include "hmg.ch"
/*----------------------------------------------------------------------*/
CLASS LABEL FROM CONTROL
// Internal Data
DATA lAutoSize INIT .F.
DATA cValue INIT ''
DATA lWordWrap INIT .T.
DATA nAlignment INIT Qt_AlignAbsolute
// Properties
METHOD AutoSize SETGET
METHOD Value SETGET
METHOD WordWrap SETGET
METHOD Alignment SETGET
METHOD VAlignment SETGET
// Methods
METHOD Create( oParentQtObject )
METHOD New()
ENDCLASS
/*----------------------------------------------------------------------*/
METHOD AutoSize( lValue ) CLASS LABEL
LOCAL oFM
IF Pcount() == 0
RETURN ::lAutoSize
ELSEIF Pcount() == 1
IF lValue
oFM := QFontMetrics( ::oFont )
Self:Width := oFM:width( ::cValue )
ENDIF
::lAutoSize := lValue
ENDIF
RETURN NIL
/*----------------------------------------------------------------------*/
METHOD Value( cValue ) CLASS LABEL
IF Pcount() == 0
RETURN ::oQTObject:Text()
ELSEIF Pcount() == 1
::oQTObject:setText( cValue )
::cValue := cValue
IF ::lAutoSize
// update width of label
Self:AutoSize := ::lAutoSize
ENDIF
ENDIF
RETURN NIL
/*----------------------------------------------------------------------*/
METHOD Create( oParentQtObject ) CLASS LABEL
IF valtype( ::oContainer ) == 'U'
::oQTObject:SetParent(oParentQtObject)
ELSE
::oQTObject:SetParent(::oContainer)
ENDIF
::oParent:AddData( ::cName , Self )
// Setting '::lCreated' flag, so, runtime properties can be invoked
::lCreated := .T.
// Set Properties
IF ValType( ::cValue ) != 'U'; Self:Value := ::cValue ; ENDIF
IF ValType( ::nRow ) != 'U'; Self:Row := ::nRow ; ENDIF
IF ValType( ::nCol ) != 'U'; Self:Col := ::nCol ; ENDIF
IF ValType( ::nWidth ) != 'U'; Self:Width := ::nWidth ; ENDIF
IF ValType( ::nHeight ) != 'U'; Self:Height := ::nHeight ; ENDIF
IF ValType( ::cFontName ) != 'U'; Self:FontName := ::cFontName ; ENDIF
IF ValType( ::nFontSize ) != 'U'; Self:FontSize := ::nFontSize ; ENDIF
IF ValType( ::lBold ) != 'U'; Self:FontBold := ::lBold ; ENDIF
IF ValType( ::lItalic ) != 'U'; Self:FontItalic := ::lItalic ; ENDIF
IF ValType( ::lUnderline ) != 'U'; Self:FontUnderline := ::lUnderline ; ENDIF
IF ValType( ::lStrikeout ) != 'U'; Self:FontStrikeOut := ::lStrikeout ; ENDIF
IF ValType( ::cToolTip ) != 'U'; Self:ToolTip := ::cToolTip ; ENDIF
IF ValType( ::lTabStop ) != 'U'; Self:TabStop := ::lTabStop ; ENDIF
IF ValType( ::aFontColor ) != 'U'; Self:FontColor := ::aFontColor ; ENDIF
IF ValType( ::aBackColor ) != 'U'; Self:BackColor := ::aBackColor ; ENDIF
IF ValType( ::lWordWrap ) != 'U'; Self:WordWrap := ::lWordWrap ; ENDIF
IF ValType( ::lAutoSize ) != 'U'; Self:AutoSize := ::lAutoSize ; ENDIF
// set default label word wrapping to .T.
// Self:WordWrap := .T.
// Set Font & Show Object
::oQTObject:SetFont( ::oFont )
::oQTObject:show()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD NEW() CLASS LABEL
super:new()
::oQTObject := QLabel()
::oFont := QFont()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD WordWrap( lValue ) CLASS LABEL
IF Pcount() == 0
RETURN ::oQTObject:WordWrap()
ELSEIF Pcount() == 1
::lWordWrap := lValue
::oQTObject:SetWordWrap( lValue )
ENDIF
RETURN NIL
/*----------------------------------------------------------------------*/
METHOD Alignment( nAlign ) CLASS LABEL
LOCAL nSet, nRet := LBL_LEFT
// we need convert different numbers FOR alignment in HMG and QT
IF Pcount() == 0
// reset horizontal alignment settings
nSet := numAND( ::oQTObject:Alignment(),0x0F )
DO CASE
CASE nSet == Qt_AlignLeft
RETURN LBL_LEFT
CASE nSet == Qt_AlignHCenter
RETURN LBL_CENTER
CASE nSet == Qt_AlignRight
RETURN LBL_RIGHT
ENDCASE
ELSEIF Pcount() == 1
// FOR compatibility with future vertical alignment
// first read Alignment and reset horizontal alignment
nSet := numAND( ::oQTObject:Alignment(),0xF0 )
DO CASE
CASE nAlign == LBL_LEFT
nSet := numXOR( nSet, Qt_AlignLeft )
nRet := LBL_LEFT
CASE nAlign == LBL_CENTER
nSet := numXOR( nSet, Qt_AlignHCenter )
nRet := LBL_CENTER
CASE nAlign == LBL_RIGHT
nSet := numXOR( nSet, Qt_AlignRight )
nRet := LBL_RIGHT
ENDCASE
::oQTObject:SetAlignment( nSet )
::nAlignMent := nSet
ENDIF
RETURN nRet
/*----------------------------------------------------------------------*/
METHOD VAlignment( nAlign ) CLASS LABEL
LOCAL nSet, nRet := LBL_VCENTER
// we need convert different numbers FOR alignment in HMG and QT
IF Pcount() == 0
// reset vertical alignment settings
nSet := numAND( ::oQTObject:Alignment(),0xF0 )
DO CASE
CASE nSet == Qt_AlignTop
RETURN LBL_TOP
CASE nSet == Qt_AlignVCenter
RETURN LBL_VCENTER
CASE nSet == Qt_AlignBottom
RETURN LBL_BOTTOM
ENDCASE
ELSEIF Pcount() == 1
// FOR compatibility with future vertical alignment
// first read Alignment and reset horizontal alignment
nSet := numAND( ::oQTObject:Alignment(),0x0F )
DO CASE
CASE nAlign == LBL_TOP
nSet := numXOR( nSet, Qt_AlignTop )
nRet := LBL_TOP
CASE nAlign == LBL_VCENTER
nSet := numXOR( nSet, Qt_AlignVCenter )
nRet := LBL_VCENTER
CASE nAlign == LBL_BOTTOM
nSet := numXOR( nSet, Qt_AlignBottom )
nRet := LBL_BOTTOM
ENDCASE
::oQTObject:SetAlignment( nSet )
::Alignment := nSet
ENDIF
RETURN nRet
/*----------------------------------------------------------------------*/
Note that this was a 2 minutes job and may have bugs !