playback_dock.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * playback_dock.cpp - playback controls dock
  3. * Copyright (C) 2017 caryoscelus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "playback_dock.h"
  19. #include "ui_playback_dock.h"
  20. namespace studio {
  21. PlaybackDock::PlaybackDock(std::shared_ptr<core::Context> context_, QWidget* parent) :
  22. QDockWidget(parent),
  23. ContextListener(context_),
  24. ui(std::make_unique<Ui::PlaybackDock>()),
  25. timer(new QTimer(this))
  26. {
  27. ui->setupUi(this);
  28. connect(ui->move_start_button, SIGNAL(clicked()), this, SLOT(move_start()));
  29. connect(ui->move_end_button, SIGNAL(clicked()), this, SLOT(move_end()));
  30. connect(ui->play_button, SIGNAL(toggled(bool)), this, SLOT(toggle_playback(bool)));
  31. connect(ui->timeline_zoom, SIGNAL(valueChanged(int)), ui->timeline, SLOT(set_zoom_level(int)));
  32. // TODO: move actual playing out of dock
  33. connect(timer, SIGNAL(timeout()), this, SLOT(next_frame()));
  34. set_context(get_context());
  35. }
  36. PlaybackDock::~PlaybackDock() {
  37. }
  38. void PlaybackDock::set_context(std::shared_ptr<core::Context> context_) {
  39. ContextListener::set_context(context_);
  40. ui->timeline->set_context(context_);
  41. }
  42. void PlaybackDock::closeEvent(QCloseEvent* event) {
  43. QDockWidget::closeEvent(event);
  44. deleteLater();
  45. }
  46. void PlaybackDock::toggle_playback(bool play) {
  47. if (auto context = get_context()) {
  48. if (play)
  49. timer->start(1000/context->get_fps());
  50. else
  51. timer->stop();
  52. }
  53. }
  54. void PlaybackDock::next_frame() {
  55. if (auto context = get_context()) {
  56. auto time = context->get_time();
  57. context->set_time(time + core::Time(0, context->get_fps(), 1));
  58. }
  59. }
  60. void PlaybackDock::move_start() {
  61. if (auto context = get_context()) {
  62. context->to_start();
  63. }
  64. }
  65. void PlaybackDock::move_end() {
  66. if (auto context = get_context()) {
  67. context->to_end();
  68. }
  69. }
  70. }