File: playbackcontrols.cpp

package info (click to toggle)
olive-editor 20200620-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,228 kB
  • sloc: cpp: 51,932; sh: 56; makefile: 7; xml: 7
file content (226 lines) | stat: -rw-r--r-- 7,300 bytes parent folder | download
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/***

  Olive - Non-Linear Video Editor
  Copyright (C) 2019 Olive Team

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

***/

#include "playbackcontrols.h"

#include <QDebug>
#include <QEvent>
#include <QHBoxLayout>

#include "core.h"
#include "config/config.h"
#include "ui/icons/icons.h"

OLIVE_NAMESPACE_ENTER

PlaybackControls::PlaybackControls(QWidget *parent) :
  QWidget(parent),
  time_base_(0)
{
  // Create lower controls
  QHBoxLayout* lower_control_layout = new QHBoxLayout(this);
  lower_control_layout->setSpacing(0);
  lower_control_layout->setMargin(0);

  QSizePolicy lower_container_size_policy(QSizePolicy::Minimum, QSizePolicy::Expanding);
  lower_container_size_policy.setHorizontalStretch(1);

  // In the lower-left, we create a current timecode label wrapped in a QWidget for fixed sizing
  lower_left_container_ = new QWidget();
  lower_left_container_->setVisible(false);
  lower_left_container_->setSizePolicy(lower_container_size_policy);

  lower_control_layout->addWidget(lower_left_container_);

  QHBoxLayout* lower_left_layout = new QHBoxLayout(lower_left_container_);
  lower_left_layout->setSpacing(0);
  lower_left_layout->setMargin(0);

  cur_tc_lbl_ = new TimeSlider();
  connect(cur_tc_lbl_, &TimeSlider::ValueChanged, this, &PlaybackControls::TimeChanged);
  lower_left_layout->addWidget(cur_tc_lbl_);
  lower_left_layout->addStretch();

  // This is only here
  QWidget* blank_widget = new QWidget();
  //new QHBoxLayout(blank_widget);
  blank_widget->setSizePolicy(lower_container_size_policy);
  lower_control_layout->addWidget(blank_widget);

  // In the lower-middle, we create playback control buttons
  QWidget* lower_middle_container = new QWidget();
  lower_middle_container->setSizePolicy(lower_container_size_policy);
  lower_control_layout->addWidget(lower_middle_container);

  QHBoxLayout* lower_middle_layout = new QHBoxLayout(lower_middle_container);
  lower_middle_layout->setSpacing(0);
  lower_middle_layout->setMargin(0);

  // Go To Start Button
  go_to_start_btn_ = new QPushButton();
  lower_middle_layout->addWidget(go_to_start_btn_);
  connect(go_to_start_btn_, &QPushButton::clicked, this, &PlaybackControls::BeginClicked);

  // Prev Frame Button
  prev_frame_btn_ = new QPushButton();
  lower_middle_layout->addWidget(prev_frame_btn_);
  connect(prev_frame_btn_, &QPushButton::clicked, this, &PlaybackControls::PrevFrameClicked);

  // Play/Pause Button
  playpause_stack_ = new QStackedWidget();
  lower_middle_layout->addWidget(playpause_stack_);

  play_btn_ = new QPushButton();
  playpause_stack_->addWidget(play_btn_);
  connect(play_btn_, &QPushButton::clicked, this, &PlaybackControls::PlayClicked);

  pause_btn_ = new QPushButton();
  playpause_stack_->addWidget(pause_btn_);
  connect(pause_btn_, &QPushButton::clicked, this, &PlaybackControls::PauseClicked);

  // Default to showing play button
  playpause_stack_->setCurrentWidget(play_btn_);
  playpause_stack_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);

  // Next Frame Button
  next_frame_btn_ = new QPushButton();
  lower_middle_layout->addWidget(next_frame_btn_);
  connect(next_frame_btn_, &QPushButton::clicked, this, &PlaybackControls::NextFrameClicked);

  // Go To End Button
  go_to_end_btn_ = new QPushButton();
  lower_middle_layout->addWidget(go_to_end_btn_);
  connect(go_to_end_btn_, &QPushButton::clicked, this, &PlaybackControls::EndClicked);

  QWidget* av_btn_widget = new QWidget();
  av_btn_widget->setSizePolicy(lower_container_size_policy);
  QHBoxLayout* av_btn_layout = new QHBoxLayout(av_btn_widget);
  av_btn_layout->setSpacing(0);
  av_btn_layout->setMargin(0);
  video_drag_btn_ = new DragButton();
  connect(video_drag_btn_, &QPushButton::clicked, this, &PlaybackControls::VideoClicked);
  connect(video_drag_btn_, &DragButton::MousePressed, this, &PlaybackControls::VideoPressed);
  av_btn_layout->addWidget(video_drag_btn_);
  audio_drag_btn_ = new DragButton();
  connect(audio_drag_btn_, &QPushButton::clicked, this, &PlaybackControls::AudioClicked);
  connect(audio_drag_btn_, &DragButton::MousePressed, this, &PlaybackControls::AudioPressed);
  av_btn_layout->addWidget(audio_drag_btn_);
  lower_control_layout->addWidget(av_btn_widget);

  // The lower-right, we create another timecode label, this time to show the end timecode
  lower_right_container_ = new QWidget();
  lower_right_container_->setVisible(false);
  lower_right_container_->setSizePolicy(lower_container_size_policy);
  lower_control_layout->addWidget(lower_right_container_);

  QHBoxLayout* lower_right_layout = new QHBoxLayout(lower_right_container_);
  lower_right_layout->setSpacing(0);
  lower_right_layout->setMargin(0);

  lower_right_layout->addStretch();
  end_tc_lbl_ = new QLabel();
  lower_right_layout->addWidget(end_tc_lbl_);

  UpdateIcons();

  SetTimebase(0);

  SetAudioVideoDragButtonsVisible(false);

  connect(Core::instance(), &Core::TimecodeDisplayChanged, this, &PlaybackControls::TimecodeChanged);
}

