mainUI.go (2161B)
1 // Copyright © 2018 MTRNord <info@nordgedanken.de> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mainUI 16 17 import ( 18 "github.com/matrix-org/gomatrix" 19 "github.com/therecipe/qt/core" 20 "github.com/therecipe/qt/gui" 21 "github.com/therecipe/qt/uitools" 22 "github.com/therecipe/qt/widgets" 23 ) 24 25 // MainUI defines the data for the main ui (that one with the chats) 26 type MainUI struct { 27 widget *widgets.QWidget 28 cli *gomatrix.Client 29 window *widgets.QMainWindow 30 windowWidth int 31 windowHeight int 32 } 33 34 // NewMainUI gives you a MainUI struct with prefilled data 35 func NewMainUI(windowWidth, windowHeight int, window *widgets.QMainWindow) (mainUI *MainUI) { 36 mainUI = &MainUI{ 37 windowWidth: windowWidth, 38 windowHeight: windowHeight, 39 window: window, 40 } 41 return 42 } 43 44 // SetCli sets the gomatrix Client for the MainUI 45 func (m *MainUI) SetCli(cli *gomatrix.Client) { 46 m.cli = cli 47 } 48 49 // GetWidget returns the QWidget of the MainUI 50 func (m *MainUI) GetWidget() (widget *widgets.QWidget) { 51 return m.widget 52 } 53 54 // NewUI prepares the new UI 55 func (m *MainUI) NewUI() error { 56 m.widget = widgets.NewQWidget(nil, 0) 57 58 var loader = uitools.NewQUiLoader(nil) 59 var file = core.NewQFile2(":/qml/ui/chat.ui") 60 61 file.Open(core.QIODevice__ReadOnly) 62 mainWidget := loader.Load(file, m.widget) 63 file.Close() 64 65 var layout = widgets.NewQHBoxLayout() 66 m.window.SetLayout(layout) 67 layout.InsertWidget(0, mainWidget, 0, core.Qt__AlignTop|core.Qt__AlignLeft) 68 layout.SetSpacing(0) 69 layout.SetContentsMargins(0, 0, 0, 0) 70 71 m.widget.ConnectResizeEvent(func(event *gui.QResizeEvent) { 72 mainWidget.Resize(event.Size()) 73 event.Accept() 74 }) 75 76 return nil 77 }