commit 9178ecf86a24b150cc39dad966e21201e1471a4b
parent 9bb8d52fcc48d2460cd636bcaceb00c15723cedd
Author: MTRNord <mtrnord1@gmail.com>
Date: Tue, 22 Aug 2017 15:17:53 +0200
Start reworking of the UI \(^^)/
Diffstat:
| M | main.go | | | 8 | +++++++- |
| M | matrix/ownUser.go | | | 53 | +++++++++++++++++++++++++++++++++++++++-------------- |
| M | qml/Main.ui | | | 130 | +++++++++++++++++++++++++++++++++++++------------------------------------------ |
| M | qml/login.ui | | | 17 | ++++++++++------- |
| M | uis.go | | | 62 | ++++++++++++++++++++++++++++++++++---------------------------- |
5 files changed, 151 insertions(+), 119 deletions(-)
diff --git a/main.go b/main.go
@@ -9,6 +9,7 @@ import (
)
var localLog *log.Logger
+var window *widgets.QMainWindow
func main() {
var file *os.File
@@ -25,11 +26,16 @@ func main() {
windowWidth := (screen.Width() / 2)
windowHeight := (screen.Height() / 2)
+ window = widgets.NewQMainWindow(nil, 0)
+ window.SetMinimumSize2(windowWidth, windowHeight)
+
loginUI := NewLoginUI(windowWidth, windowHeight)
+ loginUI.Resize2(windowWidth, windowHeight)
loginUI.SetMinimumSize2(windowWidth, windowHeight)
//Show loginUI
- loginUI.Show()
+ window.SetCentralWidget(loginUI)
+ window.Show()
//enter the main event loop
widgets.QApplication_Exec()
diff --git a/matrix/ownUser.go b/matrix/ownUser.go
@@ -1,19 +1,22 @@
package matrix
import (
+ "log"
+ "os"
+ "strings"
+
+ "github.com/Nordgedanken/Neo/util"
"github.com/matrix-org/gomatrix"
+ "github.com/therecipe/qt/gui"
)
+var localLog *log.Logger
+
// RespUserDisplayName is the Response type of GetUserDisplayName()
type RespUserDisplayName struct {
DisplayName string `json:"displayname"`
}
-// RespOwnUserAvatar is the Response type of GetUserDisplayName()
-// type RespOwnUserAvatar struct {
-// DisplayName string `json:"displayname"`
-// }
-
// GetUserDisplayName returns the Dispaly name to a MXID
func GetUserDisplayName(mxid string, cli *gomatrix.Client) (resp *RespUserDisplayName, err error) {
urlPath := cli.BuildURL("profile", mxid, "displayname")
@@ -22,12 +25,34 @@ func GetUserDisplayName(mxid string, cli *gomatrix.Client) (resp *RespUserDispla
}
// GetOwnUserAvatar returns a *gui.QPixmap of an UserAvatar
-// func GetOwnUserAvatar(cli *gomatrix.Client) *gui.QPixmap {
-// avatarURL, avatarErr := cli.GetAvatarURL()
-// if avatarErr != nil {
-// localLog.Println(avatarErr)
-// }
-//
-// avatar := gui.NewQPixmap()
-// avatar.LoadFromData()
-// }
+func GetOwnUserAvatar(cli *gomatrix.Client) *gui.QPixmap {
+ var file *os.File
+ localLog = util.Logger()
+ localLog, file = util.StartFileLog(localLog)
+ defer file.Close()
+ avatarURL, avatarErr := cli.GetAvatarURL()
+ if avatarErr != nil {
+ localLog.Println(avatarErr)
+ }
+
+ var IMGdata string
+ if avatarURL != "" {
+ hsURL := cli.HomeserverURL.String()
+ avatarURL_splits := strings.Split(strings.Replace(avatarURL, "mxc://", "", -1), "/")
+
+ urlPath := hsURL + "/_matrix/media/r0/thumbnail/" + avatarURL_splits[0] + "/" + avatarURL_splits[1] + "?width=100&height=100"
+ println(urlPath)
+
+ data, err := cli.MakeRequest("GET", urlPath, nil, nil)
+ if err != nil {
+ localLog.Println(err)
+ }
+ IMGdata = string(data[:])
+ } else {
+ IMGdata = ""
+ }
+
+ avatar := gui.NewQPixmap()
+ avatar.LoadFromData(IMGdata, uint(len(IMGdata)), "", 0)
+ return avatar
+}
diff --git a/qml/Main.ui b/qml/Main.ui
@@ -1,162 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>MainForm</class>
- <widget class="QWidget" name="MainForm">
+ <class>centralWidget</class>
+ <widget class="QWidget" name="centralWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>1007</width>
- <height>652</height>
+ <width>1036</width>
+ <height>717</height>
</rect>
</property>
<property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="font">
- <font>
- <underline>true</underline>
- </font>
- </property>
<property name="windowTitle">
<string>Neo</string>
</property>
- <widget class="QColumnView" name="columnView">
+ <property name="title" stdset="0">
+ <string/>
+ </property>
+ <widget class="QLabel" name="RoomNameLabel">
<property name="geometry">
<rect>
- <x>0</x>
- <y>0</y>
- <width>1001</width>
- <height>651</height>
+ <x>261</x>
+ <y>10</y>
+ <width>740</width>
+ <height>47</height>
</rect>
</property>
+ <property name="font">
+ <font>
+ <family>Arial</family>
+ <pointsize>31</pointsize>
+ <underline>false</underline>
+ </font>
+ </property>
+ <property name="text">
+ <string>Titel</string>
+ </property>
</widget>
- <widget class="QScrollArea" name="scrollArea">
+ <widget class="QScrollArea" name="scrollArea_2">
<property name="geometry">
<rect>
- <x>220</x>
- <y>60</y>
- <width>781</width>
- <height>591</height>
+ <x>250</x>
+ <y>80</y>
+ <width>756</width>
+ <height>571</height>
</rect>
</property>
<property name="widgetResizable">
- <bool>true</bool>
+ <bool>false</bool>
</property>
- <widget class="QWidget" name="scrollAreaWidgetContents">
+ <widget class="QWidget" name="scrollAreaWidgetContents_14">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>779</width>
- <height>589</height>
+ <width>239</width>
+ <height>568</height>
</rect>
</property>
</widget>
</widget>
- <widget class="QScrollArea" name="scrollArea_2">
+ <widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
- <x>0</x>
- <y>60</y>
- <width>211</width>
- <height>591</height>
+ <x>2</x>
+ <y>80</y>
+ <width>239</width>
+ <height>571</height>
</rect>
</property>
<property name="widgetResizable">
- <bool>true</bool>
+ <bool>false</bool>
</property>
- <widget class="QWidget" name="scrollAreaWidgetContents_2">
+ <widget class="QWidget" name="scrollAreaWidgetContents_13">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>209</width>
- <height>589</height>
+ <width>237</width>
+ <height>569</height>
</rect>
</property>
</widget>
</widget>
- <widget class="QLabel" name="RoomNameLabel">
- <property name="geometry">
- <rect>
- <x>230</x>
- <y>10</y>
- <width>741</width>
- <height>41</height>
- </rect>
- </property>
- <property name="font">
- <font>
- <family>Arial</family>
- <pointsize>31</pointsize>
- <underline>false</underline>
- </font>
- </property>
- <property name="text">
- <string>Titel</string>
- </property>
- </widget>
<widget class="QLabel" name="UsernameLabel">
<property name="geometry">
<rect>
<x>80</x>
<y>10</y>
- <width>121</width>
- <height>21</height>
+ <width>164</width>
+ <height>32</height>
</rect>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>16</pointsize>
+ <underline>true</underline>
</font>
</property>
<property name="text">
<string>Username</string>
</property>
</widget>
- <widget class="QLabel" name="MXIDLabel">
+ <widget class="QLabel" name="AvatarLabel">
<property name="geometry">
<rect>
- <x>80</x>
- <y>35</y>
- <width>121</width>
- <height>21</height>
+ <x>0</x>
+ <y>0</y>
+ <width>70</width>
+ <height>70</height>
</rect>
</property>
<property name="font">
<font>
<family>Arial</family>
- <pointsize>10</pointsize>
+ <pointsize>31</pointsize>
<underline>false</underline>
</font>
</property>
<property name="text">
- <string>@User:matrix.org</string>
+ <string>MR</string>
+ </property>
+ <property name="scaledContents">
+ <bool>true</bool>
</property>
</widget>
- <widget class="QLabel" name="AvatarLabel">
+ <widget class="QLabel" name="MXIDLabel">
<property name="geometry">
<rect>
- <x>0</x>
- <y>0</y>
- <width>71</width>
- <height>51</height>
+ <x>80</x>
+ <y>40</y>
+ <width>159</width>
+ <height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Arial</family>
- <pointsize>31</pointsize>
+ <pointsize>10</pointsize>
<underline>false</underline>
</font>
</property>
<property name="text">
- <string>MR</string>
+ <string>@User:matrix.org</string>
</property>
</widget>
</widget>
diff --git a/qml/login.ui b/qml/login.ui
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>LoginForm</class>
- <widget class="QWidget" name="LoginForm">
+ <class>centralWidget</class>
+ <widget class="QWidget" name="centralWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>813</width>
- <height>356</height>
+ <width>1280</width>
+ <height>720</height>
</rect>
</property>
<property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -22,8 +22,8 @@
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
- <x>330</x>
- <y>80</y>
+ <x>510</x>
+ <y>287</y>
<width>258</width>
<height>147</height>
</rect>
@@ -48,6 +48,9 @@
</item>
<item>
<layout class="QFormLayout" name="LoginFormLayout">
+ <property name="formAlignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </property>
<item row="0" column="0">
<widget class="QLabel" name="UsernameLabel">
<property name="font">
diff --git a/uis.go b/uis.go
@@ -16,48 +16,54 @@ var password string
//NewLoginUI initializes the login Screen
func NewLoginUI(windowWidth, windowHeight int) *widgets.QWidget {
widget := widgets.NewQWidget(nil, 0)
+ layout := widgets.NewQVBoxLayout()
+ widget.SetLayout(layout)
- loader := uitools.NewQUiLoader(nil)
- file := core.NewQFile2(":/qml/login.ui")
+ // UsernameInput
+ usernameInput := widgets.NewQLineEdit(nil)
+ usernameInput.SetPlaceholderText("Insert MXID")
+ layout.AddWidget(usernameInput, 0, 0)
- file.Open(core.QIODevice__ReadOnly)
- loginWidget := loader.Load(file, widget)
- file.Close()
+ // PasswordInput
+ passwordInput := widgets.NewQLineEdit(nil)
+ passwordInput.SetPlaceholderText("Insert password")
+ passwordInput.SetEchoMode(widgets.QLineEdit__Password)
+ layout.AddWidget(passwordInput, 0, 0)
- var (
- inputUsername = widgets.NewQLineEditFromPointer(widget.FindChild("UsernameInput", core.Qt__FindChildrenRecursively).Pointer())
- inputPassword = widgets.NewQLineEditFromPointer(widget.FindChild("PasswordInput", core.Qt__FindChildrenRecursively).Pointer())
- SubmitButton = widgets.NewQPushButtonFromPointer(widget.FindChild("loginButton", core.Qt__FindChildrenRecursively).Pointer())
- )
+ // UsernameInput-Label
+ usernameLabel := widgets.NewQLabel(nil, 0)
+ usernameLabel.SetText("Username: ")
+ usernameLabel.SetBuddy(usernameLabel)
+
+ // PasswordInput-Label
+ passwordLabel := widgets.NewQLabel(nil, 0)
+ passwordLabel.SetText("Password: ")
+ passwordLabel.SetBuddy(passwordLabel)
- inputUsername.ConnectTextChanged(func(value string) {
+ // loginButton
+ loginButton := widgets.NewQPushButton2("LOGIN", nil)
+ layout.AddWidget(loginButton, 0, 0)
+
+ usernameInput.ConnectTextChanged(func(value string) {
username = value
})
- inputPassword.ConnectTextChanged(func(value string) {
+ passwordInput.ConnectTextChanged(func(value string) {
password = value
})
- SubmitButton.ConnectClicked(func(checked bool) {
+ loginButton.ConnectClicked(func(checked bool) {
localLog.Println("Starting Login Sequenze")
cli, err := matrix.LoginUser(username, password)
if err != nil {
localLog.Println(err)
}
MainUI := NewMainUI(windowWidth, windowHeight, cli)
- MainUI.SetMinimumSize2(windowWidth, windowHeight)
//Show MainUI
- widget.Close()
- MainUI.Show()
+ window.SetCentralWidget(MainUI)
})
- loginWidget.SetMinimumSize2(windowWidth, windowHeight)
-
- layout := widgets.NewQVBoxLayout()
- layout.AddWidget(loginWidget, 0, 0)
- widget.SetLayout(layout)
-
widget.SetWindowTitle("Neo - Login")
return widget
@@ -71,13 +77,13 @@ func NewMainUI(windowWidth, windowHeight int, cli *gomatrix.Client) *widgets.QWi
file := core.NewQFile2(":/qml/Main.ui")
file.Open(core.QIODevice__ReadOnly)
- loginWidget := loader.Load(file, widget)
+ mainWidget := loader.Load(file, widget)
file.Close()
var (
usernameLabel = widgets.NewQLabelFromPointer(widget.FindChild("UsernameLabel", core.Qt__FindChildrenRecursively).Pointer())
mxidLabel = widgets.NewQLabelFromPointer(widget.FindChild("MXIDLabel", core.Qt__FindChildrenRecursively).Pointer())
- //avatarLogo = widgets.NewQLabelFromPointer(widget.FindChild("AvatarLabel", core.Qt__FindChildrenRecursively).Pointer())
+ avatarLogo = widgets.NewQLabelFromPointer(widget.FindChild("AvatarLabel", core.Qt__FindChildrenRecursively).Pointer())
)
// Set MXID Label
@@ -90,13 +96,13 @@ func NewMainUI(windowWidth, windowHeight int, cli *gomatrix.Client) *widgets.QWi
}
usernameLabel.SetText(fmt.Sprint(DisplayNameResp.DisplayName))
- loginWidget.SetMinimumSize2(windowWidth, windowHeight)
+ // Set Avatar
+ avatarLogo.SetAlignment(core.Qt__AlignBottom | core.Qt__AlignRight)
+ avatarLogo.SetPixmap(matrix.GetOwnUserAvatar(cli))
layout := widgets.NewQVBoxLayout()
- layout.AddWidget(loginWidget, 0, 0)
+ layout.AddWidget(mainWidget, 0, 0)
widget.SetLayout(layout)
- widget.SetWindowTitle("Neo - Login")
-
return widget
}