• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 18685379784

21 Oct 2025 01:25PM UTC coverage: 72.522% (+0.1%) from 72.391%
18685379784

push

github

paulmthompson
fix failing tests

18 of 40 new or added lines in 1 file covered. (45.0%)

1765 existing lines in 32 files now uncovered.

53998 of 74457 relevant lines covered (72.52%)

46177.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.28
/src/WhiskerToolbox/TimeScrollBar/TimeScrollBar.cpp
1
#include "TimeScrollBar.hpp"
2

3
#include "ui_TimeScrollBar.h"
4

5
#include "DataManager.hpp"
6
#include "TimeFrame/TimeFrame.hpp"
7

8
#include <QFileDialog>
9
#include <QTimer>
10

11
#include <iostream>
12

13
TimeScrollBar::TimeScrollBar(QWidget *parent) :
41✔
14
    QWidget(parent),
15
    ui(new Ui::TimeScrollBar)
41✔
16
{
17
    ui->setupUi(this);
41✔
18

19
    _timer = new QTimer(this);
41✔
20

21
    connect(_timer, &QTimer::timeout, this, &TimeScrollBar::_vidLoop);
41✔
22

23
    connect(ui->horizontalScrollBar, &QScrollBar::valueChanged, this, &TimeScrollBar::Slider_Scroll);
41✔
24
    connect(ui->horizontalScrollBar, &QScrollBar::sliderMoved, this, &TimeScrollBar::Slider_Drag); // For drag events
41✔
25

26
    connect(ui->play_button, &QPushButton::clicked, this, &TimeScrollBar::PlayButton);
41✔
27
    connect(ui->rewind, &QPushButton::clicked, this, &TimeScrollBar::RewindButton);
41✔
28
    connect(ui->fastforward, &QPushButton::clicked, this, &TimeScrollBar::FastForwardButton);
41✔
29

30
    // Set up spin box with keyboard tracking disabled (only update on Enter key or arrow clicks)
31
    ui->frame_spinbox->setKeyboardTracking(false);
41✔
32
    connect(ui->frame_spinbox, QOverload<int>::of(&QSpinBox::valueChanged), this, &TimeScrollBar::FrameSpinBoxChanged);
41✔
33
};
41✔
34

35
TimeScrollBar::~TimeScrollBar() {
81✔
36
    delete ui;
41✔
37
    _timer->stop();
41✔
38
}
81✔
39

40
/*
41
We can click and hold the slider to move to a new position
42
In the case that we are dragging the slider, to make this optimally smooth, we should not add any new decoding frames
43
until we have finished the most recent one.
44
 */
45

46
void TimeScrollBar::Slider_Drag(int newPos)
×
47
{
48
    static_cast<void>(newPos);
49

50
    auto current_frame = ui->horizontalScrollBar->sliderPosition();
×
51
    auto snap_frame = _getSnapFrame(current_frame);
×
52
    ui->horizontalScrollBar->setSliderPosition(snap_frame);
×
53
}
×
54

55

56
void TimeScrollBar::Slider_Scroll(int newPos)
×
57
{
58
    if (_verbose) {
×
59
        std::cout << "The slider position is " << ui->horizontalScrollBar->sliderPosition() << std::endl;
×
60
    }
61

62
    auto frame_id = _data_manager->getTime()->checkFrameInbounds(newPos);
×
63
    ui->horizontalScrollBar->setSliderPosition(newPos);
×
64
    _data_manager->setCurrentTime(frame_id);
×
65
    _updateFrameLabels(frame_id);
×
66

67
    emit timeChanged(frame_id);
×
68
}
×
69

70

