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/
|
||||
qtbox
|
||||
|
||||
@@ -8,79 +8,86 @@ import (
|
||||
"github.com/therecipe/qt/widgets"
|
||||
)
|
||||
|
||||
var workingPath string = "/home/jorenchik/Code/mdemory/memorybase"
|
||||
|
||||
func main() {
|
||||
// Create a new application
|
||||
app := widgets.NewQApplication(len(os.Args), os.Args)
|
||||
// InitApp
|
||||
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)
|
||||
leftLayout := widgets.NewQVBoxLayout()
|
||||
mdemLabel := widgets.NewQLabel2("Mdems", nil, 0)
|
||||
model := widgets.NewQFileSystemModel(nil)
|
||||
mdemList := widgets.NewQTreeView(nil)
|
||||
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
|
||||
model.SetRootPath(workingPath)
|
||||
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(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)
|
||||
top := widgets.NewQWidget(nil, 0)
|
||||
hTop := widgets.NewQHBoxLayout()
|
||||
deckListLabel := widgets.NewQLabel2("Mdem: file.mdem", nil, 0)
|
||||
top.SetLayout(hTop)
|
||||
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)
|
||||
refresh := 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)
|
||||
refresh.SetText("Refresh")
|
||||
shuffle.SetText("Shuffle")
|
||||
practice.SetText("Practice")
|
||||
|
||||
mdemScroll := widgets.NewQScrollArea(nil)
|
||||
mdemScroll := widgets.NewQScrollArea(nil)
|
||||
hMdemScroll := widgets.NewQVBoxLayout()
|
||||
mdemScroll.SetLayout(hMdemScroll)
|
||||
var mdem widgets.QWidget_ITF
|
||||
{ // CreateMdem
|
||||
|
||||
{ // createMdem
|
||||
id := fmt.Sprintf("mdem_%d", 1)
|
||||
mdem := widgets.NewQWidget(nil, 0)
|
||||
// DefineMdem
|
||||
mdem := widgets.NewQWidget(nil, 0)
|
||||
mdem.SetMinimumHeight(60)
|
||||
|
||||
hMdem := widgets.NewQHBoxLayout()
|
||||
hMdem.AddStretch(1)
|
||||
mdem.SetLayout(hMdem)
|
||||
|
||||
// DefineId
|
||||
id := fmt.Sprintf("mdem_%d", 1)
|
||||
mdem.SetObjectName(id)
|
||||
mdem.SetStyleSheet(fmt.Sprintf(`
|
||||
QWidget#%s {
|
||||
@@ -89,41 +96,48 @@ func main() {
|
||||
}
|
||||
`, id))
|
||||
|
||||
// AddContent
|
||||
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)
|
||||
hideButton.SetText("Hide")
|
||||
showAnswer.SetText("Show")
|
||||
hMdem.AddWidget(hideButton, 0, 0)
|
||||
hMdem.AddWidget(showAnswer, 0, 0)
|
||||
|
||||
hMdemScroll.AddWidget(mdem, 0, 0)
|
||||
}
|
||||
|
||||
hMdemScroll.AddWidget(mdem, 0, 0)
|
||||
hMdemScroll.AddStretch(1)
|
||||
|
||||
rightLayout.AddWidget(mdemScroll, 1, 0)
|
||||
|
||||
pagination := widgets.NewQWidget(nil, 0)
|
||||
// Pagination
|
||||
pagination := widgets.NewQWidget(nil, 0)
|
||||
hPagination := widgets.NewQHBoxLayout()
|
||||
pagination.SetLayout(hPagination)
|
||||
|
||||
// TEMP: mock pagination
|
||||
prevButton := widgets.NewQToolButton(nil)
|
||||
prevButton.SetText("<")
|
||||
hPagination.AddWidget(prevButton, 0, 0)
|
||||
for i := 0; i < 5; i++ {
|
||||
button := widgets.NewQToolButton(nil)
|
||||
button.SetText(fmt.Sprintf("%d", i+1))
|
||||
hPagination.AddWidget(button, 0, 0)
|
||||
}
|
||||
nextButton := widgets.NewQToolButton(nil)
|
||||
nextButton.SetText(">")
|
||||
hPagination.AddWidget(nextButton, 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)
|
||||
hSplitter.AddWidget(leftWidget)
|
||||
hSplitter.AddWidget(rightWidget)
|
||||
hSplitter.SetStretchFactor(0, 1)
|
||||
hSplitter.SetStretchFactor(1, 3)
|
||||
window.SetCentralWidget(hSplitter)
|
||||
|
||||
window.Show()
|
||||
app.Exec()
|
||||
|
||||
Reference in New Issue
Block a user