-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
148 lines (114 loc) · 4.12 KB
/
ui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"strconv"
"time"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/uitools"
"github.com/therecipe/qt/widgets"
)
var (
appGeoSettings AppGeoSettings
)
var (
ui_tools_list *widgets.QListWidget
ui_image_preview *widgets.QLabel
ui_session_history_list *widgets.QTableWidget
pix *gui.QPixmap
)
func NewImageShareForm() *widgets.QWidget {
widget := widgets.NewQWidget(nil, 0)
loader := uitools.NewQUiLoader(nil)
file := core.NewQFile2(root + "ImageShareUi2.ui")
file.Open(core.QIODevice__ReadOnly)
formWidget := loader.Load(file, widget)
file.Close()
loadJSON(root+"appGeo.json", &appGeoSettings)
widget.SetGeometry2(
appGeoSettings.MainWindowGeo.Pos[0],
appGeoSettings.MainWindowGeo.Pos[1],
appGeoSettings.MainWindowGeo.Size[0],
appGeoSettings.MainWindowGeo.Size[1],
)
ui_tools_list = widgets.NewQListWidgetFromPointer(
widget.FindChild(
"ToolsListView", core.Qt__FindChildrenRecursively).Pointer())
ui_image_preview = widgets.NewQLabelFromPointer(
widget.FindChild(
"ImagePreview", core.Qt__FindChildrenRecursively).Pointer())
ui_session_history_list = widgets.NewQTableWidgetFromPointer(
widget.FindChild(
"SessionHistoryList", core.Qt__FindChildrenRecursively).Pointer())
ui_splitter := widgets.NewQSplitterFromPointer(
widget.FindChild(
"splitter", core.Qt__FindChildrenRecursively).Pointer())
ui_frame := widgets.NewQFrameFromPointer(
widget.FindChild(
"ImagePreviewFrame", core.Qt__FindChildrenRecursively).Pointer())
ui_tools_list.Resize2(
appGeoSettings.ToolsListView.Width,
appGeoSettings.ToolsListView.Height)
ui_frame.Resize2(
appGeoSettings.ImagePreviewFrame.Width,
appGeoSettings.ImagePreviewFrame.Height)
ui_session_history_list.Resize2(
appGeoSettings.SessionHistoryList.Width,
appGeoSettings.SessionHistoryList.Height)
pix = gui.NewQPixmap5(root+"ss.png", "", 0)
ui_image_preview.SetScaledContents(false)
ui_image_preview.SetPixmap(
pix.Scaled(
ui_frame.Size(),
core.Qt__KeepAspectRatio,
core.Qt__SmoothTransformation))
ui_session_history_list.ResizeColumnsToContents()
ui_session_history_list.SetSelectionBehavior(widgets.QAbstractItemView__SelectRows)
layout := widgets.NewQVBoxLayout()
layout.AddWidget(formWidget, 0, 0)
widget.SetLayout(layout)
widget.SetWindowTitle("ImageShare")
widget.ConnectResizeEvent(func(event *gui.QResizeEvent) {
newFrameSize := ui_frame.Size()
ui_image_preview.SetPixmap(
pix.Scaled(
newFrameSize,
core.Qt__KeepAspectRatio,
core.Qt__SmoothTransformation))
})
ui_splitter.ConnectSplitterMoved(func(pos int, index int) {
updateScaling(ui_frame.Size())
})
ui_session_history_list.ConnectCellClicked(func(row int, column int) {
item := ui_session_history_list.Item(row, 0)
pix.Load(path+item.Text(), "", 0)
ui_image_preview.SetPixmap(pix.FromImage(pix.ToImage(), 0))
updateScaling(ui_frame.Size())
})
widget.ConnectCloseEvent(func(event *gui.QCloseEvent) {
geo := widget.Geometry()
appGeoSettings.MainWindowGeo.Pos = []int{geo.X(), geo.Y()}
appGeoSettings.MainWindowGeo.Size = []int{geo.Width(), geo.Height()}
appGeoSettings.ToolsListView.Height = ui_tools_list.Height()
appGeoSettings.ToolsListView.Width = ui_tools_list.Width()
appGeoSettings.SessionHistoryList.Height = ui_session_history_list.Height()
appGeoSettings.SessionHistoryList.Width = ui_session_history_list.Width()
appGeoSettings.ImagePreviewFrame.Height = ui_frame.Height()
appGeoSettings.ImagePreviewFrame.Width = ui_frame.Width()
saveJSON(appGeoSettings, root+"appGeo.json")
})
return widget
}
func updateHistoryList(link, fname string, size int) {
params := []string{fname, strconv.Itoa(size), link}
ui_session_history_list.SetRowCount(ui_session_history_list.RowCount() + 1)
for i := 0; i < 3; i++ {
ui_session_history_list.SetItem(
ui_session_history_list.RowCount()-1, i, widgets.NewQTableWidgetItem2(params[i], 0))
}
}
func updateScaling(newFrameSize *core.QSize) {
time.Sleep(time.Millisecond * 20)
ui_image_preview.SetPixmap(pix.Scaled(
newFrameSize,
core.Qt__KeepAspectRatio, core.Qt__SmoothTransformation))
}