71
void TimeScrollBar::_updateFrameLabels(int frame_num) {
×
72

73
    auto video_timeframe = _data_manager->getTime(TimeKey("time"));
×
74
    
75
    auto video_time = video_timeframe->getTimeAtIndex(TimeFrameIndex(frame_num));
×
76

77
    ui->time_label->setText(QString::number(video_time));
×
78

79
    // Update the spin box value without triggering valueChanged signal
80
    ui->frame_spinbox->blockSignals(true);
×
81
    ui->frame_spinbox->setValue(frame_num);
×
82
    ui->frame_spinbox->blockSignals(false);
×
83
}
×
84

85
void TimeScrollBar::updateScrollBarNewMax(int new_max) {
×
86

87
    ui->frame_count_label->setText(QString::number(new_max));
×
88
    ui->horizontalScrollBar->setMaximum(new_max);
×
89
    ui->frame_spinbox->setMaximum(new_max);
×
90

91
}
×
92

93

94
void TimeScrollBar::PlayButton()
×
95
{
96

97
    const int timer_period_ms = 40;
×
98

99
    if (_play_mode) {
×
100

101
        _timer->stop();
×
102
        ui->play_button->setText(QString("Play"));
×
103
        _play_mode = false;
×
104

105
        ui->horizontalScrollBar->blockSignals(true);
×
106
        ui->horizontalScrollBar->setValue(_data_manager->getCurrentTime());
×
107
        ui->horizontalScrollBar->blockSignals(false);
×
108

109
    } else {
110
        ui->play_button->setText(QString("Pause"));
×
111
        _timer->start(timer_period_ms);
×
112
        _play_mode = true;
×
113
    }
114
}
×
115

116
/*
117
Increases the speed of a playing video in increments of the base_fps (default = 25)
118
*/
119
void TimeScrollBar::RewindButton()
×
120
{
121
    const int play_speed_base_fps = 25;
×
122
    if (_play_speed > 1)
×
123
    {
124
        _play_speed--;
×
125
        ui->fps_label->setText(QString::number(play_speed_base_fps * _play_speed));
×
126
    }
127
}
×
128

129
/*
130
Decreases the speed of a playing video in increments of the base_fps (default = 25)
131
*/
132
void TimeScrollBar::FastForwardButton()
×
133
{
134
    const int play_speed_base_fps = 25;
×
135

136
    _play_speed++;
×
137
    ui->fps_label->setText(QString::number(play_speed_base_fps * _play_speed));
×
138
}
×
139

140
void TimeScrollBar::_vidLoop()
×
141
{
142
    auto current_time = _data_manager->getCurrentTime() + _play_speed;
×
143
     ui->horizontalScrollBar->setSliderPosition(current_time);
×
144
}
×
145

146
void TimeScrollBar::changeScrollBarValue(int new_value, bool relative)
×
147
{
148
    auto min_value = ui->horizontalScrollBar->minimum();
×
149
    auto max_value = ui->horizontalScrollBar->maximum();
×
150

151
    if (relative)
×
152
    {
153
        new_value = _data_manager->getCurrentTime() + new_value;
×
154
    }
155

156
    if (new_value < min_value) {
×
157
        std::cout << "Cannot set value below minimum" << std::endl;
×
158
        return;
×
159
    }
160

161
    if (new_value > max_value) {
×
162
        std::cout << "Cannot set value above maximum" << std::endl;
×
163
        return;
×
164
    }
165

166
    Slider_Scroll(new_value);
×
167

168
}
169

170
void TimeScrollBar::FrameSpinBoxChanged(int new_frame)
×
171
{
172
    auto frame_id = _data_manager->getTime()->checkFrameInbounds(new_frame);
×
173
    _data_manager->setCurrentTime(frame_id);
×
174
    ui->horizontalScrollBar->setSliderPosition(frame_id);
×
175
    _updateFrameLabels(frame_id);
×
176

177
    emit timeChanged(frame_id);
×
178
}
×
179

UNCOV
180
int TimeScrollBar::getFrameJumpValue() const
×
181
{
UNCOV
182
    return ui->frame_jump_spinbox->value();
×
183
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc