--!movie
--!encoding=utf-8
--****************************************************************************
-- @file Qt5 WebEngine Demo
-- @author Valentin Schmidt
-- @version 0.2
--****************************************************************************
global $
global Qt
-- widgets
global gMainWindow
global gBrowser
global gAddressBar
global gStatusBar
----------------------------------------
-- START
----------------------------------------
on startMovie
--_player.debugPlaybackEnabled = TRUE
-- libs
$.import("detacher")
-- init Qt5
Qt = xtra("Qt5").new()
-- create main window
gMainWindow = Qt.MainWindow.new()
gMainWindow.setWindowTitle("Qt5 WebEngine Demo")
gMainWindow.setWindowIcon(_movie.path&"resources/icons/app.png")
-- install an event filter
gMainWindow.installEventFilter(#slotEvent)
-- create a WebEngineView
gBrowser = Qt.WebEngineView.new(gMainWindow)
-- add WebEngineView as central widget to main window
gMainWindow.setCentralWidget(gBrowser)
-- create a toolbar
toolBarNav = Qt.ToolBar.new(gMainWindow)
toolBarNav.setMovable(FALSE)
toolBarNav.setIconSize(16,16)
gMainWindow.addToolBar(toolBarNav)
btn = Qt.ToolButton.new(toolBarNav)
btn.setIcon(_movie.path&"resources/icons/nav-back.png")
btn.setToolTip("Go back one page")
btn.connect(#pressed, #back, gBrowser)
toolBarNav.addWidget(btn)
btn = Qt.ToolButton.new(toolBarNav)
btn.setIcon(_movie.path&"resources/icons/nav-forward.png")
btn.setToolTip("Go forward one page")
btn.connect(#pressed, #forward, gBrowser)
toolBarNav.addWidget(btn)
btn = Qt.ToolButton.new(toolBarNav)
btn.setIcon(_movie.path&"resources/icons/nav-reload.png")
btn.setToolTip("Reload current page")
btn.connect(#pressed, #reload, gBrowser)
toolBarNav.addWidget(btn)
btn = Qt.ToolButton.new(toolBarNav)
btn.setIcon(_movie.path&"resources/icons/nav-stop.png")
btn.setToolTip("Stop loading this page")
btn.connect(#pressed, #stop, gBrowser)
toolBarNav.addWidget(btn)
-- add address input field
gAddressBar = Qt.LineEdit.new(toolBarNav)
gAddressBar.connect(#returnPressed, #slotGotoUrl)
gAddressBar.installEventFilter(#slotAddressBarEvent)
toolBarNav.addWidget(gAddressBar)
-- add "go" button
goBtn = Qt.PushButton.new(toolBarNav)
goBtn.setText(" Go! ")
goBtn.setToolTip("Go to the address in the Location Bar")
goBtn.connect(#pressed, #slotGotoUrl)
toolBarNav.addWidget(goBtn)
-- create a statusbar
gStatusBar = Qt.StatusBar.new(gMainWindow)
gMainWindow.setStatusBar(gStatusBar)
-- connect browser with other widgets
gBrowser.connect(#urlChanged, #setText, gAddressBar)
gBrowser.page().connect(#linkHovered, #showMessage, gStatusBar)
-- navigate to some example URL
gBrowser.setUrl("http://valentin.dasdeck.com/")
-- show the main window
gMainWindow.show()
end
----------------------------------------
-- @callback
----------------------------------------
on slotEvent (evt)
case (evt) of
#Close:
-- quit when main window was closed
--_movie.halt()
exitCode(0)
end case
end
----------------------------------------
-- @callback
----------------------------------------
on slotGotoUrl (widget)
str = gAddressBar.text()
if str="" then return
if not (str contains "//") then put "http://" before str
gBrowser.setUrl(str)
end
----------------------------------------
-- @callback
----------------------------------------
on slotAddressBarEvent (evt, widget)
if evt=#FocusIn then $.detacher.detach(#selectAll, widget)
end