void PlaybackControls::SetTimecodeEnabled(bool enabled)
{
  lower_left_container_->setVisible(enabled);
  lower_right_container_->setVisible(enabled);
}

void PlaybackControls::SetTimebase(const rational &r)
{
  time_base_ = r;
  cur_tc_lbl_->SetTimebase(r);

  cur_tc_lbl_->setEnabled(!r.isNull());
}

void PlaybackControls::SetAudioVideoDragButtonsVisible(bool e)
{
  video_drag_btn_->setVisible(e);
  audio_drag_btn_->setVisible(e);
}

void PlaybackControls::SetTime(const int64_t &r)
{
  cur_tc_lbl_->SetValue(r);
}

void PlaybackControls::SetEndTime(const int64_t &r)
{
  if (time_base_.isNull()) {
    return;
  }

  end_time_ = r;

  end_tc_lbl_->setText(Timecode::timestamp_to_timecode(end_time_,
                                                       time_base_,
                                                       Core::instance()->GetTimecodeDisplay()));
}

void PlaybackControls::ShowPauseButton()
{
  // Play was clicked, toggle to pause
  playpause_stack_->setCurrentWidget(pause_btn_);
}

void PlaybackControls::ShowPlayButton()
{
  playpause_stack_->setCurrentWidget(play_btn_);
}

void PlaybackControls::changeEvent(QEvent *e)
{
  QWidget::changeEvent(e);

  if (e->type() == QEvent::StyleChange) {
    UpdateIcons();
  }
}

void PlaybackControls::UpdateIcons()
{
  go_to_start_btn_->setIcon(icon::GoToStart);
  prev_frame_btn_->setIcon(icon::PrevFrame);
  play_btn_->setIcon(icon::Play);
  pause_btn_->setIcon(icon::Pause);
  next_frame_btn_->setIcon(icon::NextFrame);
  go_to_end_btn_->setIcon(icon::GoToEnd);
  video_drag_btn_->setIcon(icon::Video);
  audio_drag_btn_->setIcon(icon::Audio);
}

void PlaybackControls::TimecodeChanged()
{
  // Update end time
  SetEndTime(end_time_);
}

OLIVE_NAMESPACE_EXIT