1. --!movie
  2. --!encoding=utf-8
  3.  
  4. --****************************************************************************
  5. -- @file Qt5 WebEngine Demo
  6. -- @author Valentin Schmidt
  7. -- @version 0.2
  8. --****************************************************************************
  9.  
  10. global $
  11.  
  12. global Qt
  13.  
  14. -- widgets
  15. global gMainWindow
  16. global gBrowser
  17. global gAddressBar
  18. global gStatusBar
  19.  
  20. ----------------------------------------
  21. -- START
  22. ----------------------------------------
  23. on startMovie
  24.     --_player.debugPlaybackEnabled = TRUE
  25.  
  26.     -- libs
  27.     $.import("detacher")
  28.  
  29.     -- init Qt5
  30.     Qt = xtra("Qt5").new()
  31.  
  32.     -- create main window
  33.     gMainWindow = Qt.MainWindow.new()
  34.     gMainWindow.setWindowTitle("Qt5 WebEngine Demo")
  35.     gMainWindow.setWindowIcon(_movie.path&"resources/icons/app.png")
  36.  
  37.     -- install an event filter
  38.     gMainWindow.installEventFilter(#slotEvent)
  39.  
  40.     -- create a WebEngineView
  41.     gBrowser = Qt.WebEngineView.new(gMainWindow)
  42.  
  43.     -- add WebEngineView as central widget to main window
  44.     gMainWindow.setCentralWidget(gBrowser)
  45.  
  46.     -- create a toolbar
  47.     toolBarNav = Qt.ToolBar.new(gMainWindow)
  48.     toolBarNav.setMovable(FALSE)
  49.     toolBarNav.setIconSize(16,16)
  50.     gMainWindow.addToolBar(toolBarNav)
  51.  
  52.     btn = Qt.ToolButton.new(toolBarNav)
  53.     btn.setIcon(_movie.path&"resources/icons/nav-back.png")
  54.     btn.setToolTip("Go back one page")
  55.     btn.connect(#pressed, #back, gBrowser)
  56.     toolBarNav.addWidget(btn)
  57.  
  58.     btn = Qt.ToolButton.new(toolBarNav)
  59.     btn.setIcon(_movie.path&"resources/icons/nav-forward.png")
  60.     btn.setToolTip("Go forward one page")
  61.     btn.connect(#pressed, #forward, gBrowser)
  62.     toolBarNav.addWidget(btn)
  63.  
  64.     btn = Qt.ToolButton.new(toolBarNav)
  65.     btn.setIcon(_movie.path&"resources/icons/nav-reload.png")
  66.     btn.setToolTip("Reload current page")
  67.     btn.connect(#pressed, #reload, gBrowser)
  68.     toolBarNav.addWidget(btn)
  69.  
  70.     btn = Qt.ToolButton.new(toolBarNav)
  71.     btn.setIcon(_movie.path&"resources/icons/nav-stop.png")
  72.     btn.setToolTip("Stop loading this page")
  73.     btn.connect(#pressed, #stop, gBrowser)
  74.     toolBarNav.addWidget(btn)
  75.  
  76.     -- add address input field
  77.     gAddressBar = Qt.LineEdit.new(toolBarNav)
  78.     gAddressBar.connect(#returnPressed, #slotGotoUrl)
  79.     gAddressBar.installEventFilter(#slotAddressBarEvent)
  80.     toolBarNav.addWidget(gAddressBar)
  81.  
  82.     -- add "go" button
  83.     goBtn = Qt.PushButton.new(toolBarNav)
  84.     goBtn.setText(" Go! ")
  85.     goBtn.setToolTip("Go to the address in the Location Bar")
  86.     goBtn.connect(#pressed, #slotGotoUrl)
  87.     toolBarNav.addWidget(goBtn)
  88.  
  89.     -- create a statusbar
  90.     gStatusBar = Qt.StatusBar.new(gMainWindow)
  91.     gMainWindow.setStatusBar(gStatusBar)
  92.  
  93.     -- connect browser with other widgets
  94.     gBrowser.connect(#urlChanged, #setText, gAddressBar)
  95.     gBrowser.page().connect(#linkHovered, #showMessage, gStatusBar)
  96.  
  97.     -- navigate to some example URL
  98.     gBrowser.setUrl("http://valentin.dasdeck.com/")
  99.  
  100.     -- show the main window
  101.     gMainWindow.show()
  102. end
  103.  
  104. ----------------------------------------
  105. -- @callback
  106. ----------------------------------------
  107. on slotEvent (evt)
  108.     case (evt) of
  109.     #Close:
  110.         -- quit when main window was closed
  111.         --_movie.halt()
  112.         exitCode(0)
  113.     end case
  114. end
  115.  
  116. ----------------------------------------
  117. -- @callback
  118. ----------------------------------------
  119. on slotGotoUrl (widget)
  120.     str = gAddressBar.text()
  121.     if str="" then return
  122.     if not (str contains "//") then put "http://" before str
  123.     gBrowser.setUrl(str)
  124. end
  125.  
  126. ----------------------------------------
  127. -- @callback
  128. ----------------------------------------
  129. on slotAddressBarEvent (evt, widget)
  130.     if evt=#FocusIn then $.detacher.detach(#selectAll, widget)
  131. end
  132.  
[raw code]