mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
treeview file explorer & other improvements
This commit is contained in:
1
src/mdemory-app-qt/.gitignore
vendored
1
src/mdemory-app-qt/.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
build/
|
build/
|
||||||
|
qtbox
|
||||||
|
|||||||
@@ -8,79 +8,86 @@ import (
|
|||||||
"github.com/therecipe/qt/widgets"
|
"github.com/therecipe/qt/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var workingPath string = "/home/jorenchik/Code/mdemory/memorybase"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Create a new application
|
// InitApp
|
||||||
app := widgets.NewQApplication(len(os.Args), os.Args)
|
app := widgets.NewQApplication(len(os.Args), os.Args)
|
||||||
|
window := widgets.NewQMainWindow(nil, 0)
|
||||||
|
hSplitter := widgets.NewQSplitter(nil)
|
||||||
|
window.SetWindowTitle("MDemory")
|
||||||
|
window.SetMinimumSize2(400, 300)
|
||||||
|
|
||||||
// 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)
|
leftWidget := widgets.NewQWidget(nil, 0)
|
||||||
leftLayout := widgets.NewQVBoxLayout()
|
leftLayout := widgets.NewQVBoxLayout()
|
||||||
|
mdemLabel := widgets.NewQLabel2("Mdems", nil, 0)
|
||||||
|
model := widgets.NewQFileSystemModel(nil)
|
||||||
|
mdemList := widgets.NewQTreeView(nil)
|
||||||
leftWidget.SetLayout(leftLayout)
|
leftWidget.SetLayout(leftLayout)
|
||||||
mdemLabel := widgets.NewQLabel2("Mdems", nil, 0)
|
|
||||||
deckLabel := widgets.NewQLabel2("Decks", nil, 0)
|
|
||||||
// LeftContent
|
|
||||||
leftLayout.AddWidget(mdemLabel, 0, 0)
|
leftLayout.AddWidget(mdemLabel, 0, 0)
|
||||||
mdemList := widgets.NewQListView(nil)
|
model.SetRootPath(workingPath)
|
||||||
|
|
||||||
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)
|
mdemList.SetModel(model)
|
||||||
|
|
||||||
|
rootIndex := model.Index2("/home/jorenchik/Code/mdemory/memorybase", 0)
|
||||||
|
fmt.Printf("Root index: %s\n", model.FileName(rootIndex))
|
||||||
|
mdemList.SetRootIndex(rootIndex)
|
||||||
|
|
||||||
|
mdemList.HideColumn(1)
|
||||||
|
mdemList.HideColumn(2)
|
||||||
|
mdemList.HideColumn(3)
|
||||||
|
mdemList.ConnectDoubleClicked(func(index *core.QModelIndex) {
|
||||||
|
item := model.FilePath(index)
|
||||||
|
widgets.QMessageBox_Information(
|
||||||
|
nil,
|
||||||
|
"Item Clicked",
|
||||||
|
"You clicked: " + item,
|
||||||
|
widgets.QMessageBox__Ok, widgets.QMessageBox__Ok,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
deckLabel := widgets.NewQLabel2("Decks", nil, 0)
|
||||||
|
deckList := widgets.NewQListView(nil)
|
||||||
leftLayout.AddWidget(mdemList, 1, 0)
|
leftLayout.AddWidget(mdemList, 1, 0)
|
||||||
leftLayout.AddWidget(deckLabel, 0, 0)
|
leftLayout.AddWidget(deckLabel, 0, 0)
|
||||||
deckList := widgets.NewQListView(nil)
|
|
||||||
leftLayout.AddWidget(deckList, 1, 0)
|
leftLayout.AddWidget(deckList, 1, 0)
|
||||||
|
|
||||||
// Right
|
|
||||||
rightWidget := widgets.NewQWidget(nil, 0)
|
rightWidget := widgets.NewQWidget(nil, 0)
|
||||||
rightLayout := widgets.NewQVBoxLayout()
|
rightLayout := widgets.NewQVBoxLayout()
|
||||||
rightWidget.SetLayout(rightLayout)
|
rightWidget.SetLayout(rightLayout)
|
||||||
|
|
||||||
top := widgets.NewQWidget(nil, 0)
|
top := widgets.NewQWidget(nil, 0)
|
||||||
hTop := widgets.NewQHBoxLayout()
|
hTop := widgets.NewQHBoxLayout()
|
||||||
top.SetLayout(hTop)
|
|
||||||
deckListLabel := widgets.NewQLabel2("Mdem: file.mdem", nil, 0)
|
deckListLabel := widgets.NewQLabel2("Mdem: file.mdem", nil, 0)
|
||||||
|
top.SetLayout(hTop)
|
||||||
rightLayout.AddWidget(top, 0, 0)
|
rightLayout.AddWidget(top, 0, 0)
|
||||||
|
|
||||||
hTop.AddWidget(deckListLabel, 0, 0)
|
hTop.AddWidget(deckListLabel, 0, 0)
|
||||||
hTop.AddStretch(1)
|
hTop.AddStretch(1)
|
||||||
refresh := widgets.NewQToolButton(nil)
|
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 := widgets.NewQToolButton(nil)
|
||||||
practice.SetText("Practice")
|
shuffle := widgets.NewQToolButton(nil)
|
||||||
|
hTop.AddWidget(refresh, 0, 0)
|
||||||
|
hTop.AddWidget(shuffle, 0, 0)
|
||||||
hTop.AddWidget(practice, 0, 0)
|
hTop.AddWidget(practice, 0, 0)
|
||||||
|
refresh.SetText("Refresh")
|
||||||
|
shuffle.SetText("Shuffle")
|
||||||
|
practice.SetText("Practice")
|
||||||
|
|
||||||
mdemScroll := widgets.NewQScrollArea(nil)
|
mdemScroll := widgets.NewQScrollArea(nil)
|
||||||
hMdemScroll := widgets.NewQVBoxLayout()
|
hMdemScroll := widgets.NewQVBoxLayout()
|
||||||
mdemScroll.SetLayout(hMdemScroll)
|
mdemScroll.SetLayout(hMdemScroll)
|
||||||
|
var mdem widgets.QWidget_ITF
|
||||||
|
{ // CreateMdem
|
||||||
|
|
||||||
{ // createMdem
|
// DefineMdem
|
||||||
id := fmt.Sprintf("mdem_%d", 1)
|
mdem := widgets.NewQWidget(nil, 0)
|
||||||
mdem := widgets.NewQWidget(nil, 0)
|
|
||||||
mdem.SetMinimumHeight(60)
|
mdem.SetMinimumHeight(60)
|
||||||
|
|
||||||
hMdem := widgets.NewQHBoxLayout()
|
hMdem := widgets.NewQHBoxLayout()
|
||||||
|
hMdem.AddStretch(1)
|
||||||
mdem.SetLayout(hMdem)
|
mdem.SetLayout(hMdem)
|
||||||
|
|
||||||
|
// DefineId
|
||||||
|
id := fmt.Sprintf("mdem_%d", 1)
|
||||||
mdem.SetObjectName(id)
|
mdem.SetObjectName(id)
|
||||||
mdem.SetStyleSheet(fmt.Sprintf(`
|
mdem.SetStyleSheet(fmt.Sprintf(`
|
||||||
QWidget#%s {
|
QWidget#%s {
|
||||||
@@ -89,41 +96,48 @@ func main() {
|
|||||||
}
|
}
|
||||||
`, id))
|
`, id))
|
||||||
|
|
||||||
|
// AddContent
|
||||||
mdemText := widgets.NewQLabel2(
|
mdemText := widgets.NewQLabel2(
|
||||||
"What is the capital of Latvia?", nil, 0,
|
"What is the capital of Latvia?", nil, 0,
|
||||||
)
|
)
|
||||||
hMdem.AddWidget(mdemText, 0, 0)
|
hMdem.AddWidget(mdemText, 0, 0)
|
||||||
hMdem.AddStretch(1)
|
|
||||||
hideButton := widgets.NewQToolButton(nil)
|
hideButton := widgets.NewQToolButton(nil)
|
||||||
hideButton.SetText("Hide")
|
|
||||||
hMdem.AddWidget(hideButton, 0, 0)
|
|
||||||
showAnswer := widgets.NewQToolButton(nil)
|
showAnswer := widgets.NewQToolButton(nil)
|
||||||
|
hideButton.SetText("Hide")
|
||||||
showAnswer.SetText("Show")
|
showAnswer.SetText("Show")
|
||||||
|
hMdem.AddWidget(hideButton, 0, 0)
|
||||||
hMdem.AddWidget(showAnswer, 0, 0)
|
hMdem.AddWidget(showAnswer, 0, 0)
|
||||||
|
|
||||||
hMdemScroll.AddWidget(mdem, 0, 0)
|
|
||||||
}
|
}
|
||||||
|
hMdemScroll.AddWidget(mdem, 0, 0)
|
||||||
hMdemScroll.AddStretch(1)
|
hMdemScroll.AddStretch(1)
|
||||||
|
|
||||||
rightLayout.AddWidget(mdemScroll, 1, 0)
|
rightLayout.AddWidget(mdemScroll, 1, 0)
|
||||||
|
|
||||||
pagination := widgets.NewQWidget(nil, 0)
|
// Pagination
|
||||||
|
pagination := widgets.NewQWidget(nil, 0)
|
||||||
hPagination := widgets.NewQHBoxLayout()
|
hPagination := widgets.NewQHBoxLayout()
|
||||||
pagination.SetLayout(hPagination)
|
pagination.SetLayout(hPagination)
|
||||||
|
|
||||||
|
// TEMP: mock pagination
|
||||||
|
prevButton := widgets.NewQToolButton(nil)
|
||||||
|
prevButton.SetText("<")
|
||||||
|
hPagination.AddWidget(prevButton, 0, 0)
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
button := widgets.NewQToolButton(nil)
|
button := widgets.NewQToolButton(nil)
|
||||||
button.SetText(fmt.Sprintf("%d", i+1))
|
button.SetText(fmt.Sprintf("%d", i+1))
|
||||||
hPagination.AddWidget(button, 0, 0)
|
hPagination.AddWidget(button, 0, 0)
|
||||||
}
|
}
|
||||||
|
nextButton := widgets.NewQToolButton(nil)
|
||||||
|
nextButton.SetText(">")
|
||||||
|
hPagination.AddWidget(nextButton, 0, 0)
|
||||||
|
|
||||||
hPagination.AddStretch(1)
|
hPagination.AddStretch(1)
|
||||||
rightLayout.AddWidget(pagination, 0, 0)
|
rightLayout.AddWidget(pagination, 0, 0)
|
||||||
|
|
||||||
// FillMainLayout
|
hSplitter.AddWidget(leftWidget)
|
||||||
hLayout.AddWidget(leftWidget, 1, 0)
|
hSplitter.AddWidget(rightWidget)
|
||||||
hLayout.AddWidget(rightWidget, 4, 0)
|
hSplitter.SetStretchFactor(0, 1)
|
||||||
// SetupCentralWidget
|
hSplitter.SetStretchFactor(1, 3)
|
||||||
window.SetCentralWidget(centralWidget)
|
window.SetCentralWidget(hSplitter)
|
||||||
|
|
||||||
window.Show()
|
window.Show()
|
||||||
app.Exec()
|
app.Exec()
|
||||||
|
|||||||
Reference in New Issue
Block a user