File: globshared.prg
Code: Select all
CLASS VAR s_cImgSplash INIT NIL SHARED
CLASS VAR s_nCounterSplash INIT 0 SHARED
Code: Select all
METHOD SplashScreen SETGET
Code: Select all
METHOD SplashScreen( cImg, nCounter ) CLASS HMGAPP
IF PCOUNT() == 0
RETURN ::s_cImgSplash
ELSEIF ::s_lQtStarted == .F. .AND. File( cImg )
::s_cImgSplash := cImg
IF hb_IsNumeric( nCounter )
::s_nCounterSplash := nCounter
ELSE
::s_nCounterSplash := 5
ENDIF
ENDIF
RETURN Self
Code: Select all
METHOD Reset() CLASS HMGAPP
::s_oQtApp := NIL
::s_oQtRes := NIL
::s_aResources := {}
::s_cStyle := NIL
::s_oDefaultParent := NIL
::s_nObjectCounter := 0
::s_oMainWindow := NIL
::s_lGridCellFlag := .F.
::s_oMainMenu := NIL
::s_oParentWindow := NIL
::s_cNewPopUpMenuName:= NIL
::s_cNewMenuItemName := NIL
::s_nCountry := NIL
::s_oCurWindow := NIL
::s_nLanguage := NIL
::s_bOnShutDown := NIL
::s_bOnStartUp := NIL
::s_cPlugInDir := NIL
::s_oQtLocale := NIL
::s_lQtStarted := .F.
::s_oTopParent := NIL
::s_cImgSplash := NIL
::s_nCounterSplash := 0
RETURN Self
Code: Select all
METHOD Start() CLASS HMGAPP
LOCAL cPath, cFile, cExt, nX, cResFileName, oImg, oSplash, nSec
// check if it's already started
IF ::s_lQtStarted == .T.
RETURN Self
ENDIF
// split program name for two reason
// 1. to have the current path
// 2. to have the program name and register default resource with program name
hb_fNameSplit( hb_ProgName(), @cPath, @cFile, @cExt )
::s_lQtStarted := .T.
::s_oQtApp := QApplication()
::s_oQtRes := QResource()
// Show Splash Screen
IF VALTYPE( ::s_cImgSplash ) == "C"
oImg := QPixmap():new()
oImg:Load( ::s_cImgSplash )
oSplash := QSplashScreen():new()
oSplash:setPixmap( oImg )
oSplash:Show()
nSec := seconds()
DO WHILE .t.
IF seconds() > nSec + ::s_nCounterSplash
EXIT
ENDIF
ENDDO
ENDIF
// localization
IF VALTYPE( ::s_nLanguage ) == "U"
::s_oQtLocale := QLocale()
::s_oQtLocale:setDefault( QLocale() )
ELSEIF VALTYPE( ::s_nLanguage ) == "N"
IF VALTYPE( ::s_nCountry ) == "U" ; ::s_nCountry := 0 ; ENDIF // 0 is like QLocale_AnyCountry
::s_oQtLocale := QLocale( ::s_nLanguage, ::s_nCountry )
::s_oQtLocale:setDefault( QLocale( ::s_nLanguage, ::s_nCountry ) )
ENDIF
// if ::s_cPlugInDir not evaluated create a default <exePath\Qt\plugins>. If qt.conf exists take that
IF VALTYPE( ::s_cPlugInDir ) == "U"
::s_cPlugInDir := cPath + "Qt" + hb_ps() + "plugins"
ENDIF
::s_oQtApp:addLibraryPath( ::s_cPlugInDir )
::s_oDefaultParent := Self
::s_oTopParent := Self
::oQtObject := ::s_oQtApp:DeskTop()
// by default register resource file with the same name of program (see harbour)
Self:RegisterResource( cFile )
FOR nX := 1 TO LEN( ::s_aResources )
cResFileName := ::s_aResources[nX]
IF TYPE( cResFileName ) == "UI" // to find if exist this function
::s_oQtRes:registerResource_1( &cResFileName )
ENDIF
NEXT nX
// Set Widget Style
IF VALTYPE( ::s_cStyle ) == "C"
::s_oQtApp:SetStyle( ::s_cStyle )
ENDIF
// check OnStartUp
IF hb_IsBlock( ::s_bOnStartUp ) == .T.
EVAL( ::s_bOnStartUp )
ENDIF
// Close Splash Screen
IF VALTYPE( ::s_cImgSplash ) == "C"
oSplash:Close()
ENDIF
RETURN Self
Code: Select all
Function Main
LOCAL oWindow
HbQt_ErrorSys()
HMGAPP():SplashScreen( "hmgsplash.png", 5 )
WITH OBJECT oWindow := Window():New()
:Row := 0
:Col := 0
:Width := 518
:Height := 400
:Title := 'Splash Screen'
:Type := WND_MAIN
:OnInit := { || oWindow:Center() }
END WITH
oWindow:Activate()
RETURN NIL