Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

Commit

Permalink
Add thumbnail display
Browse files Browse the repository at this point in the history
  • Loading branch information
NGnius committed Aug 5, 2019
1 parent 783e63b commit 39140f7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
46 changes: 32 additions & 14 deletions display.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

"github.com/therecipe/qt/widgets"
"github.com/therecipe/qt/gui"
)

const (
Expand Down Expand Up @@ -48,10 +49,9 @@ type Display struct {
nameField *widgets.QLineEdit
creatorLabel *widgets.QLabel
creatorField *widgets.QLineEdit
/* TODO: implement thumbnail button + functionality
imageLabel *widgets.QPixmap
imageButton *widgets.QPushButton
*/
// TODO: implement thumbnail button + functionality
thumbnailImage *gui.QIcon
thumbnailButton *widgets.QPushButton
idLabel *widgets.QLabel
descriptionLabel *widgets.QLabel
descriptionField *widgets.QPlainTextEdit
Expand All @@ -78,33 +78,38 @@ func (d *Display) Run() {
// create a window
// with a minimum size of 250*200
d.window = widgets.NewQMainWindow(nil, 0)
d.window.SetMinimumSize2(250, 200)
//d.window.SetMinimumSize2(250, 200)
d.window.SetWindowTitle("rxsm")

d.switchModeButton = widgets.NewQPushButton2("toggle mode", nil)
d.switchModeButton = widgets.NewQPushButton2("Toggle Mode", nil)
d.switchModeButton.ConnectClicked(d.onModeButtonClicked)
d.currentModeLabel = widgets.NewQLabel2("build", nil, 0)
d.currentModeLabel = widgets.NewQLabel2("Build", nil, 0)

d.saveSelector = widgets.NewQComboBox(nil)
d.saveSelector.AddItems(makeSelectorOptions(*d.activeSaves))
d.saveSelector.ConnectCurrentIndexChanged(d.onSaveSelectedChanged)
d.newSaveButton = widgets.NewQPushButton2("new", nil)
d.newSaveButton = widgets.NewQPushButton2("New", nil)
d.newSaveButton.ConnectClicked(d.onNewSaveButtonClicked)

d.nameField = widgets.NewQLineEdit(nil)
d.creatorLabel = widgets.NewQLabel2("by", nil, 0)
d.creatorField = widgets.NewQLineEdit(nil)
d.thumbnailImage = gui.NewQIcon5("")
d.thumbnailButton = widgets.NewQPushButton2("", d.window)
d.thumbnailButton.SetSizePolicy(widgets.NewQSizePolicy2(4, 1, 0x00000001))
d.thumbnailButton.ConnectClicked(d.onThumbnailButtonClicked)
d.thumbnailButton.SetFlat(true)
d.idLabel = widgets.NewQLabel2("id: ##", nil, 0)
d.descriptionLabel = widgets.NewQLabel2("Description:", nil, 0)
d.descriptionField = widgets.NewQPlainTextEdit(nil)

d.saveButton = widgets.NewQPushButton2("save", nil)
d.saveButton = widgets.NewQPushButton2("Save", nil)
d.saveButton.ConnectClicked(d.onSaveButtonClicked)
d.cancelButton = widgets.NewQPushButton2("cancel", nil)
d.cancelButton = widgets.NewQPushButton2("Cancel", nil)
d.cancelButton.ConnectClicked(d.onCancelButtonClicked)
d.activateButton = widgets.NewQPushButton2("activate", nil)
d.activateButton = widgets.NewQPushButton2("Activate", nil)
d.activateButton.ConnectClicked(d.onActivateButtonClicked)
d.moveButton = widgets.NewQPushButton2("toggle location", nil)
d.moveButton = widgets.NewQPushButton2("Toggle Location", nil)
d.moveButton.ConnectClicked(d.onMoveToButtonClicked)

// toggle mode to populate fields
Expand All @@ -118,9 +123,10 @@ func (d *Display) Run() {
headerLayout.AddWidget3(d.newSaveButton, 1, 5, 1, 1, 0)

infoLayout := widgets.NewQGridLayout2()
infoLayout.AddWidget3(d.nameField, 0, 0, 1, 6, 0)
infoLayout.AddWidget3(d.nameField, 0, 0, 1, 4, 0)
infoLayout.AddWidget3(d.thumbnailButton, 0, 4, 2, 2, 0)
infoLayout.AddWidget2(d.creatorLabel, 1, 0, 0)
infoLayout.AddWidget3(d.creatorField, 1, 1, 1, 5, 0)
infoLayout.AddWidget3(d.creatorField, 1, 1, 1, 3, 0)

descriptionLayout := widgets.NewQGridLayout2()
descriptionLayout.AddWidget3(d.descriptionLabel, 0, 0, 1, 5, 0)
Expand Down Expand Up @@ -169,6 +175,13 @@ func (d *Display) populateFields() {
oldIdText := d.idLabel.Text()
d.idLabel.SetText(oldIdText[:len(oldIdText)-2]+DoubleDigitStr(d.selectedSave.Data.Id))
d.descriptionField.SetPlainText(d.selectedSave.Data.Description)
d.thumbnailImage.Swap(gui.NewQIcon5(d.selectedSave.ThumbnailPath))
d.thumbnailButton.SetIcon(d.thumbnailImage)
tSize := d.thumbnailButton.Size()
tSize.SetHeight((tSize.Height()*4)/3)
tSize.SetWidth((tSize.Width()*4)/3)
d.thumbnailButton.SetIcon(d.thumbnailImage)
d.thumbnailButton.SetIconSize(tSize)
}

func (d *Display) syncBackFields() {
Expand Down Expand Up @@ -224,6 +237,11 @@ func (d *Display) onNewSaveButtonClicked(bool) {
// propagation calls d.onSaveSelectedChanged(len(*d.activeSaves)-1)
}

func (d *Display) onThumbnailButtonClicked(bool) {
// TODO: implement thumbnail picker dialogue
log.Println("Thumbnail button clicked (unimplemented)")
}

func (d *Display) onSaveButtonClicked(bool) {
d.syncBackFields()
saveErr := d.selectedSave.Data.Save()
Expand Down
6 changes: 3 additions & 3 deletions saver.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ type Save struct {
Data *GameData
dataPath string
savePath string
thumbnailPath string
ThumbnailPath string
folder string
}

func NewSave(folder string) (Save, error) {
newSave := Save {
dataPath: filepath.Join(folder, GameDataFile),
savePath: filepath.Join(folder, GameSaveFile),
thumbnailPath: filepath.Join(folder, ThumbnailFile),
ThumbnailPath: filepath.Join(folder, ThumbnailFile),
folder: folder}
newGD, gdErr := NewGameData(newSave.dataPath)
newSave.Data = newGD
Expand Down Expand Up @@ -164,7 +164,7 @@ func (s *Save) Move(to string) (error) {
s.dataPath = filepath.Join(to, GameDataFile)
s.Data.path = s.dataPath
s.savePath = filepath.Join(to, GameSaveFile)
s.thumbnailPath = filepath.Join(to, ThumbnailFile)
s.ThumbnailPath = filepath.Join(to, ThumbnailFile)
return nil
}

Expand Down

0 comments on commit 39140f7

Please sign in to comment.