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 (
"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.
// Expected format:
//
......@@ -72,9 +68,11 @@ func (w *Window) PrintQuantumInformation() {
return
}
quantum := float64(w.quantumField.Value())
beginning := w.scene.Events[0].Date.UnixNano()
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
currentQuantum := math.Ceil(float64(durationFromBeginning)/quantum) + 1
......@@ -115,6 +113,7 @@ func (w *Window) initTimer() {
w.scene.currentTime = w.scene.Events[0].Date
}
quantum := time.Duration(w.quantumField.Value())
endOfQuantum := w.scene.currentTime.Add(quantum * time.Nanosecond)
for i := w.scene.currentEvent; i < nbEvents; i++ {
......
......@@ -20,6 +20,8 @@ type Window struct {
playButton *ui.QPushButton
stopButton *ui.QPushButton
replayButton *ui.QPushButton
quantumField *ui.QSpinBox
speedSlider *ui.QSlider
scene *Scene
circleSize float64
pixmaps map[string]*ui.QPixmap
......
......@@ -140,10 +140,13 @@
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
<enum>Qt::ClickFocus</enum>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="suffix">
<string> us</string>
<string> ns</string>
</property>
<property name="minimum">
<number>1</number>
......@@ -183,6 +186,18 @@
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</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">
<enum>Qt::Horizontal</enum>
</property>
......@@ -190,7 +205,7 @@
<enum>QSlider::TicksBothSides</enum>
</property>
<property name="tickInterval">
<number>5</number>
<number>1</number>
</property>
</widget>
</item>
......
......@@ -38,6 +38,9 @@ func NewWindow() *Window {
w.stopButton = ui.NewPushButtonFromDriver(widget.FindChild("stopButton"))
w.replayButton = ui.NewPushButtonFromDriver(widget.FindChild("replayButton"))
w.quantumField = ui.NewSpinBoxFromDriver(widget.FindChild("quantumField"))
w.speedSlider = ui.NewSliderFromDriver(widget.FindChild("speedSlider"))
// Load pixmaps
w.pixmaps = map[string]*ui.QPixmap{
"ttp": ui.NewPixmapWithFilenameFormatFlags(":/images/server_key.png", "", ui.Qt_AutoColor),
......@@ -119,6 +122,7 @@ func (w *Window) addActions() {
w.playButton.OnClicked(func() {
w.playButton.SetDisabled(true)
w.stopButton.SetDisabled(false)
speed := 2000 / w.speedSlider.Value()
w.timer.StartWithMsec(speed)
})
......@@ -134,6 +138,17 @@ func (w *Window) addActions() {
w.scene.currentEvent = 0
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.
......
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