basic ui layout

This commit is contained in:
jorenchik
2024-09-06 19:36:13 +03:00
parent 4af914a610
commit 1fdbff42f2
6 changed files with 163 additions and 0 deletions

1
src/mdemory-app-qt/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build/

View File

@@ -0,0 +1,7 @@
module github.com/jorenchik/mdemory/src/mdemory-app-qt
go 1.23.0
require github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d
require github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e // indirect

25
src/mdemory-app-qt/go.sum Normal file
View File

@@ -0,0 +1,25 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e h1:XWcjeEtTFTOVA9Fs1w7n2XBftk5ib4oZrhzWk0B+3eA=
github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d h1:T+d8FnaLSvM/1BdlDXhW4d5dr2F07bAbB+LpgzMxx+o=
github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d/go.mod h1:SUUR2j3aE1z6/g76SdD6NwACEpvCxb3fvG82eKbD6us=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

BIN
src/mdemory-app-qt/main Executable file

Binary file not shown.

130
src/mdemory-app-qt/main.go Normal file
View File

@@ -0,0 +1,130 @@
package main
import (
"fmt"
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"
)
func main() {
// Create a new application
app := widgets.NewQApplication(len(os.Args), os.Args)
// Create a new window
window := widgets.NewQMainWindow(nil, 0)
window.SetWindowTitle("Go Qt Example")
window.SetMinimumSize2(400, 200)
// MainLayout
centralWidget := widgets.NewQWidget(nil, 0)
hLayout := widgets.NewQHBoxLayout()
centralWidget.SetLayout(hLayout)
// Left
leftWidget := widgets.NewQWidget(nil, 0)
leftLayout := widgets.NewQVBoxLayout()
leftWidget.SetLayout(leftLayout)
mdemLabel := widgets.NewQLabel2("Mdems", nil, 0)
deckLabel := widgets.NewQLabel2("Decks", nil, 0)
// LeftContent
leftLayout.AddWidget(mdemLabel, 0, 0)
mdemList := widgets.NewQListView(nil)
var items []string
items = append(items, "countries.mdem")
items = append(items, "capitals.mdem")
model := core.NewQStringListModel2(items, nil)
// Add items to the model
// Set the model to the QListView
mdemList.SetModel(model)
leftLayout.AddWidget(mdemList, 1, 0)
leftLayout.AddWidget(deckLabel, 0, 0)
deckList := widgets.NewQListView(nil)
leftLayout.AddWidget(deckList, 1, 0)
// Right
rightWidget := widgets.NewQWidget(nil, 0)
rightLayout := widgets.NewQVBoxLayout()
rightWidget.SetLayout(rightLayout)
top := widgets.NewQWidget(nil, 0)
hTop := widgets.NewQHBoxLayout()
top.SetLayout(hTop)
deckListLabel := widgets.NewQLabel2("Mdem: file.mdem", nil, 0)
rightLayout.AddWidget(top, 0, 0)
hTop.AddWidget(deckListLabel, 0, 0)
hTop.AddStretch(1)
refresh := widgets.NewQToolButton(nil)
refresh.SetText("Refresh")
hTop.AddWidget(refresh, 0, 0)
shuffle := widgets.NewQToolButton(nil)
shuffle.SetText("Shuffle")
hTop.AddWidget(shuffle, 0, 0)
practice := widgets.NewQToolButton(nil)
practice.SetText("Practice")
hTop.AddWidget(practice, 0, 0)
mdemScroll := widgets.NewQScrollArea(nil)
hMdemScroll := widgets.NewQVBoxLayout()
mdemScroll.SetLayout(hMdemScroll)
{ // createMdem
id := fmt.Sprintf("mdem_%d", 1)
mdem := widgets.NewQWidget(nil, 0)
mdem.SetMinimumHeight(60)
hMdem := widgets.NewQHBoxLayout()
mdem.SetLayout(hMdem)
mdem.SetObjectName(id)
mdem.SetStyleSheet(fmt.Sprintf(`
QWidget#%s {
border: 1px solid gray;
background: white;
}
`, id))
mdemText := widgets.NewQLabel2(
"What is the capital of Latvia?", nil, 0,
)
hMdem.AddWidget(mdemText, 0, 0)
hMdem.AddStretch(1)
hideButton := widgets.NewQToolButton(nil)
hideButton.SetText("Hide")
hMdem.AddWidget(hideButton, 0, 0)
showAnswer := widgets.NewQToolButton(nil)
showAnswer.SetText("Show")
hMdem.AddWidget(showAnswer, 0, 0)
hMdemScroll.AddWidget(mdem, 0, 0)
}
hMdemScroll.AddStretch(1)
rightLayout.AddWidget(mdemScroll, 1, 0)
pagination := widgets.NewQWidget(nil, 0)
hPagination := widgets.NewQHBoxLayout()
pagination.SetLayout(hPagination)
for i := 0; i < 5; i++ {
button := widgets.NewQToolButton(nil)
button.SetText(fmt.Sprintf("%d", i+1))
hPagination.AddWidget(button, 0, 0)
}
hPagination.AddStretch(1)
rightLayout.AddWidget(pagination, 0, 0)
// FillMainLayout
hLayout.AddWidget(leftWidget, 1, 0)
hLayout.AddWidget(rightWidget, 4, 0)
// SetupCentralWidget
window.SetCentralWidget(centralWidget)
window.Show()
app.Exec()
}

BIN
src/mdemory-app-qt/mdemory-app-qt Executable file

Binary file not shown.