morpheus

A Matrix client written in Go-QT
git clone git://archive.git.mtrnord.blog/Nordgedanken/morpheus.git
Log | Files | Refs | README | LICENSE

commit 315fd2648baf5cc827f573cdba1ab1869e0d8885
parent affe7a92927bfdfce9bc00a2c1c72368d182b01c
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 29 Aug 2017 19:16:58 +0200

Update commonmark and make Avatar Round

Signed-off-by: MTRNord <mtrnord1@gmail.com>

Diffstat:
Melements.go | 5++---
Mmain.go | 1+
Mmatrix/ownUser.go | 46+++++++++++++++++++++++++++++++++++++++++++++-
Muis.go | 7++-----
4 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/elements.go b/elements.go @@ -1,7 +1,7 @@ package main import ( - "github.com/golang-commonmark/markdown" + "github.com/rhinoman/go-commonmark" "github.com/therecipe/qt/core" "github.com/therecipe/qt/gui" "github.com/therecipe/qt/uitools" @@ -27,8 +27,7 @@ func AddMessage(body string, avatar *gui.QPixmap) *widgets.QWidget { avatarLogo := widgets.NewQLabelFromPointer(widget.FindChild("avatar", core.Qt__FindChildrenRecursively).Pointer()) messageContent := widgets.NewQLabelFromPointer(widget.FindChild("messageContent", core.Qt__FindChildrenRecursively).Pointer()) - md := markdown.New(markdown.XHTMLOutput(true), markdown.Nofollow(true)) - mardownMessage := md.RenderToString([]byte(body)) + mardownMessage := commonmark.Md2Html(body, 0) messageContent.SetText(mardownMessage) avatarLogo.SetPixmap(avatar) diff --git a/main.go b/main.go @@ -9,6 +9,7 @@ import ( "github.com/matrix-org/gomatrix" "github.com/therecipe/qt/widgets" "github.com/tidwall/buntdb" + _ "image/png" "sync" ) diff --git a/matrix/ownUser.go b/matrix/ownUser.go @@ -5,10 +5,16 @@ import ( "os" "strings" + "bytes" + "fmt" "github.com/Nordgedanken/Morpheus/util" "github.com/matrix-org/gomatrix" "github.com/therecipe/qt/gui" "github.com/tidwall/buntdb" + "image" + "image/color" + "image/draw" + "image/png" ) var localLog *log.Logger @@ -20,6 +26,27 @@ func init() { defer file.Close() } +type circle struct { + p image.Point + r int +} + +func (c *circle) ColorModel() color.Model { + return color.AlphaModel +} + +func (c *circle) Bounds() image.Rectangle { + return image.Rect(c.p.X-c.r, c.p.Y-c.r, c.p.X+c.r, c.p.Y+c.r) +} + +func (c *circle) At(x, y int) color.Color { + xx, yy, rr := float64(x-c.p.X)+0.5, float64(y-c.p.Y)+0.5, float64(c.r) + if xx*xx+yy*yy < rr*rr { + return color.Alpha{255} + } + return color.Alpha{0} +} + // getOwnUserAvatar returns a *gui.QPixmap of an UserAvatar func GetOwnUserAvatar(cli *gomatrix.Client) *gui.QPixmap { // Init local vars @@ -76,8 +103,25 @@ func GetOwnUserAvatar(cli *gomatrix.Client) *gui.QPixmap { IMGdata = avatarData } + r := bytes.NewReader([]byte(IMGdata)) + srcIMG, _, err := image.Decode(r) + if err != nil { + localLog.Println(err) + } + // Convert avatarimage to QPixmap for usage in QT + canvas := image.NewRGBA(srcIMG.Bounds()) + cx := srcIMG.Bounds().Min.X + srcIMG.Bounds().Dx()/2 + cy := srcIMG.Bounds().Min.Y + srcIMG.Bounds().Dy()/2 + draw.DrawMask(canvas, canvas.Bounds(), srcIMG, image.ZP, &circle{image.Point{cx, cy}, 110}, image.ZP, draw.Over) avatar := gui.NewQPixmap() - avatar.LoadFromData(IMGdata, uint(len(IMGdata)), "", 0) + buf := new(bytes.Buffer) + Converr := png.Encode(buf, canvas) + if Converr != nil { + localLog.Println(Converr) + } + + str := fmt.Sprintf("%s", buf) + avatar.LoadFromData(str, uint(len(str)), "", 0) return avatar } diff --git a/uis.go b/uis.go @@ -2,8 +2,8 @@ package main import ( "github.com/Nordgedanken/Morpheus/matrix" - "github.com/golang-commonmark/markdown" "github.com/matrix-org/gomatrix" + "github.com/rhinoman/go-commonmark" "github.com/therecipe/qt/core" "github.com/therecipe/qt/gui" "github.com/therecipe/qt/uitools" @@ -261,8 +261,7 @@ func NewMainUI(windowWidth, windowHeight int, cli *gomatrix.Client) *widgets.QWi var message string window.ConnectKeyPressEvent(func(ev *gui.QKeyEvent) { if int(ev.Key()) == int(core.Qt__Key_Enter) || int(ev.Key()) == int(core.Qt__Key_Return) { - md := markdown.New(markdown.XHTMLOutput(true), markdown.Nofollow(true)) - mardownMessage := md.RenderToString([]byte(message)) + mardownMessage := commonmark.Md2Html(message, 0) if mardownMessage == message { cli.SendText("!zTIXGmDjyRcAqbrWab:matrix.ffslfl.net", message) } else { @@ -277,7 +276,5 @@ func NewMainUI(windowWidth, windowHeight int, cli *gomatrix.Client) *widgets.QWi message = value }) - localLog.Println("Started Syncing") - return widget }