Commit c4d3b49c authored by Loïck Bonniot's avatar Loïck Bonniot

[d] Update quantum and speed feature

parent 11dcecc3
Pipeline #562 passed with stage
...@@ -11,10 +11,6 @@ import ( ...@@ -11,10 +11,6 @@ import (
"github.com/visualfc/goqt/ui" "github.com/visualfc/goqt/ui"
) )
// TEMPORARY
const quantum = 100 // discretization argument for events (ns)
const speed = 1000 // duration of a quantum (ms)
// AddEvent interprets an incoming event into a graphic one. // AddEvent interprets an incoming event into a graphic one.
// Expected format: // Expected format:
// //
...@@ -72,9 +68,11 @@ func (w *Window) PrintQuantumInformation() { ...@@ -72,9 +68,11 @@ func (w *Window) PrintQuantumInformation() {
return return
} }
quantum := float64(w.quantumField.Value())
beginning := w.scene.Events[0].Date.UnixNano() beginning := w.scene.Events[0].Date.UnixNano()
totalDuration := w.scene.Events[len(w.scene.Events)-1].Date.UnixNano() - beginning totalDuration := w.scene.Events[len(w.scene.Events)-1].Date.UnixNano() - beginning
nbQuantum := math.Max(1, math.Ceil(float64(totalDuration)/quantum)) nbQuantum := math.Floor(float64(totalDuration)/quantum) + 1
durationFromBeginning := w.scene.currentTime.UnixNano() - beginning durationFromBeginning := w.scene.currentTime.UnixNano() - beginning
currentQuantum := math.Ceil(float64(durationFromBeginning)/quantum) + 1 currentQuantum := math.Ceil(float64(durationFromBeginning)/quantum) + 1
...@@ -115,6 +113,7 @@ func (w *Window) initTimer() { ...@@ -115,6 +113,7 @@ func (w *Window) initTimer() {
w.scene.currentTime = w.scene.Events[0].Date w.scene.currentTime = w.scene.Events[0].Date
} }
quantum := time.Duration(w.quantumField.Value())
endOfQuantum := w.scene.currentTime.Add(quantum * time.Nanosecond) endOfQuantum := w.scene.currentTime.Add(quantum * time.Nanosecond)
for i := w.scene.currentEvent; i < nbEvents; i++ { for i := w.scene.currentEvent; i < nbEvents; i++ {
......
...@@ -20,6 +20,8 @@ type Window struct { ...@@ -20,6 +20,8 @@ type Window struct {
playButton *ui.QPushButton playButton *ui.QPushButton
stopButton *ui.QPushButton stopButton *ui.QPushButton
replayButton *ui.QPushButton replayButton *ui.QPushButton
quantumField *ui.QSpinBox
speedSlider *ui.QSlider
scene *Scene scene *Scene
circleSize float64 circleSize float64
pixmaps map[string]*ui.QPixmap pixmaps map[string]*ui.QPixmap
......
...@@ -140,10 +140,13 @@ ...@@ -140,10 +140,13 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::TabFocus</enum> <enum>Qt::ClickFocus</enum>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property> </property>
<property name="suffix"> <property name="suffix">
<string> us</string> <string> ns</string>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>1</number> <number>1</number>
...@@ -183,6 +186,18 @@ ...@@ -183,6 +186,18 @@
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::TabFocus</enum> <enum>Qt::TabFocus</enum>
</property> </property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>20</number>
</property>
<property name="pageStep">
<number>2</number>
</property>
<property name="value">
<number>4</number>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
...@@ -190,7 +205,7 @@ ...@@ -190,7 +205,7 @@
<enum>QSlider::TicksBothSides</enum> <enum>QSlider::TicksBothSides</enum>
</property> </property>
<property name="tickInterval"> <property name="tickInterval">
<number>5</number> <number>1</number>
</property> </property>
</widget> </widget>
</item> </item>
......
...@@ -38,6 +38,9 @@ func NewWindow() *Window { ...@@ -38,6 +38,9 @@ func NewWindow() *Window {
w.stopButton = ui.NewPushButtonFromDriver(widget.FindChild("stopButton")) w.stopButton = ui.NewPushButtonFromDriver(widget.FindChild("stopButton"))
w.replayButton = ui.NewPushButtonFromDriver(widget.FindChild("replayButton")) w.replayButton = ui.NewPushButtonFromDriver(widget.FindChild("replayButton"))
w.quantumField = ui.NewSpinBoxFromDriver(widget.FindChild("quantumField"))
w.speedSlider = ui.NewSliderFromDriver(widget.FindChild("speedSlider"))
// Load pixmaps // Load pixmaps
w.pixmaps = map[string]*ui.QPixmap{ w.pixmaps = map[string]*ui.QPixmap{
"ttp": ui.NewPixmapWithFilenameFormatFlags(":/images/server_key.png", "", ui.Qt_AutoColor), "ttp": ui.NewPixmapWithFilenameFormatFlags(":/images/server_key.png", "", ui.Qt_AutoColor),
...@@ -119,6 +122,7 @@ func (w *Window) addActions() { ...@@ -119,6 +122,7 @@ func (w *Window) addActions() {
w.playButton.OnClicked(func() { w.playButton.OnClicked(func() {
w.playButton.SetDisabled(true) w.playButton.SetDisabled(true)
w.stopButton.SetDisabled(false) w.stopButton.SetDisabled(false)
speed := 2000 / w.speedSlider.Value()
w.timer.StartWithMsec(speed) w.timer.StartWithMsec(speed)
}) })
...@@ -134,6 +138,17 @@ func (w *Window) addActions() { ...@@ -134,6 +138,17 @@ func (w *Window) addActions() {
w.scene.currentEvent = 0 w.scene.currentEvent = 0
w.PrintQuantumInformation() w.PrintQuantumInformation()
}) })
w.quantumField.OnValueChanged(func(_ string) {
w.replayButton.Click()
})
w.speedSlider.OnValueChanged(func(_ int32) {
if !w.playButton.IsEnabled() { // playing right now
w.stopButton.Click()
w.playButton.Click()
}
})
} }
// initScene creates the Qt graphic scene associated to our custom scene. // initScene creates the Qt graphic scene associated to our custom scene.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment